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")]
17 html_root_url = "https://doc.rust-lang.org/nightly/",
18 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/"
20 #![feature(core_intrinsics)]
21 #![feature(lang_items)]
24 #![feature(panic_unwind)]
25 #![feature(staged_api)]
26 #![feature(std_internals)]
27 #![feature(unwind_attributes)]
28 #![feature(abi_thiscall)]
29 #![feature(rustc_attrs)]
32 #![feature(panic_runtime)]
34 use alloc::boxed::Box;
35 use core::panic::BoxMeUp;
37 // If adding to this list, you should also look at libstd::panicking's identical
38 // list of Payload types and likely add to there as well.
40 if #[cfg(target_os = "emscripten")] {
43 } else if #[cfg(target_arch = "wasm32")] {
46 } else if #[cfg(target_os = "hermit")] {
49 } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
52 } else if #[cfg(target_env = "msvc")] {
56 // Rust runtime's startup objects depend on these symbols, so make them public.
57 #[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
58 pub use imp::eh_frame_registry::*;
65 /// Handler in libstd called when a panic object is dropped outside of
67 fn __rust_drop_panic() -> !;
73 pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> core::raw::TraitObject {
74 let payload = payload as *mut imp::Payload;
75 let payload = *(payload);
76 core::mem::transmute(imp::cleanup(payload))
79 // Entry point for raising an exception, just delegates to the platform-specific
83 pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
84 let payload = payload as *mut &mut dyn BoxMeUp;
85 let payload = (*payload).take_box();
87 // Miri panic support: cfg'd out of normal builds just to be sure.
88 // When going through normal codegen, `miri_start_panic` is a NOP, so the
89 // Miri-enabled sysroot still supports normal unwinding. But when executed in
90 // Miri, this line initiates unwinding.
92 core::intrinsics::miri_start_panic(payload);
94 imp::panic(Box::from_raw(payload))