]> git.lizzy.rs Git - rust.git/commitdiff
provide mutable borrows when hooking memory write access
authorRalf Jung <post@ralfj.de>
Mon, 29 Oct 2018 15:34:54 +0000 (16:34 +0100)
committerRalf Jung <post@ralfj.de>
Mon, 29 Oct 2018 15:34:58 +0000 (16:34 +0100)
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/mod.rs

index 5a5002dece5ab6790e868ccca4a924c9f64519b4..7aeadfa408a90547a27eb2481a43e6d2c1fa39de 100644 (file)
     EvalContext, PlaceTy, OpTy, Pointer, MemPlace, MemoryKind,
 };
 
-/// Classifying memory accesses
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum MemoryAccess {
-    Read,
-    Write,
-}
-
 /// Whether this kind of memory is allowed to leak
 pub trait MayLeak: Copy {
     fn may_leak(self) -> bool;
@@ -181,17 +174,22 @@ fn box_alloc(
         dest: PlaceTy<'tcx, Self::PointerTag>,
     ) -> EvalResult<'tcx>;
 
-    /// Hook for performing extra checks on a memory 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.
+    /// Hook for performing extra checks on a memory read access.
     #[inline]
-    fn memory_accessed(
+    fn memory_read(
         _alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
         _ptr: Pointer<Self::PointerTag>,
         _size: Size,
-        _access: MemoryAccess,
+    ) -> 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(())
     }
index 689a29cff6e9e465554829b05194cf14da53f332..91f3813e2b1fdbacf0455a5bc93c0dff1fd1141a 100644 (file)
@@ -30,7 +30,7 @@
 use super::{
     Pointer, AllocId, Allocation, ConstValue, GlobalId,
     EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
-    Machine, MemoryAccess, AllocMap, MayLeak, ScalarMaybeUndef, ErrorHandled,
+    Machine, AllocMap, MayLeak, ScalarMaybeUndef, ErrorHandled,
 };
 
 #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
@@ -644,7 +644,7 @@ fn get_bytes_internal(
         }
 
         let alloc = self.get(ptr.alloc_id)?;
-        M::memory_accessed(alloc, ptr, size, MemoryAccess::Read)?;
+        M::memory_read(alloc, ptr, size)?;
 
         assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
         assert_eq!(size.bytes() as usize as u64, size.bytes());
@@ -690,7 +690,7 @@ fn get_bytes_mut(
         self.clear_relocations(ptr, size)?;
 
         let alloc = self.get_mut(ptr.alloc_id)?;
-        M::memory_accessed(alloc, ptr, size, MemoryAccess::Write)?;
+        M::memory_written(alloc, ptr, size)?;
 
         assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
         assert_eq!(size.bytes() as usize as u64, size.bytes());
index 55037a99e0124827ce4adffb000862d856e30bcd..5620ea4cee25411ab3689386a172c9b52007f1c5 100644 (file)
@@ -34,7 +34,7 @@
 
 pub use self::memory::{Memory, MemoryKind};
 
-pub use self::machine::{Machine, AllocMap, MemoryAccess, MayLeak};
+pub use self::machine::{Machine, AllocMap, MayLeak};
 
 pub use self::operand::{ScalarMaybeUndef, Value, ValTy, Operand, OpTy};