From 52d7246a9368048154b9cb666f4b7a79377bd17d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 16 Nov 2019 09:27:06 +0100 Subject: [PATCH] miri panic_unwind: fix hack for SEH platforms --- src/libpanic_unwind/lib.rs | 5 ----- src/libpanic_unwind/miri.rs | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index 5f345c2133f6b..d97a7a8a87d8d 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -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; diff --git a/src/libpanic_unwind/miri.rs b/src/libpanic_unwind/miri.rs index 254a9383b4223..7fdbf46ea487d 100644 --- a/src/libpanic_unwind/miri.rs +++ b/src/libpanic_unwind/miri.rs @@ -1,3 +1,5 @@ +#![allow(nonstandard_style)] + use core::any::Any; use alloc::boxed::Box; @@ -13,7 +15,6 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box { 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"] @@ -21,3 +22,26 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box { 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, +};