* fix

* fix

* fix

* removed allow(unused)

* removed feature from powerset

* fixing win

* tidying up

* cfg guards galore

* cfg for unused

* more cfg

* more fixes

* more cfgs

Co-authored-by: Dominik Maier <dmnk@google.com>
This commit is contained in:
Dongjia "toka" Zhang 2022-10-04 17:29:42 +02:00 committed by GitHub
parent caa560b7a0
commit e4f0e1df99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 26 deletions

View File

@ -95,7 +95,7 @@ jobs:
# cargo-hack's --feature-powerset would be nice here but libafl has a too many knobs # cargo-hack's --feature-powerset would be nice here but libafl has a too many knobs
- name: Check each feature - name: Check each feature
# Skipping python as it has to be built with the `maturin` tool # 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 - name: Build examples
run: cargo build --examples --verbose run: cargo build --examples --verbose

View File

@ -32,7 +32,7 @@ pub fn read_time_counter() -> u64 {
/// Read a timestamp for measurements /// Read a timestamp for measurements
/// ///
/// Fetches the counter-virtual count register /// 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")] #[cfg(target_arch = "aarch64")]
#[must_use] #[must_use]
pub fn read_time_counter() -> u64 { pub fn read_time_counter() -> u64 {

View File

@ -234,8 +234,10 @@ where
#[derive(Debug)] #[derive(Debug)]
pub struct InProcessHandlers { pub struct InProcessHandlers {
/// On crash C function pointer /// On crash C function pointer
#[cfg(any(unix, feature = "std"))]
pub crash_handler: *const c_void, pub crash_handler: *const c_void,
/// On timeout C function pointer /// On timeout C function pointer
#[cfg(any(unix, feature = "std"))]
pub timeout_handler: *const c_void, pub timeout_handler: *const c_void,
} }
@ -362,20 +364,26 @@ impl InProcessHandlers {
> as *const c_void, > as *const c_void,
}) })
} }
#[cfg(not(any(unix, all(windows, feature = "std"))))] #[cfg(not(any(unix, feature = "std")))]
Ok(Self { Ok(Self {})
crash_handler: ptr::null(),
timeout_handler: ptr::null(),
})
} }
/// Replace the handlers with `nop` handlers, deactivating the handlers /// Replace the handlers with `nop` handlers, deactivating the handlers
#[must_use] #[must_use]
pub fn nop() -> Self { pub fn nop() -> Self {
Self { let ret;
crash_handler: ptr::null(), #[cfg(any(unix, feature = "std"))]
timeout_handler: ptr::null(), {
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, executor_ptr: *const c_void,
pub current_input_ptr: *const c_void, pub current_input_ptr: *const c_void,
/// The timeout handler /// The timeout handler
#[allow(unused)] // for no_std #[cfg(any(unix, feature = "std"))]
crash_handler: *const c_void, crash_handler: *const c_void,
/// The timeout handler /// The timeout handler
#[allow(unused)] // for no_std #[cfg(any(unix, feature = "std"))]
timeout_handler: *const c_void, timeout_handler: *const c_void,
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
pub tp_timer: *mut c_void, pub(crate) tp_timer: *mut c_void,
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
pub in_target: u64, pub(crate) in_target: u64,
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
pub critical: *mut c_void, pub(crate) critical: *mut c_void,
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
pub timeout_input_ptr: *mut c_void, pub(crate) timeout_input_ptr: *mut c_void,
} }
unsafe impl Send for InProcessExecutorHandlerData {} unsafe impl Send for InProcessExecutorHandlerData {}
unsafe impl Sync for InProcessExecutorHandlerData {} unsafe impl Sync for InProcessExecutorHandlerData {}
#[allow(unused)]
impl InProcessExecutorHandlerData { impl InProcessExecutorHandlerData {
#[cfg(any(unix, feature = "std"))]
fn executor_mut<'a, E>(&self) -> &'a mut E { fn executor_mut<'a, E>(&self) -> &'a mut E {
unsafe { (self.executor_ptr as *mut E).as_mut().unwrap() } unsafe { (self.executor_ptr as *mut E).as_mut().unwrap() }
} }
#[cfg(any(unix, feature = "std"))]
fn state_mut<'a, S>(&self) -> &'a mut S { fn state_mut<'a, S>(&self) -> &'a mut S {
unsafe { (self.state_ptr as *mut S).as_mut().unwrap() } 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 { fn event_mgr_mut<'a, EM>(&self) -> &'a mut EM {
unsafe { (self.event_mgr_ptr as *mut EM).as_mut().unwrap() } 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 { fn fuzzer_mut<'a, Z>(&self) -> &'a mut Z {
unsafe { (self.fuzzer_ptr as *mut Z).as_mut().unwrap() } unsafe { (self.fuzzer_ptr as *mut Z).as_mut().unwrap() }
} }
#[cfg(all(unix, feature = "std"))]
fn current_input<'a, I>(&self) -> &'a I { fn current_input<'a, I>(&self) -> &'a I {
unsafe { (self.current_input_ptr as *const I).as_ref().unwrap() } 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 { fn take_current_input<'a, I>(&mut self) -> &'a I {
let r = unsafe { (self.current_input_ptr as *const I).as_ref().unwrap() }; let r = unsafe { (self.current_input_ptr as *const I).as_ref().unwrap() };
self.current_input_ptr = ptr::null(); self.current_input_ptr = ptr::null();
r r
} }
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
fn is_valid(&self) -> bool { fn is_valid(&self) -> bool {
self.in_target == 1 self.in_target == 1
} }
@ -458,16 +471,18 @@ pub(crate) static mut GLOBAL_STATE: InProcessExecutorHandlerData = InProcessExec
/// The current input for signal handling /// The current input for signal handling
current_input_ptr: ptr::null(), current_input_ptr: ptr::null(),
/// The crash handler fn /// The crash handler fn
#[cfg(any(unix, feature = "std"))]
crash_handler: ptr::null(), crash_handler: ptr::null(),
/// The timeout handler fn /// The timeout handler fn
#[cfg(any(unix, feature = "std"))]
timeout_handler: ptr::null(), timeout_handler: ptr::null(),
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
tp_timer: null_mut(), tp_timer: null_mut(),
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
in_target: 0, in_target: 0,
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
critical: null_mut(), critical: null_mut(),
#[cfg(windows)] #[cfg(all(windows, feature = "std"))]
timeout_input_ptr: null_mut(), timeout_input_ptr: null_mut(),
}; };
@ -1892,6 +1907,7 @@ pub mod child_signal_handlers {
mod tests { mod tests {
use core::marker::PhantomData; use core::marker::PhantomData;
#[cfg(all(feature = "std", feature = "fork", unix))]
use serial_test::serial; use serial_test::serial;
#[cfg(all(feature = "std", feature = "fork", unix))] #[cfg(all(feature = "std", feature = "fork", unix))]

View File

@ -70,6 +70,9 @@ Welcome to `LibAFL`
while_true while_true
) )
)] )]
// Till they fix this buggy lint in clippy
#![allow(clippy::borrow_as_ptr)]
#![allow(clippy::borrow_deref_ref)]
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[macro_use] #[macro_use]