Remove some arguments from pre_exec/post_exec in ExecutorHook (#1933)

* refactor

* no std, fmt

* win mac

* state

* frida

* ctx

* trait bound

* clip
This commit is contained in:
Dongjia "toka" Zhang 2024-03-13 18:49:09 +01:00 committed by GitHub
parent 4f3d9d2e50
commit afa2965f3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 266 additions and 230 deletions

View File

@ -18,7 +18,10 @@ use clap::{Arg, Command};
use libafl::{ use libafl::{
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager, events::SimpleRestartingEventManager,
executors::{inprocess::HookableInProcessExecutor, ExitKind}, executors::{
inprocess::{HookableInProcessExecutor, InProcessExecutor},
ExitKind,
},
feedback_or, feedback_or,
feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback}, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback},
fuzzer::{Fuzzer, StdFuzzer}, fuzzer::{Fuzzer, StdFuzzer},
@ -332,7 +335,7 @@ fn fuzz(
}; };
let mut tracing_harness = harness; let mut tracing_harness = harness;
let ctx_hook = CtxHook::default(); let ctx_hook = CtxHook::new();
// Create the executor for an in-process function with one observer for edge coverage and one for the execution time // Create the executor for an in-process function with one observer for edge coverage and one for the execution time
let mut executor = HookableInProcessExecutor::with_timeout_generic( let mut executor = HookableInProcessExecutor::with_timeout_generic(
tuple_list!(ctx_hook), tuple_list!(ctx_hook),
@ -346,8 +349,7 @@ fn fuzz(
// Setup a tracing stage in which we log comparisons // Setup a tracing stage in which we log comparisons
let tracing = TracingStage::new( let tracing = TracingStage::new(
HookableInProcessExecutor::with_timeout_generic( InProcessExecutor::with_timeout(
tuple_list!(ctx_hook),
&mut tracing_harness, &mut tracing_harness,
tuple_list!(cmplog_observer), tuple_list!(cmplog_observer),
&mut fuzzer, &mut fuzzer,

View File

@ -5,6 +5,7 @@ use core::ptr::addr_of_mut;
use core::sync::atomic::{compiler_fence, Ordering}; use core::sync::atomic::{compiler_fence, Ordering};
use core::{ use core::{
ffi::c_void, ffi::c_void,
marker::PhantomData,
ptr::{self, null_mut}, ptr::{self, null_mut},
time::Duration, time::Duration,
}; };
@ -30,12 +31,16 @@ use crate::{
events::{EventFirer, EventRestarter}, events::{EventFirer, EventRestarter},
executors::{hooks::ExecutorHook, inprocess::HasInProcessHooks, Executor, HasObservers}, executors::{hooks::ExecutorHook, inprocess::HasInProcessHooks, Executor, HasObservers},
feedbacks::Feedback, feedbacks::Feedback,
inputs::UsesInput,
state::{HasCorpus, HasExecutions, HasSolutions}, state::{HasCorpus, HasExecutions, HasSolutions},
Error, HasObjective, Error, HasObjective,
}; };
/// The inmem executor's handlers. /// The inmem executor's handlers.
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct InProcessHooks { pub struct InProcessHooks<S>
where
S: UsesInput,
{
/// On crash C function pointer /// On crash C function pointer
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub crash_handler: *const c_void, pub crash_handler: *const c_void,
@ -45,6 +50,7 @@ pub struct InProcessHooks {
/// `TImer` struct /// `TImer` struct
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub timer: TimerStruct, pub timer: TimerStruct,
phantom: PhantomData<S>,
} }
/// Any hooks that is about timeout /// Any hooks that is about timeout
@ -80,7 +86,10 @@ pub trait HasTimeout {
fn handle_timeout(&mut self, data: &mut InProcessExecutorHandlerData) -> bool; fn handle_timeout(&mut self, data: &mut InProcessExecutorHandlerData) -> bool;
} }
impl HasTimeout for InProcessHooks { impl<S> HasTimeout for InProcessHooks<S>
where
S: UsesInput,
{
#[cfg(feature = "std")] #[cfg(feature = "std")]
fn timer(&self) -> &TimerStruct { fn timer(&self) -> &TimerStruct {
&self.timer &self.timer
@ -184,13 +193,15 @@ impl HasTimeout for InProcessHooks {
} }
} }
impl ExecutorHook for InProcessHooks { impl<S> ExecutorHook<S> for InProcessHooks<S>
fn init<E: HasObservers, S>(&mut self, _state: &mut S) {} where
S: UsesInput,
{
fn init<E: HasObservers>(&mut self, _state: &mut S) {}
/// Call before running a target. /// Call before running a target.
#[allow(clippy::unused_self)] #[allow(clippy::unused_self)]
#[allow(unused_variables)] #[allow(unused_variables)]
fn pre_exec<EM, I, S, Z>(&mut self, fuzzer: &mut Z, state: &mut S, mgr: &mut EM, input: &I) { fn pre_exec(&mut self, state: &mut S, input: &S::Input) {
#[cfg(feature = "std")] #[cfg(feature = "std")]
unsafe { unsafe {
let data = addr_of_mut!(GLOBAL_STATE); let data = addr_of_mut!(GLOBAL_STATE);
@ -204,26 +215,23 @@ impl ExecutorHook for InProcessHooks {
/// Call after running a target. /// Call after running a target.
#[allow(clippy::unused_self)] #[allow(clippy::unused_self)]
fn post_exec<EM, I, S, Z>( fn post_exec(&mut self, _state: &mut S, _input: &S::Input) {
&mut self,
_fuzzer: &mut Z,
_state: &mut S,
_mgr: &mut EM,
_input: &I,
) {
// timeout stuff // timeout stuff
#[cfg(all(feature = "std", not(all(miri, target_vendor = "apple"))))] #[cfg(all(feature = "std", not(all(miri, target_vendor = "apple"))))]
self.timer_mut().unset_timer(); self.timer_mut().unset_timer();
} }
} }
impl InProcessHooks { impl<S> InProcessHooks<S>
where
S: UsesInput,
{
/// Create new [`InProcessHooks`]. /// Create new [`InProcessHooks`].
#[cfg(unix)] #[cfg(unix)]
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error> pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
where where
E: Executor<EM, Z> + HasObservers + HasInProcessHooks, E: Executor<EM, Z> + HasObservers + HasInProcessHooks<E::State>,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>, EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>, OF: Feedback<E::State>,
E::State: HasExecutions + HasSolutions + HasCorpus, E::State: HasExecutions + HasSolutions + HasCorpus,
@ -246,6 +254,7 @@ impl InProcessHooks {
as *const _, as *const _,
#[cfg(feature = "std")] #[cfg(feature = "std")]
timer: TimerStruct::new(exec_tmout), timer: TimerStruct::new(exec_tmout),
phantom: PhantomData,
}) })
} }
} }
@ -255,7 +264,7 @@ impl InProcessHooks {
#[allow(unused)] #[allow(unused)]
pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error> pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
where where
E: Executor<EM, Z> + HasObservers + HasInProcessHooks, E: Executor<EM, Z> + HasObservers + HasInProcessHooks<E::State>,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>, EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>, OF: Feedback<E::State>,
E::State: State + HasExecutions + HasSolutions + HasCorpus, E::State: State + HasExecutions + HasSolutions + HasCorpus,
@ -292,11 +301,14 @@ impl InProcessHooks {
crash_handler, crash_handler,
timeout_handler, timeout_handler,
timer, timer,
phantom: PhantomData,
}); });
} }
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
{ {
ret = Ok(Self {}); ret = Ok(Self {
phantom: PhantomData,
});
} }
ret ret
@ -307,14 +319,16 @@ impl InProcessHooks {
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error> pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
where where
E: Executor<EM, Z> + HasObservers + HasInProcessHooks, E: Executor<EM, Z> + HasObservers + HasInProcessHooks<E::State>,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>, EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>, OF: Feedback<E::State>,
E::State: HasExecutions + HasSolutions + HasCorpus, E::State: HasExecutions + HasSolutions + HasCorpus,
Z: HasObjective<Objective = OF, State = E::State>, Z: HasObjective<Objective = OF, State = E::State>,
{ {
#[cfg_attr(miri, allow(unused_variables))] #[cfg_attr(miri, allow(unused_variables))]
let ret = Self {}; let ret = Self {
phantom: PhantomData,
};
Ok(ret) Ok(ret)
} }
@ -329,6 +343,7 @@ impl InProcessHooks {
timeout_handler: ptr::null(), timeout_handler: ptr::null(),
#[cfg(feature = "std")] #[cfg(feature = "std")]
timer: TimerStruct::new(Duration::from_millis(5000)), timer: TimerStruct::new(Duration::from_millis(5000)),
phantom: PhantomData,
} }
} }
} }

