From e17f4b846f4048dc427d6612d1029f0abe871505 Mon Sep 17 00:00:00 2001 From: bitwave Date: Fri, 24 Sep 2021 20:26:45 +0200 Subject: [PATCH] Added documentation for no_std build and fuzzing (#282) * added unfinished no_std docs * docs: added missing example * Update no_std.md Co-authored-by: Dominik Maier --- docs/src/SUMMARY.md | 3 +- docs/src/advanced_features/no_std/no_std.md | 35 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 docs/src/advanced_features/no_std/no_std.md diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 301179947d..81bf4b3818 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -18,4 +18,5 @@ - [Advanced Features](./advanced_features/advanced_features.md) - - [Concolic Tracing & Hybrid Fuzzing](./advanced_features/concolic/concolic.md) \ No newline at end of file + - [Concolic Tracing & Hybrid Fuzzing](./advanced_features/concolic/concolic.md) + - [Using LibAFL in no_std environments](./advanced_features/no_std/no_std.md) \ No newline at end of file diff --git a/docs/src/advanced_features/no_std/no_std.md b/docs/src/advanced_features/no_std/no_std.md new file mode 100644 index 0000000000..d17ed3c52c --- /dev/null +++ b/docs/src/advanced_features/no_std/no_std.md @@ -0,0 +1,35 @@ +# Using LibAFL in no_std environments + +It is possible to use LibAFL in `no_std` environments e.g. custom platforms like microcontrolles, kernels, hypervisors, and more. + +You can simply add LibAFL to your `Cargo.toml` file: + +```toml +libafl = { path = "path/to/libafl/", default-features = false} +``` + +Then build your project e.g. for `aarch64-unknown-none` using +``` +cargo build --no-default-features --target aarch64-unknown-none +``` + +## Use custom timing + +The minimum amount of input LibAFL needs for `no_std` is a monotonically increasing timestamp. +For this, anywhere in your project you need to implement the `external_current_millis` function, which returns the current time in milliseconds. + +// Assume this a clock source from a custom stdlib, which you want to use, which returns current time in seconds. +```c +int my_real_seconds(void) +{ + return *CLOCK; +} +``` +and here we use it in Rust. `external_current_millis` is then called from LibAFL. +Note that it needs to be `no_mangle` in order to get picked up by LibAFL at linktime. +```rust +#[no_mangle] +pub extern "C" fn external_current_millis() -> u64 { + unsafe { my_real_seconds()*1000 } +} +```