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)]
33 // `real_imp` is unused with Miri, so silence warnings.
34 #![cfg_attr(miri, allow(dead_code))]
36 use alloc::boxed::Box;
38 use core::panic::BoxMeUp;
41 if #[cfg(target_os = "emscripten")] {
44 } else if #[cfg(target_os = "hermit")] {
47 } else if #[cfg(target_env = "msvc")] {
51 all(target_family = "windows", target_env = "gnu"),
52 target_os = "cloudabi",
53 target_family = "unix",
54 all(target_vendor = "fortanix", target_env = "sgx"),
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 real_imp::eh_frame_registry::*;
62 // Targets that don't support unwinding.
64 // - os=none ("bare metal" targets)
66 // - nvptx64-nvidia-cuda
67 // - avr-unknown-unknown
76 // Use the Miri runtime.
77 // We still need to also load the normal runtime above, as rustc expects certain lang
78 // items from there to be defined.
82 // Use the real runtime.
88 /// Handler in libstd called when a panic object is dropped outside of
90 fn __rust_drop_panic() -> !;
95 #[rustc_std_internal_symbol]
96 #[allow(improper_ctypes_definitions)]
97 pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) {
98 Box::into_raw(imp::cleanup(payload))
101 // Entry point for raising an exception, just delegates to the platform-specific
103 #[rustc_std_internal_symbol]
105 pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
106 let payload = payload as *mut &mut dyn BoxMeUp;
107 let payload = (*payload).take_box();
109 imp::panic(Box::from_raw(payload))