View File

@ -2,6 +2,7 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use core::{ use core::{
ffi::c_void, ffi::c_void,
marker::PhantomData,
ptr::{addr_of_mut, null}, ptr::{addr_of_mut, null},
sync::atomic::{compiler_fence, Ordering}, sync::atomic::{compiler_fence, Ordering},
}; };
@ -19,30 +20,29 @@ use crate::{
inprocess_fork::{child_signal_handlers, ForkHandlerFuncPtr}, inprocess_fork::{child_signal_handlers, ForkHandlerFuncPtr},
HasObservers, HasObservers,
}, },
inputs::UsesInput,
Error, Error,
}; };
/// The inmem fork executor's hooks. /// The inmem fork executor's hooks.
#[derive(Debug)] #[derive(Debug)]
pub struct InChildProcessHooks { pub struct InChildProcessHooks<S> {
/// On crash C function pointer /// On crash C function pointer
pub crash_handler: *const c_void, pub crash_handler: *const c_void,
/// On timeout C function pointer /// On timeout C function pointer
pub timeout_handler: *const c_void, pub timeout_handler: *const c_void,
phantom: PhantomData<S>,
} }
impl ExecutorHook for InChildProcessHooks { impl<S> ExecutorHook<S> for InChildProcessHooks<S>
where
S: UsesInput,
{
/// Init this hook /// Init this hook
fn init<E: HasObservers, S>(&mut self, _state: &mut S) {} fn init<E: HasObservers>(&mut self, _state: &mut S) {}
/// Call before running a target. /// Call before running a target.
fn pre_exec<EM, I, S, Z>( fn pre_exec(&mut self, _state: &mut S, _input: &S::Input) {
&mut self,
_fuzzer: &mut Z,
_state: &mut S,
_mgr: &mut EM,
_input: &I,
) {
unsafe { unsafe {
let data = addr_of_mut!(FORK_EXECUTOR_GLOBAL_DATA); let data = addr_of_mut!(FORK_EXECUTOR_GLOBAL_DATA);
(*data).crash_handler = self.crash_handler; (*data).crash_handler = self.crash_handler;
@ -51,17 +51,10 @@ impl ExecutorHook for InChildProcessHooks {
} }
} }
fn post_exec<EM, I, S, Z>( fn post_exec(&mut self, _state: &mut S, _input: &S::Input) {}
&mut self,
_fuzzer: &mut Z,
_state: &mut S,
_mgr: &mut EM,
_input: &I,
) {
}
} }
impl InChildProcessHooks { impl<S> InChildProcessHooks<S> {
/// Create new [`InChildProcessHooks`]. /// Create new [`InChildProcessHooks`].
pub fn new<E>() -> Result<Self, Error> pub fn new<E>() -> Result<Self, Error>
where where
@ -77,6 +70,7 @@ impl InChildProcessHooks {
Ok(Self { Ok(Self {
crash_handler: child_signal_handlers::child_crash_handler::<E> as *const c_void, crash_handler: child_signal_handlers::child_crash_handler::<E> as *const c_void,
timeout_handler: child_signal_handlers::child_timeout_handler::<E> as *const c_void, timeout_handler: child_signal_handlers::child_timeout_handler::<E> as *const c_void,
phantom: PhantomData,
}) })
} }
} }
@ -87,6 +81,7 @@ impl InChildProcessHooks {
Self { Self {
crash_handler: null(), crash_handler: null(),
timeout_handler: null(), timeout_handler: null(),
phantom: PhantomData,
} }
} }
} }

