Move the memory_accessed hook onto the Extra value

This commit is contained in:
Oliver Scherer 2018-10-23 18:32:50 +02:00
parent 48f6941acf
commit 6def30ba6a
3 changed files with 31 additions and 21 deletions

View File

@ -40,6 +40,36 @@ pub struct Allocation<Tag=(),Extra=()> {
pub extra: Extra,
}
trait AllocationExtra<Tag> {
/// Hook for performing extra checks on a memory read access.
///
/// Takes read-only access to the allocation so we can keep all the memory read
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
/// need to mutate.
#[inline]
fn memory_read(
&self,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}
/// Hook for performing extra checks on a memory write access.
///
/// Takes read-only access to the allocation so we can keep all the memory read
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
/// need to mutate.
#[inline]
fn memory_written(
&mut self,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}
}
impl<Tag, Extra: Default> Allocation<Tag, Extra> {
/// Creates a read-only allocation initialized by the given bytes
pub fn from_bytes(slice: &[u8], align: Align) -> Self {

View File

@ -26,7 +26,7 @@ pub use self::error::{
pub use self::value::{Scalar, ConstValue};
pub use self::allocation::Allocation;
pub use self::allocation::{Allocation, MemoryAccess};
use std::fmt;
use mir;

View File

@ -174,26 +174,6 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
dest: PlaceTy<'tcx, Self::PointerTag>,
) -> EvalResult<'tcx>;
/// Hook for performing extra checks on a memory read access.
#[inline]
fn memory_read(
_alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}
/// Hook for performing extra checks on a memory write access.
#[inline]
fn memory_written(
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}
/// Hook for performing extra checks when memory gets deallocated.
#[inline]
fn memory_deallocated(