Make adaptive serialization into default (#2296)

* no adaptive

* add another api

* allow unused
This commit is contained in:
Dongjia "toka" Zhang 2024-06-09 00:10:30 +02:00 committed by GitHub
parent 454176427b
commit f4699ba385
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 113 additions and 443 deletions

View File

@ -53,9 +53,6 @@ gzip = ["libafl_bolts/gzip"]
## If set, will use the `fork()` syscall to spawn children, instead of launching a new command, if supported by the OS (has no effect on `Windows`). ## If set, will use the `fork()` syscall to spawn children, instead of launching a new command, if supported by the OS (has no effect on `Windows`).
fork = ["libafl_bolts/derive"] fork = ["libafl_bolts/derive"]
## Collected stats to decide if observers must be serialized or not (which should reduce mem use and increase speed)
adaptive_serialization = []
## If this feature is set, `LibAFL` targets (and the fuzzer) will crash on `SIGPIPE` on unix systems. ## If this feature is set, `LibAFL` targets (and the fuzzer) will crash on `SIGPIPE` on unix systems.
handle_sigpipe = [] handle_sigpipe = []

View File

@ -8,12 +8,8 @@
// 4. The "main broker", the gathers the stats from the fuzzer clients and broadcast the newly found testcases from the main evaluator. // 4. The "main broker", the gathers the stats from the fuzzer clients and broadcast the newly found testcases from the main evaluator.
use alloc::{boxed::Box, string::String, vec::Vec}; use alloc::{boxed::Box, string::String, vec::Vec};
use core::fmt::Debug; use core::{fmt::Debug, time::Duration};
#[cfg(feature = "adaptive_serialization")]
use core::time::Duration;
#[cfg(feature = "adaptive_serialization")]
use libafl_bolts::tuples::{Handle, Handled};
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
use libafl_bolts::{ use libafl_bolts::{
compress::GzipCompressor, compress::GzipCompressor,
@ -22,6 +18,7 @@ use libafl_bolts::{
use libafl_bolts::{ use libafl_bolts::{
llmp::{LlmpClient, LlmpClientDescription, Tag}, llmp::{LlmpClient, LlmpClientDescription, Tag},
shmem::{NopShMemProvider, ShMemProvider}, shmem::{NopShMemProvider, ShMemProvider},
tuples::Handle,
ClientId, ClientId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -29,8 +26,6 @@ use serde::{Deserialize, Serialize};
use super::NopEventManager; use super::NopEventManager;
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
use crate::events::llmp::COMPRESS_THRESHOLD; use crate::events::llmp::COMPRESS_THRESHOLD;
#[cfg(feature = "adaptive_serialization")]
use crate::observers::TimeObserver;
#[cfg(feature = "scalability_introspection")] #[cfg(feature = "scalability_introspection")]
use crate::state::HasScalabilityMonitor; use crate::state::HasScalabilityMonitor;
use crate::{ use crate::{
@ -42,7 +37,7 @@ use crate::{
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{EvaluatorObservers, ExecutionProcessor}, fuzzer::{EvaluatorObservers, ExecutionProcessor},
inputs::{Input, NopInput, UsesInput}, inputs::{Input, NopInput, UsesInput},
observers::ObserversTuple, observers::{ObserversTuple, TimeObserver},
state::{HasExecutions, HasLastReportTime, NopState, UsesState}, state::{HasExecutions, HasLastReportTime, NopState, UsesState},
Error, HasMetadata, Error, HasMetadata,
}; };
@ -61,8 +56,7 @@ where
client: LlmpClient<SP>, client: LlmpClient<SP>,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor, compressor: GzipCompressor,
#[cfg(feature = "adaptive_serialization")] time_ref: Option<Handle<TimeObserver>>,
time_ref: Handle<TimeObserver>,
is_main: bool, is_main: bool,
} }
@ -99,12 +93,12 @@ impl CentralizedEventManagerBuilder {
Self { is_main } Self { is_main }
} }
/// Creates a new [`CentralizedEventManager`]. /// Creates a new `CentralizedEventManager`
#[cfg(not(feature = "adaptive_serialization"))]
pub fn build_from_client<EM, SP>( pub fn build_from_client<EM, SP>(
self, self,
inner: EM, inner: EM,
client: LlmpClient<SP>, client: LlmpClient<SP>,
time_obs: Option<Handle<TimeObserver>>,
) -> Result<CentralizedEventManager<EM, SP>, Error> ) -> Result<CentralizedEventManager<EM, SP>, Error>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -115,28 +109,7 @@ impl CentralizedEventManagerBuilder {
client, client,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD), compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
is_main: self.is_main, time_ref: time_obs,
})
}
/// Creates a new [`CentralizedEventManager`].
#[cfg(feature = "adaptive_serialization")]
pub fn build_from_client<EM, SP>(
self,
inner: EM,
client: LlmpClient<SP>,
time_obs: &TimeObserver,
) -> Result<CentralizedEventManager<EM, SP>, Error>
where
SP: ShMemProvider,
EM: UsesState,
{
Ok(CentralizedEventManager {
inner,
client,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
time_ref: time_obs.handle(),
is_main: self.is_main, is_main: self.is_main,
}) })
} }
@ -145,12 +118,13 @@ impl CentralizedEventManagerBuilder {
/// ///
/// If the port is not yet bound, it will act as a broker; otherwise, it /// If the port is not yet bound, it will act as a broker; otherwise, it
/// will act as a client. /// will act as a client.
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))] #[cfg(feature = "std")]
pub fn build_on_port<EM, SP>( pub fn build_on_port<EM, SP>(
self, self,
inner: EM, inner: EM,
shmem_provider: SP, shmem_provider: SP,
port: u16, port: u16,
time_obs: Option<Handle<TimeObserver>>,
) -> Result<CentralizedEventManager<EM, SP>, Error> ) -> Result<CentralizedEventManager<EM, SP>, Error>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -162,45 +136,20 @@ impl CentralizedEventManagerBuilder {
client, client,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD), compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
is_main: self.is_main, time_ref: time_obs,
})
}
/// Create a centralized event manager on a port
///
/// If the port is not yet bound, it will act as a broker; otherwise, it
/// will act as a client.
#[cfg(all(feature = "std", feature = "adaptive_serialization"))]
pub fn build_on_port<EM, SP>(
self,
inner: EM,
shmem_provider: SP,
port: u16,
time_obs: &TimeObserver,
) -> Result<CentralizedEventManager<EM, SP>, Error>
where
SP: ShMemProvider,
EM: UsesState,
{
let client = LlmpClient::create_attach_to_tcp(shmem_provider, port)?;
Ok(CentralizedEventManager {
inner,
client,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
time_ref: time_obs.handle(),
is_main: self.is_main, is_main: self.is_main,
}) })
} }
/// If a client respawns, it may reuse the existing connection, previously /// If a client respawns, it may reuse the existing connection, previously
/// stored by [`LlmpClient::to_env()`]. /// stored by [`LlmpClient::to_env()`].
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))] #[cfg(feature = "std")]
pub fn build_existing_client_from_env<EM, SP>( pub fn build_existing_client_from_env<EM, SP>(
self, self,
inner: EM, inner: EM,
shmem_provider: SP, shmem_provider: SP,
env_name: &str, env_name: &str,
time_obs: Option<Handle<TimeObserver>>,
) -> Result<CentralizedEventManager<EM, SP>, Error> ) -> Result<CentralizedEventManager<EM, SP>, Error>
where where
EM: UsesState, EM: UsesState,
@ -211,41 +160,19 @@ impl CentralizedEventManagerBuilder {
client: LlmpClient::on_existing_from_env(shmem_provider, env_name)?, client: LlmpClient::on_existing_from_env(shmem_provider, env_name)?,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD), compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
is_main: self.is_main, time_ref: time_obs,
})
}
/// If a client respawns, it may reuse the existing connection, previously
/// stored by [`LlmpClient::to_env()`].
#[cfg(all(feature = "std", feature = "adaptive_serialization"))]
pub fn build_existing_client_from_env<EM, SP>(
self,
inner: EM,
shmem_provider: SP,
env_name: &str,
time_obs: &TimeObserver,
) -> Result<CentralizedEventManager<EM, SP>, Error>
where
EM: UsesState,
SP: ShMemProvider,
{
Ok(CentralizedEventManager {
inner,
client: LlmpClient::on_existing_from_env(shmem_provider, env_name)?,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
time_ref: time_obs.handle(),
is_main: self.is_main, is_main: self.is_main,
}) })
} }
/// Create an existing client from description /// Create an existing client from description
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))] #[cfg(feature = "std")]
pub fn existing_client_from_description<EM, SP>( pub fn existing_client_from_description<EM, SP>(
self, self,
inner: EM, inner: EM,
shmem_provider: SP, shmem_provider: SP,
description: &LlmpClientDescription, description: &LlmpClientDescription,
time_obs: Option<Handle<TimeObserver>>,
) -> Result<CentralizedEventManager<EM, SP>, Error> ) -> Result<CentralizedEventManager<EM, SP>, Error>
where where
EM: UsesState, EM: UsesState,
@ -256,29 +183,7 @@ impl CentralizedEventManagerBuilder {
client: LlmpClient::existing_client_from_description(shmem_provider, description)?, client: LlmpClient::existing_client_from_description(shmem_provider, description)?,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD), compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
is_main: self.is_main, time_ref: time_obs,
})
}
/// Create an existing client from description
#[cfg(all(feature = "std", feature = "adaptive_serialization"))]
pub fn existing_client_from_description<EM, SP>(
self,
inner: EM,
shmem_provider: SP,
description: &LlmpClientDescription,
time_obs: &TimeObserver,
) -> Result<CentralizedEventManager<EM, SP>, Error>
where
EM: UsesState,
SP: ShMemProvider,
{
Ok(CentralizedEventManager {
inner,
client: LlmpClient::existing_client_from_description(shmem_provider, description)?,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
time_ref: time_obs.handle(),
is_main: self.is_main, is_main: self.is_main,
}) })
} }
@ -291,7 +196,6 @@ where
type State = EM::State; type State = EM::State;
} }
#[cfg(feature = "adaptive_serialization")]
impl<EM, SP> AdaptiveSerializer for CentralizedEventManager<EM, SP> impl<EM, SP> AdaptiveSerializer for CentralizedEventManager<EM, SP>
where where
EM: AdaptiveSerializer + UsesState, EM: AdaptiveSerializer + UsesState,
@ -323,19 +227,11 @@ where
self.inner.should_serialize_cnt_mut() self.inner.should_serialize_cnt_mut()
} }
fn time_ref(&self) -> &Handle<TimeObserver> { fn time_ref(&self) -> &Option<Handle<TimeObserver>> {
&self.time_ref &self.time_ref
} }
} }
#[cfg(not(feature = "adaptive_serialization"))]
impl<EM, SP> AdaptiveSerializer for CentralizedEventManager<EM, SP>
where
EM: AdaptiveSerializer + UsesState,
SP: ShMemProvider,
{
}
impl<EM, SP> EventFirer for CentralizedEventManager<EM, SP> impl<EM, SP> EventFirer for CentralizedEventManager<EM, SP>
where where
EM: AdaptiveSerializer + EventFirer + HasEventManagerId, EM: AdaptiveSerializer + EventFirer + HasEventManagerId,
@ -399,15 +295,6 @@ where
self.inner.log(state, severity_level, message) self.inner.log(state, severity_level, message)
} }
#[cfg(not(feature = "adaptive_serialization"))]
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
where
OT: ObserversTuple<Self::State> + Serialize,
{
Ok(Some(postcard::to_allocvec(observers)?))
}
#[cfg(feature = "adaptive_serialization")]
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error> fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
where where
OT: ObserversTuple<Self::State> + Serialize, OT: ObserversTuple<Self::State> + Serialize,