View File

@ -1,7 +1,7 @@
//! Hooks for the executors. //! Hooks for the executors.
//! These will be executed right before and after the executor's harness run. //! These will be executed right before and after the executor's harness run.
use crate::executors::HasObservers; use crate::{executors::HasObservers, inputs::UsesInput};
/// windows crash/timeout handler and asan death callback /// windows crash/timeout handler and asan death callback
#[cfg(windows)] #[cfg(windows)]
@ -23,80 +23,58 @@ pub mod inprocess;
pub mod timer; pub mod timer;
/// The hook that runs before and after the executor runs the target /// The hook that runs before and after the executor runs the target
pub trait ExecutorHook { pub trait ExecutorHook<S>
where
S: UsesInput,
{
/// Init this hook /// Init this hook
fn init<E: HasObservers, S>(&mut self, state: &mut S); fn init<E: HasObservers>(&mut self, state: &mut S);
/// The hook that runs before runs the target /// The hook that runs before runs the target
fn pre_exec<EM, I, S, Z>(&mut self, fuzzer: &mut Z, state: &mut S, mgr: &mut EM, input: &I); fn pre_exec(&mut self, state: &mut S, input: &S::Input);
/// The hook that runs before runs the target /// The hook that runs before runs the target
fn post_exec<EM, I, S, Z>(&mut self, fuzzer: &mut Z, state: &mut S, mgr: &mut EM, input: &I); fn post_exec(&mut self, state: &mut S, input: &S::Input);
} }
/// The hook that runs before and after the executor runs the target /// The hook that runs before and after the executor runs the target
pub trait ExecutorHooksTuple { pub trait ExecutorHooksTuple<S>
/// Init these hooks
fn init_all<E: HasObservers, S>(&mut self, state: &mut S);
/// The hooks that runs before runs the target
fn pre_exec_all<EM, I, S, Z>(&mut self, fuzzer: &mut Z, state: &mut S, mgr: &mut EM, input: &I);
/// The hooks that runs after runs the target
fn post_exec_all<EM, I, S, Z>(
&mut self,
fuzzer: &mut Z,
state: &mut S,
mgr: &mut EM,
input: &I,
);
}
impl ExecutorHooksTuple for () {
fn init_all<E, S>(&mut self, _state: &mut S) {}
fn pre_exec_all<EM, I, S, Z>(
&mut self,
_fuzzer: &mut Z,
_state: &mut S,
_mgr: &mut EM,
_input: &I,
) {
}
fn post_exec_all<EM, I, S, Z>(
&mut self,
_fuzzer: &mut Z,
_state: &mut S,
_mgr: &mut EM,
_input: &I,
) {
}
}
impl<Head, Tail> ExecutorHooksTuple for (Head, Tail)
where where
Head: ExecutorHook, S: UsesInput,
Tail: ExecutorHooksTuple,
{ {
fn init_all<E: HasObservers, S>(&mut self, state: &mut S) { /// Init these hooks
self.0.init::<E, S>(state); fn init_all<E: HasObservers>(&mut self, state: &mut S);
self.1.init_all::<E, S>(state); /// The hooks that runs before runs the target
fn pre_exec_all(&mut self, state: &mut S, input: &S::Input);
/// The hooks that runs after runs the target
fn post_exec_all(&mut self, state: &mut S, input: &S::Input);
} }
fn pre_exec_all<EM, I, S, Z>( impl<S> ExecutorHooksTuple<S> for ()
&mut self, where
fuzzer: &mut Z, S: UsesInput,
state: &mut S, {
mgr: &mut EM, fn init_all<E: HasObservers>(&mut self, _state: &mut S) {}
input: &I, fn pre_exec_all(&mut self, _state: &mut S, _input: &S::Input) {}
) { fn post_exec_all(&mut self, _state: &mut S, _input: &S::Input) {}
self.0.pre_exec(fuzzer, state, mgr, input);
self.1.pre_exec_all(fuzzer, state, mgr, input);
} }
fn post_exec_all<EM, I, S, Z>( impl<Head, Tail, S> ExecutorHooksTuple<S> for (Head, Tail)
&mut self, where
fuzzer: &mut Z, S: UsesInput,
state: &mut S, Head: ExecutorHook<S>,
mgr: &mut EM, Tail: ExecutorHooksTuple<S>,
input: &I, {
) { fn init_all<E: HasObservers>(&mut self, state: &mut S) {
self.0.post_exec(fuzzer, state, mgr, input); self.0.init::<E>(state);
self.1.post_exec_all(fuzzer, state, mgr, input); self.1.init_all::<E>(state);
}
fn pre_exec_all(&mut self, state: &mut S, input: &S::Input) {
self.0.pre_exec(state, input);
self.1.pre_exec_all(state, input);
}
fn post_exec_all(&mut self, state: &mut S, input: &S::Input) {
self.0.post_exec(state, input);
self.1.post_exec_all(state, input);
} }
} }

View File

