From 969aa12c7e3d09ba6f86c42d4686d2f137809256 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Wed, 6 Mar 2024 19:05:32 +0100 Subject: [PATCH] aa (#1913) --- libafl/src/executors/inprocess/inner.rs | 114 --------------------- libafl/src/executors/inprocess/mod.rs | 20 +++- libafl/src/executors/inprocess/stateful.rs | 20 +++- 3 files changed, 30 insertions(+), 124 deletions(-) diff --git a/libafl/src/executors/inprocess/inner.rs b/libafl/src/executors/inprocess/inner.rs index 04afc5e660..5069e3894e 100644 --- a/libafl/src/executors/inprocess/inner.rs +++ b/libafl/src/executors/inprocess/inner.rs @@ -156,120 +156,6 @@ where } } -impl GenericInProcessExecutorInner<(), OT, S> -where - OT: ObserversTuple, - S: HasExecutions + HasSolutions + HasCorpus + State, -{ - /// Create a new in mem executor with the default timeout (5 sec) - pub fn new( - observers: OT, - fuzzer: &mut Z, - state: &mut S, - event_mgr: &mut EM, - ) -> Result - where - E: Executor + HasObservers + HasInProcessHooks, - EM: EventFirer + EventRestarter, - OF: Feedback, - S: State, - Z: HasObjective, - { - Self::with_timeout_generic::( - tuple_list!(), - observers, - fuzzer, - state, - event_mgr, - Duration::from_millis(5000), - ) - } - - /// Create a new in mem executor with the default timeout and use batch mode (5 sec) - /// Do not use batched mode timeouts with cmplog cores. It is not supported - #[cfg(all(feature = "std", target_os = "linux"))] - pub fn batched_timeouts( - observers: OT, - fuzzer: &mut Z, - state: &mut S, - event_mgr: &mut EM, - exec_tmout: Duration, - ) -> Result - where - E: Executor + HasObservers + HasInProcessHooks, - EM: EventFirer + EventRestarter, - OF: Feedback, - S: State, - Z: HasObjective, - { - let mut me = Self::with_timeout_generic::( - tuple_list!(), - observers, - fuzzer, - state, - event_mgr, - exec_tmout, - )?; - me.hooks_mut().0.timer_mut().batch_mode = true; - Ok(me) - } - - /// Create a new in mem executor. - /// Caution: crash and restart in one of them will lead to odd behavior if multiple are used, - /// depending on different corpus or state. - /// * `user_hooks` - the hooks run before and after the harness's execution - /// * `harness_fn` - the harness, executing the function - /// * `observers` - the observers observing the target during execution - /// This may return an error on unix, if signal handler setup fails - pub fn with_timeout( - observers: OT, - _fuzzer: &mut Z, - state: &mut S, - _event_mgr: &mut EM, - timeout: Duration, - ) -> Result - where - E: Executor + HasObservers + HasInProcessHooks, - EM: EventFirer + EventRestarter, - OF: Feedback, - S: State, - Z: HasObjective, - { - let default = InProcessHooks::new::(timeout)?; - let mut hooks = tuple_list!(default).merge(tuple_list!()); - hooks.init_all::(state); - - #[cfg(windows)] - // Some initialization necessary for windows. - unsafe { - /* - See https://github.com/AFLplusplus/LibAFL/pull/403 - This one reserves certain amount of memory for the stack. - If stack overflow happens during fuzzing on windows, the program is transferred to our exception handler for windows. - However, if we run out of the stack memory again in this exception handler, we'll crash with STATUS_ACCESS_VIOLATION. - We need this API call because with the llmp_compression - feature enabled, the exception handler uses a lot of stack memory (in the compression lib code) on release build. - As far as I have observed, the compression uses around 0x10000 bytes, but for safety let's just reserve 0x20000 bytes for our exception handlers. - This number 0x20000 could vary depending on the compilers optimization for future compression library changes. - */ - let mut stack_reserved = 0x20000; - SetThreadStackGuarantee(&mut stack_reserved)?; - } - - #[cfg(all(feature = "std", windows))] - { - // set timeout for the handler - *hooks.0.millis_sec_mut() = timeout.as_millis() as i64; - } - - Ok(Self { - observers, - hooks, - phantom: PhantomData, - }) - } -} - impl GenericInProcessExecutorInner where HT: ExecutorHooksTuple, diff --git a/libafl/src/executors/inprocess/mod.rs b/libafl/src/executors/inprocess/mod.rs index b0962d192a..515ed0aa56 100644 --- a/libafl/src/executors/inprocess/mod.rs +++ b/libafl/src/executors/inprocess/mod.rs @@ -189,7 +189,7 @@ where /// Create a new in mem executor with the default timeout and use batch mode(5 sec) #[cfg(all(feature = "std", target_os = "linux"))] - pub fn batched_timeouts( + pub fn batched_timeout( harness_fn: &'a mut H, observers: OT, fuzzer: &mut Z, @@ -204,8 +204,13 @@ where S: State, Z: HasObjective, { - let inner = GenericInProcessExecutorInner::batched_timeouts::( - observers, fuzzer, state, event_mgr, exec_tmout, + let inner = GenericInProcessExecutorInner::batched_timeout_generic::( + tuple_list!(), + observers, + fuzzer, + state, + event_mgr, + exec_tmout, )?; Ok(Self { @@ -237,8 +242,13 @@ where S: State, Z: HasObjective, { - let inner = GenericInProcessExecutorInner::with_timeout::( - observers, fuzzer, state, event_mgr, timeout, + let inner = GenericInProcessExecutorInner::with_timeout_generic::( + tuple_list!(), + observers, + fuzzer, + state, + event_mgr, + timeout, )?; Ok(Self { diff --git a/libafl/src/executors/inprocess/stateful.rs b/libafl/src/executors/inprocess/stateful.rs index f44a398663..601d1428f0 100644 --- a/libafl/src/executors/inprocess/stateful.rs +++ b/libafl/src/executors/inprocess/stateful.rs @@ -182,7 +182,7 @@ where /// Create a new in mem executor with the default timeout and use batch mode(5 sec) #[cfg(all(feature = "std", target_os = "linux"))] - pub fn batched_timeouts( + pub fn batched_timeout( harness_fn: &'a mut H, exposed_executor_state: ES, observers: OT, @@ -198,8 +198,13 @@ where S: State, Z: HasObjective, { - let inner = GenericInProcessExecutorInner::batched_timeouts::( - observers, fuzzer, state, event_mgr, exec_tmout, + let inner = GenericInProcessExecutorInner::batched_timeout_generic::( + tuple_list!(), + observers, + fuzzer, + state, + event_mgr, + exec_tmout, )?; Ok(Self { @@ -233,8 +238,13 @@ where S: State, Z: HasObjective, { - let inner = GenericInProcessExecutorInner::with_timeout::( - observers, fuzzer, state, event_mgr, timeout, + let inner = GenericInProcessExecutorInner::with_timeout_generic::( + tuple_list!(), + observers, + fuzzer, + state, + event_mgr, + timeout, )?; Ok(Self {