View File

@ -34,15 +34,6 @@ use libafl_bolts::llmp::LlmpBroker;
use libafl_bolts::os::dup2; use libafl_bolts::os::dup2;
#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] #[cfg(all(feature = "std", any(windows, not(feature = "fork"))))]
use libafl_bolts::os::startable_self; use libafl_bolts::os::startable_self;
#[cfg(feature = "adaptive_serialization")]
use libafl_bolts::tuples::Handle;
#[cfg(all(
unix,
feature = "std",
feature = "fork",
feature = "adaptive_serialization"
))]
use libafl_bolts::tuples::Handled;
#[cfg(all(unix, feature = "std", feature = "fork"))] #[cfg(all(unix, feature = "std", feature = "fork"))]
use libafl_bolts::{ use libafl_bolts::{
core_affinity::get_core_ids, core_affinity::get_core_ids,
@ -51,13 +42,12 @@ use libafl_bolts::{
use libafl_bolts::{ use libafl_bolts::{
core_affinity::{CoreId, Cores}, core_affinity::{CoreId, Cores},
shmem::ShMemProvider, shmem::ShMemProvider,
tuples::tuple_list, tuples::{tuple_list, Handle},
}; };
#[cfg(feature = "std")] #[cfg(feature = "std")]
use typed_builder::TypedBuilder; use typed_builder::TypedBuilder;
use super::hooks::EventManagerHooksTuple; use super::hooks::EventManagerHooksTuple;
#[cfg(feature = "adaptive_serialization")]
use crate::observers::TimeObserver; use crate::observers::TimeObserver;
#[cfg(all(unix, feature = "std", feature = "fork"))] #[cfg(all(unix, feature = "std", feature = "fork"))]
use crate::{ use crate::{
@ -131,8 +121,9 @@ pub struct Launcher<'a, CF, EMH, MT, S, SP> {
/// clusters. /// clusters.
#[builder(default = None)] #[builder(default = None)]
remote_broker_addr: Option<SocketAddr>, remote_broker_addr: Option<SocketAddr>,
#[cfg(feature = "adaptive_serialization")] /// The time observer for addaptive serialization
time_ref: Handle<TimeObserver>, #[builder(default = None)]
time_ref: Option<Handle<TimeObserver>>,
/// If this launcher should spawn a new `broker` on `[Self::broker_port]` (default). /// If this launcher should spawn a new `broker` on `[Self::broker_port]` (default).
/// The reason you may not want this is, if you already have a [`Launcher`] /// The reason you may not want this is, if you already have a [`Launcher`]
/// with a different configuration (for the same target) running on this machine. /// with a different configuration (for the same target) running on this machine.
@ -282,7 +273,6 @@ where
.configuration(self.configuration) .configuration(self.configuration)
.serialize_state(self.serialize_state) .serialize_state(self.serialize_state)
.hooks(hooks); .hooks(hooks);
#[cfg(feature = "adaptive_serialization")]
let builder = builder.time_ref(self.time_ref.clone()); let builder = builder.time_ref(self.time_ref.clone());
let (state, mgr) = builder.build().launch()?; let (state, mgr) = builder.build().launch()?;
@ -308,7 +298,6 @@ where
.serialize_state(self.serialize_state) .serialize_state(self.serialize_state)
.hooks(hooks); .hooks(hooks);
#[cfg(feature = "adaptive_serialization")]
let builder = builder.time_ref(self.time_ref.clone()); let builder = builder.time_ref(self.time_ref.clone());
builder.build().launch()?; builder.build().launch()?;
@ -360,7 +349,6 @@ where
.serialize_state(self.serialize_state) .serialize_state(self.serialize_state)
.hooks(hooks); .hooks(hooks);
#[cfg(feature = "adaptive_serialization")]
let builder = builder.time_ref(self.time_ref.clone()); let builder = builder.time_ref(self.time_ref.clone());
let (state, mgr) = builder.build().launch()?; let (state, mgr) = builder.build().launch()?;
@ -455,7 +443,6 @@ where
.serialize_state(self.serialize_state) .serialize_state(self.serialize_state)
.hooks(hooks); .hooks(hooks);
#[cfg(feature = "adaptive_serialization")]
let builder = builder.time_ref(self.time_ref.clone()); let builder = builder.time_ref(self.time_ref.clone());
builder.build().launch()?; builder.build().launch()?;
@ -506,8 +493,8 @@ pub struct CentralizedLauncher<'a, CF, IM, MF, MT, S, SP> {
#[builder(default = 1338_u16)] #[builder(default = 1338_u16)]
centralized_broker_port: u16, centralized_broker_port: u16,
/// The time observer by which to adaptively serialize /// The time observer by which to adaptively serialize
#[cfg(feature = "adaptive_serialization")] #[builder(default = None)]
time_obs: &'a TimeObserver, time_obs: Option<Handle<TimeObserver>>,
/// The list of cores to run on /// The list of cores to run on
cores: &'a Cores, cores: &'a Cores,
/// A file name to write all client output to /// A file name to write all client output to
@ -597,8 +584,7 @@ where
.serialize_state(centralized_launcher.serialize_state) .serialize_state(centralized_launcher.serialize_state)
.hooks(tuple_list!()); .hooks(tuple_list!());
#[cfg(feature = "adaptive_serialization")] let builder = builder.time_ref(centralized_launcher.time_obs.clone());
let builder = builder.time_ref(centralized_launcher.time_obs.handle());
builder.build().launch() builder.build().launch()
}; };
@ -738,18 +724,11 @@ where
let mut centralized_builder = CentralizedEventManager::builder(); let mut centralized_builder = CentralizedEventManager::builder();
centralized_builder = centralized_builder.is_main(true); centralized_builder = centralized_builder.is_main(true);
#[cfg(not(feature = "adaptive_serialization"))]
let c_mgr = centralized_builder.build_on_port( let c_mgr = centralized_builder.build_on_port(
mgr, mgr,
self.shmem_provider.clone(), self.shmem_provider.clone(),
self.centralized_broker_port, self.centralized_broker_port,
)?; self.time_obs.clone(),
#[cfg(feature = "adaptive_serialization")]
let c_mgr = centralized_builder.build_on_port(
mgr,
self.shmem_provider.clone(),
self.centralized_broker_port,
self.time_obs,
)?; )?;
self.main_run_client.take().unwrap()(state, c_mgr, *bind_to) self.main_run_client.take().unwrap()(state, c_mgr, *bind_to)
@ -760,18 +739,11 @@ where
let centralized_builder = CentralizedEventManager::builder(); let centralized_builder = CentralizedEventManager::builder();
#[cfg(not(feature = "adaptive_serialization"))]
let c_mgr = centralized_builder.build_on_port( let c_mgr = centralized_builder.build_on_port(
mgr, mgr,
self.shmem_provider.clone(), self.shmem_provider.clone(),
self.centralized_broker_port, self.centralized_broker_port,
)?; self.time_obs.clone(),
#[cfg(feature = "adaptive_serialization")]
let c_mgr = centralized_builder.build_on_port(
mgr,
self.shmem_provider.clone(),
self.centralized_broker_port,
self.time_obs,
)?; )?;
self.secondary_run_client.take().unwrap()(state, c_mgr, *bind_to) self.secondary_run_client.take().unwrap()(state, c_mgr, *bind_to)
@ -796,8 +768,7 @@ where
.serialize_state(self.serialize_state) .serialize_state(self.serialize_state)
.hooks(tuple_list!()); .hooks(tuple_list!());
#[cfg(feature = "adaptive_serialization")] let builder = builder.time_ref(self.time_obs.clone());
let builder = builder.time_ref(self.time_obs.handle());
builder.build().launch()?; builder.build().launch()?;

View File

@ -8,8 +8,6 @@ use core::{marker::PhantomData, time::Duration};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::net::TcpStream; use std::net::TcpStream;
#[cfg(feature = "adaptive_serialization")]
use libafl_bolts::tuples::Handle;
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
use libafl_bolts::{ use libafl_bolts::{
compress::GzipCompressor, compress::GzipCompressor,
@ -19,6 +17,7 @@ use libafl_bolts::{
current_time, current_time,
llmp::{LlmpClient, LlmpClientDescription}, llmp::{LlmpClient, LlmpClientDescription},
shmem::{NopShMemProvider, ShMemProvider}, shmem::{NopShMemProvider, ShMemProvider},
tuples::Handle,
ClientId, ClientId,
}; };
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -30,22 +29,18 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
use crate::events::llmp::COMPRESS_THRESHOLD; use crate::events::llmp::COMPRESS_THRESHOLD;
#[cfg(feature = "adaptive_serialization")]
use crate::events::AdaptiveSerializer;
#[cfg(feature = "adaptive_serialization")]
use crate::observers::TimeObserver;
use crate::{ use crate::{
events::{ events::{
hooks::EventManagerHooksTuple, hooks::EventManagerHooksTuple,
llmp::{LLMP_TAG_EVENT_TO_BOTH, _LLMP_TAG_EVENT_TO_BROKER}, llmp::{LLMP_TAG_EVENT_TO_BOTH, _LLMP_TAG_EVENT_TO_BROKER},
CustomBufEventResult, CustomBufHandlerFn, Event, EventConfig, EventFirer, EventManager, AdaptiveSerializer, CustomBufEventResult, CustomBufHandlerFn, Event, EventConfig,
EventManagerId, EventProcessor, EventRestarter, HasCustomBufHandlers, HasEventManagerId, EventFirer, EventManager, EventManagerId, EventProcessor, EventRestarter,
ProgressReporter, HasCustomBufHandlers, HasEventManagerId, ProgressReporter,
}, },
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor}, fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
inputs::{NopInput, UsesInput}, inputs::{NopInput, UsesInput},
observers::ObserversTuple, observers::{ObserversTuple, TimeObserver},
state::{HasExecutions, HasLastReportTime, NopState, State, UsesState}, state::{HasExecutions, HasLastReportTime, NopState, State, UsesState},
Error, HasMetadata, Error, HasMetadata,
}; };
@ -74,16 +69,11 @@ where
/// A node will not re-use the observer values sent over LLMP /// A node will not re-use the observer values sent over LLMP
/// from nodes with other configurations. /// from nodes with other configurations.
configuration: EventConfig, configuration: EventConfig,
#[cfg(feature = "adaptive_serialization")]
serialization_time: Duration, serialization_time: Duration,
#[cfg(feature = "adaptive_serialization")]
deserialization_time: Duration, deserialization_time: Duration,
#[cfg(feature = "adaptive_serialization")]
serializations_cnt: usize, serializations_cnt: usize,
#[cfg(feature = "adaptive_serialization")]
should_serialize_cnt: usize, should_serialize_cnt: usize,
#[cfg(feature = "adaptive_serialization")] pub(crate) time_ref: Option<Handle<TimeObserver>>,
pub(crate) time_ref: Handle<TimeObserver>,
phantom: PhantomData<S>, phantom: PhantomData<S>,
} }
@ -149,12 +139,11 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
} }
/// Create a manager from a raw LLMP client /// Create a manager from a raw LLMP client
#[cfg(feature = "adaptive_serialization")]
pub fn build_from_client<S, SP>( pub fn build_from_client<S, SP>(
self, self,
llmp: LlmpClient<SP>, llmp: LlmpClient<SP>,
configuration: EventConfig, configuration: EventConfig,
time_ref: Handle<TimeObserver>, time_ref: Option<Handle<TimeObserver>>,
) -> Result<LlmpEventManager<EMH, S, SP>, Error> ) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -179,42 +168,17 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
}) })
} }
/// Create a manager from a raw LLMP client
#[cfg(not(feature = "adaptive_serialization"))]
pub fn build_from_client<S, SP>(
self,
llmp: LlmpClient<SP>,
configuration: EventConfig,
) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where
SP: ShMemProvider,
S: State,
{
Ok(LlmpEventManager {
throttle: self.throttle,
last_sent: Duration::from_secs(0),
hooks: self.hooks,
always_interesting: self.always_interesting,
llmp,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
configuration,
phantom: PhantomData,
custom_buf_handlers: vec![],
})
}
/// Create an LLMP event manager on a port /// Create an LLMP event manager on a port
/// ///
/// If the port is not yet bound, it will act as a broker; otherwise, it /// If the port is not yet bound, it will act as a broker; otherwise, it
/// will act as a client. /// will act as a client.
#[cfg(all(feature = "std", feature = "adaptive_serialization"))] #[cfg(feature = "std")]
pub fn build_on_port<S, SP>( pub fn build_on_port<S, SP>(
self, self,
shmem_provider: SP, shmem_provider: SP,
port: u16, port: u16,
configuration: EventConfig, configuration: EventConfig,
time_ref: Handle<TimeObserver>, time_ref: Option<Handle<TimeObserver>>,
) -> Result<LlmpEventManager<EMH, S, SP>, Error> ) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -240,45 +204,15 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
}) })
} }
/// Create an LLMP event manager on a port
///
/// If the port is not yet bound, it will act as a broker; otherwise, it
/// will act as a client.
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))]
pub fn build_on_port<S, SP>(
self,
shmem_provider: SP,
port: u16,
configuration: EventConfig,
) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where
SP: ShMemProvider,
S: State,
{
let llmp = LlmpClient::create_attach_to_tcp(shmem_provider, port)?;
Ok(LlmpEventManager {
throttle: self.throttle,
last_sent: Duration::from_secs(0),
hooks: self.hooks,
always_interesting: self.always_interesting,
llmp,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
configuration,
phantom: PhantomData,
custom_buf_handlers: vec![],
})
}
/// If a client respawns, it may reuse the existing connection, previously /// If a client respawns, it may reuse the existing connection, previously
/// stored by [`LlmpClient::to_env()`]. /// stored by [`LlmpClient::to_env()`].
#[cfg(all(feature = "std", feature = "adaptive_serialization"))] #[cfg(feature = "std")]
pub fn build_existing_client_from_env<S, SP>( pub fn build_existing_client_from_env<S, SP>(
self, self,
shmem_provider: SP, shmem_provider: SP,
env_name: &str, env_name: &str,
configuration: EventConfig, configuration: EventConfig,
time_ref: Handle<TimeObserver>, time_ref: Option<Handle<TimeObserver>>,
) -> Result<LlmpEventManager<EMH, S, SP>, Error> ) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -304,42 +238,13 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
}) })
} }
/// If a client respawns, it may reuse the existing connection, previously
/// stored by [`LlmpClient::to_env()`].
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))]
pub fn build_existing_client_from_env<S, SP>(
self,
shmem_provider: SP,
env_name: &str,
configuration: EventConfig,
) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where
SP: ShMemProvider,
S: State,
{
let llmp = LlmpClient::on_existing_from_env(shmem_provider, env_name)?;
Ok(LlmpEventManager {
throttle: self.throttle,
last_sent: Duration::from_secs(0),
hooks: self.hooks,
always_interesting: self.always_interesting,
llmp,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
configuration,
phantom: PhantomData,
custom_buf_handlers: vec![],
})
}
/// Create an existing client from description /// Create an existing client from description
#[cfg(feature = "adaptive_serialization")]
pub fn build_existing_client_from_description<S, SP>( pub fn build_existing_client_from_description<S, SP>(
self, self,
shmem_provider: SP, shmem_provider: SP,
description: &LlmpClientDescription, description: &LlmpClientDescription,
configuration: EventConfig, configuration: EventConfig,
time_ref: Handle<TimeObserver>, time_ref: Option<Handle<TimeObserver>>,
) -> Result<LlmpEventManager<EMH, S, SP>, Error> ) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -364,36 +269,8 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
custom_buf_handlers: vec![], custom_buf_handlers: vec![],
}) })
} }
/// Create an existing client from description
#[cfg(not(feature = "adaptive_serialization"))]
pub fn build_existing_client_from_description<S, SP>(
self,
shmem_provider: SP,
description: &LlmpClientDescription,
configuration: EventConfig,
) -> Result<LlmpEventManager<EMH, S, SP>, Error>
where
SP: ShMemProvider,
S: State,
{
let llmp = LlmpClient::existing_client_from_description(shmem_provider, description)?;
Ok(LlmpEventManager {
throttle: self.throttle,
last_sent: Duration::from_secs(0),
hooks: self.hooks,
always_interesting: self.always_interesting,
llmp,
#[cfg(feature = "llmp_compression")]
compressor: GzipCompressor::with_threshold(COMPRESS_THRESHOLD),
configuration,
phantom: PhantomData,
custom_buf_handlers: vec![],
})
}
} }
#[cfg(feature = "adaptive_serialization")]
impl<EMH, S, SP> AdaptiveSerializer for LlmpEventManager<EMH, S, SP> impl<EMH, S, SP> AdaptiveSerializer for LlmpEventManager<EMH, S, SP>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -425,7 +302,7 @@ where
&mut self.should_serialize_cnt &mut self.should_serialize_cnt
} }
fn time_ref(&self) -> &Handle<TimeObserver> { fn time_ref(&self) -> &Option<Handle<TimeObserver>> {
&self.time_ref &self.time_ref
} }
} }
@ -556,11 +433,9 @@ where
let res = if client_config.match_with(&self.configuration) let res = if client_config.match_with(&self.configuration)
&& observers_buf.is_some() && observers_buf.is_some()
{ {
#[cfg(feature = "adaptive_serialization")]
let start = current_time(); let start = current_time();
let observers: E::Observers = let observers: E::Observers =
postcard::from_bytes(observers_buf.as_ref().unwrap())?; postcard::from_bytes(observers_buf.as_ref().unwrap())?;
#[cfg(feature = "adaptive_serialization")]
{ {
self.deserialization_time = current_time() - start; self.deserialization_time = current_time() - start;
} }
@ -671,15 +546,6 @@ where
Ok(()) Ok(())
} }
#[cfg(not(feature = "adaptive_serialization"))]
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
where
OT: ObserversTuple<Self::State> + Serialize,
{
Ok(Some(postcard::to_allocvec(observers)?))
}
#[cfg(feature = "adaptive_serialization")]
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error> fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
where where
OT: ObserversTuple<Self::State> + Serialize, OT: ObserversTuple<Self::State> + Serialize,

