]> git.lizzy.rs Git - rust.git/blob - src/machine.rs
Initial data-race detector,
[rust.git] / src / machine.rs
1 //! Global machine state as well as implementation of the interpreter engine
2 //! `Machine` trait.
3
4 use std::borrow::Cow;
5 use std::cell::RefCell;
6 use std::num::NonZeroU64;
7 use std::rc::Rc;
8 use std::time::Instant;
9 use std::fmt;
10
11 use log::trace;
12 use rand::rngs::StdRng;
13 use rand::SeedableRng;
14
15 use rustc_data_structures::fx::FxHashMap;
16 use rustc_middle::{
17     mir,
18     ty::{
19         self,
20         layout::{LayoutCx, LayoutError, TyAndLayout},
21         TyCtxt,
22     },
23 };
24 use rustc_span::symbol::{sym, Symbol};
25 use rustc_span::def_id::DefId;
26 use rustc_target::abi::{LayoutOf, Size};
27
28 use crate::*;
29
30 // Some global facts about the emulated machine.
31 pub const PAGE_SIZE: u64 = 4 * 1024; // FIXME: adjust to target architecture
32 pub const STACK_ADDR: u64 = 32 * PAGE_SIZE; // not really about the "stack", but where we start assigning integer addresses to allocations
33 pub const STACK_SIZE: u64 = 16 * PAGE_SIZE; // whatever
34 pub const NUM_CPUS: u64 = 1;
35
36 /// Extra data stored with each stack frame
37 #[derive(Debug)]
38 pub struct FrameData<'tcx> {
39     /// Extra data for Stacked Borrows.
40     pub call_id: stacked_borrows::CallId,
41
42     /// If this is Some(), then this is a special "catch unwind" frame (the frame of `try_fn`
43     /// called by `try`). When this frame is popped during unwinding a panic,
44     /// we stop unwinding, use the `CatchUnwindData` to handle catching.
45     pub catch_unwind: Option<CatchUnwindData<'tcx>>,
46 }
47
48 /// Extra memory kinds
49 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
50 pub enum MiriMemoryKind {
51     /// `__rust_alloc` memory.
52     Rust,
53     /// `malloc` memory.
54     C,
55     /// Windows `HeapAlloc` memory.
56     WinHeap,
57     /// Memory for args, errno, and other parts of the machine-managed environment.
58     /// This memory may leak.
59     Machine,
60     /// Memory for env vars. Separate from `Machine` because we clean it up and leak-check it.
61     Env,
62     /// Globals copied from `tcx`.
63     /// This memory may leak.
64     Global,
65     /// Memory for extern statics.
66     /// This memory may leak.
67     ExternStatic,
68     /// Memory for thread-local statics.
69     /// This memory may leak.
70     Tls,
71 }
72
73 impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
74     #[inline(always)]
75     fn into(self) -> MemoryKind<MiriMemoryKind> {
76         MemoryKind::Machine(self)
77     }
78 }
79
80 impl MayLeak for MiriMemoryKind {
81     #[inline(always)]
82     fn may_leak(self) -> bool {
83         use self::MiriMemoryKind::*;
84         match self {
85             Rust | C | WinHeap | Env => false,
86             Machine | Global | ExternStatic | Tls => true,
87         }
88     }
89 }
90
91 impl fmt::Display for MiriMemoryKind {
92     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93         use self::MiriMemoryKind::*;
94         match self {
95             Rust => write!(f, "Rust heap"),
96             C => write!(f, "C heap"),
97             WinHeap => write!(f, "Windows heap"),
98             Machine => write!(f, "machine-managed memory"),
99             Env => write!(f, "environment variable"),
100             Global => write!(f, "global (static or const)"),
101             ExternStatic => write!(f, "extern static"),
102             Tls =>  write!(f, "thread-local static"),
103         }
104     }
105 }
106
107 /// Extra per-allocation data
108 #[derive(Debug, Clone)]
109 pub struct AllocExtra {
110     /// Stacked Borrows state is only added if it is enabled.
111     pub stacked_borrows: Option<stacked_borrows::AllocExtra>,
112     /// Data race detection via the use of a vector-clock.
113     pub data_race: data_race::AllocExtra,
114 }
115
116 /// Extra global memory data
117 #[derive(Clone, Debug)]
118 pub struct MemoryExtra {
119     pub stacked_borrows: Option<stacked_borrows::MemoryExtra>,
120     pub data_race: data_race::MemoryExtra,
121     pub intptrcast: intptrcast::MemoryExtra,
122
123     /// Mapping extern static names to their canonical allocation.
124     extern_statics: FxHashMap<Symbol, AllocId>,
125
126     /// The random number generator used for resolving non-determinism.
127     /// Needs to be queried by ptr_to_int, hence needs interior mutability.
128     pub(crate) rng: RefCell<StdRng>,
129
130     /// An allocation ID to report when it is being allocated
131     /// (helps for debugging memory leaks and use after free bugs).
132     tracked_alloc_id: Option<AllocId>,
133
134     /// Controls whether alignment of memory accesses is being checked.
135     pub(crate) check_alignment: AlignmentCheck,
136 }
137
138 impl MemoryExtra {
139     pub fn new(config: &MiriConfig) -> Self {
140         let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
141         let stacked_borrows = if config.stacked_borrows {
142             Some(Rc::new(RefCell::new(stacked_borrows::GlobalState::new(
143                 config.tracked_pointer_tag,
144                 config.tracked_call_id,
145                 config.track_raw,
146             ))))
147         } else {
148             None
149         };
150         let data_race = Rc::new(data_race::GlobalState::new());
151         MemoryExtra {
152             stacked_borrows,
153             data_race,
154             intptrcast: Default::default(),
155             extern_statics: FxHashMap::default(),
156             rng: RefCell::new(rng),
157             tracked_alloc_id: config.tracked_alloc_id,
158             check_alignment: config.check_alignment,
159         }
160     }
161
162     fn add_extern_static<'tcx, 'mir>(
163         this: &mut MiriEvalContext<'mir, 'tcx>,
164         name: &str,
165         ptr: Scalar<Tag>,
166     ) {
167         let ptr = ptr.assert_ptr();
168         assert_eq!(ptr.offset, Size::ZERO);
169         this.memory
170             .extra
171             .extern_statics
172             .insert(Symbol::intern(name), ptr.alloc_id)
173             .unwrap_none();
174     }
175
176     /// Sets up the "extern statics" for this machine.
177     pub fn init_extern_statics<'tcx, 'mir>(
178         this: &mut MiriEvalContext<'mir, 'tcx>,
179     ) -> InterpResult<'tcx> {
180         match this.tcx.sess.target.target_os.as_str() {
181             "linux" => {
182                 // "__cxa_thread_atexit_impl"
183                 // This should be all-zero, pointer-sized.
184                 let layout = this.machine.layouts.usize;
185                 let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into());
186                 this.write_scalar(Scalar::from_machine_usize(0, this), place.into())?;
187                 Self::add_extern_static(this, "__cxa_thread_atexit_impl", place.ptr);
188                 // "environ"
189                 Self::add_extern_static(this, "environ", this.machine.env_vars.environ.unwrap().ptr);
190             }
191             "windows" => {
192                 // "_tls_used"
193                 // This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
194                 let layout = this.machine.layouts.u8;
195                 let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into());
196                 this.write_scalar(Scalar::from_u8(0), place.into())?;
197                 Self::add_extern_static(this, "_tls_used", place.ptr);
198             }
199             _ => {} // No "extern statics" supported on this target
200         }
201         Ok(())
202     }
203 }
204
205 /// Precomputed layouts of primitive types
206 pub struct PrimitiveLayouts<'tcx> {
207     pub unit: TyAndLayout<'tcx>,
208     pub i8: TyAndLayout<'tcx>,
209     pub i32: TyAndLayout<'tcx>,
210     pub isize: TyAndLayout<'tcx>,
211     pub u8: TyAndLayout<'tcx>,
212     pub u32: TyAndLayout<'tcx>,
213     pub usize: TyAndLayout<'tcx>,
214 }
215
216 impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
217     fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, LayoutError<'tcx>> {
218         Ok(Self {
219             unit: layout_cx.layout_of(layout_cx.tcx.mk_unit())?,
220             i8: layout_cx.layout_of(layout_cx.tcx.types.i8)?,
221             i32: layout_cx.layout_of(layout_cx.tcx.types.i32)?,
222             isize: layout_cx.layout_of(layout_cx.tcx.types.isize)?,
223             u8: layout_cx.layout_of(layout_cx.tcx.types.u8)?,
224             u32: layout_cx.layout_of(layout_cx.tcx.types.u32)?,
225             usize: layout_cx.layout_of(layout_cx.tcx.types.usize)?,
226         })
227     }
228 }
229
230 /// The machine itself.
231 pub struct Evaluator<'mir, 'tcx> {
232     /// Environment variables set by `setenv`.
233     /// Miri does not expose env vars from the host to the emulated program.
234     pub(crate) env_vars: EnvVars<'tcx>,
235
236     /// Program arguments (`Option` because we can only initialize them after creating the ecx).
237     /// These are *pointers* to argc/argv because macOS.
238     /// We also need the full command line as one string because of Windows.
239     pub(crate) argc: Option<Scalar<Tag>>,
240     pub(crate) argv: Option<Scalar<Tag>>,
241     pub(crate) cmd_line: Option<Scalar<Tag>>,
242
243     /// TLS state.
244     pub(crate) tls: TlsData<'tcx>,
245
246     /// If enabled, the `env_vars` field is populated with the host env vars during initialization
247     /// and random number generation is delegated to the host.
248     pub(crate) communicate: bool,
249
250     /// Whether to enforce the validity invariant.
251     pub(crate) validate: bool,
252
253     pub(crate) file_handler: shims::posix::FileHandler,
254     pub(crate) dir_handler: shims::posix::DirHandler,
255
256     /// The "time anchor" for this machine's monotone clock (for `Instant` simulation).
257     pub(crate) time_anchor: Instant,
258
259     /// The set of threads.
260     pub(crate) threads: ThreadManager<'mir, 'tcx>,
261
262     /// Precomputed `TyLayout`s for primitive data types that are commonly used inside Miri.
263     pub(crate) layouts: PrimitiveLayouts<'tcx>,
264
265     /// Allocations that are considered roots of static memory (that may leak).
266     pub(crate) static_roots: Vec<AllocId>,
267 }
268
269 impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
270     pub(crate) fn new(
271         communicate: bool,
272         validate: bool,
273         layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
274     ) -> Self {
275         let layouts = PrimitiveLayouts::new(layout_cx)
276             .expect("Couldn't get layouts of primitive types");
277         Evaluator {
278             // `env_vars` could be initialized properly here if `Memory` were available before
279             // calling this method.
280             env_vars: EnvVars::default(),
281             argc: None,
282             argv: None,
283             cmd_line: None,
284             tls: TlsData::default(),
285             communicate,
286             validate,
287             file_handler: Default::default(),
288             dir_handler: Default::default(),
289             time_anchor: Instant::now(),
290             layouts,
291             threads: ThreadManager::default(),
292             static_roots: Vec::new(),
293         }
294     }
295 }
296
297 /// A rustc InterpCx for Miri.
298 pub type MiriEvalContext<'mir, 'tcx> = InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>;
299
300 /// A little trait that's useful to be inherited by extension traits.
301 pub trait MiriEvalContextExt<'mir, 'tcx> {
302     fn eval_context_ref<'a>(&'a self) -> &'a MiriEvalContext<'mir, 'tcx>;
303     fn eval_context_mut<'a>(&'a mut self) -> &'a mut MiriEvalContext<'mir, 'tcx>;
304 }
305 impl<'mir, 'tcx> MiriEvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {
306     #[inline(always)]
307     fn eval_context_ref(&self) -> &MiriEvalContext<'mir, 'tcx> {
308         self
309     }
310     #[inline(always)]
311     fn eval_context_mut(&mut self) -> &mut MiriEvalContext<'mir, 'tcx> {
312         self
313     }
314 }
315
316 /// Machine hook implementations.
317 impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
318     type MemoryKind = MiriMemoryKind;
319
320     type FrameExtra = FrameData<'tcx>;
321     type MemoryExtra = MemoryExtra;
322     type AllocExtra = AllocExtra;
323     type PointerTag = Tag;
324     type ExtraFnVal = Dlsym;
325
326     type MemoryMap =
327         MonoHashMap<AllocId, (MemoryKind<MiriMemoryKind>, Allocation<Tag, Self::AllocExtra>)>;
328
329     const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);
330
331     #[inline(always)]
332     fn enforce_alignment(memory_extra: &MemoryExtra) -> bool {
333         memory_extra.check_alignment != AlignmentCheck::None
334     }
335
336     #[inline(always)]
337     fn force_int_for_alignment_check(memory_extra: &Self::MemoryExtra) -> bool {
338         memory_extra.check_alignment == AlignmentCheck::Int
339     }
340
341     #[inline(always)]
342     fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
343         ecx.machine.validate
344     }
345
346     #[inline(always)]
347     fn find_mir_or_eval_fn(
348         ecx: &mut InterpCx<'mir, 'tcx, Self>,
349         instance: ty::Instance<'tcx>,
350         args: &[OpTy<'tcx, Tag>],
351         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
352         unwind: Option<mir::BasicBlock>,
353     ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
354         ecx.find_mir_or_eval_fn(instance, args, ret, unwind)
355     }
356
357     #[inline(always)]
358     fn call_extra_fn(
359         ecx: &mut InterpCx<'mir, 'tcx, Self>,
360         fn_val: Dlsym,
361         args: &[OpTy<'tcx, Tag>],
362         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
363         _unwind: Option<mir::BasicBlock>,
364     ) -> InterpResult<'tcx> {
365         ecx.call_dlsym(fn_val, args, ret)
366     }
367
368     #[inline(always)]
369     fn call_intrinsic(
370         ecx: &mut rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
371         instance: ty::Instance<'tcx>,
372         args: &[OpTy<'tcx, Tag>],
373         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
374         unwind: Option<mir::BasicBlock>,
375     ) -> InterpResult<'tcx> {
376         ecx.call_intrinsic(instance, args, ret, unwind)
377     }
378
379     #[inline(always)]
380     fn assert_panic(
381         ecx: &mut InterpCx<'mir, 'tcx, Self>,
382         msg: &mir::AssertMessage<'tcx>,
383         unwind: Option<mir::BasicBlock>,
384     ) -> InterpResult<'tcx> {
385         ecx.assert_panic(msg, unwind)
386     }
387
388     #[inline(always)]
389     fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, !> {
390         throw_machine_stop!(TerminationInfo::Abort(None))
391     }
392
393     #[inline(always)]
394     fn binary_ptr_op(
395         ecx: &rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
396         bin_op: mir::BinOp,
397         left: ImmTy<'tcx, Tag>,
398         right: ImmTy<'tcx, Tag>,
399     ) -> InterpResult<'tcx, (Scalar<Tag>, bool, ty::Ty<'tcx>)> {
400         ecx.binary_ptr_op(bin_op, left, right)
401     }
402
403     fn box_alloc(
404         ecx: &mut InterpCx<'mir, 'tcx, Self>,
405         dest: PlaceTy<'tcx, Tag>,
406     ) -> InterpResult<'tcx> {
407         trace!("box_alloc for {:?}", dest.layout.ty);
408         let layout = ecx.layout_of(dest.layout.ty.builtin_deref(false).unwrap().ty)?;
409         // First argument: `size`.
410         // (`0` is allowed here -- this is expected to be handled by the lang item).
411         let size = Scalar::from_machine_usize(layout.size.bytes(), ecx);
412
413         // Second argument: `align`.
414         let align = Scalar::from_machine_usize(layout.align.abi.bytes(), ecx);
415
416         // Call the `exchange_malloc` lang item.
417         let malloc = ecx.tcx.lang_items().exchange_malloc_fn().unwrap();
418         let malloc = ty::Instance::mono(ecx.tcx.tcx, malloc);
419         ecx.call_function(
420             malloc,
421             &[size.into(), align.into()],
422             Some(dest),
423             // Don't do anything when we are done. The `statement()` function will increment
424             // the old stack frame's stmt counter to the next statement, which means that when
425             // `exchange_malloc` returns, we go on evaluating exactly where we want to be.
426             StackPopCleanup::None { cleanup: true },
427         )?;
428         Ok(())
429     }
430
431     fn thread_local_static_alloc_id(
432         ecx: &mut InterpCx<'mir, 'tcx, Self>,
433         def_id: DefId,
434     ) -> InterpResult<'tcx, AllocId> {
435         ecx.get_or_create_thread_local_alloc_id(def_id)
436     }
437
438     fn extern_static_alloc_id(
439         memory: &Memory<'mir, 'tcx, Self>,
440         def_id: DefId,
441     ) -> InterpResult<'tcx, AllocId> {
442         let attrs = memory.tcx.get_attrs(def_id);
443         let link_name = match memory.tcx.sess.first_attr_value_str_by_name(&attrs, sym::link_name) {
444             Some(name) => name,
445             None => memory.tcx.item_name(def_id),
446         };
447         if let Some(&id) = memory.extra.extern_statics.get(&link_name) {
448             Ok(id)
449         } else {
450             throw_unsup_format!("`extern` static {:?} is not supported by Miri", def_id)
451         }
452     }
453
454     fn init_allocation_extra<'b>(
455         memory_extra: &MemoryExtra,
456         id: AllocId,
457         alloc: Cow<'b, Allocation>,
458         kind: Option<MemoryKind<Self::MemoryKind>>,
459     ) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
460         if Some(id) == memory_extra.tracked_alloc_id {
461             register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
462         }
463
464         let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
465         let alloc = alloc.into_owned();
466         let (stacks, base_tag) =
467             if let Some(stacked_borrows) = &memory_extra.stacked_borrows {
468                 let (stacks, base_tag) =
469                     Stacks::new_allocation(id, alloc.size, Rc::clone(stacked_borrows), kind);
470                 (Some(stacks), base_tag)
471             } else {
472                 // No stacks, no tag.
473                 (None, Tag::Untagged)
474             };
475         let race_alloc = data_race::AllocExtra::new_allocation(&memory_extra.data_race, alloc.size);
476         let mut stacked_borrows = memory_extra.stacked_borrows.as_ref().map(|sb| sb.borrow_mut());
477         let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
478             |alloc| {
479                 if let Some(stacked_borrows) = &mut stacked_borrows {
480                     // Only globals may already contain pointers at this point
481                     assert_eq!(kind, MiriMemoryKind::Global.into());
482                     stacked_borrows.global_base_ptr(alloc)
483                 } else {
484                     Tag::Untagged
485                 }
486             },
487             AllocExtra { stacked_borrows: stacks, data_race: race_alloc },
488         );
489         (Cow::Owned(alloc), base_tag)
490     }
491
492     #[inline(always)]
493     fn before_deallocation(
494         memory_extra: &mut Self::MemoryExtra,
495         id: AllocId,
496     ) -> InterpResult<'tcx> {
497         if Some(id) == memory_extra.tracked_alloc_id {
498             register_diagnostic(NonHaltingDiagnostic::FreedAlloc(id));
499         }
500
501         Ok(())
502     }
503
504     #[inline(always)]
505     fn tag_global_base_pointer(memory_extra: &MemoryExtra, id: AllocId) -> Self::PointerTag {
506         if let Some(stacked_borrows) = &memory_extra.stacked_borrows {
507             stacked_borrows.borrow_mut().global_base_ptr(id)
508         } else {
509             Tag::Untagged
510         }
511     }
512
513     #[inline(always)]
514     fn retag(
515         ecx: &mut InterpCx<'mir, 'tcx, Self>,
516         kind: mir::RetagKind,
517         place: PlaceTy<'tcx, Tag>,
518     ) -> InterpResult<'tcx> {
519         if ecx.memory.extra.stacked_borrows.is_some() {
520             ecx.retag(kind, place)
521         } else {
522             Ok(())
523         }
524     }
525
526     #[inline(always)]
527     fn init_frame_extra(
528         ecx: &mut InterpCx<'mir, 'tcx, Self>,
529         frame: Frame<'mir, 'tcx, Tag>,
530     ) -> InterpResult<'tcx, Frame<'mir, 'tcx, Tag, FrameData<'tcx>>> {
531         let stacked_borrows = ecx.memory.extra.stacked_borrows.as_ref();
532         let call_id = stacked_borrows.map_or(NonZeroU64::new(1).unwrap(), |stacked_borrows| {
533             stacked_borrows.borrow_mut().new_call()
534         });
535         let extra = FrameData { call_id, catch_unwind: None };
536         Ok(frame.with_extra(extra))
537     }
538
539     fn stack<'a>(
540         ecx: &'a InterpCx<'mir, 'tcx, Self>
541     ) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
542         ecx.active_thread_stack()
543     }
544
545     fn stack_mut<'a>(
546         ecx: &'a mut InterpCx<'mir, 'tcx, Self>
547     ) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> {
548         ecx.active_thread_stack_mut()
549     }
550
551     #[inline(always)]
552     fn after_stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
553         if ecx.memory.extra.stacked_borrows.is_some() {
554             ecx.retag_return_place()
555         } else {
556             Ok(())
557         }
558     }
559
560     #[inline(always)]
561     fn after_stack_pop(
562         ecx: &mut InterpCx<'mir, 'tcx, Self>,
563         frame: Frame<'mir, 'tcx, Tag, FrameData<'tcx>>,
564         unwinding: bool,
565     ) -> InterpResult<'tcx, StackPopJump> {
566         ecx.handle_stack_pop(frame.extra, unwinding)
567     }
568
569     #[inline(always)]
570     fn int_to_ptr(
571         memory: &Memory<'mir, 'tcx, Self>,
572         int: u64,
573     ) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
574         intptrcast::GlobalState::int_to_ptr(int, memory)
575     }
576
577     #[inline(always)]
578     fn ptr_to_int(
579         memory: &Memory<'mir, 'tcx, Self>,
580         ptr: Pointer<Self::PointerTag>,
581     ) -> InterpResult<'tcx, u64> {
582         intptrcast::GlobalState::ptr_to_int(ptr, memory)
583     }
584 }
585
586 impl AllocationExtra<Tag> for AllocExtra {
587     #[inline(always)]
588     fn memory_read<'tcx>(
589         alloc: &Allocation<Tag, AllocExtra>,
590         ptr: Pointer<Tag>,
591         size: Size,
592     ) -> InterpResult<'tcx> {
593         alloc.extra.data_race.read(ptr, size)?;
594         if let Some(stacked_borrows) = &alloc.extra.stacked_borrows {
595             stacked_borrows.memory_read(ptr, size)
596         } else {
597             Ok(())
598         }
599     }
600
601     #[inline(always)]
602     fn memory_written<'tcx>(
603         alloc: &mut Allocation<Tag, AllocExtra>,
604         ptr: Pointer<Tag>,
605         size: Size,
606     ) -> InterpResult<'tcx> {
607         alloc.extra.data_race.write(ptr, size)?;
608         if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
609             stacked_borrows.memory_written(ptr, size)
610         } else {
611             Ok(())
612         }
613     }
614
615     #[inline(always)]
616     fn memory_deallocated<'tcx>(
617         alloc: &mut Allocation<Tag, AllocExtra>,
618         ptr: Pointer<Tag>,
619         size: Size,
620     ) -> InterpResult<'tcx> {
621         alloc.extra.data_race.deallocate(ptr, size)?;
622         if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
623             stacked_borrows.memory_deallocated(ptr, size)
624         } else {
625             Ok(())
626         }
627     }
628 }