Skip to content

Commit

Permalink
Change when to setup the ctrl c handler. (AFLplusplus#2198)
Browse files Browse the repository at this point in the history
* copy

* fmt

* aa

* a

* Goodbye z3, i hope i won't build you forever

* doc

* fmt

* fix

* aa
  • Loading branch information
tokatoka authored May 16, 2024
1 parent 41d41f2 commit e31658b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
19 changes: 9 additions & 10 deletions libafl/src/events/llmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ where
handle.status()
}
ForkResult::Child => {
println!("AAA!");
self.shmem_provider.post_fork(true)?;
break (staterestorer, self.shmem_provider.clone(), core_id);
}
Expand Down Expand Up @@ -1607,16 +1608,6 @@ where
ctr = ctr.wrapping_add(1);
}
} else {
// At this point we are the fuzzer *NOT* the restarter.
// We setup signal handlers to clean up shmem segments used by state restorer
#[cfg(all(unix, not(miri)))]
if let Err(_e) =
unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) }
{
// We can live without a proper ctrl+c signal handler. Print and ignore.
log::error!("Failed to setup signal handlers: {_e}");
}

// We are the newly started fuzzing instance (i.e. on Windows), first, connect to our own restore map.
// We get here *only on Windows*, if we were started by a restarting fuzzer.
// A staterestorer and a receiver for single communication
Expand All @@ -1627,6 +1618,14 @@ where
)
};

// At this point we are the fuzzer *NOT* the restarter.
// We setup signal handlers to clean up shmem segments used by state restorer
#[cfg(all(unix, not(miri)))]
if let Err(_e) = unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } {
// We can live without a proper ctrl+c signal handler. Print and ignore.
log::error!("Failed to setup signal handlers: {_e}");
}

if let Some(core_id) = core_id {
let core_id: CoreId = core_id;
core_id.set_affinity()?;
Expand Down
18 changes: 8 additions & 10 deletions libafl/src/events/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,22 +537,20 @@ where
ctr = ctr.wrapping_add(1);
}
} else {
// At this point we are the fuzzer *NOT* the restarter.
// We setup signal handlers to clean up shmem segments used by state restorer
#[cfg(all(unix, not(miri)))]
if let Err(_e) =
unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) }
{
// We can live without a proper ctrl+c signal handler. Print and ignore.
log::error!("Failed to setup signal handlers: {_e}");
}

// We are the newly started fuzzing instance (i.e. on Windows), first, connect to our own restore map.
// We get here *only on Windows*, if we were started by a restarting fuzzer.
// A staterestorer and a receiver for single communication
StateRestorer::from_env(shmem_provider, _ENV_FUZZER_SENDER)?
};

// At this point we are the fuzzer *NOT* the restarter.
// We setup signal handlers to clean up shmem segments used by state restorer
#[cfg(all(unix, not(miri)))]
if let Err(_e) = unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } {
// We can live without a proper ctrl+c signal handler. Print and ignore.
log::error!("Failed to setup signal handlers: {_e}");
}

// If we're restarting, deserialize the old state.
let (state, mgr) = match staterestorer.restore::<(S, Duration, Vec<ClientStats>)>()? {
None => {
Expand Down
18 changes: 8 additions & 10 deletions libafl/src/events/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,6 @@ where
ctr = ctr.wrapping_add(1);
}
} else {
// At this point we are the fuzzer *NOT* the restarter.
// We setup signal handlers to clean up shmem segments used by state restorer
#[cfg(all(unix, not(miri)))]
if let Err(_e) =
unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) }
{
// We can live without a proper ctrl+c signal handler. Print and ignore.
log::error!("Failed to setup signal handlers: {_e}");
}

// We are the newly started fuzzing instance (i.e. on Windows), first, connect to our own restore map.
// We get here *only on Windows*, if we were started by a restarting fuzzer.
// A staterestorer and a receiver for single communication
Expand All @@ -1315,6 +1305,14 @@ where
)
};

// At this point we are the fuzzer *NOT* the restarter.
// We setup signal handlers to clean up shmem segments used by state restorer
#[cfg(all(unix, not(miri)))]
if let Err(_e) = unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } {
// We can live without a proper ctrl+c signal handler. Print and ignore.
log::error!("Failed to setup signal handlers: {_e}");
}

if let Some(core_id) = core_id {
let core_id: CoreId = core_id;
core_id.set_affinity()?;
Expand Down

0 comments on commit e31658b

Please sign in to comment.