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 <domenukk@gmail.com>
This commit is contained in:
bitwave 2021-09-24 20:26:45 +02:00 committed by GitHub
parent 1fde608145
commit e17f4b846f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -18,4 +18,5 @@
- [Advanced Features](./advanced_features/advanced_features.md)
- [Concolic Tracing & Hybrid Fuzzing](./advanced_features/concolic/concolic.md)
- [Concolic Tracing & Hybrid Fuzzing](./advanced_features/concolic/concolic.md)
- [Using LibAFL in no_std environments](./advanced_features/no_std/no_std.md)

View File

@ -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 }
}
```