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(html_root_url = "https://doc.rust-lang.org/nightly/",
17 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
19 #![feature(core_intrinsics)]
20 #![feature(lang_items)]
23 #![feature(panic_unwind)]
25 #![feature(staged_api)]
26 #![feature(std_internals)]
27 #![feature(unwind_attributes)]
30 #![feature(panic_runtime)]
32 use alloc::boxed::Box;
36 use core::panic::BoxMeUp;
39 if #[cfg(target_os = "emscripten")] {
42 } else if #[cfg(target_arch = "wasm32")] {
45 } else if #[cfg(target_os = "hermit")] {
48 } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
51 } else if #[cfg(target_env = "msvc")] {
55 // Rust runtime's startup objects depend on these symbols, so make them public.
56 #[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
57 pub use imp::eh_frame_registry::*;
65 // Entry point for catching an exception, implemented using the `try` intrinsic
68 // The interaction between the `payload` function and the compiler is pretty
69 // hairy and tightly coupled, for more information see the compiler's
70 // implementation of this.
72 pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
75 vtable_ptr: *mut usize)
77 let mut payload = imp::payload();
78 if intrinsics::r#try(f, data, &mut payload as *mut _ as *mut _) == 0 {
81 let obj = mem::transmute::<_, raw::TraitObject>(imp::cleanup(payload));
82 *data_ptr = obj.data as usize;
83 *vtable_ptr = obj.vtable as usize;
88 // Entry point for raising an exception, just delegates to the platform-specific
92 pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
93 let payload = payload as *mut &mut dyn BoxMeUp;
94 imp::panic(Box::from_raw((*payload).box_me_up()))