@ -122,7 +122,7 @@ pub mod unix_signal_handler {
_context: Option<&mut ucontext_t>, _context: Option<&mut ucontext_t>,
data: &mut InProcessExecutorHandlerData, data: &mut InProcessExecutorHandlerData,
) where ) where
E: HasObservers + HasInProcessHooks, E: HasObservers + HasInProcessHooks<E::State>,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>, EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>, OF: Feedback<E::State>,
E::State: HasExecutions + HasSolutions + HasCorpus, E::State: HasExecutions + HasSolutions + HasCorpus,

View File

@ -233,7 +233,7 @@ pub mod windows_exception_handler {
global_state: *mut c_void, global_state: *mut c_void,
_p1: *mut u8, _p1: *mut u8,
) where ) where
E: HasObservers + HasInProcessHooks, E: HasObservers + HasInProcessHooks<E::State>,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>, EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>, OF: Feedback<E::State>,
E::State: State + HasExecutions + HasSolutions + HasCorpus, E::State: State + HasExecutions + HasSolutions + HasCorpus,

View File

@ -36,20 +36,20 @@ use crate::{
/// The internal state of `GenericInProcessExecutor`. /// The internal state of `GenericInProcessExecutor`.
pub struct GenericInProcessExecutorInner<HT, OT, S> pub struct GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
/// The observers, observing each run /// The observers, observing each run
pub(super) observers: OT, pub(super) observers: OT,
// Crash and timeout hah // Crash and timeout hah
pub(super) hooks: (InProcessHooks, HT), pub(super) hooks: (InProcessHooks<S>, HT),
phantom: PhantomData<S>, phantom: PhantomData<S>,
} }
impl<HT, OT, S> Debug for GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> Debug for GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: State, S: State,
{ {
@ -62,7 +62,7 @@ where
impl<HT, OT, S> UsesState for GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> UsesState for GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -71,7 +71,7 @@ where
impl<HT, OT, S> UsesObservers for GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> UsesObservers for GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -80,7 +80,7 @@ where
impl<HT, OT, S> HasObservers for GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> HasObservers for GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -97,7 +97,7 @@ where
impl<HT, OT, S> GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -160,7 +160,7 @@ where
impl<HT, OT, S> GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: HasExecutions + HasSolutions + HasCorpus + State, S: HasExecutions + HasSolutions + HasCorpus + State,
{ {
@ -173,7 +173,7 @@ where
event_mgr: &mut EM, event_mgr: &mut EM,
) -> Result<Self, Error> ) -> Result<Self, Error>
where where
E: Executor<EM, Z, State = S> + HasObservers + HasInProcessHooks, E: Executor<EM, Z, State = S> + HasObservers + HasInProcessHooks<S>,
EM: EventFirer<State = S> + EventRestarter, EM: EventFirer<State = S> + EventRestarter,
OF: Feedback<S>, OF: Feedback<S>,
S: State, S: State,
@ -200,7 +200,7 @@ where
exec_tmout: Duration, exec_tmout: Duration,
) -> Result<Self, Error> ) -> Result<Self, Error>
where where
E: Executor<EM, Z, State = S> + HasObservers + HasInProcessHooks, E: Executor<EM, Z, State = S> + HasObservers + HasInProcessHooks<S>,
EM: EventFirer<State = S> + EventRestarter, EM: EventFirer<State = S> + EventRestarter,
OF: Feedback<S>, OF: Feedback<S>,
S: State, S: State,
@ -229,7 +229,7 @@ where
timeout: Duration, timeout: Duration,
) -> Result<Self, Error> ) -> Result<Self, Error>
where where
E: Executor<EM, Z, State = S> + HasObservers + HasInProcessHooks, E: Executor<EM, Z, State = S> + HasObservers + HasInProcessHooks<S>,
EM: EventFirer<State = S> + EventRestarter, EM: EventFirer<State = S> + EventRestarter,
OF: Feedback<S>, OF: Feedback<S>,
S: State, S: State,
@ -237,7 +237,7 @@ where
{ {
let default = InProcessHooks::new::<E, EM, OF, Z>(timeout)?; let default = InProcessHooks::new::<E, EM, OF, Z>(timeout)?;
let mut hooks = tuple_list!(default).merge(user_hooks); let mut hooks = tuple_list!(default).merge(user_hooks);
hooks.init_all::<Self, S>(state); hooks.init_all::<Self>(state);
#[cfg(windows)] #[cfg(windows)]
// Some initialization necessary for windows. // Some initialization necessary for windows.
@ -271,32 +271,32 @@ where
/// The inprocess handlers /// The inprocess handlers
#[inline] #[inline]
pub fn hooks(&self) -> &(InProcessHooks, HT) { pub fn hooks(&self) -> &(InProcessHooks<S>, HT) {
&self.hooks &self.hooks
} }
/// The inprocess handlers (mutable) /// The inprocess handlers (mutable)
#[inline] #[inline]
pub fn hooks_mut(&mut self) -> &mut (InProcessHooks, HT) { pub fn hooks_mut(&mut self) -> &mut (InProcessHooks<S>, HT) {
&mut self.hooks &mut self.hooks
} }
} }
impl<HT, OT, S> HasInProcessHooks for GenericInProcessExecutorInner<HT, OT, S> impl<HT, OT, S> HasInProcessHooks<S> for GenericInProcessExecutorInner<HT, OT, S>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions + HasSolutions + HasCorpus, S: State + HasExecutions + HasSolutions + HasCorpus,
{ {
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks(&self) -> &InProcessHooks { fn inprocess_hooks(&self) -> &InProcessHooks<S> {
&self.hooks.0 &self.hooks.0
} }
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks { fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks<S> {
&mut self.hooks.0 &mut self.hooks.0
} }
} }

View File

