]> git.lizzy.rs Git - rust.git/blob - src/libpanic_unwind/miri.rs
Rollup merge of #73870 - sexxi-goose:projection-ty, r=nikomatsakis
[rust.git] / src / libpanic_unwind / miri.rs
1 //! Unwinding panics for Miri.
2 use alloc::boxed::Box;
3 use core::any::Any;
4
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>>;
8
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)
14 }
15
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 _);
19     *payload_box
20 }