more no_std work

This commit is contained in:
Dominik Maier 2020-11-27 01:49:49 +01:00
parent 933e8588ee
commit 5ad556b419
3 changed files with 26 additions and 7 deletions

View File

@ -1,3 +1,6 @@
#[macro_use]
extern crate alloc;
use core::convert::TryInto;
use core::ffi::c_void;
use core::mem::size_of;
@ -16,7 +19,7 @@ unsafe fn llmp_test_clientloop(client: *mut llmp_client, _data: *mut c_void) ->
counter += 1;
let llmp_message = llmp_client_alloc_next(client, size_of::<u32>());
std::ptr::copy(
core::ptr::copy(
counter.to_be_bytes().as_ptr(),
(*llmp_message).buf.as_mut_ptr(),
size_of::<u32>(),
@ -30,7 +33,7 @@ unsafe fn llmp_test_clientloop(client: *mut llmp_client, _data: *mut c_void) ->
unsafe fn u32_from_msg(message: *const llmp_message) -> u32 {
u32::from_be_bytes(
std::slice::from_raw_parts((*message).buf.as_ptr(), size_of::<u32>())
alloc::slice::from_raw_parts((*message).buf.as_ptr(), size_of::<u32>())
.try_into()
.unwrap(),
)
@ -62,7 +65,7 @@ unsafe fn test_adder_clientloop(client: *mut llmp_client, _data: *mut c_void) ->
);
let llmp_message = llmp_client_alloc_next(client, size_of::<u32>());
std::ptr::copy(
core::ptr::copy(
current_result.to_be_bytes().as_ptr(),
(*llmp_message).buf.as_mut_ptr(),
size_of::<u32>(),

View File

@ -1,5 +1,10 @@
#[cfg(feature = "std")]
pub mod llmp;
use alloc::borrow::ToOwned;
use alloc::string::String;
use core::marker::PhantomData;
#[cfg(feature = "std")]
pub mod llmp_translated; // TODO: Abstract away.
#[cfg(feature = "std")]
@ -9,7 +14,7 @@ pub mod shmem_translated;
pub use crate::events::llmp::LLMP;
#[cfg(feature = "std")]
use std::{io::Write, marker::PhantomData};
use std::io::Write;
use crate::corpus::{Corpus, Testcase};
use crate::engines::State;
@ -190,6 +195,7 @@ where
_marker,
} => {
//TODO: broker.log()
#[cfg(feature = "std")]
println!("{}[{}]: {}", sender_id, severity_level, message);
Ok(BrokerEventResult::Handled)
}

View File

@ -1,7 +1,14 @@
use std::boxed::Box;
use std::cell::RefCell;
#![cfg_attr(not(feature = "std"), no_std)]
#[macro_use]
extern crate alloc;
use alloc::boxed::Box;
use alloc::rc::Rc;
use core::cell::RefCell;
#[cfg(feature = "std")]
use std::io::stderr;
use std::rc::Rc;
use afl::corpus::InMemoryCorpus;
use afl::engines::{generate_initial_inputs, Engine, State, StdEngine, StdState};
@ -40,6 +47,9 @@ pub extern "C" fn afl_libfuzzer_main() {
let mut corpus = InMemoryCorpus::new();
let mut generator = RandPrintablesGenerator::new(32);
// TODO: No_std event manager
#[cfg(feature = "std")]
let mut events = LoggerEventManager::new(stderr());
let edges_observer = Rc::new(RefCell::new(StdMapObserver::new_from_ptr(