libafl-fuzz: fix libafl-fuzz scheduler (#2545)

This commit is contained in:
Aarnav 2024-09-23 18:56:09 +02:00 committed by GitHub
parent 085db55f19
commit 7432bd0f59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 29 deletions

View File

@ -10,24 +10,18 @@ use libafl::{
state::{HasCorpus, HasRand, State}, state::{HasCorpus, HasRand, State},
Error, HasMetadata, Error, HasMetadata,
}; };
use libafl_bolts::{serdeany::SerdeAny, AsIter, HasRefCnt}; use libafl_bolts::{serdeany::SerdeAny, tuples::MatchName, AsIter, HasRefCnt};
pub enum SupportedSchedulers<CS, F, I, M, O, S, Q> { pub enum SupportedSchedulers<W, Q> {
Queue(Q, PhantomData<(CS, F, I, M, O, S, Q)>), Queue(Q, PhantomData<W>),
Weighted( Weighted(W, PhantomData<Q>),
MinimizerScheduler<CS, F, I, M, O, S>,
PhantomData<(CS, F, I, M, O, S, Q)>,
),
} }
impl<CS, F, I, M, O, S, Q> RemovableScheduler<I, S> for SupportedSchedulers<CS, F, I, M, O, S, Q> impl<W, Q, I, S> RemovableScheduler<I, S> for SupportedSchedulers<W, Q>
where where
CS: Scheduler<I, S> + RemovableScheduler<I, S>,
F: TestcaseScore<I, S>,
I: Input, I: Input,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
O: CanTrack,
Q: Scheduler<I, S> + RemovableScheduler<I, S>, Q: Scheduler<I, S> + RemovableScheduler<I, S>,
W: Scheduler<I, S> + RemovableScheduler<I, S>,
S: UsesInput + HasTestcase + HasMetadata + HasCorpus<Input = I> + HasRand + State, S: UsesInput + HasTestcase + HasMetadata + HasCorpus<Input = I> + HasRand + State,
{ {
fn on_remove( fn on_remove(
@ -50,14 +44,11 @@ where
} }
} }
impl<CS, F, I, M, O, S, Q> Scheduler<I, S> for SupportedSchedulers<CS, F, I, M, O, S, Q> impl<W, Q, I, S> Scheduler<I, S> for SupportedSchedulers<W, Q>
where where
CS: Scheduler<I, S>,
F: TestcaseScore<I, S>,
I: Input, I: Input,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
O: CanTrack,
Q: Scheduler<I, S>, Q: Scheduler<I, S>,
W: Scheduler<I, S>,
S: UsesInput + HasTestcase + HasMetadata + HasCorpus<Input = I> + HasRand + State, S: UsesInput + HasTestcase + HasMetadata + HasCorpus<Input = I> + HasRand + State,
{ {
fn on_add(&mut self, state: &mut S, id: CorpusId) -> Result<(), Error> { fn on_add(&mut self, state: &mut S, id: CorpusId) -> Result<(), Error> {
@ -92,7 +83,7 @@ where
} }
fn on_evaluation<OTB>(&mut self, state: &mut S, input: &I, observers: &OTB) -> Result<(), Error> fn on_evaluation<OTB>(&mut self, state: &mut S, input: &I, observers: &OTB) -> Result<(), Error>
where where
OTB: ObserversTuple<S>, OTB: MatchName,
{ {
match self { match self {
Self::Queue(queue, _) => queue.on_evaluation(state, input, observers), Self::Queue(queue, _) => queue.on_evaluation(state, input, observers),
@ -112,21 +103,15 @@ where
} }
} }
impl<CS, F, I, M, O, S, Q> HasQueueCycles for SupportedSchedulers<CS, F, I, M, O, S, Q> impl<W, Q> HasQueueCycles for SupportedSchedulers<W, Q>
where where
CS: Scheduler<I, S> + HasQueueCycles, Q: HasQueueCycles,
F: TestcaseScore<I, S>, W: HasQueueCycles,
I: Input,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
O: CanTrack,
Q: Scheduler<I, S> + HasQueueCycles,
S: UsesInput + HasTestcase + HasMetadata + HasCorpus<Input = I> + HasRand + State,
{ {
fn queue_cycles(&self) -> u64 { fn queue_cycles(&self) -> u64 {
match self { match self {
Self::Queue(queue, _) => queue.queue_cycles(), Self::Queue(queue, _) => queue.queue_cycles(),
Self::Weighted(weighted, _) => weighted.base().queue_cycles(), Self::Weighted(weighted, _) => weighted.queue_cycles(),
} }
} }
} }

View File

@ -8,6 +8,7 @@ use hashbrown::{HashMap, HashSet};
use libafl_bolts::{rands::Rand, serdeany::SerdeAny, tuples::MatchName, AsIter, HasRefCnt}; use libafl_bolts::{rands::Rand, serdeany::SerdeAny, tuples::MatchName, AsIter, HasRefCnt};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::HasQueueCycles;
use crate::{ use crate::{
corpus::{Corpus, CorpusId, Testcase}, corpus::{Corpus, CorpusId, Testcase},
feedbacks::MapIndexesMetadata, feedbacks::MapIndexesMetadata,
@ -350,7 +351,14 @@ where
Ok(()) Ok(())
} }
} }
impl<CS, F, M, O> HasQueueCycles for MinimizerScheduler<CS, F, M, O>
where
CS: HasQueueCycles,
{
fn queue_cycles(&self) -> u64 {
self.base.queue_cycles()
}
}
impl<CS, F, M, O> MinimizerScheduler<CS, F, M, O> impl<CS, F, M, O> MinimizerScheduler<CS, F, M, O>
where where
O: CanTrack, O: CanTrack,