Skip to content

Commit 52d7246

Browse files
committed
miri panic_unwind: fix hack for SEH platforms
1 parent 065e1b8 commit 52d7246

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/libpanic_unwind/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ cfg_if::cfg_if! {
3939
if #[cfg(miri)] {
4040
#[path = "miri.rs"]
4141
mod imp;
42-
// On MSVC we need the SEH lang items as well...
43-
// This should match the conditions of the `seh.rs` import below.
44-
#[cfg(all(target_env = "msvc", not(target_arch = "aarch64")))]
45-
#[allow(unused)]
46-
mod seh;
4742
} else if #[cfg(target_os = "emscripten")] {
4843
#[path = "emcc.rs"]
4944
mod imp;

src/libpanic_unwind/miri.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(nonstandard_style)]
2+
13
use core::any::Any;
24
use alloc::boxed::Box;
35

@@ -13,11 +15,33 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
1315
Box::from_raw(ptr)
1416
}
1517

16-
1718
// This is required by the compiler to exist (e.g., it's a lang item),
1819
// but is never used by Miri. Therefore, we just use a stub here
1920
#[lang = "eh_personality"]
2021
#[cfg(not(test))]
2122
fn rust_eh_personality() {
2223
unsafe { core::intrinsics::abort() }
2324
}
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+
};

0 commit comments

Comments
 (0)