Skip to content

Commit

Permalink
Adding more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbor committed Jun 13, 2024
1 parent c96da03 commit 72ddd5e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ use core::ptr;
pub mod ubsan;
#[cfg(feature = "std")]
mod userspace;
mod primitives;

/// This module contains the primitives that need to be implemented to enable the usage of this
/// library in a program environment.
///
/// An implementation for the user space is provided in [`crate::userspace`] and can be enabled
/// with the `std` feature.
pub mod primitives;
mod spinlock;

pub fn test() {
Expand Down
15 changes: 12 additions & 3 deletions src/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
extern "C" {
pub fn zan_write(buffer: *const u8, nbytes: usize);
pub fn zan_abort();
pub fn zan_disable_interrupts();
/// Prints out an error message to a debug output
///
/// # Arguments
/// * `buffer`: pointer to character array containing at least `nbytes`
/// * `nbytes`: number of bytes in the buffer
pub fn zan_write(buffer: *const u8, nbytes: usize);

/// Aborts the program
pub fn zan_abort();

/// Tries to disable interrupts or signals to ensure coherent debug output
pub fn zan_disable_interrupts();
}


Expand Down
2 changes: 1 addition & 1 deletion src/ubsan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::eprintln;


static LOCK: Spinlock = Spinlock::new();
static PROLOGUE_HEADER: &str = "=== UNDEFINED BEHAVIOUR DETECTED ===";
const PROLOGUE_HEADER: &str = "=== UNDEFINED BEHAVIOUR DETECTED ===";
const TYPE_CHECK_KINDS: [&str; 8] = [
"load of",
"store to",
Expand Down
6 changes: 4 additions & 2 deletions src/userspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ use std::io::Write;
use std::process::exit;
use std::slice;

/// Write error message to stderr
#[no_mangle]
pub unsafe extern "C" fn zan_write(buffer: *const u8, nbytes: usize) {
let buf = slice::from_raw_parts(buffer, nbytes);
stderr().write_all(buf).unwrap();
}

/// Abort the program by exiting with error code
#[no_mangle]
pub unsafe extern "C" fn zan_abort() {
exit(1);
}

/// Right now this does nothing, but it would be great to disable UNIX signals for example
#[no_mangle]
// didn't find a sane way to do this without additional crates
pub fn zan_disable_interrupts() {}
pub unsafe fn zan_disable_interrupts() {}

0 comments on commit 72ddd5e

Please sign in to comment.