diff --git a/libafl/src/observers/mod.rs b/libafl/src/observers/mod.rs index b9a087b986..197abd1dea 100644 --- a/libafl/src/observers/mod.rs +++ b/libafl/src/observers/mod.rs @@ -20,11 +20,6 @@ pub mod concolic; pub mod value; -// Rust is breaking this with 'error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `type_id`' and so we disable this component for the moment -//#[cfg(nightly)] -//pub mod owned; -//#[cfg(nightly)] -//pub use owned::*; use alloc::{ string::{String, ToString}, vec::Vec, diff --git a/libafl/src/observers/owned.rs b/libafl/src/observers/owned.rs deleted file mode 100644 index d3d21f6169..0000000000 --- a/libafl/src/observers/owned.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! A dynamic collection of owned observers, working only with unstable rust - -use core::{any::Any, fmt::Debug}; - -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use libafl_bolts::{ - anymap::{pack_type_id, AsAny}, - tuples::MatchName, - }; - -use crate::{ - - executors::ExitKind, - observers::{Observer, ObserversTuple}, - Error, -}; - -////////// Warning, unsafe as hell, this bypass the standard library /////////// - -extern "rust-intrinsic" { - fn type_id() -> u64; -} - -unsafe fn downcast_ref_unsafe(any: &dyn Any) -> &T { - &*(any as *const dyn Any as *const T) -} - -unsafe fn downcast_mut_unsafe(any: &mut dyn Any) -> &mut T { - &mut *(any as *mut dyn Any as *mut T) -} - -//////////////////////////////////////////////////////////////////////////////// - -/// Combine `Observer` and `AsAny` -pub trait AnyObserver: Observer + AsAny {} - -crate::create_anymap_for_trait!( - observers_anymap, - super, - AnyObserver, - derive(Debug) -); -pub use observers_anymap::{AnyMap as ObserversAnyMap, NamedAnyMap as NamedObserversAnyMap}; - -/// An owned list of `Observer` trait objects -/// This is not really serializable, using this struct needs [`crate::events::EventConfig::AlwaysUnique`] as configuration -#[derive(Debug, Default)] -pub struct ObserversOwnedMap { - /// The named trait objects map - pub map: NamedObserversAnyMap, -} - -impl Serialize for ObserversOwnedMap { - fn serialize(&self, _serializer: T) -> Result - where - T: Serializer, - { - panic!("Cannot serialize ObserversOwnedMap, use EventConfig::AlwaysUnique as event manager configuration"); - } -} - -impl<'de, I: 'static + Debug, S: 'static + Debug> Deserialize<'de> for ObserversOwnedMap { - fn deserialize(_deserializer: D) -> Result - where - D: Deserializer<'de>, - { - panic!("Cannot deserialize ObserversOwnedMap, use EventConfig::AlwaysUnique as event manager configuration"); - } -} - -impl ObserversTuple for ObserversOwnedMap { - fn pre_exec_all(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.map - .for_each_mut(&mut |_, ob| ob.pre_exec(state, input)) - } - - fn post_exec_all( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.map - .for_each_mut(&mut |_, ob| ob.post_exec(state, input, exit_kind)) - } - - fn pre_exec_child_all(&mut self, state: &mut S, input: &I) -> Result<(), Error> { - self.map - .for_each_mut(&mut |_, ob| ob.pre_exec_child(state, input)) - } - - fn post_exec_child_all( - &mut self, - state: &mut S, - input: &I, - exit_kind: &ExitKind, - ) -> Result<(), Error> { - self.map - .for_each_mut(&mut |_, ob| ob.post_exec_child(state, input, exit_kind)) - } -} - -impl MatchName for ObserversOwnedMap { - fn match_name(&self, name: &str) -> Option<&T> { - unsafe { - let t = pack_type_id(type_id::()); - self.map - .by_typeid(name, &t) - .map(|x| downcast_ref_unsafe(x.as_any())) - } - } - fn match_name_mut(&mut self, name: &str) -> Option<&mut T> { - unsafe { - let t = pack_type_id(type_id::()); - self.map - .by_typeid_mut(name, &t) - .map(|x| downcast_mut_unsafe(x.as_any_mut())) - } - } -}