diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index f8d7274494..16e5a75868 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -95,7 +95,7 @@ jobs: # cargo-hack's --feature-powerset would be nice here but libafl has a too many knobs - name: Check each feature # Skipping python as it has to be built with the `maturin` tool - run: cargo hack check --feature-powerset --depth=2 --exclude-features=agpl,nautilus,python,sancov_pcguard_edges,arm,aarch64,i386 --no-dev-deps + run: cargo hack check --feature-powerset --depth=2 --exclude-features=prelude,agpl,nautilus,python,sancov_pcguard_edges,arm,aarch64,i386 --no-dev-deps - name: Build examples run: cargo build --examples --verbose diff --git a/libafl/src/bolts/cpu.rs b/libafl/src/bolts/cpu.rs index eb2c4eea38..fbc4dfbf69 100644 --- a/libafl/src/bolts/cpu.rs +++ b/libafl/src/bolts/cpu.rs @@ -32,7 +32,7 @@ pub fn read_time_counter() -> u64 { /// Read a timestamp for measurements /// /// Fetches the counter-virtual count register -/// as we do not need to remove the cntvct_el2 offset. +/// as we do not need to remove the `cntvct_el2` offset. #[cfg(target_arch = "aarch64")] #[must_use] pub fn read_time_counter() -> u64 { diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 6f73b57b88..de4154f712 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -234,8 +234,10 @@ where #[derive(Debug)] pub struct InProcessHandlers { /// On crash C function pointer + #[cfg(any(unix, feature = "std"))] pub crash_handler: *const c_void, /// On timeout C function pointer + #[cfg(any(unix, feature = "std"))] pub timeout_handler: *const c_void, } @@ -362,20 +364,26 @@ impl InProcessHandlers { > as *const c_void, }) } - #[cfg(not(any(unix, all(windows, feature = "std"))))] - Ok(Self { - crash_handler: ptr::null(), - timeout_handler: ptr::null(), - }) + #[cfg(not(any(unix, feature = "std")))] + Ok(Self {}) } /// Replace the handlers with `nop` handlers, deactivating the handlers #[must_use] pub fn nop() -> Self { - Self { - crash_handler: ptr::null(), - timeout_handler: ptr::null(), + let ret; + #[cfg(any(unix, feature = "std"))] + { + ret = Self { + crash_handler: ptr::null(), + timeout_handler: ptr::null(), + }; } + #[cfg(not(any(unix, feature = "std")))] + { + ret = Self {}; + } + ret } } @@ -388,53 +396,58 @@ pub(crate) struct InProcessExecutorHandlerData { executor_ptr: *const c_void, pub current_input_ptr: *const c_void, /// The timeout handler - #[allow(unused)] // for no_std + #[cfg(any(unix, feature = "std"))] crash_handler: *const c_void, /// The timeout handler - #[allow(unused)] // for no_std + #[cfg(any(unix, feature = "std"))] timeout_handler: *const c_void, - #[cfg(windows)] - pub tp_timer: *mut c_void, - #[cfg(windows)] - pub in_target: u64, - #[cfg(windows)] - pub critical: *mut c_void, - #[cfg(windows)] - pub timeout_input_ptr: *mut c_void, + #[cfg(all(windows, feature = "std"))] + pub(crate) tp_timer: *mut c_void, + #[cfg(all(windows, feature = "std"))] + pub(crate) in_target: u64, + #[cfg(all(windows, feature = "std"))] + pub(crate) critical: *mut c_void, + #[cfg(all(windows, feature = "std"))] + pub(crate) timeout_input_ptr: *mut c_void, } unsafe impl Send for InProcessExecutorHandlerData {} unsafe impl Sync for InProcessExecutorHandlerData {} -#[allow(unused)] impl InProcessExecutorHandlerData { + #[cfg(any(unix, feature = "std"))] fn executor_mut<'a, E>(&self) -> &'a mut E { unsafe { (self.executor_ptr as *mut E).as_mut().unwrap() } } + #[cfg(any(unix, feature = "std"))] fn state_mut<'a, S>(&self) -> &'a mut S { unsafe { (self.state_ptr as *mut S).as_mut().unwrap() } } + #[cfg(any(unix, feature = "std"))] fn event_mgr_mut<'a, EM>(&self) -> &'a mut EM { unsafe { (self.event_mgr_ptr as *mut EM).as_mut().unwrap() } } + #[cfg(any(unix, feature = "std"))] fn fuzzer_mut<'a, Z>(&self) -> &'a mut Z { unsafe { (self.fuzzer_ptr as *mut Z).as_mut().unwrap() } } + #[cfg(all(unix, feature = "std"))] fn current_input<'a, I>(&self) -> &'a I { unsafe { (self.current_input_ptr as *const I).as_ref().unwrap() } } + #[cfg(any(unix, feature = "std"))] fn take_current_input<'a, I>(&mut self) -> &'a I { let r = unsafe { (self.current_input_ptr as *const I).as_ref().unwrap() }; self.current_input_ptr = ptr::null(); r } - #[cfg(windows)] + #[cfg(all(windows, feature = "std"))] fn is_valid(&self) -> bool { self.in_target == 1 } @@ -458,16 +471,18 @@ pub(crate) static mut GLOBAL_STATE: InProcessExecutorHandlerData = InProcessExec /// The current input for signal handling current_input_ptr: ptr::null(), /// The crash handler fn + #[cfg(any(unix, feature = "std"))] crash_handler: ptr::null(), /// The timeout handler fn + #[cfg(any(unix, feature = "std"))] timeout_handler: ptr::null(), - #[cfg(windows)] + #[cfg(all(windows, feature = "std"))] tp_timer: null_mut(), - #[cfg(windows)] + #[cfg(all(windows, feature = "std"))] in_target: 0, - #[cfg(windows)] + #[cfg(all(windows, feature = "std"))] critical: null_mut(), - #[cfg(windows)] + #[cfg(all(windows, feature = "std"))] timeout_input_ptr: null_mut(), }; @@ -1892,6 +1907,7 @@ pub mod child_signal_handlers { mod tests { use core::marker::PhantomData; + #[cfg(all(feature = "std", feature = "fork", unix))] use serial_test::serial; #[cfg(all(feature = "std", feature = "fork", unix))] diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index dd341a279b..7131ebe2d7 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -70,6 +70,9 @@ Welcome to `LibAFL` while_true ) )] +// Till they fix this buggy lint in clippy +#![allow(clippy::borrow_as_ptr)] +#![allow(clippy::borrow_deref_ref)] #[cfg(feature = "std")] #[macro_use]