Use Associated Types for Has* traits and AsSlice (#881)

* More Associated Types

* AsSlice associated-ified

* added script to find unused files

* fixes for python

* build all the things

* windows fixes
This commit is contained in:
Dominik Maier 2022-11-10 09:31:04 +01:00 committed by GitHub
parent 18f288e2d3
commit 6b6570ae5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 210 additions and 118 deletions

View File

@ -574,7 +574,7 @@ impl LlmpMsg {
slice::from_raw_parts(self.buf.as_ptr(), self.buf_len as usize)
}
/// Gets the buffer from this message as slice, with the corrent length.
/// Gets the buffer from this message as slice, with the correct length.
#[inline]
pub fn try_as_slice<SHM: ShMem>(&self, map: &mut LlmpSharedMap<SHM>) -> Result<&[u8], Error> {
unsafe {
@ -586,7 +586,7 @@ impl LlmpMsg {
}
}
/// Returns true, if the pointer is, indeed, in the page of this shared map.
/// Returns `true`, if the pointer is, indeed, in the page of this shared map.
#[inline]
pub fn in_shmem<SHM: ShMem>(&self, map: &mut LlmpSharedMap<SHM>) -> bool {
let map_size = map.shmem.as_slice().len();

View File

@ -35,15 +35,19 @@ use core::{iter::Iterator, time};
use std::time::{SystemTime, UNIX_EPOCH};
/// Can be converted to a slice
pub trait AsSlice<T> {
pub trait AsSlice {
/// Type of the entries in this slice
type Entry;
/// Convert to a slice
fn as_slice(&self) -> &[T];
fn as_slice(&self) -> &[Self::Entry];
}
/// Can be converted to a mutable slice
pub trait AsMutSlice<T> {
pub trait AsMutSlice {
/// Type of the entries in this mut slice
type Entry;
/// Convert to a slice
fn as_mut_slice(&mut self) -> &mut [T];
fn as_mut_slice(&mut self) -> &mut [Self::Entry];
}
/// Create an `Iterator` from a reference

View File

@ -95,18 +95,20 @@ where
}
}
impl<SH> AsSlice<u8> for ServedShMem<SH>
impl<SH> AsSlice for ServedShMem<SH>
where
SH: ShMem,
{
type Entry = u8;
fn as_slice(&self) -> &[u8] {
self.inner.as_slice()
}
}
impl<SH> AsMutSlice<u8> for ServedShMem<SH>
impl<SH> AsMutSlice for ServedShMem<SH>
where
SH: ShMem,
{
type Entry = u8;
fn as_mut_slice(&mut self) -> &mut [u8] {
self.inner.as_mut_slice()
}

View File

@ -290,7 +290,8 @@ impl<'a, T> From<OwnedSliceMut<'a, T>> for OwnedSlice<'a, T> {
}
}
impl<'a, T: Sized> AsSlice<T> for OwnedSlice<'a, T> {
impl<'a, T: Sized> AsSlice for OwnedSlice<'a, T> {
type Entry = T;
/// Get the [`OwnedSlice`] as slice.
#[must_use]
fn as_slice(&self) -> &[T] {
@ -416,7 +417,8 @@ impl<'a, T: 'a + Sized> OwnedSliceMut<'a, T> {
}
}
impl<'a, T: Sized> AsSlice<T> for OwnedSliceMut<'a, T> {
impl<'a, T: Sized> AsSlice for OwnedSliceMut<'a, T> {
type Entry = T;
/// Get the value as slice
#[must_use]
fn as_slice(&self) -> &[T] {
@ -427,7 +429,8 @@ impl<'a, T: Sized> AsSlice<T> for OwnedSliceMut<'a, T> {
}
}
}
impl<'a, T: Sized> AsMutSlice<T> for OwnedSliceMut<'a, T> {
impl<'a, T: Sized> AsMutSlice for OwnedSliceMut<'a, T> {
type Entry = T;
/// Get the value as mut slice
#[must_use]
fn as_mut_slice(&mut self) -> &mut [T] {

View File

@ -137,7 +137,8 @@ impl ShMemId {
alloc::str::from_utf8(&self.id[..self.null_pos()]).unwrap()
}
}
impl AsSlice<u8> for ShMemId {
impl AsSlice for ShMemId {
type Entry = u8;
fn as_slice(&self) -> &[u8] {
&self.id
}
@ -158,7 +159,7 @@ impl Display for ShMemId {
/// A [`ShMem`] is an interface to shared maps.
/// They are the backbone of [`crate::bolts::llmp`] for inter-process communication.
/// All you need for scaling on a new target is to implement this interface, as well as the respective [`ShMemProvider`].
pub trait ShMem: Sized + Debug + Clone + AsSlice<u8> + AsMutSlice<u8> {
pub trait ShMem: Sized + Debug + Clone + AsSlice<Entry = u8> + AsMutSlice<Entry = u8> {
/// Get the id of this shared memory mapping
fn id(&self) -> ShMemId;
@ -312,19 +313,21 @@ where
}
}
impl<T> AsSlice<u8> for RcShMem<T>
impl<T> AsSlice for RcShMem<T>
where
T: ShMemProvider + Debug,
{
type Entry = u8;
fn as_slice(&self) -> &[u8] {
self.internal.as_slice()
}
}
impl<T> AsMutSlice<u8> for RcShMem<T>
impl<T> AsMutSlice for RcShMem<T>
where
T: ShMemProvider + Debug,
{
type Entry = u8;
fn as_mut_slice(&mut self) -> &mut [u8] {
self.internal.as_mut_slice()
}
@ -754,13 +757,15 @@ pub mod unix_shmem {
}
}
impl AsSlice<u8> for MmapShMem {
impl AsSlice for MmapShMem {
type Entry = u8;
fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.map, self.map_size) }
}
}
impl AsMutSlice<u8> for MmapShMem {
impl AsMutSlice for MmapShMem {
type Entry = u8;
fn as_mut_slice(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.map, self.map_size) }
}
@ -867,13 +872,15 @@ pub mod unix_shmem {
}
}
impl AsSlice<u8> for CommonUnixShMem {
impl AsSlice for CommonUnixShMem {
type Entry = u8;
fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.map, self.map_size) }
}
}
impl AsMutSlice<u8> for CommonUnixShMem {
impl AsMutSlice for CommonUnixShMem {
type Entry = u8;
fn as_mut_slice(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.map, self.map_size) }
}
@ -1077,13 +1084,16 @@ pub mod unix_shmem {
}
}
impl AsSlice<u8> for AshmemShMem {
impl AsSlice for AshmemShMem {
type Entry = u8;
fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.map, self.map_size) }
}
}
impl AsMutSlice<u8> for AshmemShMem {
impl AsMutSlice for AshmemShMem {
type Entry = u8;
fn as_mut_slice(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.map, self.map_size) }
}
@ -1275,12 +1285,14 @@ pub mod win32_shmem {
}
}
impl AsSlice<u8> for Win32ShMem {
impl AsSlice for Win32ShMem {
type Entry = u8;
fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.map, self.map_size) }
}
}
impl AsMutSlice<u8> for Win32ShMem {
impl AsMutSlice for Win32ShMem {
type Entry = u8;
fn as_mut_slice(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.map, self.map_size) }
}

