1 //! Global machine state as well as implementation of the interpreter engine
5 use std::cell::RefCell;
7 use std::num::NonZeroU64;
8 use std::time::Instant;
10 use rand::rngs::StdRng;
11 use rand::SeedableRng;
13 use rustc_data_structures::fx::FxHashMap;
18 layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout},
22 use rustc_span::def_id::{CrateNum, DefId};
23 use rustc_span::symbol::{sym, Symbol};
24 use rustc_target::abi::Size;
25 use rustc_target::spec::abi::Abi;
29 // Some global facts about the emulated machine.
30 pub const PAGE_SIZE: u64 = 4 * 1024; // FIXME: adjust to target architecture
31 pub const STACK_ADDR: u64 = 32 * PAGE_SIZE; // not really about the "stack", but where we start assigning integer addresses to allocations
32 pub const STACK_SIZE: u64 = 16 * PAGE_SIZE; // whatever
33 pub const NUM_CPUS: u64 = 1;
35 /// Extra data stored with each stack frame
36 pub struct FrameData<'tcx> {
37 /// Extra data for Stacked Borrows.
38 pub call_id: stacked_borrows::CallId,
40 /// If this is Some(), then this is a special "catch unwind" frame (the frame of `try_fn`
41 /// called by `try`). When this frame is popped during unwinding a panic,
42 /// we stop unwinding, use the `CatchUnwindData` to handle catching.
43 pub catch_unwind: Option<CatchUnwindData<'tcx>>,
45 /// If `measureme` profiling is enabled, holds timing information
46 /// for the start of this frame. When we finish executing this frame,
47 /// we use this to register a completed event with `measureme`.
48 pub timing: Option<measureme::DetachedTiming>,
51 impl<'tcx> std::fmt::Debug for FrameData<'tcx> {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 // Omitting `timing`, it does not support `Debug`.
54 let FrameData { call_id, catch_unwind, timing: _ } = self;
55 f.debug_struct("FrameData")
56 .field("call_id", call_id)
57 .field("catch_unwind", catch_unwind)
62 /// Extra memory kinds
63 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
64 pub enum MiriMemoryKind {
65 /// `__rust_alloc` memory.
69 /// Windows `HeapAlloc` memory.
71 /// Memory for args, errno, and other parts of the machine-managed environment.
72 /// This memory may leak.
74 /// Memory allocated by the runtime (e.g. env vars). Separate from `Machine`
75 /// because we clean it up and leak-check it.
77 /// Globals copied from `tcx`.
78 /// This memory may leak.
80 /// Memory for extern statics.
81 /// This memory may leak.
83 /// Memory for thread-local statics.
84 /// This memory may leak.
88 impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
90 fn into(self) -> MemoryKind<MiriMemoryKind> {
91 MemoryKind::Machine(self)
95 impl MayLeak for MiriMemoryKind {
97 fn may_leak(self) -> bool {
98 use self::MiriMemoryKind::*;
100 Rust | C | WinHeap | Runtime => false,
101 Machine | Global | ExternStatic | Tls => true,
106 impl fmt::Display for MiriMemoryKind {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108 use self::MiriMemoryKind::*;
110 Rust => write!(f, "Rust heap"),
111 C => write!(f, "C heap"),
112 WinHeap => write!(f, "Windows heap"),
113 Machine => write!(f, "machine-managed memory"),
114 Runtime => write!(f, "language runtime memory"),
115 Global => write!(f, "global (static or const)"),
116 ExternStatic => write!(f, "extern static"),
117 Tls => write!(f, "thread-local static"),
122 /// Pointer provenance (tag).
123 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
125 pub alloc_id: AllocId,
126 /// Stacked Borrows tag.
130 impl Provenance for Tag {
131 /// We use absolute addresses in the `offset` of a `Pointer<Tag>`.
132 const OFFSET_IS_ADDR: bool = true;
134 /// We cannot err on partial overwrites, it happens too often in practice (due to unions).
135 const ERR_ON_PARTIAL_PTR_OVERWRITE: bool = false;
137 fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138 let (tag, addr) = ptr.into_parts(); // address is absolute
139 write!(f, "0x{:x}", addr.bytes())?;
140 // Forward `alternate` flag to `alloc_id` printing.
142 write!(f, "[{:#?}]", tag.alloc_id)?;
144 write!(f, "[{:?}]", tag.alloc_id)?;
146 // Print Stacked Borrows tag.
147 write!(f, "{:?}", tag.sb)
150 fn get_alloc_id(self) -> AllocId {
155 /// Extra per-allocation data
156 #[derive(Debug, Clone)]
157 pub struct AllocExtra {
158 /// Stacked Borrows state is only added if it is enabled.
159 pub stacked_borrows: Option<stacked_borrows::AllocExtra>,
160 /// Data race detection via the use of a vector-clock,
161 /// this is only added if it is enabled.
162 pub data_race: Option<data_race::AllocExtra>,
165 /// Extra global memory data
167 pub struct MemoryExtra {
168 pub stacked_borrows: Option<stacked_borrows::MemoryExtra>,
169 pub data_race: Option<data_race::MemoryExtra>,
170 pub intptrcast: intptrcast::MemoryExtra,
172 /// Mapping extern static names to their base pointer.
173 extern_statics: FxHashMap<Symbol, Pointer<Tag>>,
175 /// The random number generator used for resolving non-determinism.
176 /// Needs to be queried by ptr_to_int, hence needs interior mutability.
177 pub(crate) rng: RefCell<StdRng>,
179 /// An allocation ID to report when it is being allocated
180 /// (helps for debugging memory leaks and use after free bugs).
181 tracked_alloc_id: Option<AllocId>,
183 /// Controls whether alignment of memory accesses is being checked.
184 pub(crate) check_alignment: AlignmentCheck,
186 /// Failure rate of compare_exchange_weak, between 0.0 and 1.0
187 pub(crate) cmpxchg_weak_failure_rate: f64,
191 pub fn new(config: &MiriConfig) -> Self {
192 let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
193 let stacked_borrows = if config.stacked_borrows {
194 Some(RefCell::new(stacked_borrows::GlobalState::new(
195 config.tracked_pointer_tag,
196 config.tracked_call_id,
203 if config.data_race_detector { Some(data_race::GlobalState::new()) } else { None };
207 intptrcast: Default::default(),
208 extern_statics: FxHashMap::default(),
209 rng: RefCell::new(rng),
210 tracked_alloc_id: config.tracked_alloc_id,
211 check_alignment: config.check_alignment,
212 cmpxchg_weak_failure_rate: config.cmpxchg_weak_failure_rate,
216 fn add_extern_static<'tcx, 'mir>(
217 this: &mut MiriEvalContext<'mir, 'tcx>,
219 ptr: Pointer<Option<Tag>>,
221 let ptr = ptr.into_pointer_or_addr().unwrap();
222 this.memory.extra.extern_statics.try_insert(Symbol::intern(name), ptr).unwrap();
225 /// Sets up the "extern statics" for this machine.
226 pub fn init_extern_statics<'tcx, 'mir>(
227 this: &mut MiriEvalContext<'mir, 'tcx>,
228 ) -> InterpResult<'tcx> {
229 match this.tcx.sess.target.os.as_str() {
232 Self::add_extern_static(
235 this.machine.env_vars.environ.unwrap().ptr,
237 // A couple zero-initialized pointer-sized extern statics.
238 // Most of them are for weak symbols, which we all set to null (indicating that the
239 // symbol is not supported, and triggering fallback code which ends up calling a
240 // syscall that we do support).
241 for name in &["__cxa_thread_atexit_impl", "getrandom", "statx"] {
242 let layout = this.machine.layouts.usize;
243 let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into())?;
244 this.write_scalar(Scalar::from_machine_usize(0, this), &place.into())?;
245 Self::add_extern_static(this, name, place.ptr);
250 // This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
251 let layout = this.machine.layouts.u8;
252 let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into())?;
253 this.write_scalar(Scalar::from_u8(0), &place.into())?;
254 Self::add_extern_static(this, "_tls_used", place.ptr);
256 _ => {} // No "extern statics" supported on this target
262 /// Precomputed layouts of primitive types
263 pub struct PrimitiveLayouts<'tcx> {
264 pub unit: TyAndLayout<'tcx>,
265 pub i8: TyAndLayout<'tcx>,
266 pub i32: TyAndLayout<'tcx>,
267 pub isize: TyAndLayout<'tcx>,
268 pub u8: TyAndLayout<'tcx>,
269 pub u32: TyAndLayout<'tcx>,
270 pub usize: TyAndLayout<'tcx>,
271 pub bool: TyAndLayout<'tcx>,
274 impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
275 fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, LayoutError<'tcx>> {
277 unit: layout_cx.layout_of(layout_cx.tcx.mk_unit())?,
278 i8: layout_cx.layout_of(layout_cx.tcx.types.i8)?,
279 i32: layout_cx.layout_of(layout_cx.tcx.types.i32)?,
280 isize: layout_cx.layout_of(layout_cx.tcx.types.isize)?,
281 u8: layout_cx.layout_of(layout_cx.tcx.types.u8)?,
282 u32: layout_cx.layout_of(layout_cx.tcx.types.u32)?,
283 usize: layout_cx.layout_of(layout_cx.tcx.types.usize)?,
284 bool: layout_cx.layout_of(layout_cx.tcx.types.bool)?,
289 /// The machine itself.
290 pub struct Evaluator<'mir, 'tcx> {
291 /// Environment variables set by `setenv`.
292 /// Miri does not expose env vars from the host to the emulated program.
293 pub(crate) env_vars: EnvVars<'tcx>,
295 /// Program arguments (`Option` because we can only initialize them after creating the ecx).
296 /// These are *pointers* to argc/argv because macOS.
297 /// We also need the full command line as one string because of Windows.
298 pub(crate) argc: Option<MemPlace<Tag>>,
299 pub(crate) argv: Option<MemPlace<Tag>>,
300 pub(crate) cmd_line: Option<MemPlace<Tag>>,
303 pub(crate) tls: TlsData<'tcx>,
305 /// What should Miri do when an op requires communicating with the host,
306 /// such as accessing host env vars, random number generation, and
307 /// file system access.
308 pub(crate) isolated_op: IsolatedOp,
310 /// Whether to enforce the validity invariant.
311 pub(crate) validate: bool,
313 /// Whether to enforce validity (e.g., initialization) of integers and floats.
314 pub(crate) enforce_number_validity: bool,
316 /// Whether to enforce [ABI](Abi) of function calls.
317 pub(crate) enforce_abi: bool,
319 pub(crate) file_handler: shims::posix::FileHandler,
320 pub(crate) dir_handler: shims::posix::DirHandler,
322 /// The "time anchor" for this machine's monotone clock (for `Instant` simulation).
323 pub(crate) time_anchor: Instant,
325 /// The set of threads.
326 pub(crate) threads: ThreadManager<'mir, 'tcx>,
328 /// Precomputed `TyLayout`s for primitive data types that are commonly used inside Miri.
329 pub(crate) layouts: PrimitiveLayouts<'tcx>,
331 /// Allocations that are considered roots of static memory (that may leak).
332 pub(crate) static_roots: Vec<AllocId>,
334 /// The `measureme` profiler used to record timing information about
335 /// the emulated program.
336 profiler: Option<measureme::Profiler>,
337 /// Used with `profiler` to cache the `StringId`s for event names
338 /// uesd with `measureme`.
339 string_cache: FxHashMap<String, measureme::StringId>,
341 /// Cache of `Instance` exported under the given `Symbol` name.
342 /// `None` means no `Instance` exported under the given name is found.
343 pub(crate) exported_symbols_cache: FxHashMap<Symbol, Option<Instance<'tcx>>>,
345 /// Whether to raise a panic in the context of the evaluated process when unsupported
346 /// functionality is encountered. If `false`, an error is propagated in the Miri application context
347 /// instead (default behavior)
348 pub(crate) panic_on_unsupported: bool,
350 /// Equivalent setting as RUST_BACKTRACE on encountering an error.
351 pub(crate) backtrace_style: BacktraceStyle,
353 /// Crates which are considered local for the purposes of error reporting.
354 pub(crate) local_crates: Vec<CrateNum>,
357 impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
358 pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Self {
359 let local_crates = helpers::get_local_crates(&layout_cx.tcx);
361 PrimitiveLayouts::new(layout_cx).expect("Couldn't get layouts of primitive types");
362 let profiler = config.measureme_out.as_ref().map(|out| {
363 measureme::Profiler::new(out).expect("Couldn't create `measureme` profiler")
366 // `env_vars` could be initialized properly here if `Memory` were available before
367 // calling this method.
368 env_vars: EnvVars::default(),
372 tls: TlsData::default(),
373 isolated_op: config.isolated_op,
374 validate: config.validate,
375 enforce_number_validity: config.check_number_validity,
376 enforce_abi: config.check_abi,
377 file_handler: Default::default(),
378 dir_handler: Default::default(),
379 time_anchor: Instant::now(),
381 threads: ThreadManager::default(),
382 static_roots: Vec::new(),
384 string_cache: Default::default(),
385 exported_symbols_cache: FxHashMap::default(),
386 panic_on_unsupported: config.panic_on_unsupported,
387 backtrace_style: config.backtrace_style,
392 pub(crate) fn communicate(&self) -> bool {
393 self.isolated_op == IsolatedOp::Allow
396 /// Check whether the stack frame that this `FrameInfo` refers to is part of a local crate.
397 pub(crate) fn is_local(&self, frame: &FrameInfo<'_>) -> bool {
398 let def_id = frame.instance.def_id();
399 def_id.is_local() || self.local_crates.contains(&def_id.krate)
403 /// A rustc InterpCx for Miri.
404 pub type MiriEvalContext<'mir, 'tcx> = InterpCx<'mir, 'tcx, Evaluator<'mir, 'tcx>>;
406 /// A little trait that's useful to be inherited by extension traits.
407 pub trait MiriEvalContextExt<'mir, 'tcx> {
408 fn eval_context_ref<'a>(&'a self) -> &'a MiriEvalContext<'mir, 'tcx>;
409 fn eval_context_mut<'a>(&'a mut self) -> &'a mut MiriEvalContext<'mir, 'tcx>;
411 impl<'mir, 'tcx> MiriEvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {
413 fn eval_context_ref(&self) -> &MiriEvalContext<'mir, 'tcx> {
417 fn eval_context_mut(&mut self) -> &mut MiriEvalContext<'mir, 'tcx> {
422 /// Machine hook implementations.
423 impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
424 type MemoryKind = MiriMemoryKind;
426 type FrameExtra = FrameData<'tcx>;
427 type MemoryExtra = MemoryExtra;
428 type AllocExtra = AllocExtra;
429 type PointerTag = Tag;
430 type ExtraFnVal = Dlsym;
433 MonoHashMap<AllocId, (MemoryKind<MiriMemoryKind>, Allocation<Tag, Self::AllocExtra>)>;
435 const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);
437 const PANIC_ON_ALLOC_FAIL: bool = false;
440 fn enforce_alignment(memory_extra: &MemoryExtra) -> bool {
441 memory_extra.check_alignment != AlignmentCheck::None
445 fn force_int_for_alignment_check(memory_extra: &Self::MemoryExtra) -> bool {
446 memory_extra.check_alignment == AlignmentCheck::Int
450 fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
455 fn enforce_number_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
456 ecx.machine.enforce_number_validity
460 fn enforce_abi(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
461 ecx.machine.enforce_abi
465 fn find_mir_or_eval_fn(
466 ecx: &mut InterpCx<'mir, 'tcx, Self>,
467 instance: ty::Instance<'tcx>,
469 args: &[OpTy<'tcx, Tag>],
470 ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
471 unwind: StackPopUnwind,
472 ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
473 ecx.find_mir_or_eval_fn(instance, abi, args, ret, unwind)
478 ecx: &mut InterpCx<'mir, 'tcx, Self>,
481 args: &[OpTy<'tcx, Tag>],
482 ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
483 _unwind: StackPopUnwind,
484 ) -> InterpResult<'tcx> {
485 ecx.call_dlsym(fn_val, abi, args, ret)
490 ecx: &mut rustc_const_eval::interpret::InterpCx<'mir, 'tcx, Self>,
491 instance: ty::Instance<'tcx>,
492 args: &[OpTy<'tcx, Tag>],
493 ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
494 unwind: StackPopUnwind,
495 ) -> InterpResult<'tcx> {
496 ecx.call_intrinsic(instance, args, ret, unwind)
501 ecx: &mut InterpCx<'mir, 'tcx, Self>,
502 msg: &mir::AssertMessage<'tcx>,
503 unwind: Option<mir::BasicBlock>,
504 ) -> InterpResult<'tcx> {
505 ecx.assert_panic(msg, unwind)
509 fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>, msg: String) -> InterpResult<'tcx, !> {
510 throw_machine_stop!(TerminationInfo::Abort(msg))
515 ecx: &rustc_const_eval::interpret::InterpCx<'mir, 'tcx, Self>,
517 left: &ImmTy<'tcx, Tag>,
518 right: &ImmTy<'tcx, Tag>,
519 ) -> InterpResult<'tcx, (Scalar<Tag>, bool, ty::Ty<'tcx>)> {
520 ecx.binary_ptr_op(bin_op, left, right)
523 fn thread_local_static_base_pointer(
524 ecx: &mut InterpCx<'mir, 'tcx, Self>,
526 ) -> InterpResult<'tcx, Pointer<Tag>> {
527 ecx.get_or_create_thread_local_alloc(def_id)
530 fn extern_static_base_pointer(
531 memory: &Memory<'mir, 'tcx, Self>,
533 ) -> InterpResult<'tcx, Pointer<Tag>> {
534 let attrs = memory.tcx.get_attrs(def_id);
535 let link_name = match memory.tcx.sess.first_attr_value_str_by_name(&attrs, sym::link_name) {
537 None => memory.tcx.item_name(def_id),
539 if let Some(&ptr) = memory.extra.extern_statics.get(&link_name) {
542 throw_unsup_format!("`extern` static {:?} is not supported by Miri", def_id)
546 fn init_allocation_extra<'b>(
547 mem: &Memory<'mir, 'tcx, Self>,
549 alloc: Cow<'b, Allocation>,
550 kind: Option<MemoryKind<Self::MemoryKind>>,
551 ) -> Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>> {
552 if Some(id) == mem.extra.tracked_alloc_id {
553 register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(id));
556 let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
557 let alloc = alloc.into_owned();
558 let stacks = if let Some(stacked_borrows) = &mem.extra.stacked_borrows {
559 Some(Stacks::new_allocation(id, alloc.size(), stacked_borrows, kind))
563 let race_alloc = if let Some(data_race) = &mem.extra.data_race {
564 Some(data_race::AllocExtra::new_allocation(&data_race, alloc.size(), kind))
568 let alloc: Allocation<Tag, Self::AllocExtra> = alloc.convert_tag_add_extra(
570 AllocExtra { stacked_borrows: stacks, data_race: race_alloc },
571 |ptr| Evaluator::tag_alloc_base_pointer(mem, ptr),
576 fn tag_alloc_base_pointer(
577 mem: &Memory<'mir, 'tcx, Self>,
578 ptr: Pointer<AllocId>,
580 let absolute_addr = intptrcast::GlobalState::rel_ptr_to_addr(&mem, ptr);
581 let sb_tag = if let Some(stacked_borrows) = &mem.extra.stacked_borrows {
582 stacked_borrows.borrow_mut().base_tag(ptr.provenance)
586 Pointer::new(Tag { alloc_id: ptr.provenance, sb: sb_tag }, Size::from_bytes(absolute_addr))
591 mem: &Memory<'mir, 'tcx, Self>,
593 ) -> Pointer<Option<Self::PointerTag>> {
594 intptrcast::GlobalState::ptr_from_addr(addr, mem)
597 /// Convert a pointer with provenance into an allocation-offset pair,
598 /// or a `None` with an absolute address if that conversion is not possible.
600 mem: &Memory<'mir, 'tcx, Self>,
601 ptr: Pointer<Self::PointerTag>,
602 ) -> (AllocId, Size) {
603 let rel = intptrcast::GlobalState::abs_ptr_to_rel(mem, ptr);
604 (ptr.provenance.alloc_id, rel)
609 memory_extra: &Self::MemoryExtra,
610 alloc_extra: &AllocExtra,
613 ) -> InterpResult<'tcx> {
614 if let Some(data_race) = &alloc_extra.data_race {
615 data_race.read(tag.alloc_id, range, memory_extra.data_race.as_ref().unwrap())?;
617 if let Some(stacked_borrows) = &alloc_extra.stacked_borrows {
618 stacked_borrows.memory_read(
622 memory_extra.stacked_borrows.as_ref().unwrap(),
631 memory_extra: &mut Self::MemoryExtra,
632 alloc_extra: &mut AllocExtra,
635 ) -> InterpResult<'tcx> {
636 if let Some(data_race) = &mut alloc_extra.data_race {
637 data_race.write(tag.alloc_id, range, memory_extra.data_race.as_mut().unwrap())?;
639 if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows {
640 stacked_borrows.memory_written(
644 memory_extra.stacked_borrows.as_mut().unwrap(),
652 fn memory_deallocated(
653 memory_extra: &mut Self::MemoryExtra,
654 alloc_extra: &mut AllocExtra,
657 ) -> InterpResult<'tcx> {
658 if Some(tag.alloc_id) == memory_extra.tracked_alloc_id {
659 register_diagnostic(NonHaltingDiagnostic::FreedAlloc(tag.alloc_id));
661 if let Some(data_race) = &mut alloc_extra.data_race {
662 data_race.deallocate(tag.alloc_id, range, memory_extra.data_race.as_mut().unwrap())?;
664 if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows {
665 stacked_borrows.memory_deallocated(
669 memory_extra.stacked_borrows.as_mut().unwrap(),
678 ecx: &mut InterpCx<'mir, 'tcx, Self>,
679 kind: mir::RetagKind,
680 place: &PlaceTy<'tcx, Tag>,
681 ) -> InterpResult<'tcx> {
682 if ecx.memory.extra.stacked_borrows.is_some() { ecx.retag(kind, place) } else { Ok(()) }
687 ecx: &mut InterpCx<'mir, 'tcx, Self>,
688 frame: Frame<'mir, 'tcx, Tag>,
689 ) -> InterpResult<'tcx, Frame<'mir, 'tcx, Tag, FrameData<'tcx>>> {
690 // Start recording our event before doing anything else
691 let timing = if let Some(profiler) = ecx.machine.profiler.as_ref() {
692 let fn_name = frame.instance.to_string();
693 let entry = ecx.machine.string_cache.entry(fn_name.clone());
694 let name = entry.or_insert_with(|| profiler.alloc_string(&*fn_name));
696 Some(profiler.start_recording_interval_event_detached(
698 measureme::EventId::from_label(*name),
699 ecx.get_active_thread().to_u32(),
705 let stacked_borrows = ecx.memory.extra.stacked_borrows.as_ref();
706 let call_id = stacked_borrows.map_or(NonZeroU64::new(1).unwrap(), |stacked_borrows| {
707 stacked_borrows.borrow_mut().new_call()
710 let extra = FrameData { call_id, catch_unwind: None, timing };
711 Ok(frame.with_extra(extra))
715 ecx: &'a InterpCx<'mir, 'tcx, Self>,
716 ) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
717 ecx.active_thread_stack()
721 ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
722 ) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> {
723 ecx.active_thread_stack_mut()
727 fn after_stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
728 if ecx.memory.extra.stacked_borrows.is_some() { ecx.retag_return_place() } else { Ok(()) }
733 ecx: &mut InterpCx<'mir, 'tcx, Self>,
734 mut frame: Frame<'mir, 'tcx, Tag, FrameData<'tcx>>,
736 ) -> InterpResult<'tcx, StackPopJump> {
737 let timing = frame.extra.timing.take();
738 let res = ecx.handle_stack_pop(frame.extra, unwinding);
739 if let Some(profiler) = ecx.machine.profiler.as_ref() {
740 profiler.finish_recording_interval_event(timing.unwrap());