remove serde bounds for Observer (#202)

This commit is contained in:
Andrea Fioraldi 2021-07-02 15:07:51 +02:00 committed by GitHub
parent 44f6e4c389
commit f0743cbb17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 39 deletions

View File

@ -81,7 +81,7 @@ where
impl<'a, I, OT, S, SP, ST> Launcher<'a, I, OT, S, SP, ST> impl<'a, I, OT, S, SP, ST> Launcher<'a, I, OT, S, SP, ST>
where where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
ST: Stats + Clone, ST: Stats + Clone,
SP: ShMemProvider + 'static, SP: ShMemProvider + 'static,
S: DeserializeOwned, S: DeserializeOwned,

View File

@ -362,7 +362,7 @@ where
event: Event<I>, event: Event<I>,
) -> Result<(), Error> ) -> Result<(), Error>
where where
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
E: Executor<Self, I, S, Z> + HasObservers<I, OT, S>, E: Executor<Self, I, S, Z> + HasObservers<I, OT, S>,
Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>,
{ {
@ -461,7 +461,7 @@ where
SP: ShMemProvider, SP: ShMemProvider,
E: Executor<Self, I, S, Z> + HasObservers<I, OT, S>, E: Executor<Self, I, S, Z> + HasObservers<I, OT, S>,
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, //CE: CustomEvent<I>, Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, //CE: CustomEvent<I>,
{ {
fn process(&mut self, fuzzer: &mut Z, state: &mut S, executor: &mut E) -> Result<usize, Error> { fn process(&mut self, fuzzer: &mut Z, state: &mut S, executor: &mut E) -> Result<usize, Error> {
@ -501,7 +501,7 @@ impl<E, I, OT, S, SP, Z> EventManager<E, I, S, Z> for LlmpEventManager<I, OT, S,
where where
E: Executor<Self, I, S, Z> + HasObservers<I, OT, S>, E: Executor<Self, I, S, Z> + HasObservers<I, OT, S>,
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
SP: ShMemProvider, SP: ShMemProvider,
Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, //CE: CustomEvent<I>, Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, //CE: CustomEvent<I>,
{ {
@ -510,7 +510,7 @@ where
impl<I, OT, S, SP> HasEventManagerId for LlmpEventManager<I, OT, S, SP> impl<I, OT, S, SP> HasEventManagerId for LlmpEventManager<I, OT, S, SP>
where where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
SP: ShMemProvider, SP: ShMemProvider,
{ {
/// Gets the id assigned to this sender. /// Gets the id assigned to this sender.
@ -626,7 +626,7 @@ where
E: Executor<LlmpEventManager<I, OT, S, SP>, I, S, Z> + HasObservers<I, OT, S>, E: Executor<LlmpEventManager<I, OT, S, SP>, I, S, Z> + HasObservers<I, OT, S>,
I: Input, I: Input,
Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
SP: ShMemProvider + 'static, SP: ShMemProvider + 'static,
//CE: CustomEvent<I>, //CE: CustomEvent<I>,
{ {
@ -641,7 +641,7 @@ where
I: Input, I: Input,
S: Serialize, S: Serialize,
Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>, Z: ExecutionProcessor<I, OT, S> + EvaluatorObservers<I, OT, S>,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
SP: ShMemProvider + 'static, SP: ShMemProvider + 'static,
//CE: CustomEvent<I>, //CE: CustomEvent<I>,
{ {
@ -650,7 +650,7 @@ where
impl<I, OT, S, SP> HasEventManagerId for LlmpRestartingEventManager<I, OT, S, SP> impl<I, OT, S, SP> HasEventManagerId for LlmpRestartingEventManager<I, OT, S, SP>
where where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
S: Serialize, S: Serialize,
SP: ShMemProvider + 'static, SP: ShMemProvider + 'static,
{ {
@ -668,7 +668,7 @@ const _ENV_FUZZER_BROKER_CLIENT_INITIAL: &str = "_AFL_ENV_FUZZER_BROKER_CLIENT";
impl<I, OT, S, SP> LlmpRestartingEventManager<I, OT, S, SP> impl<I, OT, S, SP> LlmpRestartingEventManager<I, OT, S, SP>
where where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
SP: ShMemProvider + 'static, SP: ShMemProvider + 'static,
//CE: CustomEvent<I>, //CE: CustomEvent<I>,
{ {
@ -719,7 +719,7 @@ where
I: Input, I: Input,
S: DeserializeOwned, S: DeserializeOwned,
ST: Stats + Clone, ST: Stats + Clone,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
S: DeserializeOwned, S: DeserializeOwned,
{ {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
@ -743,7 +743,7 @@ where
pub struct RestartingMgr<I, OT, S, SP, ST> pub struct RestartingMgr<I, OT, S, SP, ST>
where where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
S: DeserializeOwned, S: DeserializeOwned,
SP: ShMemProvider + 'static, SP: ShMemProvider + 'static,
ST: Stats, ST: Stats,
@ -775,7 +775,7 @@ where
impl<I, OT, S, SP, ST> RestartingMgr<I, OT, S, SP, ST> impl<I, OT, S, SP, ST> RestartingMgr<I, OT, S, SP, ST>
where where
I: Input, I: Input,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
S: DeserializeOwned, S: DeserializeOwned,
SP: ShMemProvider, SP: ShMemProvider,
ST: Stats + Clone, ST: Stats + Clone,

View File

@ -215,7 +215,7 @@ where
/// Serialize all observers for this type and manager /// Serialize all observers for this type and manager
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Vec<u8>, Error> fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Vec<u8>, Error>
where where
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::Serialize,
{ {
Ok(postcard::to_allocvec(observers)?) Ok(postcard::to_allocvec(observers)?)
} }
@ -247,7 +247,7 @@ pub trait EventProcessor<E, I, S, Z> {
/// Deserialize all observers for this type and manager /// Deserialize all observers for this type and manager
fn deserialize_observers<OT>(&mut self, observers_buf: &[u8]) -> Result<OT, Error> fn deserialize_observers<OT>(&mut self, observers_buf: &[u8]) -> Result<OT, Error>
where where
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::de::DeserializeOwned,
{ {
Ok(postcard::from_bytes(observers_buf)?) Ok(postcard::from_bytes(observers_buf)?)
} }

View File

@ -311,7 +311,7 @@ where
F: Feedback<I, S>, F: Feedback<I, S>,
I: Input, I: Input,
OF: Feedback<I, S>, OF: Feedback<I, S>,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::Serialize + serde::de::DeserializeOwned,
S: HasCorpus<C, I> + HasSolutions<SC, I> + HasClientPerfStats + HasExecutions, S: HasCorpus<C, I> + HasSolutions<SC, I> + HasClientPerfStats + HasExecutions,
{ {
/// Evaluate if a set of observation channels has an interesting state /// Evaluate if a set of observation channels has an interesting state
@ -419,7 +419,7 @@ impl<C, CS, F, I, OF, OT, S, SC> EvaluatorObservers<I, OT, S>
where where
C: Corpus<I>, C: Corpus<I>,
CS: CorpusScheduler<I, S>, CS: CorpusScheduler<I, S>,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::Serialize + serde::de::DeserializeOwned,
F: Feedback<I, S>, F: Feedback<I, S>,
I: Input, I: Input,
OF: Feedback<I, S>, OF: Feedback<I, S>,
@ -452,7 +452,7 @@ where
C: Corpus<I>, C: Corpus<I>,
CS: CorpusScheduler<I, S>, CS: CorpusScheduler<I, S>,
E: Executor<EM, I, S, Self> + HasObservers<I, OT, S>, E: Executor<EM, I, S, Self> + HasObservers<I, OT, S>,
OT: ObserversTuple<I, S>, OT: ObserversTuple<I, S> + serde::Serialize + serde::de::DeserializeOwned,
EM: EventManager<E, I, S, Self>, EM: EventManager<E, I, S, Self>,
F: Feedback<I, S>, F: Feedback<I, S>,
I: Input, I: Input,

View File

@ -70,7 +70,7 @@ impl CmpValuesMetadata {
} }
/// A [`CmpMap`] traces comparisons during the current execution /// A [`CmpMap`] traces comparisons during the current execution
pub trait CmpMap: Serialize + DeserializeOwned { pub trait CmpMap {
/// Get the number of cmps /// Get the number of cmps
fn len(&self) -> usize; fn len(&self) -> usize;
@ -176,7 +176,7 @@ where
#[serde(bound = "CM: serde::de::DeserializeOwned")] #[serde(bound = "CM: serde::de::DeserializeOwned")]
pub struct StdCmpObserver<'a, CM> pub struct StdCmpObserver<'a, CM>
where where
CM: CmpMap, CM: CmpMap + Serialize + DeserializeOwned,
{ {
map: OwnedRefMut<'a, CM>, map: OwnedRefMut<'a, CM>,
size: Option<OwnedRefMut<'a, usize>>, size: Option<OwnedRefMut<'a, usize>>,
@ -185,7 +185,7 @@ where
impl<'a, CM, I, S> CmpObserver<CM, I, S> for StdCmpObserver<'a, CM> impl<'a, CM, I, S> CmpObserver<CM, I, S> for StdCmpObserver<'a, CM>
where where
CM: CmpMap, CM: CmpMap + Serialize + DeserializeOwned,
{ {
/// Get the number of usable cmps (all by default) /// Get the number of usable cmps (all by default)
fn usable_count(&self) -> usize { fn usable_count(&self) -> usize {
@ -206,7 +206,7 @@ where
impl<'a, CM, I, S> Observer<I, S> for StdCmpObserver<'a, CM> impl<'a, CM, I, S> Observer<I, S> for StdCmpObserver<'a, CM>
where where
CM: CmpMap, CM: CmpMap + Serialize + DeserializeOwned,
{ {
fn pre_exec(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> { fn pre_exec(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> {
self.map.as_mut().reset()?; self.map.as_mut().reset()?;
@ -216,7 +216,7 @@ where
impl<'a, CM> Named for StdCmpObserver<'a, CM> impl<'a, CM> Named for StdCmpObserver<'a, CM>
where where
CM: CmpMap, CM: CmpMap + Serialize + DeserializeOwned,
{ {
fn name(&self) -> &str { fn name(&self) -> &str {
&self.name &self.name
@ -225,7 +225,7 @@ where
impl<'a, CM> StdCmpObserver<'a, CM> impl<'a, CM> StdCmpObserver<'a, CM>
where where
CM: CmpMap, CM: CmpMap + Serialize + DeserializeOwned,
{ {
/// Creates a new [`StdCmpObserver`] with the given name and map. /// Creates a new [`StdCmpObserver`] with the given name and map.
#[must_use] #[must_use]

View File

@ -20,7 +20,7 @@ use crate::{
/// Observers observe different information about the target. /// Observers observe different information about the target.
/// They can then be used by various sorts of feedback. /// They can then be used by various sorts of feedback.
pub trait Observer<I, S>: Named + serde::Serialize + serde::de::DeserializeOwned { pub trait Observer<I, S>: Named {
/// The testcase finished execution, calculate any changes. /// The testcase finished execution, calculate any changes.
/// Reserved for future use. /// Reserved for future use.
#[inline] #[inline]
@ -42,7 +42,7 @@ pub trait Observer<I, S>: Named + serde::Serialize + serde::de::DeserializeOwned
} }
/// A haskell-style tuple of observers /// A haskell-style tuple of observers
pub trait ObserversTuple<I, S>: MatchName + serde::Serialize + serde::de::DeserializeOwned { pub trait ObserversTuple<I, S>: MatchName {
/// This is called right before the next execution. /// This is called right before the next execution.
fn pre_exec_all(&mut self, state: &mut S, input: &I) -> Result<(), Error>; fn pre_exec_all(&mut self, state: &mut S, input: &I) -> Result<(), Error>;

View File

@ -27,4 +27,4 @@ cc = { version = "1.0", features = ["parallel"] }
rangemap = "0.1.10" rangemap = "0.1.10"
libafl = { path = "../libafl", version = "0.4.0", features = [] } libafl = { path = "../libafl", version = "0.4.0", features = [] }
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
serde-big-array = "0.3.2" # serde-big-array = "0.3.2"

View File

@ -8,15 +8,11 @@ use libafl::{
Error, Error,
}; };
use serde::{Deserialize, Serialize};
use crate::{CMPLOG_MAP_H, CMPLOG_MAP_W}; use crate::{CMPLOG_MAP_H, CMPLOG_MAP_W};
/// The `CmpLog` map size /// The `CmpLog` map size
pub const CMPLOG_MAP_SIZE: usize = CMPLOG_MAP_W * CMPLOG_MAP_H; pub const CMPLOG_MAP_SIZE: usize = CMPLOG_MAP_W * CMPLOG_MAP_H;
big_array! { BigArray; }
/// `CmpLog` instruction kind /// `CmpLog` instruction kind
pub const CMPLOG_KIND_INS: u8 = 0; pub const CMPLOG_KIND_INS: u8 = 0;
/// `CmpLog` return kind /// `CmpLog` return kind
@ -24,7 +20,7 @@ pub const CMPLOG_KIND_RTN: u8 = 1;
/// The header for `CmpLog` hits. /// The header for `CmpLog` hits.
#[repr(C)] #[repr(C)]
#[derive(Serialize, Deserialize, Default, Debug, Clone, Copy)] #[derive(Default, Debug, Clone, Copy)]
pub struct CmpLogHeader { pub struct CmpLogHeader {
hits: u16, hits: u16,
shape: u8, shape: u8,
@ -33,16 +29,14 @@ pub struct CmpLogHeader {
/// The operands logged during `CmpLog`. /// The operands logged during `CmpLog`.
#[repr(C)] #[repr(C)]
#[derive(Serialize, Deserialize, Default, Debug, Clone, Copy)] #[derive(Default, Debug, Clone, Copy)]
pub struct CmpLogOperands(u64, u64); pub struct CmpLogOperands(u64, u64);
/// A struct containing the `CmpLog` metadata for a `LibAFL` run. /// A struct containing the `CmpLog` metadata for a `LibAFL` run.
#[repr(C)] #[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct CmpLogMap { pub struct CmpLogMap {
#[serde(with = "BigArray")]
headers: [CmpLogHeader; CMPLOG_MAP_W], headers: [CmpLogHeader; CMPLOG_MAP_W],
#[serde(with = "BigArray")]
operands: [[CmpLogOperands; CMPLOG_MAP_H]; CMPLOG_MAP_W], operands: [[CmpLogOperands; CMPLOG_MAP_H]; CMPLOG_MAP_W],
} }
@ -137,7 +131,6 @@ pub static mut libafl_cmplog_enabled: u8 = 0;
pub use libafl_cmplog_enabled as CMPLOG_ENABLED; pub use libafl_cmplog_enabled as CMPLOG_ENABLED;
/// A [`CmpObserver`] observer for `CmpLog` /// A [`CmpObserver`] observer for `CmpLog`
#[derive(Serialize, Deserialize, Debug)]
pub struct CmpLogObserver<'a> { pub struct CmpLogObserver<'a> {
map: OwnedRefMut<'a, CmpLogMap>, map: OwnedRefMut<'a, CmpLogMap>,
size: Option<OwnedRefMut<'a, usize>>, size: Option<OwnedRefMut<'a, usize>>,

View File

@ -1,8 +1,5 @@
//! `libafl_targets` contains runtime code, injected in the target itself during compilation. //! `libafl_targets` contains runtime code, injected in the target itself during compilation.
#[macro_use]
extern crate serde_big_array;
include!(concat!(env!("OUT_DIR"), "/constants.rs")); include!(concat!(env!("OUT_DIR"), "/constants.rs"));
#[cfg(any(feature = "sancov_pcguard_edges", feature = "sancov_pcguard_hitcounts"))] #[cfg(any(feature = "sancov_pcguard_edges", feature = "sancov_pcguard_hitcounts"))]