From 634cdcf217cdf5e7e68e419aa7fe9fe7c31793ca Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Fri, 27 Nov 2020 21:54:01 +0100 Subject: [PATCH] fixed llmp test, moved to xxh3 const --- afl/Cargo.toml | 2 +- afl/llmp_test/src/main.rs | 31 ++++++++----------------------- afl/src/corpus/testcase.rs | 2 +- afl/src/events/llmp_translated.rs | 4 ++-- afl/src/lib.rs | 6 ++++++ afl/src/utils.rs | 11 +++++++++-- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/afl/Cargo.toml b/afl/Cargo.toml index 407ec699d9..7fd34a1dce 100644 --- a/afl/Cargo.toml +++ b/afl/Cargo.toml @@ -17,7 +17,7 @@ std = [] hashbrown = { version = "0.9", features = ["serde"] } # A faster hashmap, nostd compatible libc = "0.2" # For (*nix) libc num = "*" -xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust +xxhash-rust = { version = "0.8.0-beta.5", features = ["const_xxh3"] } # xxh3 hashing for rust serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib typetag = "0.1" postcard = "0.5.1" # no_std compatible serde serialization fromat \ No newline at end of file diff --git a/afl/llmp_test/src/main.rs b/afl/llmp_test/src/main.rs index 3404706738..b3f39b9b54 100644 --- a/afl/llmp_test/src/main.rs +++ b/afl/llmp_test/src/main.rs @@ -80,7 +80,7 @@ unsafe fn test_adder_clientloop(client: *mut llmp_client, _data: *mut c_void) -> } unsafe fn broker_message_hook( - _broker: *mut llmp_broker, + _broker: *mut LlmpBroker, client_metadata: *mut llmp_broker_client_metadata, message: *mut llmp_message, _data: *mut c_void, @@ -118,33 +118,18 @@ fn main() { counter_thread_count ); - let mut broker = llmp_broker { - last_msg_sent: ptr::null_mut(), - broadcast_map_count: 0, - broadcast_maps: ptr::null_mut(), - msg_hook_count: 0, - msg_hooks: ptr::null_mut(), - llmp_client_count: 0, - llmp_clients: ptr::null_mut(), - }; - unsafe { - - llmp_broker_init(&mut broker).expect("Could not init"); + let mut broker = LlmpBroker::new().expect("Failed to create llmp broker"); for i in 0..counter_thread_count { println!("Adding client {}", i); - broker.register_childprocess_clientloop( - llmp_test_clientloop, - ptr::null_mut(), - ) - .expect("could not add child clientloop"); + broker + .register_childprocess_clientloop(llmp_test_clientloop, ptr::null_mut()) + .expect("could not add child clientloop"); } - broker.register_childprocess_clientloop( - test_adder_clientloop, - ptr::null_mut(), - ) - .expect("Error registering childprocess"); + broker + .register_childprocess_clientloop(test_adder_clientloop, ptr::null_mut()) + .expect("Error registering childprocess"); println!("Spawning broker"); diff --git a/afl/src/corpus/testcase.rs b/afl/src/corpus/testcase.rs index 44d752b9f4..bf509ac270 100644 --- a/afl/src/corpus/testcase.rs +++ b/afl/src/corpus/testcase.rs @@ -1,7 +1,7 @@ use alloc::boxed::Box; use alloc::rc::Rc; use alloc::string::String; -use core::any::{Any, TypeId}; +use core::any::Any; use core::cell::RefCell; use core::convert::Into; use core::default::Default; diff --git a/afl/src/events/llmp_translated.rs b/afl/src/events/llmp_translated.rs index 195df20564..96538e17ab 100644 --- a/afl/src/events/llmp_translated.rs +++ b/afl/src/events/llmp_translated.rs @@ -160,7 +160,7 @@ const LLMP_CLIENT_TYPE_CHILD_PROCESS: LlmpClientType = 2; /// A share mem page, as used by llmp internally #[derive(Copy, Clone)] #[repr(C, packed)] -struct llmp_page { +pub struct llmp_page { pub sender: u32, pub save_to_unmap: c_ushort, pub sender_dead: c_ushort, @@ -342,7 +342,7 @@ unsafe fn llmp_recv(page: *mut llmp_page, last_msg: *mut llmp_message) -> *mut l } /* Blocks/spins until the next message gets posted to the page, then returns that message. */ -unsafe fn llmp_recv_blocking( +pub unsafe fn llmp_recv_blocking( page: *mut llmp_page, last_msg: *mut llmp_message, ) -> *mut llmp_message { diff --git a/afl/src/lib.rs b/afl/src/lib.rs index da4070ae12..54268a2081 100644 --- a/afl/src/lib.rs +++ b/afl/src/lib.rs @@ -19,6 +19,7 @@ use alloc::string::String; use core::fmt; #[cfg(feature = "std")] use std::io; +use xxhash_rust::const_xxh3::xxh3_64_with_seed; /// Main error struct for AFL #[derive(Debug)] @@ -78,3 +79,8 @@ mod tests { assert_eq!(2 + 2, 4); } } + +#[no_mangle] +pub extern "C" fn test_xxh3_hash() -> u64 { + xxh3_64_with_seed(b"test", 0) +} diff --git a/afl/src/utils.rs b/afl/src/utils.rs index 4ae37eaf25..7ae75d2d76 100644 --- a/afl/src/utils.rs +++ b/afl/src/utils.rs @@ -4,12 +4,12 @@ use alloc::rc::Rc; use core::cell::RefCell; use core::debug_assert; use core::fmt::Debug; -use xxhash_rust::xxh3::xxh3_64_with_seed; +use xxhash_rust::const_xxh3::xxh3_64_with_seed; #[cfg(feature = "std")] use std::time::{SystemTime, UNIX_EPOCH}; -pub type StdRand = XorShift64Rand; +pub type StdRand = Xoshiro256StarRand; /// Ways to get random around here pub trait Rand: Debug { @@ -303,6 +303,8 @@ pub const fn next_pow2(val: u64) -> u64 { #[cfg(test)] mod tests { + use xxhash_rust::const_xxh3::xxh3_64_with_seed; + use crate::utils::{next_pow2, Rand, StdRand}; #[test] @@ -337,4 +339,9 @@ mod tests { assert_eq!(next_pow2(1000), 1024); assert_eq!(next_pow2(0xFFFFFFFF as u64), (0xFFFFFFFF as u64) + 1); } + + #[test] + fn test_xxh3_hash() { + assert_eq!(xxh3_64_with_seed(b"test", 0), 0); + } }