]> git.lizzy.rs Git - rust.git/blob - src/libpanic_unwind/miri.rs
7fdbf46ea487def2da2d77f096c66d2159db21aa
[rust.git] / src / libpanic_unwind / miri.rs
1 #![allow(nonstandard_style)]
2
3 use core::any::Any;
4 use alloc::boxed::Box;
5
6 pub fn payload() -> *mut u8 {
7     core::ptr::null_mut()
8 }
9
10 pub unsafe fn panic(data: Box<dyn Any + Send>) -> ! {
11     core::intrinsics::miri_start_panic(Box::into_raw(data))
12 }
13
14 pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
15     Box::from_raw(ptr)
16 }
17
18 // This is required by the compiler to exist (e.g., it's a lang item),
19 // but is never used by Miri. Therefore, we just use a stub here
20 #[lang = "eh_personality"]
21 #[cfg(not(test))]
22 fn rust_eh_personality() {
23     unsafe { core::intrinsics::abort() }
24 }
25
26 // The rest is required on *some* targets to exist (specifically, MSVC targets that use SEH).
27 // We just add it on all targets. Copied from `seh.rs`.
28 #[repr(C)]
29 pub struct _TypeDescriptor {
30     pub pVFTable: *const u8,
31     pub spare: *mut u8,
32     pub name: [u8; 11],
33 }
34
35 extern "C" {
36     #[link_name = "\x01??_7type_info@@6B@"]
37     static TYPE_INFO_VTABLE: *const u8;
38 }
39
40 const TYPE_NAME: [u8; 11] = *b"rust_panic\0";
41
42 #[cfg_attr(not(test), lang = "eh_catch_typeinfo")]
43 static mut TYPE_DESCRIPTOR: _TypeDescriptor = _TypeDescriptor {
44     pVFTable: unsafe { &TYPE_INFO_VTABLE } as *const _ as *const _,
45     spare: core::ptr::null_mut(),
46     name: TYPE_NAME,
47 };