Skip to content

Commit

Permalink
miri panic_unwind: fix hack for SEH platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Nov 16, 2019
1 parent 065e1b8 commit 52d7246
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/libpanic_unwind/lib.rs
Expand Up @@ -39,11 +39,6 @@ cfg_if::cfg_if! {
if #[cfg(miri)] {
#[path = "miri.rs"]
mod imp;
// On MSVC we need the SEH lang items as well...
// This should match the conditions of the `seh.rs` import below.
#[cfg(all(target_env = "msvc", not(target_arch = "aarch64")))]
#[allow(unused)]
mod seh;
} else if #[cfg(target_os = "emscripten")] {
#[path = "emcc.rs"]
mod imp;
Expand Down
26 changes: 25 additions & 1 deletion src/libpanic_unwind/miri.rs
@@ -1,3 +1,5 @@
#![allow(nonstandard_style)]

use core::any::Any;
use alloc::boxed::Box;

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


// This is required by the compiler to exist (e.g., it's a lang item),
// but is never used by Miri. Therefore, we just use a stub here
#[lang = "eh_personality"]
#[cfg(not(test))]
fn rust_eh_personality() {
unsafe { core::intrinsics::abort() }
}

// The rest is required on *some* targets to exist (specifically, MSVC targets that use SEH).
// We just add it on all targets. Copied from `seh.rs`.
#[repr(C)]
pub struct _TypeDescriptor {
pub pVFTable: *const u8,
pub spare: *mut u8,
pub name: [u8; 11],
}

extern "C" {
#[link_name = "\x01??_7type_info@@6B@"]
static TYPE_INFO_VTABLE: *const u8;
}

const TYPE_NAME: [u8; 11] = *b"rust_panic\0";

#[cfg_attr(not(test), lang = "eh_catch_typeinfo")]
static mut TYPE_DESCRIPTOR: _TypeDescriptor = _TypeDescriptor {
pVFTable: unsafe { &TYPE_INFO_VTABLE } as *const _ as *const _,
spare: core::ptr::null_mut(),
name: TYPE_NAME,
};

0 comments on commit 52d7246

Please sign in to comment.