]> git.lizzy.rs Git - rust.git/blob - src/machine.rs
Fix review changes
[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     ///  this is only added if it is enabled.
114     pub data_race: Option<data_race::AllocExtra>,
115 }
116
117 /// Extra global memory data
118 #[derive(Clone, Debug)]
119 pub struct MemoryExtra {
120     pub stacked_borrows: Option<stacked_borrows::MemoryExtra>,
121     pub data_race: Option<data_race::MemoryExtra>,
122     pub intptrcast: intptrcast::MemoryExtra,
123
124     /// Mapping extern static names to their canonical allocation.
125     extern_statics: FxHashMap<Symbol, AllocId>,
126
127     /// The random number generator used for resolving non-determinism.
128     /// Needs to be queried by ptr_to_int, hence needs interior mutability.
129     pub(crate) rng: RefCell<StdRng>,
130
131     /// An allocation ID to report when it is being allocated
132     /// (helps for debugging memory leaks and use after free bugs).
133     tracked_alloc_id: Option<AllocId>,
134
135     /// Controls whether alignment of memory accesses is being checked.
136     pub(crate) check_alignment: AlignmentCheck,
137 }
138
139 impl MemoryExtra {
140     pub fn new(config: &MiriConfig) -> Self {
141         let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
142         let stacked_borrows = if config.stacked_borrows {
143             Some(Rc::new(RefCell::new(stacked_borrows::GlobalState::new(
144                 config.tracked_pointer_tag,
145                 config.tracked_call_id,
146                 config.track_raw,
147             ))))
148         } else {
149             None
150         };
151         let data_race = if config.data_race_detector {
152             Some(Rc::new(data_race::GlobalState::new()))
153         } else {
154             None
155         };
156         MemoryExtra {
157             stacked_borrows,
158             data_race,
159             intptrcast: Default::default(),
160             extern_statics: FxHashMap::default(),
161             rng: RefCell::new(rng),
162             tracked_alloc_id: config.tracked_alloc_id,
163             check_alignment: config.check_alignment,
164         }
165     }
166
167     fn add_extern_static<'tcx, 'mir>(
168         this: &mut MiriEvalContext<'mir, 'tcx>,
169         name: &str,
170         ptr: Scalar<Tag>,
171     ) {
172         let ptr = ptr.assert_ptr();
173         assert_eq!(ptr.offset, Size::ZERO);
174         this.memory
175             .extra
176             .extern_statics
177             .insert(Symbol::intern(name), ptr.alloc_id)
178             .unwrap_none();
179     }
180
181     /// Sets up the "extern statics" for this machine.
182     pub fn init_extern_statics<'tcx, 'mir>(
183         this: &mut MiriEvalContext<'mir, 'tcx>,
184     ) -> InterpResult<'tcx> {
185         match this.tcx.sess.target.os.as_str() {
186             "linux" => {
187                 // "__cxa_thread_atexit_impl"
188                 // This should be all-zero, pointer-sized.
189                 let layout = this.machine.layouts.usize;
190                 let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into());
191                 this.write_scalar(Scalar::from_machine_usize(0, this), place.into())?;
192                 Self::add_extern_static(this, "__cxa_thread_atexit_impl", place.ptr);
193                 // "environ"
194                 Self::add_extern_static(this, "environ", this.machine.env_vars.environ.unwrap().ptr);
195             }
196             "windows" => {
197                 // "_tls_used"
198                 // This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
199                 let layout = this.machine.layouts.u8;
200                 let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into());
201                 this.write_scalar(Scalar::from_u8(0), place.into())?;
202                 Self::add_extern_static(this, "_tls_used", place.ptr);
203             }
204             _ => {} // No "extern statics" supported on this target
205         }
206         Ok(())
207     }
208 }
209
210 /// Precomputed layouts of primitive types
211 pub struct PrimitiveLayouts<'tcx> {
212     pub unit: TyAndLayout<'tcx>,
213     pub i8: TyAndLayout<'tcx>,
214     pub i32: TyAndLayout<'tcx>,
215     pub isize: TyAndLayout<'tcx>,
216     pub u8: TyAndLayout<'tcx>,
217     pub u32: TyAndLayout<'tcx>,
218     pub usize: TyAndLayout<'tcx>,
219 }
220
221 impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
222     fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, LayoutError<'tcx>> {
223         Ok(Self {
224             unit: layout_cx.layout_of(layout_cx.tcx.mk_unit())?,
225             i8: layout_cx.layout_of(layout_cx.tcx.types.i8)?,
226             i32: layout_cx.layout_of(layout_cx.tcx.types.i32)?,
227             isize: layout_cx.layout_of(layout_cx.tcx.types.isize)?,
228             u8: layout_cx.layout_of(layout_cx.tcx.types.u8)?,
229             u32: layout_cx.layout_of(layout_cx.tcx.types.u32)?,
230             usize: layout_cx.layout_of(layout_cx.tcx.types.usize)?,
231         })
232     }
233 }
234
235 /// The machine itself.
236 pub struct Evaluator<'mir, 'tcx> {
237     /// Environment variables set by `setenv`.
238     /// Miri does not expose env vars from the host to the emulated program.
239     pub(crate) env_vars: EnvVars<'tcx>,
240
241     /// Program arguments (`Option` because we can only initialize them after creating the ecx).
242     /// These are *pointers* to argc/argv because macOS.
243     /// We also need the full command line as one string because of Windows.
244     pub(crate) argc: Option<Scalar<Tag>>,
245     pub(crate) argv: Option<Scalar<Tag>>,
246     pub(crate) cmd_line: Option<Scalar<Tag>>,
247
248     /// TLS state.
249     pub(crate) tls: TlsData<'tcx>,
250
251     /// If enabled, the `env_vars` field is populated with the host env vars during initialization
252     /// and random number generation is delegated to the host.
253     pub(crate) communicate: bool,
254
255     /// Whether to enforce the validity invariant.
256     pub(crate) validate: bool,
257
258     pub(crate) file_handler: shims::posix::FileHandler,
259     pub(crate) dir_handler: shims::posix::DirHandler,
260
261     /// The "time anchor" for this machine's monotone clock (for `Instant` simulation).
262     pub(crate) time_anchor: Instant,
263
264     /// The set of threads.
265     pub(crate) threads: ThreadManager<'mir, 'tcx>,
266
267     /// Precomputed `TyLayout`s for primitive data types that are commonly used inside Miri.
268     pub(crate) layouts: PrimitiveLayouts<'tcx>,
269
270     /// Allocations that are considered roots of static memory (that may leak).
271     pub(crate) static_roots: Vec<AllocId>,
272 }
273
274 impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
275     pub(crate) fn new(
276         communicate: bool,
277         validate: bool,
278         layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
279     ) -> Self {
280         let layouts = PrimitiveLayouts::new(layout_cx)
281             .expect("Couldn't get layouts of primitive types");
282         Evaluator {
283             // `env_vars` could be initialized properly here if `Memory` were available before
284             // calling this method.
285             env_vars: EnvVars::default(),
286             argc: None,
287             argv: None,
288             cmd_line: None,
289             tls: TlsData::default(),
290             communicate,
291             validate,
292             file_handler: Default::default(),
293             dir_handler: Default::default(),
294             time_anchor: Instant::now(),
295             layouts,
296             threads: ThreadManager::default(),
297             static_roots: Vec::new(),
298         }
299     }
300 }
301
302 /// A rustc InterpCx for Miri.
303 pub type MiriEvalContext<'mir, 'tcx> = InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>;
304
305 /// A little trait that's useful to be inherited by extension traits.
306 pub trait MiriEvalContextExt<'mir, 'tcx> {
307     fn eval_context_ref<'a>(&'a self) -> &'a MiriEvalContext<'mir, 'tcx>;
308     fn eval_context_mut<'a>(&'a mut self) -> &'a mut MiriEvalContext<'mir, 'tcx>;
309 }
310 impl<'mir, 'tcx> MiriEvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {
311     #[inline(always)]
312     fn eval_context_ref(&self) -> &MiriEvalContext<'mir, 'tcx> {
313         self
314     }
315     #[inline(always)]
316     fn eval_context_mut(&mut self) -> &mut MiriEvalContext<'mir, 'tcx> {
317         self
318     }
319 }
320
321 /// Machine hook implementations.
322 impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
323     type MemoryKind = MiriMemoryKind;
324
325     type FrameExtra = FrameData<'tcx>;
326     type MemoryExtra = MemoryExtra;
327     type AllocExtra = AllocExtra;
328     type PointerTag = Tag;
329     type ExtraFnVal = Dlsym;
330
331     type MemoryMap =
332         MonoHashMap<AllocId, (MemoryKind<MiriMemoryKind>, Allocation<Tag, Self::AllocExtra>)>;
333
334     const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);
335
336     #[inline(always)]
337     fn enforce_alignment(memory_extra: &MemoryExtra) -> bool {
338         memory_extra.check_alignment != AlignmentCheck::None
339     }
340
341     #[inline(always)]
342     fn force_int_for_alignment_check(memory_extra: &Self::MemoryExtra) -> bool {
343         memory_extra.check_alignment == AlignmentCheck::Int
344     }
345
346     #[inline(always)]
347     fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
348         ecx.machine.validate
349     }
350
351     #[inline(always)]
352     fn find_mir_or_eval_fn(
353         ecx: &mut InterpCx<'mir, 'tcx, Self>,
354         instance: ty::Instance<'tcx>,
355         args: &[OpTy<'tcx, Tag>],
356         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
357         unwind: Option<mir::BasicBlock>,
358     ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
359         ecx.find_mir_or_eval_fn(instance, args, ret, unwind)
360     }
361
362     #[inline(always)]
363     fn call_extra_fn(
364         ecx: &mut InterpCx<'mir, 'tcx, Self>,
365         fn_val: Dlsym,
366         args: &[OpTy<'tcx, Tag>],
367         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
368         _unwind: Option<mir::BasicBlock>,
369     ) -> InterpResult<'tcx> {
370         ecx.call_dlsym(fn_val, args, ret)
371     }
372
373     #[inline(always)]
374     fn call_intrinsic(
375         ecx: &mut rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
376         instance: ty::Instance<'tcx>,
377         args: &[OpTy<'tcx, Tag>],
378         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
379         unwind: Option<mir::BasicBlock>,
380     ) -> InterpResult<'tcx> {
381         ecx.call_intrinsic(instance, args, ret, unwind)
382     }
383
384     #[inline(always)]
385     fn assert_panic(
386         ecx: &mut InterpCx<'mir, 'tcx, Self>,
387         msg: &mir::AssertMessage<'tcx>,
388         unwind: Option<mir::BasicBlock>,
389     ) -> InterpResult<'tcx> {
390         ecx.assert_panic(msg, unwind)
391     }
392
393     #[inline(always)]
394     fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>, msg: String) -> InterpResult<'tcx, !> {
395         throw_machine_stop!(TerminationInfo::Abort(msg))
396     }
397
398     #[inline(always)]
399     fn binary_ptr_op(
400         ecx: &rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
401         bin_op: mir::BinOp,
402         left: ImmTy<'tcx, Tag>,
403         right: ImmTy<'tcx, Tag>,
404     ) -> InterpResult<'tcx, (Scalar<Tag>, bool, ty::Ty<'tcx>)> {
405         ecx.binary_ptr_op(bin_op, left, right)
406     }
407
408     fn box_alloc(
409         ecx: &mut InterpCx<'mir, 'tcx, Self>,
410         dest: PlaceTy<'tcx, Tag>,
411     ) -> InterpResult<'tcx> {
412         trace!("box_alloc for {:?}", dest.layout.ty);
413         let layout = ecx.layout_of(dest.layout.ty.builtin_deref(false).unwrap().ty)?;
414         // First argument: `size`.
415         // (`0` is allowed here -- this is expected to be handled by the lang item).
416         let size = Scalar::from_machine_usize(layout.size.bytes(), ecx);
417
418         // Second argument: `align`.
419         let align = Scalar::from_machine_usize(layout.align.abi.bytes(), ecx);
420
421         // Call the `exchange_malloc` lang item.
422         let malloc = ecx.tcx.lang_items().exchange_malloc_fn().unwrap();
423         let malloc = ty::Instance::mono(ecx.tcx.tcx, malloc);
424         ecx.call_function(
425             malloc,
426             &[size.into(), align.into()],
427             Some(dest),
428             // Don't do anything when we are done. The `statement()` function will increment
429             // the old stack frame's stmt counter to the next statement, which means that when
430             // `exchange_malloc` returns, we go on evaluating exactly where we want to be.
431             StackPopCleanup::None { cleanup: true },
432         )?;
433         Ok(())
434     }
435
436     fn thread_local_static_alloc_id(
437         ecx: &mut InterpCx<'mir, 'tcx, Self>,
438         def_id: DefId,
439     ) -> InterpResult<'tcx, AllocId> {
440         ecx.get_or_create_thread_local_alloc_id(def_id)
441     }
442
443     fn extern_static_alloc_id(
444         memory: &Memory<'mir, 'tcx, Self>,
445         def_id: DefId,
446     ) -> InterpResult<'tcx, AllocId> {
447         let attrs = memory.tcx.get_attrs(def_id);
448         let link_name = match memory.tcx.sess.first_attr_value_str_by_name(&attrs, sym::link_name) {
449             Some(name) => name,
450             None => memory.tcx.item_name(def_id),
451         };
452         if let Some(&id) = memory.extra.extern_statics.get(&link_name) {
453             Ok(id)
454         } else {
455             throw_unsup_format!("`extern` static {:?} is not supported by Miri", def_id)
456         }
457     }
458
459     fn init_allocation_extra<'b>(
460         memory_extra: &MemoryExtra,
461         id: AllocId,
462         alloc: Cow<'b, Allocation>,
463         kind: Option<MemoryKind<Self::MemoryKind>>,
464     ) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
465         if Some(id) == memory_extra.tracked_alloc_id {
466             register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
467         }
468
469         let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
470         let alloc = alloc.into_owned();
471         let (stacks, base_tag) =
472             if let Some(stacked_borrows) = &memory_extra.stacked_borrows {
473                 let (stacks, base_tag) =
474                     Stacks::new_allocation(id, alloc.size, Rc::clone(stacked_borrows), kind);
475                 (Some(stacks), base_tag)
476             } else {
477                 // No stacks, no tag.
478                 (None, Tag::Untagged)
479             };
480         let race_alloc = if let Some(data_race) = &memory_extra.data_race {
481             match kind {
482                 // V-Table generation is lazy and so racy, so do not track races.
483                 // Also V-Tables are read only so no data races can be occur.
484                 // Must be disabled since V-Tables are initialized via interpreter
485                 // writes on demand and can incorrectly cause the data-race detector
486                 // to trigger.
487                 MemoryKind::Vtable => None,
488                 // User allocated and stack memory should track allocation.
489                 MemoryKind::Machine(
490                     MiriMemoryKind::Rust | MiriMemoryKind::C | MiriMemoryKind::WinHeap
491                 ) | MemoryKind::Stack => Some(
492                     data_race::AllocExtra::new_allocation(&data_race, alloc.size, true)
493                 ),
494                 // Other global memory should trace races but be allocated at the 0 timestamp.
495                 MemoryKind::Machine(
496                     MiriMemoryKind::Global | MiriMemoryKind::Machine | MiriMemoryKind::Env |
497                     MiriMemoryKind::ExternStatic | MiriMemoryKind::Tls
498                 ) | MemoryKind::CallerLocation => Some(
499                     data_race::AllocExtra::new_allocation(&data_race, alloc.size, false)
500                 )
501             }
502         } else {
503             None
504         };
505         let mut stacked_borrows = memory_extra.stacked_borrows.as_ref().map(|sb| sb.borrow_mut());
506         let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
507             |alloc| {
508                 if let Some(stacked_borrows) = &mut stacked_borrows {
509                     // Only globals may already contain pointers at this point
510                     assert_eq!(kind, MiriMemoryKind::Global.into());
511                     stacked_borrows.global_base_ptr(alloc)
512                 } else {
513                     Tag::Untagged
514                 }
515             },
516             AllocExtra { stacked_borrows: stacks, data_race: race_alloc },
517         );
518         (Cow::Owned(alloc), base_tag)
519     }
520
521     #[inline(always)]
522     fn before_deallocation(
523         memory_extra: &mut Self::MemoryExtra,
524         id: AllocId,
525     ) -> InterpResult<'tcx> {
526         if Some(id) == memory_extra.tracked_alloc_id {
527             register_diagnostic(NonHaltingDiagnostic::FreedAlloc(id));
528         }
529
530         Ok(())
531     }
532
533     #[inline(always)]
534     fn tag_global_base_pointer(memory_extra: &MemoryExtra, id: AllocId) -> Self::PointerTag {
535         if let Some(stacked_borrows) = &memory_extra.stacked_borrows {
536             stacked_borrows.borrow_mut().global_base_ptr(id)
537         } else {
538             Tag::Untagged
539         }
540     }
541
542     #[inline(always)]
543     fn retag(
544         ecx: &mut InterpCx<'mir, 'tcx, Self>,
545         kind: mir::RetagKind,
546         place: PlaceTy<'tcx, Tag>,
547     ) -> InterpResult<'tcx> {
548         if ecx.memory.extra.stacked_borrows.is_some() {
549             ecx.retag(kind, place)
550         } else {
551             Ok(())
552         }
553     }
554
555     #[inline(always)]
556     fn init_frame_extra(
557         ecx: &mut InterpCx<'mir, 'tcx, Self>,
558         frame: Frame<'mir, 'tcx, Tag>,
559     ) -> InterpResult<'tcx, Frame<'mir, 'tcx, Tag, FrameData<'tcx>>> {
560         let stacked_borrows = ecx.memory.extra.stacked_borrows.as_ref();
561         let call_id = stacked_borrows.map_or(NonZeroU64::new(1).unwrap(), |stacked_borrows| {
562             stacked_borrows.borrow_mut().new_call()
563         });
564         let extra = FrameData { call_id, catch_unwind: None };
565         Ok(frame.with_extra(extra))
566     }
567
568     fn stack<'a>(
569         ecx: &'a InterpCx<'mir, 'tcx, Self>
570     ) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
571         ecx.active_thread_stack()
572     }
573
574     fn stack_mut<'a>(
575         ecx: &'a mut InterpCx<'mir, 'tcx, Self>
576     ) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> {
577         ecx.active_thread_stack_mut()
578     }
579
580     #[inline(always)]
581     fn after_stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
582         if ecx.memory.extra.stacked_borrows.is_some() {
583             ecx.retag_return_place()
584         } else {
585             Ok(())
586         }
587     }
588
589     #[inline(always)]
590     fn after_stack_pop(
591         ecx: &mut InterpCx<'mir, 'tcx, Self>,
592         frame: Frame<'mir, 'tcx, Tag, FrameData<'tcx>>,
593         unwinding: bool,
594     ) -> InterpResult<'tcx, StackPopJump> {
595         ecx.handle_stack_pop(frame.extra, unwinding)
596     }
597
598     #[inline(always)]
599     fn int_to_ptr(
600         memory: &Memory<'mir, 'tcx, Self>,
601         int: u64,
602     ) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
603         intptrcast::GlobalState::int_to_ptr(int, memory)
604     }
605
606     #[inline(always)]
607     fn ptr_to_int(
608         memory: &Memory<'mir, 'tcx, Self>,
609         ptr: Pointer<Self::PointerTag>,
610     ) -> InterpResult<'tcx, u64> {
611         intptrcast::GlobalState::ptr_to_int(ptr, memory)
612     }
613 }
614
615 impl AllocationExtra<Tag> for AllocExtra {
616     #[inline(always)]
617     fn memory_read<'tcx>(
618         alloc: &Allocation<Tag, AllocExtra>,
619         ptr: Pointer<Tag>,
620         size: Size,
621     ) -> InterpResult<'tcx> {
622         if let Some(data_race) = &alloc.extra.data_race {
623             data_race.read(ptr, size)?;
624         }
625         if let Some(stacked_borrows) = &alloc.extra.stacked_borrows {
626             stacked_borrows.memory_read(ptr, size)
627         } else {
628             Ok(())
629         }
630     }
631
632     #[inline(always)]
633     fn memory_written<'tcx>(
634         alloc: &mut Allocation<Tag, AllocExtra>,
635         ptr: Pointer<Tag>,
636         size: Size,
637     ) -> InterpResult<'tcx> {
638         if let Some(data_race) = &mut alloc.extra.data_race {
639             data_race.write(ptr, size)?;
640         }
641         if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
642             stacked_borrows.memory_written(ptr, size)
643         } else {
644             Ok(())
645         }
646     }
647
648     #[inline(always)]
649     fn memory_deallocated<'tcx>(
650         alloc: &mut Allocation<Tag, AllocExtra>,
651         ptr: Pointer<Tag>,
652         size: Size,
653     ) -> InterpResult<'tcx> {
654         if let Some(data_race) = &mut alloc.extra.data_race {
655             data_race.deallocate(ptr, size)?;
656         }
657         if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
658             stacked_borrows.memory_deallocated(ptr, size)
659         } else {
660             Ok(())
661         }
662     }
663 }