Skip to content

Commit 403b8fc

Browse files
committed
separate index/novelty tracking funcs
1 parent f3d7e11 commit 403b8fc

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

fuzzers/libfuzzer_stb_image/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re
6868

6969
// Create an observation channel using the coverage map
7070
// We don't use the hitcounts (see the Cargo.toml, we use pcguard_edges)
71-
let edges_observer = unsafe { std_edges_map_observer("edges").with_tracking::<true, false>() };
71+
let edges_observer = unsafe { std_edges_map_observer("edges").with_index_tracking() };
7272

7373
// Create an observation channel to keep track of the execution time
7474
let time_observer = TimeObserver::new("time");

libafl/src/observers/map.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn hash_slice<T>(slice: &[T]) -> u64 {
106106
/// let edges_observer = StdMapObserver::from_ownedref("edges", OwnedMutSlice::from(vec![0u8; 16]));
107107
/// // inform the feedback to track indices (required by IndexesLenTimeMinimizerScheduler), but not novelties
108108
/// // this *MUST* be done before it is passed to MaxMapFeedback!
109-
/// let edges_observer = edges_observer.with_tracking::<true, false>();
109+
/// let edges_observer = edges_observer.with_index_tracking();
110110
///
111111
/// // init the feedback
112112
/// let mut feedback = MaxMapFeedback::new(&edges_observer);
@@ -127,19 +127,20 @@ fn hash_slice<T>(slice: &[T]) -> u64 {
127127
///
128128
/// [`MapObserver`] implementors: see [`StdMapObserver`] for an example implementation.
129129
pub trait TrackingHinted {
130-
/// The resulting type, including the new tracking hints, after calling
131-
/// [`crate::observers::map::TrackingHint::with_tracking`].
132-
type Output<const NEW_INDICES: bool, const NEW_NOVELTIES: bool>: TrackingHinted;
130+
/// The resulting type of enabling index tracking.
131+
type WithIndexTracking: TrackingHinted;
132+
/// The resulting type of enabling index tracking.
133+
type WithNoveltiesTracking: TrackingHinted;
133134

134135
/// Whether indices should be tracked for this [`MapObserver`].
135136
const INDICES: bool;
136137
/// Whether novelties should be tracked for this [`MapObserver`].
137138
const NOVELTIES: bool;
138139

139-
/// Make this map observer into one with the provided tracking hints.
140-
fn with_tracking<const NEW_INDICES: bool, const NEW_NOVELTIES: bool>(
141-
self,
142-
) -> Self::Output<NEW_INDICES, NEW_NOVELTIES>;
140+
/// Convert this map observer into one that tracks indices.
141+
fn with_index_tracking(self) -> Self::WithIndexTracking;
142+
/// Convert this map observer into one that tracks novelties.
143+
fn with_novelty_tracking(self) -> Self::WithNoveltiesTracking;
143144
}
144145

145146
/// Module which holds the necessary functions and types for map-relevant macros, namely
@@ -187,7 +188,7 @@ pub mod macros {
187188
SPACING, "= note: index tracking is required by ", $name, "\n",
188189
SPACING, "= note: see the documentation of TrackingHinted for details\n",
189190
SPACING, "|\n",
190-
SPACING, "= hint: call `.with_tracking::<true, ...>()` on the map observer present in the following error notes\n",
191+
SPACING, "= hint: call `.with_index_tracking()` on the map observer present in the following error notes\n",
191192
SPACING, "|\n",
192193
SPACING, "| ",
193194
);
@@ -237,7 +238,7 @@ pub mod macros {
237238
SPACING, "= note: novelty tracking is required by ", $name, "\n",
238239
SPACING, "= note: see the documentation of TrackingHinted for details\n",
239240
SPACING, "|\n",
240-
SPACING, "= hint: call `.with_tracking::<..., true>()` on the map observer present in the following error notes\n",
241+
SPACING, "= hint: call `.with_novelty_tracking()` on the map observer present in the following error notes\n",
241242
SPACING, "|\n",
242243
SPACING, "| ",
243244
);
@@ -869,16 +870,22 @@ impl<'a, T, const DIFFERENTIAL: bool, const ITH: bool, const NTH: bool> Tracking
869870
where
870871
T: Copy + Default + Serialize,
871872
{
872-
type Output<const NEW_INDICES: bool, const NEW_NOVELTIES: bool> =
873-
StdMapObserver<'a, T, DIFFERENTIAL, NEW_INDICES, NEW_NOVELTIES>;
873+
type WithIndexTracking = StdMapObserver<'a, T, DIFFERENTIAL, true, NTH>;
874+
type WithNoveltiesTracking = StdMapObserver<'a, T, DIFFERENTIAL, ITH, true>;
874875

875876
const INDICES: bool = ITH;
876877
const NOVELTIES: bool = NTH;
877878

878-
fn with_tracking<const NEW_INDICES: bool, const NEW_NOVELTIES: bool>(
879-
self,
880-
) -> Self::Output<NEW_INDICES, NEW_NOVELTIES> {
881-
StdMapObserver::<'a, T, DIFFERENTIAL, NEW_INDICES, NEW_NOVELTIES> {
879+
fn with_index_tracking(self) -> Self::WithIndexTracking {
880+
StdMapObserver::<'a, T, DIFFERENTIAL, true, NTH> {
881+
map: self.map,
882+
initial: self.initial,
883+
name: self.name,
884+
}
885+
}
886+
887+
fn with_novelty_tracking(self) -> Self::WithNoveltiesTracking {
888+
StdMapObserver::<'a, T, DIFFERENTIAL, ITH, true> {
882889
map: self.map,
883890
initial: self.initial,
884891
name: self.name,

0 commit comments

Comments
 (0)