1 //! Implementation of panics via stack unwinding
3 //! This crate is an implementation of panics in Rust using "most native" stack
4 //! unwinding mechanism of the platform this is being compiled for. This
5 //! essentially gets categorized into three buckets currently:
7 //! 1. MSVC targets use SEH in the `seh.rs` file.
8 //! 2. Emscripten uses C++ exceptions in the `emcc.rs` file.
9 //! 3. All other targets use libunwind/libgcc in the `gcc.rs` file.
11 //! More documentation about each implementation can be found in the respective
15 #![unstable(feature = "panic_unwind", issue = "32837")]
16 #![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
17 #![feature(core_intrinsics)]
18 #![feature(lang_items)]
19 #![feature(panic_unwind)]
20 #![feature(staged_api)]
21 #![feature(std_internals)]
22 #![feature(abi_thiscall)]
23 #![feature(rustc_attrs)]
25 #![feature(panic_runtime)]
27 // `real_imp` is unused with Miri, so silence warnings.
28 #![cfg_attr(miri, allow(dead_code))]
30 use alloc::boxed::Box;
32 use core::panic::BoxMeUp;
35 if #[cfg(target_os = "emscripten")] {
38 } else if #[cfg(target_os = "hermit")] {
41 } else if #[cfg(target_os = "l4re")] {
42 // L4Re is unix family but does not yet support unwinding.
45 } else if #[cfg(all(target_env = "msvc", not(target_arch = "arm")))] {
46 // LLVM does not support unwinding on 32 bit ARM msvc (thumbv7a-pc-windows-msvc)
50 all(target_family = "windows", target_env = "gnu"),
52 target_os = "solid_asp3",
53 all(target_family = "unix", not(target_os = "espidf")),
54 all(target_vendor = "fortanix", target_env = "sgx"),
59 // Targets that don't support unwinding.
61 // - os=none ("bare metal" targets)
64 // - nvptx64-nvidia-cuda
73 // Use the Miri runtime.
74 // We still need to also load the normal runtime above, as rustc expects certain lang
75 // items from there to be defined.
79 // Use the real runtime.
85 /// Handler in libstd called when a panic object is dropped outside of
87 fn __rust_drop_panic() -> !;
89 /// Handler in libstd called when a foreign exception is caught.
90 fn __rust_foreign_exception() -> !;
93 #[rustc_std_internal_symbol]
94 #[allow(improper_ctypes_definitions)]
95 pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) {
96 Box::into_raw(imp::cleanup(payload))
99 // Entry point for raising an exception, just delegates to the platform-specific
101 #[rustc_std_internal_symbol]
102 pub unsafe fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 {
103 let payload = Box::from_raw((*payload).take_box());