| 499 | } |
| 500 | |
| 501 | fn raw_instance<'a>(&self, store: &mut StoreOpaque) -> Result<&'a crate::vm::Instance> { |
| 502 | let frame_data = self.frame_data(store)?; |
| 503 | |
| 504 | // Read out the vmctx slot. |
| 505 | |
| 506 | // SAFETY: vmctx is always at offset 0 in the slot. (See |
| 507 | // crates/cranelift/src/func_environ.rs in |
| 508 | // `update_stack_slot_vmctx()`.) The frame/activation is |
| 509 | // still valid because we verified this in `frame_data` above. |
| 510 | let vmctx: usize = |
| 511 | unsafe { *(frame_data.slot_addr(self.cursor.frame().fp()) as *mut usize) }; |
| 512 | let vmctx: *mut VMContext = core::ptr::with_exposed_provenance_mut(vmctx); |
| 513 | let vmctx = NonNull::new(vmctx).expect("null vmctx in debug state slot"); |
| 514 | // SAFETY: the stored vmctx value is a valid instance in this |
| 515 | // store; we only visit frames from this store in the |
| 516 | // backtrace. |
| 517 | let instance = unsafe { crate::vm::Instance::from_vmctx(vmctx) }; |
| 518 | // SAFETY: the instance pointer read above is valid. |
| 519 | Ok(unsafe { instance.as_ref() }) |
| 520 | } |
| 521 | |
| 522 | /// Get the instance associated with the current frame. |
| 523 | pub fn instance(&self, mut store: impl AsContextMut) -> Result<Instance> { |