View File

@ -22,9 +22,11 @@ use libafl_bolts::os::startable_self;
use libafl_bolts::os::unix_signals::setup_signal_handler; use libafl_bolts::os::unix_signals::setup_signal_handler;
#[cfg(all(feature = "std", feature = "fork", unix))] #[cfg(all(feature = "std", feature = "fork", unix))]
use libafl_bolts::os::{fork, ForkResult}; use libafl_bolts::os::{fork, ForkResult};
#[cfg(feature = "adaptive_serialization")] use libafl_bolts::{
use libafl_bolts::tuples::{Handle, Handled}; llmp::LlmpBroker,
use libafl_bolts::{llmp::LlmpBroker, shmem::ShMemProvider, tuples::tuple_list}; shmem::ShMemProvider,
tuples::{tuple_list, Handle},
};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use libafl_bolts::{ use libafl_bolts::{
llmp::LlmpConnection, os::CTRL_C_EXIT, shmem::StdShMemProvider, staterestore::StateRestorer, llmp::LlmpConnection, os::CTRL_C_EXIT, shmem::StdShMemProvider, staterestore::StateRestorer,
@ -33,14 +35,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use typed_builder::TypedBuilder; use typed_builder::TypedBuilder;
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))] #[cfg(feature = "std")]
use crate::events::AdaptiveSerializer;
#[cfg(all(feature = "std", feature = "adaptive_serialization"))]
use crate::events::AdaptiveSerializer; use crate::events::AdaptiveSerializer;
#[cfg(all(unix, feature = "std", not(miri)))] #[cfg(all(unix, feature = "std", not(miri)))]
use crate::events::EVENTMGR_SIGHANDLER_STATE; use crate::events::EVENTMGR_SIGHANDLER_STATE;
#[cfg(feature = "adaptive_serialization")]
use crate::observers::TimeObserver;
use crate::{ use crate::{
events::{ events::{
hooks::EventManagerHooksTuple, Event, EventConfig, EventFirer, EventManager, hooks::EventManagerHooksTuple, Event, EventConfig, EventFirer, EventManager,
@ -51,7 +49,7 @@ use crate::{
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor}, fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
inputs::UsesInput, inputs::UsesInput,
monitors::Monitor, monitors::Monitor,
observers::ObserversTuple, observers::{ObserversTuple, TimeObserver},
state::{HasExecutions, HasLastReportTime, State, UsesState}, state::{HasExecutions, HasLastReportTime, State, UsesState},
Error, HasMetadata, Error, HasMetadata,
}; };
@ -73,7 +71,7 @@ where
save_state: LlmpShouldSaveState, save_state: LlmpShouldSaveState,
} }
#[cfg(all(feature = "std", feature = "adaptive_serialization"))] #[cfg(feature = "std")]
impl<EMH, S, SP> AdaptiveSerializer for LlmpRestartingEventManager<EMH, S, SP> impl<EMH, S, SP> AdaptiveSerializer for LlmpRestartingEventManager<EMH, S, SP>
where where
SP: ShMemProvider, SP: ShMemProvider,
@ -105,19 +103,11 @@ where
self.llmp_mgr.should_serialize_cnt_mut() self.llmp_mgr.should_serialize_cnt_mut()
} }
fn time_ref(&self) -> &Handle<TimeObserver> { fn time_ref(&self) -> &Option<Handle<TimeObserver>> {
&self.llmp_mgr.time_ref &self.llmp_mgr.time_ref
} }
} }
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))]
impl<EMH, S, SP> AdaptiveSerializer for LlmpRestartingEventManager<EMH, S, SP>
where
SP: ShMemProvider,
S: State,
{
}
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl<EMH, S, SP> UsesState for LlmpRestartingEventManager<EMH, S, SP> impl<EMH, S, SP> UsesState for LlmpRestartingEventManager<EMH, S, SP>
where where
@ -330,7 +320,7 @@ pub enum ManagerKind {
/// Sets up a restarting fuzzer, using the [`StdShMemProvider`], and standard features. /// Sets up a restarting fuzzer, using the [`StdShMemProvider`], and standard features.
/// The restarting mgr is a combination of restarter and runner, that can be used on systems with and without `fork` support. /// The restarting mgr is a combination of restarter and runner, that can be used on systems with and without `fork` support.
/// The restarter will spawn a new process each time the child crashes or timeouts. /// The restarter will spawn a new process each time the child crashes or timeouts.
#[cfg(all(feature = "std", not(feature = "adaptive_serialization")))] #[cfg(feature = "std")]
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub fn setup_restarting_mgr_std<MT, S>( pub fn setup_restarting_mgr_std<MT, S>(
monitor: MT, monitor: MT,
@ -345,7 +335,7 @@ pub fn setup_restarting_mgr_std<MT, S>(
> >
where where
MT: Monitor + Clone, MT: Monitor + Clone,
S: State + HasExecutions, S: State,
{ {
RestartingMgr::builder() RestartingMgr::builder()
.shmem_provider(StdShMemProvider::new()?) .shmem_provider(StdShMemProvider::new()?)
@ -360,13 +350,14 @@ where
/// Sets up a restarting fuzzer, using the [`StdShMemProvider`], and standard features. /// Sets up a restarting fuzzer, using the [`StdShMemProvider`], and standard features.
/// The restarting mgr is a combination of restarter and runner, that can be used on systems with and without `fork` support. /// The restarting mgr is a combination of restarter and runner, that can be used on systems with and without `fork` support.
/// The restarter will spawn a new process each time the child crashes or timeouts. /// The restarter will spawn a new process each time the child crashes or timeouts.
#[cfg(all(feature = "std", feature = "adaptive_serialization"))] /// This one, additionally uses the timeobserver for the adaptive serialization
#[cfg(feature = "std")]
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub fn setup_restarting_mgr_std<MT, S>( pub fn setup_restarting_mgr_std_adaptive<MT, S>(
monitor: MT, monitor: MT,
broker_port: u16, broker_port: u16,
configuration: EventConfig, configuration: EventConfig,
time_obs: &TimeObserver, time_obs: Handle<TimeObserver>,
) -> Result< ) -> Result<
( (
Option<S>, Option<S>,
@ -376,7 +367,7 @@ pub fn setup_restarting_mgr_std<MT, S>(
> >
where where
MT: Monitor + Clone, MT: Monitor + Clone,
S: State + HasExecutions, S: State,
{ {
RestartingMgr::builder() RestartingMgr::builder()
.shmem_provider(StdShMemProvider::new()?) .shmem_provider(StdShMemProvider::new()?)
@ -384,7 +375,7 @@ where
.broker_port(broker_port) .broker_port(broker_port)
.configuration(configuration) .configuration(configuration)
.hooks(tuple_list!()) .hooks(tuple_list!())
.time_ref(time_obs.handle()) .time_ref(Some(time_obs))
.build() .build()
.launch() .launch()
} }
@ -436,8 +427,8 @@ where
serialize_state: LlmpShouldSaveState, serialize_state: LlmpShouldSaveState,
/// The hooks passed to event manager: /// The hooks passed to event manager:
hooks: EMH, hooks: EMH,
#[cfg(feature = "adaptive_serialization")] #[builder(default = None)]
time_ref: Handle<TimeObserver>, time_ref: Option<Handle<TimeObserver>>,
#[builder(setter(skip), default = PhantomData)] #[builder(setter(skip), default = PhantomData)]
phantom_data: PhantomData<(EMH, S)>, phantom_data: PhantomData<(EMH, S)>,
} }
@ -448,7 +439,7 @@ impl<EMH, MT, S, SP> RestartingMgr<EMH, MT, S, SP>
where where
EMH: EventManagerHooksTuple<S> + Copy + Clone, EMH: EventManagerHooksTuple<S> + Copy + Clone,
SP: ShMemProvider, SP: ShMemProvider,
S: State + HasExecutions, S: State,
MT: Monitor + Clone, MT: Monitor + Clone,
{ {
/// Launch the broker and the clients and fuzz /// Launch the broker and the clients and fuzz
@ -500,12 +491,6 @@ where
return Err(Error::shutting_down()); return Err(Error::shutting_down());
} }
LlmpConnection::IsClient { client } => { LlmpConnection::IsClient { client } => {
#[cfg(not(feature = "adaptive_serialization"))]
let mgr: LlmpEventManager<EMH, S, SP> = LlmpEventManager::builder()
.always_interesting(self.always_interesting)
.hooks(self.hooks)
.build_from_client(client, self.configuration)?;
#[cfg(feature = "adaptive_serialization")]
let mgr: LlmpEventManager<EMH, S, SP> = LlmpEventManager::builder() let mgr: LlmpEventManager<EMH, S, SP> = LlmpEventManager::builder()
.always_interesting(self.always_interesting) .always_interesting(self.always_interesting)
.hooks(self.hooks) .hooks(self.hooks)
@ -532,16 +517,6 @@ where
} }
ManagerKind::Client { cpu_core } => { ManagerKind::Client { cpu_core } => {
// We are a client // We are a client
#[cfg(not(feature = "adaptive_serialization"))]
let mgr = LlmpEventManager::builder()
.always_interesting(self.always_interesting)
.hooks(self.hooks)
.build_on_port(
self.shmem_provider.clone(),
self.broker_port,
self.configuration,
)?;
#[cfg(feature = "adaptive_serialization")]
let mgr = LlmpEventManager::builder() let mgr = LlmpEventManager::builder()
.always_interesting(self.always_interesting) .always_interesting(self.always_interesting)
.hooks(self.hooks) .hooks(self.hooks)
@ -671,15 +646,6 @@ where
// If we're restarting, deserialize the old state. // If we're restarting, deserialize the old state.
let (state, mut mgr) = let (state, mut mgr) =
if let Some((state_opt, mgr_description)) = staterestorer.restore()? { if let Some((state_opt, mgr_description)) = staterestorer.restore()? {
#[cfg(not(feature = "adaptive_serialization"))]
let llmp_mgr = LlmpEventManager::builder()
.hooks(self.hooks)
.build_existing_client_from_description(
new_shmem_provider,
&mgr_description,
self.configuration,
)?;
#[cfg(feature = "adaptive_serialization")]
let llmp_mgr = LlmpEventManager::builder() let llmp_mgr = LlmpEventManager::builder()
.hooks(self.hooks) .hooks(self.hooks)
.build_existing_client_from_description( .build_existing_client_from_description(
@ -699,15 +665,6 @@ where
} else { } else {
log::info!("First run. Let's set it all up"); log::info!("First run. Let's set it all up");
// Mgr to send and receive msgs from/to all other fuzzer instances // Mgr to send and receive msgs from/to all other fuzzer instances
#[cfg(not(feature = "adaptive_serialization"))]
let mgr = LlmpEventManager::builder()
.hooks(self.hooks)
.build_existing_client_from_env(
new_shmem_provider,
_ENV_FUZZER_BROKER_CLIENT_INITIAL,
self.configuration,
)?;
#[cfg(feature = "adaptive_serialization")]
let mgr = LlmpEventManager::builder() let mgr = LlmpEventManager::builder()
.hooks(self.hooks) .hooks(self.hooks)
.build_existing_client_from_env( .build_existing_client_from_env(
@ -748,14 +705,12 @@ where
mod tests { mod tests {
use core::sync::atomic::{compiler_fence, Ordering}; use core::sync::atomic::{compiler_fence, Ordering};
#[cfg(feature = "adaptive_serialization")]
use libafl_bolts::tuples::Handled;
use libafl_bolts::{ use libafl_bolts::{
llmp::{LlmpClient, LlmpSharedMap}, llmp::{LlmpClient, LlmpSharedMap},
rands::StdRand, rands::StdRand,
shmem::{ShMemProvider, StdShMemProvider}, shmem::{ShMemProvider, StdShMemProvider},
staterestore::StateRestorer, staterestore::StateRestorer,
tuples::tuple_list, tuples::{tuple_list, Handled},
ClientId, ClientId,
}; };
use serial_test::serial; use serial_test::serial;
@ -782,7 +737,6 @@ mod tests {
let rand = StdRand::with_seed(0); let rand = StdRand::with_seed(0);
let time = TimeObserver::new("time"); let time = TimeObserver::new("time");
#[cfg(feature = "adaptive_serialization")]
let time_ref = time.handle(); let time_ref = time.handle();
let mut corpus = InMemoryCorpus::<BytesInput>::new(); let mut corpus = InMemoryCorpus::<BytesInput>::new();
@ -811,13 +765,8 @@ mod tests {
llmp_client.mark_safe_to_unmap(); llmp_client.mark_safe_to_unmap();
} }
#[cfg(not(feature = "adaptive_serialization"))]
let mut llmp_mgr = LlmpEventManager::builder() let mut llmp_mgr = LlmpEventManager::builder()
.build_from_client(llmp_client, "fuzzer".into()) .build_from_client(llmp_client, "fuzzer".into(), Some(time_ref.clone()))
.unwrap();
#[cfg(feature = "adaptive_serialization")]
let mut llmp_mgr = LlmpEventManager::builder()
.build_from_client(llmp_client, "fuzzer".into(), time_ref.clone())
.unwrap(); .unwrap();
let scheduler = RandScheduler::new(); let scheduler = RandScheduler::new();
@ -860,21 +809,12 @@ mod tests {
assert!(sc_cpy.has_content()); assert!(sc_cpy.has_content());
let (mut state_clone, mgr_description) = staterestorer.restore().unwrap().unwrap(); let (mut state_clone, mgr_description) = staterestorer.restore().unwrap().unwrap();
#[cfg(not(feature = "adaptive_serialization"))]
let mut llmp_clone = LlmpEventManager::builder() let mut llmp_clone = LlmpEventManager::builder()
.build_existing_client_from_description( .build_existing_client_from_description(
shmem_provider, shmem_provider,
&mgr_description, &mgr_description,
"fuzzer".into(), "fuzzer".into(),
) Some(time_ref),
.unwrap();
#[cfg(feature = "adaptive_serialization")]
let mut llmp_clone = LlmpEventManager::builder()
.build_existing_client_from_description(
shmem_provider,
&mgr_description,
"fuzzer".into(),
time_ref,
) )
.unwrap(); .unwrap();

View File

@ -32,9 +32,11 @@ use ahash::RandomState;
pub use launcher::*; pub use launcher::*;
#[cfg(all(unix, feature = "std"))] #[cfg(all(unix, feature = "std"))]
use libafl_bolts::os::unix_signals::{siginfo_t, ucontext_t, Handler, Signal, CTRL_C_EXIT}; use libafl_bolts::os::unix_signals::{siginfo_t, ucontext_t, Handler, Signal, CTRL_C_EXIT};
#[cfg(feature = "adaptive_serialization")] use libafl_bolts::{
use libafl_bolts::tuples::{Handle, MatchNameRef}; current_time,
use libafl_bolts::{current_time, ClientId}; tuples::{Handle, MatchNameRef},
ClientId,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use uuid::Uuid; use uuid::Uuid;
@ -104,9 +106,9 @@ pub struct EventManagerId(
#[cfg(feature = "introspection")] #[cfg(feature = "introspection")]
use crate::monitors::ClientPerfMonitor; use crate::monitors::ClientPerfMonitor;
#[cfg(feature = "adaptive_serialization")] use crate::{
use crate::observers::TimeObserver; inputs::UsesInput, observers::TimeObserver, stages::HasCurrentStage, state::UsesState,
use crate::{inputs::UsesInput, stages::HasCurrentStage, state::UsesState}; };
/// The log event severity /// The log event severity
#[derive(Serialize, Deserialize, Debug, Clone, Copy)] #[derive(Serialize, Deserialize, Debug, Clone, Copy)]
@ -839,11 +841,6 @@ where
} }
/// Collected stats to decide if observers must be serialized or not /// Collected stats to decide if observers must be serialized or not
#[cfg(not(feature = "adaptive_serialization"))]
pub trait AdaptiveSerializer {}
/// Collected stats to decide if observers must be serialized or not
#[cfg(feature = "adaptive_serialization")]
pub trait AdaptiveSerializer { pub trait AdaptiveSerializer {
/// Expose the collected observers serialization time /// Expose the collected observers serialization time
fn serialization_time(&self) -> Duration; fn serialization_time(&self) -> Duration;
@ -864,7 +861,7 @@ pub trait AdaptiveSerializer {
fn should_serialize_cnt_mut(&mut self) -> &mut usize; fn should_serialize_cnt_mut(&mut self) -> &mut usize;
/// A [`Handle`] to the time observer to determine the `time_factor` /// A [`Handle`] to the time observer to determine the `time_factor`
fn time_ref(&self) -> &Handle<TimeObserver>; fn time_ref(&self) -> &Option<Handle<TimeObserver>>;
/// Serialize the observer using the `time_factor` and `percentage_threshold`. /// Serialize the observer using the `time_factor` and `percentage_threshold`.
/// These parameters are unique to each of the different types of `EventManager` /// These parameters are unique to each of the different types of `EventManager`
@ -878,13 +875,16 @@ pub trait AdaptiveSerializer {
OT: ObserversTuple<S> + Serialize, OT: ObserversTuple<S> + Serialize,
S: UsesInput, S: UsesInput,
{ {
match self.time_ref() {
Some(t) => {
let exec_time = observers let exec_time = observers
.get(self.time_ref()) .get(t)
.map(|o| o.last_runtime().unwrap_or(Duration::ZERO)) .map(|o| o.last_runtime().unwrap_or(Duration::ZERO))
.unwrap(); .unwrap();
let mut must_ser = let mut must_ser = (self.serialization_time() + self.deserialization_time())
(self.serialization_time() + self.deserialization_time()) * time_factor < exec_time; * time_factor
< exec_time;
if must_ser { if must_ser {
*self.should_serialize_cnt_mut() += 1; *self.should_serialize_cnt_mut() += 1;
} }
@ -909,6 +909,9 @@ pub trait AdaptiveSerializer {
Ok(None) Ok(None)
} }
} }
None => Ok(None),
}
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -11,9 +11,12 @@ use crate::{
errors::{AsanError, AsanErrors}, errors::{AsanError, AsanErrors},
}, },
}; };
#[cfg(windows)]
extern "system" { extern "system" {
fn memcpy(dst: *mut c_void, src: *const c_void, size: usize) -> *mut c_void; fn memcpy(dst: *mut c_void, src: *const c_void, size: usize) -> *mut c_void;
} }
#[cfg(windows)]
extern "system" { extern "system" {
fn memset(s: *mut c_void, c: i32, n: usize) -> *mut c_void; fn memset(s: *mut c_void, c: i32, n: usize) -> *mut c_void;
} }

View File

@ -48,7 +48,7 @@ hexagon = ["libafl_qemu/hexagon"]
pyo3-build-config = { version = "0.21", optional = true } pyo3-build-config = { version = "0.21", optional = true }
[dependencies] [dependencies]
libafl = { path = "../libafl", version = "0.12.0", features = ["adaptive_serialization"] } libafl = { path = "../libafl", version = "0.12.0" }
libafl_bolts = { path = "../libafl_bolts", version = "0.12.0" } libafl_bolts = { path = "../libafl_bolts", version = "0.12.0" }
libafl_targets = { path = "../libafl_targets", version = "0.12.0" } libafl_targets = { path = "../libafl_targets", version = "0.12.0" }

View File

@ -295,7 +295,7 @@ impl<'a> ForkserverBytesCoverageSugar<'a> {
.cores(self.cores) .cores(self.cores)
.broker_port(self.broker_port) .broker_port(self.broker_port)
.remote_broker_addr(self.remote_broker_addr) .remote_broker_addr(self.remote_broker_addr)
.time_ref(time_ref); .time_ref(Some(time_ref));
#[cfg(unix)] #[cfg(unix)]
let launcher = launcher.stdout_file(Some("/dev/null")); let launcher = launcher.stdout_file(Some("/dev/null"));
match launcher.build().launch() { match launcher.build().launch() {

View File

@ -351,7 +351,7 @@ where
.cores(self.cores) .cores(self.cores)
.broker_port(self.broker_port) .broker_port(self.broker_port)
.remote_broker_addr(self.remote_broker_addr) .remote_broker_addr(self.remote_broker_addr)
.time_ref(time_ref); .time_ref(Some(time_ref));
#[cfg(unix)] #[cfg(unix)]
let launcher = launcher.stdout_file(Some("/dev/null")); let launcher = launcher.stdout_file(Some("/dev/null"));
match launcher.build().launch() { match launcher.build().launch() {

View File

@ -440,7 +440,7 @@ where
.cores(self.cores) .cores(self.cores)
.broker_port(self.broker_port) .broker_port(self.broker_port)
.remote_broker_addr(self.remote_broker_addr) .remote_broker_addr(self.remote_broker_addr)
.time_ref(time_ref); .time_ref(Some(time_ref));
#[cfg(unix)] #[cfg(unix)]
let launcher = launcher.stdout_file(Some("/dev/null")); let launcher = launcher.stdout_file(Some("/dev/null"));

View File

@ -17,7 +17,9 @@ use libafl::executors::{hooks::ExecutorHook, HasObservers};
))] ))]
use crate::coverage::EDGES_MAP; use crate::coverage::EDGES_MAP;
use crate::coverage::MAX_EDGES_FOUND; use crate::coverage::MAX_EDGES_FOUND;
#[cfg(feature = "sancov_ngram4")] #[cfg(feature = "sancov_ngram4")]
#[allow(unused)]
use crate::EDGES_MAP_SIZE_IN_USE; use crate::EDGES_MAP_SIZE_IN_USE;
#[cfg(feature = "pointer_maps")] #[cfg(feature = "pointer_maps")]
use crate::{coverage::EDGES_MAP_PTR, EDGES_MAP_SIZE_MAX}; use crate::{coverage::EDGES_MAP_PTR, EDGES_MAP_SIZE_MAX};
@ -29,6 +31,7 @@ compile_error!(
); );
#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))] #[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[allow(unused)]
use core::ops::ShlAssign; use core::ops::ShlAssign;
#[cfg(feature = "sancov_ngram4")] #[cfg(feature = "sancov_ngram4")]