View File

@ -43,7 +43,7 @@ where
E: Executor<EM, Z> + HasObservers,
CS: Scheduler<State = E::State>,
EM: UsesState<State = E::State>,
Z: HasScheduler<CS, State = E::State>;
Z: HasScheduler<Scheduler = CS, State = E::State>;
}
/// Minimizes a corpus according to coverage maps, weighting by the specified `TestcaseScore`.
@ -102,7 +102,7 @@ where
E: Executor<EM, Z> + HasObservers,
CS: Scheduler<State = E::State>,
EM: UsesState<State = E::State>,
Z: HasScheduler<CS, State = E::State>,
Z: HasScheduler<Scheduler = CS, State = E::State>,
{
let cfg = Config::default();
let ctx = Context::new(&cfg);

View File

@ -552,7 +552,7 @@ where
{
}
impl<S, SP> HasCustomBufHandlers<S> for LlmpEventManager<S, SP>
impl<S, SP> HasCustomBufHandlers for LlmpEventManager<S, SP>
where
S: UsesInput,
SP: ShMemProvider,

View File

@ -466,9 +466,9 @@ type CustomBufHandlerFn<S> =
dyn FnMut(&mut S, &String, &[u8]) -> Result<CustomBufEventResult, Error>;
/// Supports custom buf handlers to handle `CustomBuf` events.
pub trait HasCustomBufHandlers<S> {
pub trait HasCustomBufHandlers: UsesState {
/// Adds a custom buffer handler that will run for each incoming `CustomBuf` event.
fn add_custom_buf_handler(&mut self, handler: Box<CustomBufHandlerFn<S>>);
fn add_custom_buf_handler(&mut self, handler: Box<CustomBufHandlerFn<Self::State>>);
}
/// An eventmgr for tests, and as placeholder if you really don't need an event manager.
@ -528,10 +528,15 @@ impl<E, S, Z> EventManager<E, Z> for NopEventManager<S> where
{
}
impl<S> HasCustomBufHandlers<S> for NopEventManager<S> {
impl<S> HasCustomBufHandlers for NopEventManager<S>
where
S: UsesInput,
{
fn add_custom_buf_handler(
&mut self,
_handler: Box<dyn FnMut(&mut S, &String, &[u8]) -> Result<CustomBufEventResult, Error>>,
_handler: Box<
dyn FnMut(&mut Self::State, &String, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
}
}

View File

@ -128,7 +128,7 @@ where
{
}
impl<MT, S> HasCustomBufHandlers<S> for SimpleEventManager<MT, S>
impl<MT, S> HasCustomBufHandlers for SimpleEventManager<MT, S>
where
MT: Monitor, //CE: CustomEvent<I, OT>,
S: UsesInput,
@ -136,7 +136,9 @@ where
/// Adds a custom buffer handler that will run for each incoming `CustomBuf` event.
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &String, &[u8]) -> Result<CustomBufEventResult, Error>>,
handler: Box<
dyn FnMut(&mut Self::State, &String, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
self.custom_buf_handlers.push(handler);
}
@ -371,7 +373,7 @@ where
}
#[cfg(feature = "std")]
impl<MT, S, SP> HasCustomBufHandlers<S> for SimpleRestartingEventManager<MT, S, SP>
impl<MT, S, SP> HasCustomBufHandlers for SimpleRestartingEventManager<MT, S, SP>
where
MT: Monitor,
S: UsesInput,

View File

@ -184,7 +184,7 @@ where
Self: Executor<EM, Z, State = S>,
EM: EventFirer<State = S> + EventRestarter,
OF: Feedback<S>,
Z: HasObjective<OF, State = S>,
Z: HasObjective<Objective = OF, State = S>,
{
let handlers = InProcessHandlers::new::<Self, EM, OF, Z, H>()?;
#[cfg(windows)]
@ -342,7 +342,7 @@ impl InProcessHandlers {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
H: FnMut(&<E::State as UsesInput>::Input) -> ExitKind + ?Sized,
{
#[cfg(unix)]
@ -614,7 +614,7 @@ mod unix_signal_handler {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
{
let old_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic_info| {
@ -687,7 +687,7 @@ mod unix_signal_handler {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
{
if !data.is_valid() {
#[cfg(feature = "std")]
@ -765,7 +765,7 @@ mod unix_signal_handler {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
{
#[cfg(all(target_os = "android", target_arch = "aarch64"))]
let _context = &mut *(((_context as *mut _ as *mut libc::c_void as usize) + 128)
@ -949,7 +949,7 @@ mod windows_exception_handler {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
{
let old_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic_info| {
@ -1039,7 +1039,7 @@ mod windows_exception_handler {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
{
let data: &mut InProcessExecutorHandlerData =
&mut *(global_state as *mut InProcessExecutorHandlerData);
@ -1135,7 +1135,7 @@ mod windows_exception_handler {
EM: EventFirer<State = E::State> + EventRestarter<State = E::State>,
OF: Feedback<E::State>,
E::State: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = E::State>,
Z: HasObjective<Objective = OF, State = E::State>,
{
// Have we set a timer_before?
if !(data.tp_timer as *mut windows::Win32::System::Threading::TP_TIMER).is_null() {
@ -1701,7 +1701,7 @@ where
EM: EventFirer<State = S> + EventRestarter,
OF: Feedback<S>,
S: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = S>,
Z: HasObjective<Objective = OF, State = S>,
{
let handlers = InChildProcessHandlers::new::<Self>()?;
Ok(Self {
@ -1748,7 +1748,7 @@ where
EM: EventFirer<State = S> + EventRestarter<State = S>,
OF: Feedback<S>,
S: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = S>,
Z: HasObjective<Objective = OF, State = S>,
{
let handlers = InChildProcessHandlers::with_timeout::<Self>()?;
let milli_sec = timeout.as_millis();

View File

@ -214,13 +214,15 @@ pub struct MapIndexesMetadata {
crate::impl_serdeany!(MapIndexesMetadata);
impl AsSlice<usize> for MapIndexesMetadata {
impl AsSlice for MapIndexesMetadata {
type Entry = usize;
/// Convert to a slice
fn as_slice(&self) -> &[usize] {
self.list.as_slice()
}
}
impl AsMutSlice<usize> for MapIndexesMetadata {
impl AsMutSlice for MapIndexesMetadata {
type Entry = usize;
/// Convert to a slice
fn as_mut_slice(&mut self) -> &mut [usize] {
self.list.as_mut_slice()
@ -254,14 +256,16 @@ pub struct MapNoveltiesMetadata {
crate::impl_serdeany!(MapNoveltiesMetadata);
impl AsSlice<usize> for MapNoveltiesMetadata {
impl AsSlice for MapNoveltiesMetadata {
type Entry = usize;
/// Convert to a slice
#[must_use]
fn as_slice(&self) -> &[usize] {
self.list.as_slice()
}
}
impl AsMutSlice<usize> for MapNoveltiesMetadata {
impl AsMutSlice for MapNoveltiesMetadata {
type Entry = usize;
/// Convert to a slice
#[must_use]
fn as_mut_slice(&mut self) -> &mut [usize] {
@ -430,7 +434,7 @@ where
#[rustversion::nightly]
impl<O, S> Feedback<S> for MapFeedback<DifferentIsNovel, O, MaxReducer, S, u8>
where
O: MapObserver<Entry = u8> + AsSlice<u8>,
O: MapObserver<Entry = u8> + AsSlice<Entry = u8>,
for<'it> O: AsIter<'it, Item = u8>,
S: UsesInput + HasNamedMetadata + HasClientPerfMonitor + Debug,
{

View File

@ -31,41 +31,45 @@ use crate::{
const STATS_TIMEOUT_DEFAULT: Duration = Duration::from_secs(15);
/// Holds a scheduler
pub trait HasScheduler<CS>: UsesState
where
CS: Scheduler<State = Self::State>,
{
pub trait HasScheduler: UsesState {
/// The [`Scheduler`] for this fuzzer
type Scheduler: Scheduler<State = Self::State>;
/// The scheduler
fn scheduler(&self) -> &CS;
fn scheduler(&self) -> &Self::Scheduler;
/// The scheduler (mutable)
fn scheduler_mut(&mut self) -> &mut CS;
fn scheduler_mut(&mut self) -> &mut Self::Scheduler;
}
/// Holds an feedback
pub trait HasFeedback<F>: UsesState
pub trait HasFeedback: UsesState
where
F: Feedback<Self::State>,
Self::State: HasClientPerfMonitor,
{
/// The feedback type
type Feedback: Feedback<Self::State>;
/// The feedback
fn feedback(&self) -> &F;
fn feedback(&self) -> &Self::Feedback;
/// The feedback (mutable)
fn feedback_mut(&mut self) -> &mut F;
fn feedback_mut(&mut self) -> &mut Self::Feedback;
}
/// Holds an objective feedback
pub trait HasObjective<OF>: UsesState
pub trait HasObjective: UsesState
where
OF: Feedback<Self::State>,
Self::State: HasClientPerfMonitor,
{
/// The type of the [`Feedback`] used to find objectives for this fuzzer
type Objective: Feedback<Self::State>;
/// The objective feedback
fn objective(&self) -> &OF;
fn objective(&self) -> &Self::Objective;
/// The objective feedback (mutable)
fn objective_mut(&mut self) -> &mut OF;
fn objective_mut(&mut self) -> &mut Self::Objective;
}
/// Evaluate if an input is interesting using the feedback
@ -263,13 +267,15 @@ where
type State = CS::State;
}
impl<CS, F, OF, OT> HasScheduler<CS> for StdFuzzer<CS, F, OF, OT>
impl<CS, F, OF, OT> HasScheduler for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
CS::State: HasClientPerfMonitor,
{
type Scheduler = CS;
fn scheduler(&self) -> &CS {
&self.scheduler
}
@ -279,29 +285,33 @@ where
}
}
impl<CS, F, OF, OT> HasFeedback<F> for StdFuzzer<CS, F, OF, OT>
impl<CS, F, OF, OT> HasFeedback for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
CS::State: HasClientPerfMonitor,
{
fn feedback(&self) -> &F {
type Feedback = F;
fn feedback(&self) -> &Self::Feedback {
&self.feedback
}
fn feedback_mut(&mut self) -> &mut F {
fn feedback_mut(&mut self) -> &mut Self::Feedback {
&mut self.feedback
}
}
impl<CS, F, OF, OT> HasObjective<OF> for StdFuzzer<CS, F, OF, OT>
impl<CS, F, OF, OT> HasObjective for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
CS::State: HasClientPerfMonitor,
{
type Objective = OF;
fn objective(&self) -> &OF {
&self.objective
}

View File

@ -31,13 +31,15 @@ pub struct LogMutationMetadata {
crate::impl_serdeany!(LogMutationMetadata);
impl AsSlice<String> for LogMutationMetadata {
impl AsSlice for LogMutationMetadata {
type Entry = String;
#[must_use]
fn as_slice(&self) -> &[String] {
self.list.as_slice()
}
}
impl AsMutSlice<String> for LogMutationMetadata {
impl AsMutSlice for LogMutationMetadata {
type Entry = String;
#[must_use]
fn as_mut_slice(&mut self) -> &mut [String] {
self.list.as_mut_slice()

View File

@ -266,7 +266,8 @@ where
}
}
impl AsSlice<Vec<u8>> for Tokens {
impl AsSlice for Tokens {
type Entry = Vec<u8>;
fn as_slice(&self) -> &[Vec<u8>] {
self.tokens()
}

View File

@ -64,14 +64,16 @@ pub struct CmpValuesMetadata {
crate::impl_serdeany!(CmpValuesMetadata);
impl AsSlice<CmpValues> for CmpValuesMetadata {
impl AsSlice for CmpValuesMetadata {
type Entry = CmpValues;
/// Convert to a slice
#[must_use]
fn as_slice(&self) -> &[CmpValues] {
self.list.as_slice()
}
}
impl AsMutSlice<CmpValues> for CmpValuesMetadata {
impl AsMutSlice for CmpValuesMetadata {
type Entry = CmpValues;
/// Convert to a slice
#[must_use]
fn as_mut_slice(&mut self) -> &mut [CmpValues] {

View File

@ -404,20 +404,22 @@ where
}
}
impl<'a, T> AsSlice<T> for StdMapObserver<'a, T>
impl<'a, T> AsSlice for StdMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[must_use]
#[inline]
fn as_slice(&self) -> &[T] {
self.map.as_slice()
}
}
impl<'a, T> AsMutSlice<T> for StdMapObserver<'a, T>
impl<'a, T> AsMutSlice for StdMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[must_use]
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
@ -700,19 +702,21 @@ where
}
}
impl<'a, T, const N: usize> AsSlice<T> for ConstMapObserver<'a, T, N>
impl<'a, T, const N: usize> AsSlice for ConstMapObserver<'a, T, N>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[inline]
fn as_slice(&self) -> &[T] {
self.map.as_slice()
}
}
impl<'a, T, const N: usize> AsMutSlice<T> for ConstMapObserver<'a, T, N>
impl<'a, T, const N: usize> AsMutSlice for ConstMapObserver<'a, T, N>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
self.map.as_mut_slice()
@ -969,7 +973,7 @@ where
}
}
impl<'a, T> AsSlice<T> for VariableMapObserver<'a, T>
impl<'a, T> AsSlice for VariableMapObserver<'a, T>
where
T: Bounded
+ PartialEq
@ -980,16 +984,18 @@ where
+ serde::de::DeserializeOwned
+ Debug,
{
type Entry = T;
#[inline]
fn as_slice(&self) -> &[T] {
let cnt = self.usable_count();
&self.map.as_slice()[..cnt]
}
}
impl<'a, T> AsMutSlice<T> for VariableMapObserver<'a, T>
impl<'a, T> AsMutSlice for VariableMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
self.map.as_mut_slice()
@ -1044,7 +1050,7 @@ where
impl<S, M> Observer<S> for HitcountsMapObserver<M>
where
M: MapObserver<Entry = u8> + Observer<S> + AsMutSlice<u8>,
M: MapObserver<Entry = u8> + Observer<S> + AsMutSlice<Entry = u8>,
S: UsesInput,
{
#[inline]
@ -1155,21 +1161,23 @@ where
}
}
impl<M> AsSlice<u8> for HitcountsMapObserver<M>
impl<M> AsSlice for HitcountsMapObserver<M>
where
M: MapObserver + AsSlice<u8>,
M: MapObserver + AsSlice,
{
type Entry = <M as AsSlice>::Entry;
#[inline]
fn as_slice(&self) -> &[u8] {
fn as_slice(&self) -> &[Self::Entry] {
self.base.as_slice()
}
}
impl<M> AsMutSlice<u8> for HitcountsMapObserver<M>
impl<M> AsMutSlice for HitcountsMapObserver<M>
where
M: MapObserver + AsMutSlice<u8>,
M: MapObserver + AsMutSlice,
{
type Entry = <M as AsMutSlice>::Entry;
#[inline]
fn as_mut_slice(&mut self) -> &mut [u8] {
fn as_mut_slice(&mut self) -> &mut [Self::Entry] {
self.base.as_mut_slice()
}
}
@ -1349,21 +1357,23 @@ where
}
}
impl<M> AsSlice<u8> for HitcountsIterableMapObserver<M>
impl<M> AsSlice for HitcountsIterableMapObserver<M>
where
M: MapObserver + AsSlice<u8>,
M: MapObserver + AsSlice,
{
type Entry = <M as AsSlice>::Entry;
#[inline]
fn as_slice(&self) -> &[u8] {
fn as_slice(&self) -> &[Self::Entry] {
self.base.as_slice()
}
}
impl<M> AsMutSlice<u8> for HitcountsIterableMapObserver<M>
impl<M> AsMutSlice for HitcountsIterableMapObserver<M>
where
M: MapObserver + AsMutSlice<u8>,
M: MapObserver + AsMutSlice,
{
type Entry = <M as AsMutSlice>::Entry;
#[inline]
fn as_mut_slice(&mut self) -> &mut [u8] {
fn as_mut_slice(&mut self) -> &mut [Self::Entry] {
self.base.as_mut_slice()
}
}
@ -1873,20 +1883,22 @@ where
}
}
impl<T> AsSlice<T> for OwnedMapObserver<T>
impl<T> AsSlice for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[must_use]
#[inline]
fn as_slice(&self) -> &[T] {
self.map.as_slice()
}
}
impl<T> AsMutSlice<T> for OwnedMapObserver<T>
impl<T> AsMutSlice for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[must_use]
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
@ -2171,13 +2183,15 @@ pub mod pybind {
}
}
impl AsSlice<$datatype> for $struct_name_trait {
impl AsSlice for $struct_name_trait {
type Entry = $datatype;
fn as_slice(&self) -> &[$datatype] {
mapob_unwrap_me!($wrapper_name, self.wrapper, m, { unsafe { std::mem::transmute(m.as_slice()) }} )
}
}
impl AsMutSlice<$datatype> for $struct_name_trait {
impl AsMutSlice for $struct_name_trait {
type Entry = $datatype;
fn as_mut_slice(&mut self) -> &mut [$datatype] {
mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { unsafe { std::mem::transmute(m.as_mut_slice()) }} )
}

View File

@ -30,13 +30,16 @@ pub struct AccountingIndexesMetadata {
crate::impl_serdeany!(AccountingIndexesMetadata);
impl AsSlice<usize> for AccountingIndexesMetadata {
impl AsSlice for AccountingIndexesMetadata {
type Entry = usize;
/// Convert to a slice
fn as_slice(&self) -> &[usize] {
self.list.as_slice()
}
}
impl AsMutSlice<usize> for AccountingIndexesMetadata {
impl AsMutSlice for AccountingIndexesMetadata {
type Entry = usize;
/// Convert to a slice
fn as_mut_slice(&mut self) -> &mut [usize] {
self.list.as_mut_slice()

View File

@ -78,7 +78,7 @@ impl<CS, F, M> Scheduler for MinimizerScheduler<CS, F, M>
where
CS: Scheduler,
F: TestcaseScore<CS::State>,
M: AsSlice<usize> + SerdeAny + HasRefCnt,
M: AsSlice<Entry = usize> + SerdeAny + HasRefCnt,
CS::State: HasCorpus + HasMetadata + HasRand,
{
/// Add an entry to the corpus and return its index
@ -190,7 +190,7 @@ impl<CS, F, M> MinimizerScheduler<CS, F, M>
where
CS: Scheduler,
F: TestcaseScore<CS::State>,
M: AsSlice<usize> + SerdeAny + HasRefCnt,
M: AsSlice<Entry = usize> + SerdeAny + HasRefCnt,
CS::State: HasCorpus + HasMetadata + HasRand,
{
/// Update the `Corpus` score using the `MinimizerScheduler`

View File

@ -244,7 +244,7 @@ where
Z: ExecutesInput<E, EM, State = CS::State>
+ ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<CS>,
+ HasScheduler<Scheduler = CS>,
{
fn perform(
&mut self,

View File

@ -38,7 +38,9 @@ where
EM: EventFirer<State = CS::State> + EventRestarter + HasEventManagerId,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasRand,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// The [`crate::state::State`]
pub state: CS::State,
@ -57,7 +59,9 @@ where
EM: EventFirer<State = CS::State> + EventRestarter + HasEventManagerId,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasRand,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// Create a new `PushStageSharedState` that can be used by all [`PushStage`]s
#[must_use]
@ -80,7 +84,9 @@ where
EM: EventFirer<State = CS::State> + EventRestarter + HasEventManagerId,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasRand,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// If this stage has already been initalized.
/// This gets reset to `false` after one iteration of the stage is done.
@ -110,7 +116,9 @@ where
EM: EventFirer<State = CS::State> + EventRestarter + HasEventManagerId,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasRand,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// Create a new [`PushStageHelper`]
#[must_use]
@ -178,7 +186,9 @@ where
CS::State: HasClientPerfMonitor + HasRand + HasExecutions + HasMetadata,
EM: EventFirer<State = CS::State> + EventRestarter + HasEventManagerId + ProgressReporter,
OT: ObserversTuple<CS::State>,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// Gets the [`PushStageHelper`]
fn push_stage_helper(&self) -> &PushStageHelper<CS, EM, OT, Z>;

View File

@ -44,7 +44,9 @@ where
M: Mutator<CS::State>,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasRand + Clone + Debug,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
current_corpus_idx: Option<usize>,
testcases_to_do: usize,
@ -64,7 +66,9 @@ where
M: Mutator<CS::State>,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasCorpus + HasRand + Clone + Debug,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// Gets the number of iterations as a random number
#[allow(clippy::unused_self, clippy::unnecessary_wraps)] // TODO: we should put this function into a trait later
@ -86,7 +90,9 @@ where
OT: ObserversTuple<CS::State>,
CS::State:
HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions + HasMetadata + Clone + Debug,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
#[inline]
fn push_stage_helper(&self) -> &PushStageHelper<CS, EM, OT, Z> {
@ -197,7 +203,9 @@ where
OT: ObserversTuple<CS::State>,
CS::State:
HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions + HasMetadata + Clone + Debug,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
type Item = Result<<CS::State as UsesInput>::Input, Error>;
@ -213,7 +221,9 @@ where
M: Mutator<CS::State>,
OT: ObserversTuple<CS::State>,
CS::State: HasClientPerfMonitor + HasCorpus + HasRand + Clone + Debug,
Z: ExecutionProcessor<OT, State = CS::State> + EvaluatorObservers<OT> + HasScheduler<CS>,
Z: ExecutionProcessor<OT, State = CS::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{
/// Creates a new default mutational stage
#[must_use]

View File

@ -45,8 +45,8 @@ where
OT: ObserversTuple<CS::State>,
Z: ExecutionProcessor<OT, State = Self::State>
+ ExecutesInput<E, EM>
+ HasFeedback<F1>
+ HasScheduler<CS>,
+ HasFeedback<Feedback = F1>
+ HasScheduler<Scheduler = CS>,
{
/// The mutator registered for this stage
fn mutator(&self) -> &M;
@ -198,8 +198,8 @@ where
OT: ObserversTuple<CS::State>,
Z: ExecutionProcessor<OT, State = CS::State>
+ ExecutesInput<E, EM>
+ HasFeedback<F1>
+ HasScheduler<CS>,
+ HasFeedback<Feedback = F1>
+ HasScheduler<Scheduler = CS>,
{
fn perform(
&mut self,
@ -246,8 +246,8 @@ where
CS::State: HasClientPerfMonitor + HasCorpus + HasExecutions + HasMaxSize,
Z: ExecutionProcessor<OT, State = CS::State>
+ ExecutesInput<E, EM>
+ HasFeedback<F1>
+ HasScheduler<CS>,
+ HasFeedback<Feedback = F1>
+ HasScheduler<Scheduler = CS>,
{
/// The mutator, added to this stage
#[inline]

View File

@ -66,7 +66,7 @@ where
EM: EventFirer<State = S> + EventRestarter<State = S>,
OF: Feedback<S>,
S: State + HasExecutions + HasCorpus + HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = S>,
Z: HasObjective<Objective = OF, State = S>,
{
Ok(Self {
first_exec: true,
@ -215,7 +215,7 @@ where
EM: EventFirer<State = S> + EventRestarter,
OF: Feedback<S>,
S: HasSolutions + HasClientPerfMonitor,
Z: HasObjective<OF, State = S>,
Z: HasObjective<Objective = OF, State = S>,
{
assert!(!QT::HOOKS_DO_SIDE_EFFECTS, "When using QemuForkExecutor, the hooks must not do any side effect as they will happen in the child process and then discarded");

View File

@ -0,0 +1,8 @@
#!/bin/bash
# Script to find .rs files that don't get built.
cargo +nightly build --examples --all-features --tests
# Find all files in deps, then compare to all actual .d files. Ignore a range of files.
grep --no-filename '^[^/].*\.rs:$' target/debug/deps/*.d | sed 's/:$//' | sort -u | diff - <(find . -name '*.rs' | sed 's/\.\///' | sort -u) | grep -Ev '(target/|scripts/|symcc_runtime/|build.rs|fuzzers/)'