@ -62,7 +62,7 @@ pub struct GenericInProcessExecutor<H, HB, HT, OT, S>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -75,7 +75,7 @@ impl<H, HB, HT, OT, S> Debug for GenericInProcessExecutor<H, HB, HT, OT, S>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: State, S: State,
{ {
@ -91,7 +91,7 @@ impl<H, HB, HT, OT, S> UsesState for GenericInProcessExecutor<H, HB, HT, OT, S>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -102,7 +102,7 @@ impl<H, HB, HT, OT, S> UsesObservers for GenericInProcessExecutor<H, HB, HT, OT,
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -114,7 +114,7 @@ where
EM: UsesState<State = S>, EM: UsesState<State = S>,
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions, S: State + HasExecutions,
Z: UsesState<State = S>, Z: UsesState<State = S>,
@ -132,11 +132,11 @@ where
self.inner self.inner
.enter_target(fuzzer, state, mgr, input, executor_ptr); .enter_target(fuzzer, state, mgr, input, executor_ptr);
} }
self.inner.hooks.pre_exec_all(fuzzer, state, mgr, input); self.inner.hooks.pre_exec_all(state, input);
let ret = (self.harness_fn.borrow_mut())(input); let ret = (self.harness_fn.borrow_mut())(input);
self.inner.hooks.post_exec_all(fuzzer, state, mgr, input); self.inner.hooks.post_exec_all(state, input);
self.inner.leave_target(fuzzer, state, mgr, input); self.inner.leave_target(fuzzer, state, mgr, input);
Ok(ret) Ok(ret)
} }
@ -146,7 +146,7 @@ impl<H, HB, HT, OT, S> HasObservers for GenericInProcessExecutor<H, HB, HT, OT,
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -269,7 +269,7 @@ impl<H, HB, HT, OT, S> GenericInProcessExecutor<H, HB, HT, OT, S>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions + HasSolutions + HasCorpus, S: State + HasExecutions + HasSolutions + HasCorpus,
{ {
@ -377,43 +377,46 @@ where
/// The inprocess handlers /// The inprocess handlers
#[inline] #[inline]
pub fn hooks(&self) -> &(InProcessHooks, HT) { pub fn hooks(&self) -> &(InProcessHooks<S>, HT) {
self.inner.hooks() self.inner.hooks()
} }
/// The inprocess handlers (mutable) /// The inprocess handlers (mutable)
#[inline] #[inline]
pub fn hooks_mut(&mut self) -> &mut (InProcessHooks, HT) { pub fn hooks_mut(&mut self) -> &mut (InProcessHooks<S>, HT) {
self.inner.hooks_mut() self.inner.hooks_mut()
} }
} }
/// The struct has [`InProcessHooks`]. /// The struct has [`InProcessHooks`].
pub trait HasInProcessHooks { pub trait HasInProcessHooks<S>
where
S: UsesInput,
{
/// Get the in-process handlers. /// Get the in-process handlers.
fn inprocess_hooks(&self) -> &InProcessHooks; fn inprocess_hooks(&self) -> &InProcessHooks<S>;
/// Get the mut in-process handlers. /// Get the mut in-process handlers.
fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks; fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks<S>;
} }
impl<H, HB, HT, OT, S> HasInProcessHooks for GenericInProcessExecutor<H, HB, HT, OT, S> impl<H, HB, HT, OT, S> HasInProcessHooks<S> for GenericInProcessExecutor<H, HB, HT, OT, S>
where where
H: FnMut(&<S as UsesInput>::Input) -> ExitKind + ?Sized, H: FnMut(&<S as UsesInput>::Input) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions + HasSolutions + HasCorpus, S: State + HasExecutions + HasSolutions + HasCorpus,
{ {
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks(&self) -> &InProcessHooks { fn inprocess_hooks(&self) -> &InProcessHooks<S> {
self.inner.inprocess_hooks() self.inner.inprocess_hooks()
} }
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks { fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks<S> {
self.inner.inprocess_hooks_mut() self.inner.inprocess_hooks_mut()
} }
} }

View File

