1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Implementation of panics via stack unwinding
13 //! This crate is an implementation of panics in Rust using "most native" stack
14 //! unwinding mechanism of the platform this is being compiled for. This
15 //! essentially gets categorized into three buckets currently:
17 //! 1. MSVC targets use SEH in the `seh.rs` file.
18 //! 2. The 64-bit MinGW target half-uses SEH and half-use gcc-like information
19 //! in the `seh64_gnu.rs` module.
20 //! 3. All other targets use libunwind/libgcc in the `gcc/mod.rs` module.
22 //! More documentation about each implementation can be found in the respective
26 #![unstable(feature = "panic_unwind", issue = "32837")]
27 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
28 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
29 html_root_url = "https://doc.rust-lang.org/nightly/",
30 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
34 #![feature(core_intrinsics)]
35 #![feature(lang_items)]
37 #![cfg_attr(not(any(target_env = "msvc",
38 all(windows, target_arch = "x86_64", target_env = "gnu"))),
39 feature(panic_unwind))]
41 #![feature(staged_api)]
42 #![feature(unwind_attributes)]
43 #![cfg_attr(target_env = "msvc", feature(raw))]
46 #![feature(panic_runtime)]
50 #[cfg(not(any(target_env = "msvc", all(windows, target_arch = "x86_64", target_env = "gnu"))))]
57 // Rust runtime's startup objects depend on these symbols, so make them public.
58 #[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
59 pub use imp::eh_frame_registry::*;
62 #[cfg(target_env = "msvc")]
66 // x86_64-pc-windows-gnu
67 #[cfg(all(windows, target_arch = "x86_64", target_env = "gnu"))]
68 #[path = "seh64_gnu.rs"]
71 // i686-pc-windows-gnu and all others
72 #[cfg(any(all(unix, not(target_os = "emscripten")),
74 all(windows, target_arch = "x86", target_env = "gnu")))]
79 #[cfg(target_os = "emscripten")]
86 // Entry point for catching an exception, implemented using the `try` intrinsic
89 // The interaction between the `payload` function and the compiler is pretty
90 // hairy and tightly coupled, for more information see the compiler's
91 // implementation of this.
93 pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
96 vtable_ptr: *mut usize)
98 let mut payload = imp::payload();
99 if intrinsics::try(f, data, &mut payload as *mut _ as *mut _) == 0 {
102 let obj = mem::transmute::<_, raw::TraitObject>(imp::cleanup(payload));
103 *data_ptr = obj.data as usize;
104 *vtable_ptr = obj.vtable as usize;
109 // Entry point for raising an exception, just delegates to the platform-specific
113 pub unsafe extern "C" fn __rust_start_panic(data: usize, vtable: usize) -> u32 {
114 imp::panic(mem::transmute(raw::TraitObject {
115 data: data as *mut (),
116 vtable: vtable as *mut (),