-
-
Notifications
You must be signed in to change notification settings - Fork 437
Compile-time edge module compilation check, native support for ConstMapObserver #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
3ccc726
ef8d01a
6bb94fa
aa50cb2
5b39956
4350245
decaa67
d04be02
964da23
d66d787
505c88d
6bf7530
6e838aa
0611e32
d9dc77c
35297dc
65c3ff7
2b59798
b22cf6c
f8ac5b0
bfe4b14
925dab2
c7c8cd8
6b8035a
bb70553
ad413e7
606f5e0
c870076
f715038
236b2b3
481cee8
3d51d58
1a69530
7982f7f
93b5bbf
cb21994
f520a9a
fa035af
7263d91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,27 +6,25 @@ use core::{ | |
| hash::{Hash, Hasher}, | ||
| ops::{Deref, DerefMut}, | ||
| }; | ||
| use std::ptr::NonNull; | ||
|
|
||
| use ahash::RandomState; | ||
| use libafl_bolts::{ownedref::OwnedMutSlice, AsSlice, AsSliceMut, HasLen, Named}; | ||
| use libafl_bolts::{ownedref::OwnedMutSizedSlice, AsSlice, AsSliceMut, HasLen, Named}; | ||
| use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||
|
|
||
| use crate::{ | ||
| observers::{map::MapObserver, Observer, VariableLengthMapObserver}, | ||
| observers::{map::MapObserver, ConstantLengthMapObserver, Observer}, | ||
| Error, | ||
| }; | ||
|
|
||
| // TODO: remove the size field and implement ConstantLengthMapObserver | ||
|
|
||
| /// Use a const size to speedup `Feedback::is_interesting` when the user can | ||
| /// know the size of the map at compile time. | ||
| #[derive(Serialize, Deserialize, Debug)] | ||
| #[allow(clippy::unsafe_derive_deserialize)] | ||
| pub struct ConstMapObserver<'a, T, const N: usize> { | ||
| map: OwnedMutSlice<'a, T>, | ||
| map: OwnedMutSizedSlice<'a, T, N>, | ||
| initial: T, | ||
| name: Cow<'static, str>, | ||
| size: usize, | ||
| } | ||
|
|
||
| impl<I, S, T, const N: usize> Observer<I, S> for ConstMapObserver<'_, T, N> | ||
|
|
@@ -150,25 +148,17 @@ where | |
| } | ||
| } | ||
|
|
||
| impl<T, const N: usize> VariableLengthMapObserver for ConstMapObserver<'_, T, N> | ||
| impl<T, const N: usize> ConstantLengthMapObserver<N> for ConstMapObserver<'_, T, N> | ||
|
||
| where | ||
| T: PartialEq + Copy + Hash + Serialize + DeserializeOwned + Debug + 'static, | ||
| { | ||
| fn map_slice(&mut self) -> &[Self::Entry] { | ||
| fn map_slice(&self) -> &[Self::Entry; N] { | ||
| self.map.as_slice() | ||
| } | ||
|
|
||
| fn map_slice_mut(&mut self) -> &mut [Self::Entry] { | ||
| fn map_slice_mut(&mut self) -> &mut [Self::Entry; N] { | ||
| self.map.as_slice_mut() | ||
| } | ||
|
|
||
| fn size(&mut self) -> &usize { | ||
| &N | ||
| } | ||
|
|
||
| fn size_mut(&mut self) -> &mut usize { | ||
| &mut self.size | ||
| } | ||
| } | ||
|
|
||
| impl<T, const N: usize> Deref for ConstMapObserver<'_, T, N> { | ||
|
|
@@ -194,48 +184,24 @@ where | |
| /// Will get a pointer to the map and dereference it at any point in time. | ||
| /// The map must not move in memory! | ||
| #[must_use] | ||
| pub fn new(name: &'static str, map: &'a mut [T]) -> Self { | ||
| pub fn new(name: &'static str, map: &'a mut [T; N]) -> Self { | ||
| assert!(map.len() >= N); | ||
| Self { | ||
| map: OwnedMutSlice::from(map), | ||
| map: OwnedMutSizedSlice::from(map), | ||
| name: Cow::from(name), | ||
| initial: T::default(), | ||
| size: N, | ||
| } | ||
| } | ||
|
|
||
| /// Creates a new [`MapObserver`] from a raw pointer | ||
| /// | ||
| /// # Safety | ||
| /// Will dereference the `map_ptr` with up to len elements. | ||
| pub unsafe fn from_mut_ptr(name: &'static str, map_ptr: *mut T) -> Self { | ||
| pub unsafe fn from_mut_ptr(name: &'static str, map_ptr: NonNull<T>) -> Self { | ||
| ConstMapObserver { | ||
| map: OwnedMutSlice::from_raw_parts_mut(map_ptr, N), | ||
| map: OwnedMutSizedSlice::from_raw_parts_mut(map_ptr), | ||
| name: Cow::from(name), | ||
| initial: T::default(), | ||
| size: N, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T, const N: usize> ConstMapObserver<'_, T, N> | ||
| where | ||
| T: Default + Clone, | ||
| { | ||
| /// Creates a new [`MapObserver`] with an owned map | ||
| #[must_use] | ||
| pub fn owned(name: &'static str, map: Vec<T>) -> Self { | ||
| assert!(map.len() >= N); | ||
| let initial = if map.is_empty() { | ||
| T::default() | ||
| } else { | ||
| map[0].clone() | ||
| }; | ||
| Self { | ||
| map: OwnedMutSlice::from(map), | ||
| name: Cow::from(name), | ||
| initial, | ||
| size: N, | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.