Skip to content

Commit 937195b

Browse files
authored
Rollup merge of #66466 - RalfJung:seh, r=oli-obk
miri panic_unwind: fix hack for SEH platforms The old hack didn't work as we ended up duplicating the `eh_personality` lang item... I have no idea if rustc cares that `eh_catch_typeinfo` has a certain shape, but better safe than sorry. I cannot test this locally. r? @oli-obk Cc @Aaron1011
2 parents 404081f + e8ff465 commit 937195b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/libpanic_unwind/lib.rs

-5
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

+20-1
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,28 @@ 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+
const TYPE_NAME: [u8; 11] = *b"rust_panic\0";
36+
37+
#[cfg_attr(not(test), lang = "eh_catch_typeinfo")]
38+
static mut TYPE_DESCRIPTOR: _TypeDescriptor = _TypeDescriptor {
39+
pVFTable: core::ptr::null(),
40+
spare: core::ptr::null_mut(),
41+
name: TYPE_NAME,
42+
};

0 commit comments

Comments
 (0)