Skip to content

Commit

Permalink
rename initate_stop to request_stop, should_stop to stop_requested an…
Browse files Browse the repository at this point in the history
…d reset_stop to discard_stop_request
  • Loading branch information
R9295 committed Jul 2, 2024
1 parent a743554 commit a32fab6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion libafl/src/events/centralized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ where
}
}
Event::Stop => {
state.initiate_stop();
state.request_stop();
}
_ => {
return Err(Error::unknown(format!(
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/events/llmp/mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ where
}
}
Event::Stop => {
state.initiate_stop();
state.request_stop();
}
_ => {
return Err(Error::unknown(format!(
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/events/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ where
Ok(())
}
Event::Stop => {
state.initiate_stop();
state.request_stop();
Ok(())
}
_ => Err(Error::unknown(format!(
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/events/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ where
}
}
Event::Stop => {
state.initiate_stop();
state.request_stop();
}
_ => {
return Err(Error::unknown(format!(
Expand Down
8 changes: 4 additions & 4 deletions libafl/src/fuzzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ where
loop {
// log::info!("Starting another fuzz_loop");
manager.maybe_report_progress(state, monitor_timeout)?;
if state.should_stop() {
state.reset_stop();
if state.stop_requested() {
state.discard_stop_request();
manager.on_shutdown()?;
break;
}
Expand Down Expand Up @@ -254,8 +254,8 @@ where

for _ in 0..iters {
manager.maybe_report_progress(state, monitor_timeout)?;
if state.should_stop() {
state.reset_stop();
if state.stop_requested() {
state.discard_stop_request();
break;
}
ret = Some(self.fuzz_one(stages, executor, state, manager)?);
Expand Down
8 changes: 4 additions & 4 deletions libafl/src/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ where
}
}

if state.should_stop() {
state.reset_stop();
if state.stop_requested() {
state.discard_stop_request();
manager.on_shutdown()?;
return Err(Error::shutting_down());
}
Expand Down Expand Up @@ -297,8 +297,8 @@ where
manager: &mut EM,
) -> Result<(), Error> {
self.iter_mut().try_for_each(|x| {
if state.should_stop() {
state.reset_stop();
if state.stop_requested() {
state.discard_stop_request();
manager.on_shutdown()?;
return Err(Error::shutting_down());
}
Expand Down
45 changes: 23 additions & 22 deletions libafl/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ pub struct StdState<I, C, R, SC> {
last_report_time: Option<Duration>,
/// The current index of the corpus; used to record for resumable fuzzing.
corpus_id: Option<CorpusId>,
/// Tell the fuzzer to stop at the start of the next fuzzing iteration.
should_stop: bool,
/// Request the fuzzer to stop at the start of the next stage
/// or at the beginning of the next fuzzing iteration
stop_requested: bool,
stage_stack: StageStack,
phantom: PhantomData<I>,
}
Expand Down Expand Up @@ -537,27 +538,27 @@ where

/// A trait for types that want to expose a stop API
pub trait Stoppable {
/// Check if should stop
fn should_stop(&self) -> bool;
/// Check if stop is requested
fn stop_requested(&self) -> bool;

/// Request to stop
fn initiate_stop(&mut self);
fn request_stop(&mut self);

/// Reset stop value
fn reset_stop(&mut self);
/// Discard the stop request
fn discard_stop_request(&mut self);
}

impl<I, C, R, SC> Stoppable for StdState<I, C, R, SC> {
fn initiate_stop(&mut self) {
self.should_stop = true;
fn request_stop(&mut self) {
self.stop_requested = true;
}

fn reset_stop(&mut self) {
self.should_stop = false;
fn discard_stop_request(&mut self) {
self.stop_requested = false;
}

fn should_stop(&self) -> bool {
self.should_stop
fn stop_requested(&self) -> bool {
self.stop_requested
}
}

Expand Down Expand Up @@ -1116,7 +1117,7 @@ where
corpus,
solutions,
max_size: DEFAULT_MAX_SIZE,
should_stop: false,
stop_requested: false,
#[cfg(feature = "introspection")]
introspection_monitor: ClientPerfMonitor::new(),
#[cfg(feature = "scalability_introspection")]
Expand Down Expand Up @@ -1165,7 +1166,7 @@ impl<I, C, R, SC> HasScalabilityMonitor for StdState<I, C, R, SC> {
pub struct NopState<I> {
metadata: SerdeAnyMap,
execution: u64,
should_stop: bool,
stop_requested: bool,
rand: StdRand,
phantom: PhantomData<I>,
}
Expand All @@ -1178,7 +1179,7 @@ impl<I> NopState<I> {
metadata: SerdeAnyMap::new(),
execution: 0,
rand: StdRand::default(),
should_stop: false,
stop_requested: false,
phantom: PhantomData,
}
}
Expand Down Expand Up @@ -1212,16 +1213,16 @@ impl<I> HasExecutions for NopState<I> {
}

impl<I> Stoppable for NopState<I> {
fn initiate_stop(&mut self) {
self.should_stop = true;
fn request_stop(&mut self) {
self.stop_requested = true;
}

fn reset_stop(&mut self) {
self.should_stop = false;
fn discard_stop_request(&mut self) {
self.stop_requested = false;
}

fn should_stop(&self) -> bool {
self.should_stop
fn stop_requested(&self) -> bool {
self.stop_requested
}
}

Expand Down

0 comments on commit a32fab6

Please sign in to comment.