diff --git a/libafl/src/stages/calibrate.rs b/libafl/src/stages/calibrate.rs index 867000e745..8498e044f3 100644 --- a/libafl/src/stages/calibrate.rs +++ b/libafl/src/stages/calibrate.rs @@ -60,11 +60,14 @@ impl UnstableEntriesMetadata { } } +/// Default name for `CalibrationStage`; derived from AFL++ +pub const CALIBRATION_STAGE_NAME: &str = "calibration"; /// The calibration stage will measure the average exec time and the target's stability for this input. #[derive(Clone, Debug)] pub struct CalibrationStage { map_observer_handle: Handle, map_name: Cow<'static, str>, + name: Cow<'static, str>, stage_max: usize, /// If we should track stability track_stability: bool, @@ -349,6 +352,7 @@ where track_stability: true, restart_helper: ExecutionCountRestartHelper::default(), phantom: PhantomData, + name: Cow::Borrowed(CALIBRATION_STAGE_NAME), } } @@ -365,6 +369,13 @@ where track_stability: false, restart_helper: ExecutionCountRestartHelper::default(), phantom: PhantomData, + name: Cow::Borrowed(CALIBRATION_STAGE_NAME), } } } + +impl Named for CalibrationStage { + fn name(&self) -> &Cow<'static, str> { + &self.name + } +} diff --git a/libafl/src/stages/colorization.rs b/libafl/src/stages/colorization.rs index 627f556162..04e1d52973 100644 --- a/libafl/src/stages/colorization.rs +++ b/libafl/src/stages/colorization.rs @@ -52,10 +52,13 @@ impl Ord for Earlier { } } +/// Default name for `ColorizationStage`; derived from ALF++ +pub const COLORIZATION_STAGE_NAME: &str = "colorization"; /// The mutational stage using power schedules #[derive(Clone, Debug)] pub struct ColorizationStage { map_observer_handle: Handle, + name: Cow<'static, str>, #[allow(clippy::type_complexity)] phantom: PhantomData<(E, EM, O, E, Z)>, } @@ -72,7 +75,7 @@ where E: UsesState, { fn name(&self) -> &Cow<'static, str> { - self.map_observer_handle.name() + &self.name } } @@ -308,6 +311,7 @@ where pub fn new(map_observer: &C) -> Self { Self { map_observer_handle: map_observer.handle(), + name: Cow::Borrowed(COLORIZATION_STAGE_NAME), phantom: PhantomData, } } diff --git a/libafl/src/stages/power.rs b/libafl/src/stages/power.rs index 961046177f..9cc7d7b615 100644 --- a/libafl/src/stages/power.rs +++ b/libafl/src/stages/power.rs @@ -1,7 +1,10 @@ //! The power schedules. This stage should be invoked after the calibration stage. +use alloc::borrow::Cow; use core::{fmt::Debug, marker::PhantomData}; +use libafl_bolts::Named; + use crate::{ executors::{Executor, HasObservers}, fuzzer::Evaluator, @@ -11,10 +14,12 @@ use crate::{ state::{HasCorpus, HasCurrentTestcase, HasExecutions, HasRand, UsesState}, Error, HasMetadata, }; - +/// Default name for `PowerMutationalStage`; derived from AFL++ +pub const POWER_MUTATIONAL_STAGE_NAME: &str = "power"; /// The mutational stage using power schedules #[derive(Clone, Debug)] pub struct PowerMutationalStage { + name: Cow<'static, str>, /// The mutators we use mutator: M, /// Helper for restarts @@ -30,6 +35,12 @@ where type State = E::State; } +impl Named for PowerMutationalStage { + fn name(&self) -> &Cow<'static, str> { + &self.name + } +} + impl MutationalStage for PowerMutationalStage where E: Executor + HasObservers, @@ -112,22 +123,8 @@ where { /// Creates a new [`PowerMutationalStage`] pub fn new(mutator: M) -> Self { - Self::transforming(mutator) - } -} - -impl PowerMutationalStage -where - E: Executor + HasObservers, - EM: UsesState, - F: TestcaseScore, - M: Mutator, - E::State: HasCorpus + HasMetadata + HasRand, - Z: Evaluator, -{ - /// Creates a new transforming [`PowerMutationalStage`] - pub fn transforming(mutator: M) -> Self { Self { + name: Cow::Borrowed(POWER_MUTATIONAL_STAGE_NAME), mutator, phantom: PhantomData, restart_helper: ExecutionCountRestartHelper::default(), diff --git a/libafl/src/stages/sync.rs b/libafl/src/stages/sync.rs index 520365ba01..0c850f3951 100644 --- a/libafl/src/stages/sync.rs +++ b/libafl/src/stages/sync.rs @@ -45,9 +45,13 @@ impl SyncFromDiskMetadata { } } +/// Default name for `SyncFromDiskStage`; derived from AFL++ +pub const SYNC_FROM_DISK_STAGE_NAME: &str = "sync"; + /// A stage that loads testcases from disk to sync with other fuzzers such as AFL++ #[derive(Debug)] pub struct SyncFromDiskStage { + name: Cow<'static, str>, sync_dir: PathBuf, load_callback: CB, phantom: PhantomData<(E, EM, Z)>, @@ -65,8 +69,7 @@ where E: UsesState, { fn name(&self) -> &Cow<'static, str> { - static NAME: Cow<'static, str> = Cow::Borrowed("SyncFromDiskStage"); - &NAME + &self.name } } @@ -138,9 +141,10 @@ where #[must_use] pub fn new(sync_dir: PathBuf, load_callback: CB) -> Self { Self { + name: Cow::Borrowed(SYNC_FROM_DISK_STAGE_NAME), + phantom: PhantomData, sync_dir, load_callback, - phantom: PhantomData, } } @@ -211,6 +215,7 @@ where Input::from_file(p) } Self { + name: Cow::Borrowed(SYNC_FROM_DISK_STAGE_NAME), sync_dir, load_callback: load_callback::<_, _>, phantom: PhantomData,