@@ -27,6 +27,13 @@ use std::ptr;
2727use ty:: layout:: { self , Size , Align } ;
2828use syntax:: ast:: Mutability ;
2929
30+ /// Classifying memory accesses
31+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
32+ pub enum MemoryAccess {
33+ Read ,
34+ Write ,
35+ }
36+
3037#[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
3138pub struct Allocation < Tag =( ) , Extra =( ) > {
3239 /// The actual bytes of the allocation.
@@ -49,6 +56,22 @@ pub struct Allocation<Tag=(),Extra=()> {
4956 pub extra : Extra ,
5057}
5158
59+ trait AllocationExtra < Tag > {
60+ /// Hook for performing extra checks on a memory access.
61+ ///
62+ /// Takes read-only access to the allocation so we can keep all the memory read
63+ /// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
64+ /// need to mutate.
65+ fn memory_accessed (
66+ & self ,
67+ ptr : Pointer < Tag > ,
68+ size : Size ,
69+ access : MemoryAccess ,
70+ ) -> EvalResult < ' tcx > {
71+ Ok ( ( ) )
72+ }
73+ }
74+
5275impl < Tag , Extra : Default > Allocation < Tag , Extra > {
5376 /// Creates a read-only allocation initialized by the given bytes
5477 pub fn from_bytes ( slice : & [ u8 ] , align : Align ) -> Self {
@@ -84,7 +107,7 @@ impl<Tag, Extra: Default> Allocation<Tag, Extra> {
84107impl < ' tcx > :: serialize:: UseSpecializedDecodable for & ' tcx Allocation { }
85108
86109/// Byte accessors
87- impl < ' tcx , Tag , Extra > Allocation < Tag , Extra > {
110+ impl < ' tcx , Tag , Extra : AllocationExtra < Tag > > Allocation < Tag , Extra > {
88111 /// The last argument controls whether we error out when there are undefined
89112 /// or pointer bytes. You should never call this, call `get_bytes` or
90113 /// `get_bytes_with_undef_and_ptr` instead,
@@ -112,7 +135,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
112135 }
113136
114137 let alloc = self . get ( ptr. alloc_id ) ?;
115- M :: memory_accessed ( alloc , ptr, size, MemoryAccess :: Read ) ?;
138+ Extra :: memory_accessed ( & self . extra , ptr, size, MemoryAccess :: Read ) ?;
116139
117140 assert_eq ! ( ptr. offset. bytes( ) as usize as u64 , ptr. offset. bytes( ) ) ;
118141 assert_eq ! ( size. bytes( ) as usize as u64 , size. bytes( ) ) ;
@@ -158,7 +181,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
158181 self . clear_relocations ( ptr, size) ?;
159182
160183 let alloc = self . get_mut ( ptr. alloc_id ) ?;
161- M :: memory_accessed ( alloc, ptr, size, MemoryAccess :: Write ) ?;
184+ Extra :: memory_accessed ( alloc, ptr, size, MemoryAccess :: Write ) ?;
162185
163186 assert_eq ! ( ptr. offset. bytes( ) as usize as u64 , ptr. offset. bytes( ) ) ;
164187 assert_eq ! ( size. bytes( ) as usize as u64 , size. bytes( ) ) ;
0 commit comments