1 //! Unwinding panics for Miri.
5 // The type of the payload that the Miri engine propagates through unwinding for us.
6 // Must be pointer-sized.
7 type Payload = Box<Box<dyn Any + Send>>;
9 pub unsafe fn panic(payload: Box<dyn Any + Send>) -> u32 {
10 // The payload we pass to `miri_start_panic` will be exactly the argument we get
11 // in `cleanup` below. So we just box it up once, to get something pointer-sized.
12 let payload_box: Payload = Box::new(payload);
13 core::intrinsics::miri_start_panic(Box::into_raw(payload_box) as *mut u8)
16 pub unsafe fn cleanup(payload_box: *mut u8) -> Box<dyn Any + Send> {
17 // Recover the underlying `Box`.
18 let payload_box: Payload = Box::from_raw(payload_box as *mut _);