Skip to content

Commit caf3cc1

Browse files
committed
Add explicit Miri support to libpanic_unwind
1 parent 8ff4d41 commit caf3cc1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/libcore/intrinsics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,11 @@ extern "rust-intrinsic" {
13481348
/// See documentation of `<*const T>::offset_from` for details.
13491349
#[cfg(not(bootstrap))]
13501350
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1351+
1352+
/// Internal hook used by Miri to implement unwinding.
1353+
/// Perma-unstable: do not use
1354+
#[cfg(not(bootstrap))]
1355+
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + Send)) -> !;
13511356
}
13521357

13531358
// Some functions are defined here because they accidentally got made

src/libpanic_unwind/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ use core::raw;
3636
use core::panic::BoxMeUp;
3737

3838
cfg_if::cfg_if! {
39-
if #[cfg(target_os = "emscripten")] {
39+
if #[cfg(miri)] {
40+
#[path = "miri.rs"]
41+
mod imp;
42+
} else if #[cfg(target_os = "emscripten")] {
4043
#[path = "emcc.rs"]
4144
mod imp;
4245
} else if #[cfg(target_arch = "wasm32")] {

src/libpanic_unwind/miri.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub fn payload() -> *mut u8 {
2+
core::ptr::null_mut()
3+
}
4+
5+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
6+
core::intrinsics::miri_start_panic(Box::into_raw(data))
7+
}
8+
9+
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
10+
Box::from_raw(ptr)
11+
}
12+

0 commit comments

Comments
 (0)