@ -48,7 +48,7 @@ pub struct StatefulGenericInProcessExecutor<H, HB, HT, OT, S, ES>
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -65,7 +65,7 @@ impl<H, HB, HT, OT, S, ES> Debug for StatefulGenericInProcessExecutor<H, HB, HT,
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: State, S: State,
{ {
@ -81,7 +81,7 @@ impl<H, HB, HT, OT, S, ES> UsesState for StatefulGenericInProcessExecutor<H, HB,
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -92,7 +92,7 @@ impl<H, HB, HT, OT, S, ES> UsesObservers for StatefulGenericInProcessExecutor<H,
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -105,7 +105,7 @@ where
EM: UsesState<State = S>, EM: UsesState<State = S>,
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions, S: State + HasExecutions,
Z: UsesState<State = S>, Z: UsesState<State = S>,
@ -123,11 +123,11 @@ where
self.inner self.inner
.enter_target(fuzzer, state, mgr, input, executor_ptr); .enter_target(fuzzer, state, mgr, input, executor_ptr);
} }
self.inner.hooks.pre_exec_all(fuzzer, state, mgr, input); self.inner.hooks.pre_exec_all(state, input);
let ret = (self.harness_fn.borrow_mut())(input, &mut self.exposed_executor_state); let ret = (self.harness_fn.borrow_mut())(input, &mut self.exposed_executor_state);
self.inner.hooks.post_exec_all(fuzzer, state, mgr, input); self.inner.hooks.post_exec_all(state, input);
self.inner.leave_target(fuzzer, state, mgr, input); self.inner.leave_target(fuzzer, state, mgr, input);
Ok(ret) Ok(ret)
} }
@ -137,7 +137,7 @@ impl<H, HB, HT, OT, S, ES> HasObservers for StatefulGenericInProcessExecutor<H,
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -266,7 +266,7 @@ impl<H, HB, HT, OT, S, ES> StatefulGenericInProcessExecutor<H, HB, HT, OT, S, ES
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
{ {
@ -285,7 +285,7 @@ impl<H, HB, HT, OT, S, ES> StatefulGenericInProcessExecutor<H, HB, HT, OT, S, ES
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions + HasSolutions + HasCorpus, S: State + HasExecutions + HasSolutions + HasCorpus,
{ {
@ -398,35 +398,35 @@ where
/// The inprocess handlers /// The inprocess handlers
#[inline] #[inline]
pub fn hooks(&self) -> &(InProcessHooks, HT) { pub fn hooks(&self) -> &(InProcessHooks<S>, HT) {
self.inner.hooks() self.inner.hooks()
} }
/// The inprocess handlers (mutable) /// The inprocess handlers (mutable)
#[inline] #[inline]
pub fn hooks_mut(&mut self) -> &mut (InProcessHooks, HT) { pub fn hooks_mut(&mut self) -> &mut (InProcessHooks<S>, HT) {
self.inner.hooks_mut() self.inner.hooks_mut()
} }
} }
impl<H, HB, HT, OT, S, ES> HasInProcessHooks impl<H, HB, HT, OT, S, ES> HasInProcessHooks<S>
for StatefulGenericInProcessExecutor<H, HB, HT, OT, S, ES> for StatefulGenericInProcessExecutor<H, HB, HT, OT, S, ES>
where where
H: FnMut(&<S as UsesInput>::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&<S as UsesInput>::Input, &mut ES) -> ExitKind + ?Sized,
HB: BorrowMut<H>, HB: BorrowMut<H>,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State + HasExecutions + HasSolutions + HasCorpus, S: State + HasExecutions + HasSolutions + HasCorpus,
{ {
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks(&self) -> &InProcessHooks { fn inprocess_hooks(&self) -> &InProcessHooks<S> {
self.inner.inprocess_hooks() self.inner.inprocess_hooks()
} }
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks { fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks<S> {
self.inner.inprocess_hooks_mut() self.inner.inprocess_hooks_mut()
} }
} }

View File

@ -40,11 +40,11 @@ where
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: UsesInput, S: UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
pub(super) hooks: (InChildProcessHooks, HT), pub(super) hooks: (InChildProcessHooks<S>, HT),
pub(super) shmem_provider: SP, pub(super) shmem_provider: SP,
pub(super) observers: OT, pub(super) observers: OT,
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -59,14 +59,13 @@ where
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: UsesInput, S: UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple + Debug, HT: ExecutorHooksTuple<S> + Debug,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("GenericInProcessForkExecutorInner") f.debug_struct("GenericInProcessForkExecutorInner")
.field("hooks", &self.hooks)
.field("observers", &self.observers) .field("observers", &self.observers)
.field("shmem_provider", &self.shmem_provider) .field("shmem_provider", &self.shmem_provider)
.field("itimerspec", &self.itimerspec) .field("itimerspec", &self.itimerspec)
@ -90,7 +89,7 @@ where
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -102,7 +101,7 @@ where
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: State + UsesInput, S: State + UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: EventFirer<State = S> + EventRestarter<State = S>, EM: EventFirer<State = S> + EventRestarter<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -116,7 +115,7 @@ where
self.shmem_provider.post_fork(true)?; self.shmem_provider.post_fork(true)?;
self.enter_target(fuzzer, state, mgr, input); self.enter_target(fuzzer, state, mgr, input);
self.hooks.pre_exec_all(fuzzer, state, mgr, input); self.hooks.pre_exec_all(state, input);
self.observers self.observers
.pre_exec_child_all(state, input) .pre_exec_child_all(state, input)
@ -152,7 +151,7 @@ where
.post_exec_child_all(state, input, &ExitKind::Ok) .post_exec_child_all(state, input, &ExitKind::Ok)
.expect("Failed to run post_exec on observers"); .expect("Failed to run post_exec on observers");
self.hooks.post_exec_all(fuzzer, state, mgr, input); self.hooks.post_exec_all(state, input);
self.leave_target(fuzzer, state, mgr, input); self.leave_target(fuzzer, state, mgr, input);
libc::_exit(0); libc::_exit(0);
@ -193,7 +192,7 @@ where
impl<HT, OT, S, SP, EM, Z> GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> impl<HT, OT, S, SP, EM, Z> GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
S: State, S: State,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
SP: ShMemProvider, SP: ShMemProvider,
@ -253,7 +252,7 @@ where
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let default_hooks = InChildProcessHooks::new::<Self>()?; let default_hooks = InChildProcessHooks::new::<Self>()?;
let mut hooks = tuple_list!(default_hooks).merge(userhooks); let mut hooks = tuple_list!(default_hooks).merge(userhooks);
hooks.init_all::<Self, S>(state); hooks.init_all::<Self>(state);
let milli_sec = timeout.as_millis(); let milli_sec = timeout.as_millis();
let it_value = libc::timespec { let it_value = libc::timespec {
@ -292,7 +291,7 @@ where
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let default_hooks = InChildProcessHooks::new::<Self>()?; let default_hooks = InChildProcessHooks::new::<Self>()?;
let mut hooks = tuple_list!(default_hooks).merge(userhooks); let mut hooks = tuple_list!(default_hooks).merge(userhooks);
hooks.init_all::<Self, S>(state); hooks.init_all::<Self>(state);
let milli_sec = timeout.as_millis(); let milli_sec = timeout.as_millis();
let it_value = Timeval { let it_value = Timeval {
@ -320,7 +319,7 @@ where
impl<HT, OT, S, SP, EM, Z> UsesObservers for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> impl<HT, OT, S, SP, EM, Z> UsesObservers for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
SP: ShMemProvider, SP: ShMemProvider,
@ -332,7 +331,7 @@ where
impl<HT, OT, S, SP, EM, Z> HasObservers for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> impl<HT, OT, S, SP, EM, Z> HasObservers for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where where
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
S: State, S: State,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
SP: ShMemProvider, SP: ShMemProvider,

View File

@ -86,7 +86,7 @@ where
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: UsesInput, S: UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -101,7 +101,7 @@ where
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: UsesInput, S: UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple + Debug, HT: ExecutorHooksTuple<S> + Debug,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -129,7 +129,7 @@ where
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -143,7 +143,7 @@ where
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: State + HasExecutions, S: State + HasExecutions,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: EventFirer<State = S> + EventRestarter<State = S>, EM: EventFirer<State = S> + EventRestarter<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -181,7 +181,7 @@ where
impl<'a, H, HT, OT, S, SP, EM, Z, OF> GenericInProcessForkExecutor<'a, H, HT, OT, S, SP, EM, Z> impl<'a, H, HT, OT, S, SP, EM, Z, OF> GenericInProcessForkExecutor<'a, H, HT, OT, S, SP, EM, Z>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
SP: ShMemProvider, SP: ShMemProvider,
EM: EventFirer<State = S> + EventRestarter<State = S>, EM: EventFirer<State = S> + EventRestarter<State = S>,
@ -233,7 +233,7 @@ impl<'a, H, HT, OT, S, SP, EM, Z> UsesObservers
for GenericInProcessForkExecutor<'a, H, HT, OT, S, SP, EM, Z> for GenericInProcessForkExecutor<'a, H, HT, OT, S, SP, EM, Z>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
SP: ShMemProvider, SP: ShMemProvider,
@ -247,7 +247,7 @@ impl<'a, H, HT, OT, S, SP, EM, Z> HasObservers
for GenericInProcessForkExecutor<'a, H, HT, OT, S, SP, EM, Z> for GenericInProcessForkExecutor<'a, H, HT, OT, S, SP, EM, Z>
where where
H: FnMut(&S::Input) -> ExitKind + ?Sized, H: FnMut(&S::Input) -> ExitKind + ?Sized,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
S: State, S: State,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
SP: ShMemProvider, SP: ShMemProvider,

View File

@ -69,7 +69,7 @@ where
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: UsesInput, S: UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -86,7 +86,7 @@ where
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: UsesInput, S: UsesInput,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple + Debug, HT: ExecutorHooksTuple<S> + Debug,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -114,7 +114,7 @@ where
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: UsesState<State = S>, EM: UsesState<State = S>,
Z: UsesState<State = S>, Z: UsesState<State = S>,
{ {
@ -128,7 +128,7 @@ where
OT: ObserversTuple<S> + Debug, OT: ObserversTuple<S> + Debug,
S: State + HasExecutions, S: State + HasExecutions,
SP: ShMemProvider, SP: ShMemProvider,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
EM: EventFirer<State = S> + EventRestarter<State = S>, EM: EventFirer<State = S> + EventRestarter<State = S>,
Z: HasObjective<Objective = OF, State = S>, Z: HasObjective<Objective = OF, State = S>,
OF: Feedback<S>, OF: Feedback<S>,
@ -168,7 +168,7 @@ impl<'a, H, HT, OT, S, SP, ES, EM, Z, OF>
StatefulGenericInProcessForkExecutor<'a, H, HT, OT, S, SP, ES, EM, Z> StatefulGenericInProcessForkExecutor<'a, H, HT, OT, S, SP, ES, EM, Z>
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
SP: ShMemProvider, SP: ShMemProvider,
Z: UsesState<State = S>, Z: UsesState<State = S>,
@ -223,7 +223,7 @@ impl<'a, H, HT, OT, S, SP, ES, EM, Z> UsesObservers
for StatefulGenericInProcessForkExecutor<'a, H, HT, OT, S, SP, ES, EM, Z> for StatefulGenericInProcessForkExecutor<'a, H, HT, OT, S, SP, ES, EM, Z>
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
S: State, S: State,
SP: ShMemProvider, SP: ShMemProvider,
@ -237,7 +237,7 @@ impl<'a, H, HT, OT, S, SP, ES, EM, Z> HasObservers
for StatefulGenericInProcessForkExecutor<'a, H, HT, OT, S, SP, ES, EM, Z> for StatefulGenericInProcessForkExecutor<'a, H, HT, OT, S, SP, ES, EM, Z>
where where
H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized, H: FnMut(&S::Input, &mut ES) -> ExitKind + ?Sized,
HT: ExecutorHooksTuple, HT: ExecutorHooksTuple<S>,
S: State, S: State,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,
SP: ShMemProvider, SP: ShMemProvider,

View File

@ -230,7 +230,7 @@ where
} }
#[cfg(windows)] #[cfg(windows)]
impl<'a, 'b, 'c, H, OT, RT, S> HasInProcessHooks impl<'a, 'b, 'c, H, OT, RT, S> HasInProcessHooks<S>
for FridaInProcessExecutor<'a, 'b, 'c, H, OT, RT, S> for FridaInProcessExecutor<'a, 'b, 'c, H, OT, RT, S>
where where
H: FnMut(&S::Input) -> ExitKind, H: FnMut(&S::Input) -> ExitKind,
@ -241,13 +241,13 @@ where
{ {
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks(&self) -> &InProcessHooks { fn inprocess_hooks(&self) -> &InProcessHooks<S> {
&self.base.hooks().0 &self.base.hooks().0
} }
/// the timeout handler /// the timeout handler
#[inline] #[inline]
fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks { fn inprocess_hooks_mut(&mut self) -> &mut InProcessHooks<S> {
&mut self.base.hooks_mut().0 &mut self.base.hooks_mut().0
} }
} }

View File

@ -113,7 +113,7 @@ pub unsafe fn inproc_qemu_timeout_handler<'a, E, EM, OF, Z>(
context: Option<&'a mut ucontext_t>, context: Option<&'a mut ucontext_t>,
data: &'a mut InProcessExecutorHandlerData, data: &'a mut InProcessExecutorHandlerData,
) where ) where
E: Executor<EM, Z> + HasObservers + HasInProcessHooks, E: Executor<EM, Z> + HasObservers + HasInProcessHooks<E::State>,
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>, EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>, OF: Feedback<E::State>,
E::State: HasSolutions + HasCorpus + HasExecutions, E::State: HasSolutions + HasCorpus + HasExecutions,
@ -135,7 +135,7 @@ where
{ {
pub fn new<E, EM, OF, OT, Z>(hooks: &'a mut QemuHooks<QT, S>) -> Result<Self, Error> pub fn new<E, EM, OF, OT, Z>(hooks: &'a mut QemuHooks<QT, S>) -> Result<Self, Error>
where where
E: Executor<EM, Z, State = S> + HasInProcessHooks + HasObservers, E: Executor<EM, Z, State = S> + HasInProcessHooks<S> + HasObservers,
EM: EventFirer<State = S> + EventRestarter<State = S>, EM: EventFirer<State = S> + EventRestarter<State = S>,
OF: Feedback<S>, OF: Feedback<S>,
OT: ObserversTuple<S>, OT: ObserversTuple<S>,

View File

@ -56,28 +56,63 @@ pub static SHR_4: Ngram4 = Ngram4::from_array([1, 1, 1, 1]);
#[rustversion::nightly] #[rustversion::nightly]
pub static SHR_8: Ngram8 = Ngram8::from_array([1, 1, 1, 1, 1, 1, 1, 1]); pub static SHR_8: Ngram8 = Ngram8::from_array([1, 1, 1, 1, 1, 1, 1, 1]);
#[cfg(any(
feature = "sancov_ngram4",
feature = "sancov_ngram8",
feature = "sancov_ctx"
))]
use core::marker::PhantomData;
/// The hook to initialize ngram everytime we run the harness /// The hook to initialize ngram everytime we run the harness
#[cfg(feature = "sancov_ngram4")] #[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly] #[rustversion::nightly]
#[derive(Default, Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct NgramHook {} pub struct NgramHook<S>
where
S: libafl::inputs::UsesInput,
{
phantom: PhantomData<S>,
}
/// The hook to initialize ctx everytime we run the harness /// The hook to initialize ctx everytime we run the harness
#[cfg(feature = "sancov_ctx")] #[cfg(feature = "sancov_ctx")]
#[derive(Default, Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct CtxHook {} pub struct CtxHook<S> {
phantom: PhantomData<S>,
}
#[cfg(feature = "sancov_ctx")]
impl<S> CtxHook<S>
where
S: libafl::inputs::UsesInput,
{
/// The constructor for this struct
#[must_use]
pub fn new() -> Self {
Self {
phantom: PhantomData,
}
}
}
#[cfg(feature = "sancov_ctx")]
impl<S> Default for CtxHook<S>
where
S: libafl::inputs::UsesInput,
{
fn default() -> Self {
Self::new()
}
}
#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))] #[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly] #[rustversion::nightly]
impl ExecutorHook for NgramHook { impl<S> ExecutorHook<S> for NgramHook<S>
fn init<E: HasObservers, S>(&mut self, _state: &mut S) {} where
fn pre_exec<EM, I, S, Z>( S: libafl::inputs::UsesInput,
&mut self, {
_fuzzer: &mut Z, fn init<E: HasObservers>(&mut self, _state: &mut S) {}
_state: &mut S, fn pre_exec(&mut self, _state: &mut S, _input: &S::Input) {
_mgr: &mut EM,
_input: &I,
) {
#[cfg(feature = "sancov_ngram4")] #[cfg(feature = "sancov_ngram4")]
unsafe { unsafe {
PREV_ARRAY_4 = Ngram4::from_array([0, 0, 0, 0]); PREV_ARRAY_4 = Ngram4::from_array([0, 0, 0, 0]);
@ -88,38 +123,47 @@ impl ExecutorHook for NgramHook {
PREV_ARRAY_8 = Ngram8::from_array([0, 0, 0, 0, 0, 0, 0, 0]); PREV_ARRAY_8 = Ngram8::from_array([0, 0, 0, 0, 0, 0, 0, 0]);
} }
} }
fn post_exec<EM, I, S, Z>( fn post_exec(&mut self, _state: &mut S, _input: &S::Input) {}
&mut self, }
_fuzzer: &mut Z,
_state: &mut S, #[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
_mgr: &mut EM, #[rustversion::nightly]
_input: &I, impl<S> NgramHook<S>
) { where
S: libafl::inputs::UsesInput,
{
/// The constructor for this struct
#[must_use]
pub fn new() -> Self {
Self {
phantom: PhantomData,
}
}
}
#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly]
impl<S> Default for NgramHook<S>
where
S: libafl::inputs::UsesInput,
{
fn default() -> Self {
Self::new()
} }
} }
#[cfg(feature = "sancov_ctx")] #[cfg(feature = "sancov_ctx")]
impl ExecutorHook for CtxHook { impl<S> ExecutorHook<S> for CtxHook<S>
fn init<E: HasObservers, S>(&mut self, _state: &mut S) {} where
fn pre_exec<EM, I, S, Z>( S: libafl::inputs::UsesInput,
&mut self, {
_fuzzer: &mut Z, fn init<E: HasObservers>(&mut self, _state: &mut S) {}
_state: &mut S, fn pre_exec(&mut self, _state: &mut S, _input: &S::Input) {
_mgr: &mut EM,
_input: &I,
) {
unsafe { unsafe {
__afl_prev_ctx = 0; __afl_prev_ctx = 0;
} }
} }
fn post_exec<EM, I, S, Z>( fn post_exec(&mut self, _state: &mut S, _input: &S::Input) {}
&mut self,
_fuzzer: &mut Z,
_state: &mut S,
_mgr: &mut EM,
_input: &I,
) {
}
} }
#[rustversion::nightly] #[rustversion::nightly]