compiles with no_std

This commit is contained in:
Dominik Maier 2020-11-15 03:22:07 +01:00
parent dea240a324
commit c3275bbc3f
15 changed files with 43 additions and 22 deletions

View File

@ -1,4 +1,3 @@
extern crate alloc;
pub mod testcase;
pub use testcase::{Testcase, TestcaseMetadata};

View File

@ -1,12 +1,16 @@
extern crate alloc;
use crate::inputs::Input;
use crate::AflError;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use core::cell::RefCell;
use core::convert::Into;
use core::default::Default;
use core::option::Option;
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::fs::File;
#[cfg(feature = "std")]
@ -39,6 +43,7 @@ where
}
*/
#[cfg(feature = "std")]
pub enum FileBackedTestcase<I, P> {
/// A testcase on disk, not yet loaded
Stored { filename: P },
@ -51,6 +56,7 @@ pub enum FileBackedTestcase<I, P> {
Dirty { input: I, filename: P },
}
#[cfg(feature = "std")]
impl<I, P> FileBackedTestcase<I, P>
where
I: Input,

View File

@ -1,5 +1,7 @@
//! The engine is the core piece of every good fuzzer
extern crate alloc;
use alloc::boxed::Box;
use alloc::vec::Vec;
use crate::corpus::Corpus;
use crate::feedbacks::Feedback;
@ -83,6 +85,7 @@ where
#[cfg(test)]
mod tests {
use alloc::boxed::Box;
use alloc::rc::Rc;
use core::cell::RefCell;

View File

@ -1,9 +1,11 @@
extern crate alloc;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::vec::Vec;
use core::cell::RefCell;
use std::os::raw::c_void;
use std::ptr;
use core::ffi::c_void;
use core::ptr;
use crate::executors::{Executor, ExitKind};
use crate::feedbacks::Feedback;
@ -89,6 +91,7 @@ where
I: Input,
{
pub fn new(harness_fn: HarnessFunction<I>) -> Self {
#[cfg(feature = "std")]
unsafe {
os_signals::setup_crash_handlers::<I>();
}
@ -100,6 +103,7 @@ where
}
}
#[cfg(feature = "std")]
#[cfg(unix)]
pub mod unix_signals {
@ -130,9 +134,13 @@ pub mod unix_signals {
);
}
}
// TODO: LLMP
#[cfg(feature = "std")]
println!("Child crashed!");
#[cfg(feature = "std")]
let _ = stdout().flush();
// TODO: LLMP
}
pub extern "C" fn libaflrs_executor_inmem_handle_timeout<I>(
@ -183,13 +191,18 @@ pub mod unix_signals {
}
}
#[cfg(feature = "std")]
#[cfg(unix)]
use unix_signals as os_signals;
#[cfg(feature = "std")]
#[cfg(not(unix))]
compile_error!("InMemoryExecutor not yet supported on this OS");
#[cfg(test)]
mod tests {
extern crate alloc;
use alloc::boxed::Box;
use crate::executors::inmemory::InMemoryExecutor;
use crate::executors::{Executor, ExitKind};
use crate::inputs::Input;
@ -218,11 +231,17 @@ mod tests {
}
}
#[cfg(feature = "std")]
fn test_harness_fn_nop(_executor: &dyn Executor<NopInput>, buf: &[u8]) -> ExitKind {
println!{"Fake exec with buf of len {}", buf.len()};
ExitKind::Ok
}
#[cfg(not(feature = "std"))]
fn test_harness_fn_nop(_executor: &dyn Executor<NopInput>, _buf: &[u8]) -> ExitKind {
ExitKind::Ok
}
#[test]
fn test_inmem_post_exec() {
let mut in_mem_executor = InMemoryExecutor::new(test_harness_fn_nop);

View File

@ -1,6 +1,8 @@
extern crate alloc;
pub mod inmemory;
use alloc::boxed::Box;
use alloc::vec::Vec;
use crate::corpus::TestcaseMetadata;
use crate::feedbacks::Feedback;
use crate::inputs::Input;

View File

@ -1,10 +1,9 @@
extern crate alloc;
extern crate num;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::cell::RefCell;
use core::marker::PhantomData;
use alloc::vec::*;
use num::Integer;
use crate::corpus::TestcaseMetadata;

View File

@ -1,4 +1,3 @@
extern crate alloc;
use alloc::borrow::ToOwned;
use alloc::rc::Rc;

View File

@ -1,4 +1,3 @@
extern crate alloc;
pub mod bytes;
pub use bytes::BytesInput;
@ -30,7 +29,7 @@ pub trait Input: Clone {
#[cfg(not(feature = "std"))]
/// Write this input to the file
fn to_file<P>(&self, string: P) -> Result<(), AflError>
fn to_file<P>(&self, _path: P) -> Result<(), AflError>
where {
Err(AflError::NotImplemented("Not suppored in no_std".into()))
}
@ -49,7 +48,7 @@ where {
/// Write this input to the file
#[cfg(not(feature = "std"))]
fn from_file<P>(string: P) -> Result<Self, AflError>
fn from_file<P>(_path: P) -> Result<Self, AflError>
where {
Err(AflError::NotImplemented("Not suppored in no_std".into()))
}

View File

@ -1,4 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
#[macro_use]
extern crate alloc;

View File

@ -1,4 +1,3 @@
extern crate alloc;
pub mod scheduled;
pub use scheduled::ComposedByMutations;

View File

@ -1,4 +1,3 @@
extern crate alloc;
use crate::inputs::{HasBytesVec, Input};
use crate::mutators::Corpus;

View File

@ -1,4 +1,3 @@
extern crate alloc;
extern crate num;
use core::slice::from_raw_parts_mut;

View File

@ -1,4 +1,3 @@
extern crate alloc;
pub mod mutational;
pub use mutational::DefaultMutationalStage;

View File

@ -1,4 +1,3 @@
extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;

View File

@ -1,5 +1,4 @@
//! Utility functions for AFL
extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;