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 mod testcase;
pub use testcase::{Testcase, TestcaseMetadata}; pub use testcase::{Testcase, TestcaseMetadata};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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