Observer fix (#1807)

* fix

* Increase default edgemap size for libafl_cc and libafl_targets (#1798)

* fmt

---------

Co-authored-by: Dominik Maier <dmnk@google.com>
This commit is contained in:
Dongjia "toka" Zhang 2024-01-24 03:30:22 +01:00 committed by GitHub
parent 1458c3efff
commit bb443027f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 76 additions and 47 deletions

View File

@ -983,7 +983,7 @@ where
#[allow(clippy::unsafe_derive_deserialize)]
pub struct VariableMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize,
T: Default + Copy + 'static + Serialize + PartialEq + Bounded,
{
map: OwnedMutSlice<'a, T>,
size: OwnedMutPtr<usize>,
@ -994,7 +994,14 @@ where
impl<'a, S, T> Observer<S> for VariableMapObserver<'a, T>
where
S: UsesInput,
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: Default
+ Copy
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug
+ Bounded
+ PartialEq,
Self: MapObserver,
{
#[inline]
@ -1005,7 +1012,7 @@ where
impl<'a, T> Named for VariableMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned,
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Bounded + PartialEq,
{
#[inline]
fn name(&self) -> &str {
@ -1015,7 +1022,7 @@ where
impl<'a, T> HasLen for VariableMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned,
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + PartialEq + Bounded,
{
#[inline]
fn len(&self) -> usize {
@ -1032,7 +1039,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
type Item = T;
type IntoIter = Iter<'it, T>;
@ -1052,7 +1061,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
type Item = T;
type IntoIter = IterMut<'it, T>;
@ -1072,7 +1083,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
type Item = <Iter<'it, T> as Iterator>::Item;
type IntoIter = Iter<'it, T>;
@ -1092,7 +1105,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
type Item = <IterMut<'it, T> as Iterator>::Item;
type IntoIter = IterMut<'it, T>;
@ -1112,7 +1127,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
/// Returns an iterator over the map.
pub fn iter(&self) -> Iter<'_, T> {
@ -1134,7 +1151,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
type Entry = T;
@ -1213,7 +1232,9 @@ where
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
+ Debug
+ PartialEq
+ Bounded,
{
type Entry = T;
#[inline]
@ -1224,18 +1245,26 @@ where
}
impl<'a, T> AsMutSlice for VariableMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static
+ Default
+ Copy
+ Serialize
+ serde::de::DeserializeOwned
+ Debug
+ PartialEq
+ Bounded,
{
type Entry = T;
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
self.map.as_mut_slice()
let cnt = self.usable_count();
&mut self.map.as_mut_slice()[..cnt]
}
}
impl<'a, T> VariableMapObserver<'a, T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + PartialEq + Bounded,
{
/// Creates a new [`MapObserver`] from an [`OwnedMutSlice`]
///
@ -1810,7 +1839,7 @@ where
#[allow(clippy::unsafe_derive_deserialize)]
pub struct MultiMapObserver<'a, T, const DIFFERENTIAL: bool>
where
T: Default + Copy + 'static + Serialize + Debug,
T: 'static + Default + Copy + Serialize + Debug,
{
maps: Vec<OwnedMutSlice<'a, T>>,
intervals: IntervalTree<usize, usize>,
@ -1823,7 +1852,7 @@ where
impl<'a, S, T> Observer<S> for MultiMapObserver<'a, T, false>
where
S: UsesInput,
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
Self: MapObserver,
{
#[inline]
@ -1835,7 +1864,7 @@ where
impl<'a, S, T> Observer<S> for MultiMapObserver<'a, T, true>
where
S: UsesInput,
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
Self: MapObserver,
{
// in differential mode, we are *not* responsible for resetting the map!
@ -1843,7 +1872,7 @@ where
impl<'a, T, const DIFFERENTIAL: bool> Named for MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
#[inline]
fn name(&self) -> &str {
@ -1853,7 +1882,7 @@ where
impl<'a, T, const DIFFERENTIAL: bool> HasLen for MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
#[inline]
fn len(&self) -> usize {
@ -1863,11 +1892,11 @@ where
impl<'a, T, const DIFFERENTIAL: bool> MapObserver for MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Bounded
T: 'static
+ Bounded
+ PartialEq
+ Default
+ Copy
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
@ -1960,7 +1989,7 @@ where
impl<'a, T, const DIFFERENTIAL: bool> MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
/// Creates a new [`MultiMapObserver`], maybe in differential mode
#[must_use]
@ -1985,7 +2014,7 @@ where
impl<'a, T> MultiMapObserver<'a, T, true>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
/// Creates a new [`MultiMapObserver`] in differential mode
#[must_use]
@ -1996,7 +2025,7 @@ where
impl<'a, T> MultiMapObserver<'a, T, false>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
/// Creates a new [`MultiMapObserver`]
#[must_use]
@ -2033,7 +2062,7 @@ where
impl<'a, 'it, T, const DIFFERENTIAL: bool> AsIter<'it> for MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
'a: 'it,
{
type Item = T;
@ -2046,7 +2075,7 @@ where
impl<'a, 'it, T, const DIFFERENTIAL: bool> AsIterMut<'it> for MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
'a: 'it,
{
type Item = T;
@ -2060,7 +2089,7 @@ where
impl<'a, 'it, T, const DIFFERENTIAL: bool> IntoIterator
for &'it MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Item = <Iter<'it, T> as Iterator>::Item;
type IntoIter = Flatten<Iter<'it, OwnedMutSlice<'a, T>>>;
@ -2073,7 +2102,7 @@ where
impl<'a, 'it, T, const DIFFERENTIAL: bool> IntoIterator
for &'it mut MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Item = <IterMut<'it, T> as Iterator>::Item;
type IntoIter = Flatten<IterMut<'it, OwnedMutSlice<'a, T>>>;
@ -2085,7 +2114,7 @@ where
impl<'a, T, const DIFFERENTIAL: bool> MultiMapObserver<'a, T, DIFFERENTIAL>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
/// Returns an iterator over the map.
pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter {
@ -2100,7 +2129,7 @@ where
impl<'a, T, OTA, OTB, S> DifferentialObserver<OTA, OTB, S> for MultiMapObserver<'a, T, true>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
Self: MapObserver,
OTA: ObserversTuple<S>,
OTB: ObserversTuple<S>,
@ -2115,7 +2144,7 @@ where
#[allow(clippy::unsafe_derive_deserialize)]
pub struct OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize,
T: 'static + Default + Copy + Serialize,
{
map: Vec<T>,
initial: T,
@ -2125,7 +2154,7 @@ where
impl<S, T> Observer<S> for OwnedMapObserver<T>
where
S: UsesInput,
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
Self: MapObserver,
{
#[inline]
@ -2136,7 +2165,7 @@ where
impl<T> Named for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned,
{
#[inline]
fn name(&self) -> &str {
@ -2146,7 +2175,7 @@ where
impl<T> HasLen for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned,
{
#[inline]
fn len(&self) -> usize {
@ -2156,7 +2185,7 @@ where
impl<'it, T> AsIter<'it> for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Item = T;
type IntoIter = Iter<'it, T>;
@ -2168,7 +2197,7 @@ where
impl<'it, T> AsIterMut<'it> for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Item = T;
type IntoIter = IterMut<'it, T>;
@ -2180,7 +2209,7 @@ where
impl<'it, T> IntoIterator for &'it OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Item = <Iter<'it, T> as Iterator>::Item;
type IntoIter = Iter<'it, T>;
@ -2192,7 +2221,7 @@ where
impl<'it, T> IntoIterator for &'it mut OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Item = <IterMut<'it, T> as Iterator>::Item;
type IntoIter = IterMut<'it, T>;
@ -2204,7 +2233,7 @@ where
impl<T> OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
/// Returns an iterator over the map.
pub fn iter(&self) -> Iter<'_, T> {
@ -2219,11 +2248,11 @@ where
impl<T> MapObserver for OwnedMapObserver<T>
where
T: Bounded
T: 'static
+ Bounded
+ PartialEq
+ Default
+ Copy
+ 'static
+ Serialize
+ serde::de::DeserializeOwned
+ Debug,
@ -2300,7 +2329,7 @@ where
impl<T> AsSlice for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[must_use]
@ -2312,7 +2341,7 @@ where
impl<T> AsMutSlice for OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned + Debug,
{
type Entry = T;
#[must_use]
@ -2324,7 +2353,7 @@ where
impl<T> OwnedMapObserver<T>
where
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned,
T: 'static + Default + Copy + Serialize + serde::de::DeserializeOwned,
{
/// Creates a new [`MapObserver`] with an owned map
#[must_use]

View File

@ -311,7 +311,7 @@ pub const LIBAFL_CC_LLVM_VERSION: Option<usize> = None;
let mut cxxflags: Vec<String> = cxxflags.split_whitespace().map(String::from).collect();
let edges_map_size: usize = option_env!("LIBAFL_EDGES_MAP_SIZE")
.map_or(Ok(65536), str::parse)
.map_or(Ok(2621440), str::parse)
.expect("Could not parse LIBAFL_EDGES_MAP_SIZE");
cxxflags.push(format!("-DLIBAFL_EDGES_MAP_SIZE={edges_map_size}"));

View File

@ -96,7 +96,7 @@ where
#[must_use]
pub fn new() -> Self {
let map_size = option_env!("LIBAFL_EDGES_MAP_SIZE")
.map_or(Ok(65536), str::parse)
.map_or(Ok(2621440), str::parse)
.expect("Could not parse LIBAFL_EDGES_MAP_SIZE");
Self {
edges: (0..map_size).map(|_| None).collect(),

View File

@ -13,7 +13,7 @@ fn main() {
let mut constants_file = File::create(dest_path).expect("Could not create file");
let edges_map_size: usize = option_env!("LIBAFL_EDGES_MAP_SIZE")
.map_or(Ok(65536), str::parse)
.map_or(Ok(2621440), str::parse)
.expect("Could not parse LIBAFL_EDGES_MAP_SIZE");
let cmp_map_size: usize = option_env!("LIBAFL_CMP_MAP_SIZE")
.map_or(Ok(65536), str::parse)