]> git.lizzy.rs Git - rust.git/blob - src/libpanic_unwind/lib.rs
libpanic_unwind => 2018: remove unused extern crate.
[rust.git] / src / libpanic_unwind / lib.rs
1 //! Implementation of panics via stack unwinding
2 //!
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:
6 //!
7 //! 1. MSVC targets use SEH in the `seh.rs` file.
8 //! 2. The 64-bit MinGW target half-uses SEH and half-use gcc-like information
9 //!    in the `seh64_gnu.rs` module.
10 //! 3. All other targets use libunwind/libgcc in the `gcc/mod.rs` module.
11 //!
12 //! More documentation about each implementation can be found in the respective
13 //! module.
14
15 #![no_std]
16 #![unstable(feature = "panic_unwind", issue = "32837")]
17 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
18        issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
19
20 #![deny(rust_2018_idioms)]
21
22 #![feature(allocator_api)]
23 #![feature(alloc)]
24 #![feature(core_intrinsics)]
25 #![feature(lang_items)]
26 #![feature(libc)]
27 #![feature(nll)]
28 #![feature(panic_unwind)]
29 #![feature(raw)]
30 #![feature(staged_api)]
31 #![feature(std_internals)]
32 #![feature(unwind_attributes)]
33
34 #![panic_runtime]
35 #![feature(panic_runtime)]
36
37 use alloc::boxed::Box;
38 use core::intrinsics;
39 use core::mem;
40 use core::raw;
41 use core::panic::BoxMeUp;
42
43 #[macro_use]
44 mod macros;
45
46 cfg_if! {
47     if #[cfg(target_os = "emscripten")] {
48         #[path = "emcc.rs"]
49         mod imp;
50     } else if #[cfg(target_arch = "wasm32")] {
51         #[path = "dummy.rs"]
52         mod imp;
53     } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
54         #[path = "dummy.rs"]
55         mod imp;
56     } else if #[cfg(target_env = "msvc")] {
57         #[path = "seh.rs"]
58         mod imp;
59     } else if #[cfg(all(windows, target_arch = "x86_64", target_env = "gnu"))] {
60         #[path = "seh64_gnu.rs"]
61         mod imp;
62     } else {
63         // Rust runtime's startup objects depend on these symbols, so make them public.
64         #[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
65         pub use imp::eh_frame_registry::*;
66         #[path = "gcc.rs"]
67         mod imp;
68     }
69 }
70
71 mod dwarf;
72 mod windows;
73
74 // Entry point for catching an exception, implemented using the `try` intrinsic
75 // in the compiler.
76 //
77 // The interaction between the `payload` function and the compiler is pretty
78 // hairy and tightly coupled, for more information see the compiler's
79 // implementation of this.
80 #[no_mangle]
81 pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
82                                                   data: *mut u8,
83                                                   data_ptr: *mut usize,
84                                                   vtable_ptr: *mut usize)
85                                                   -> u32 {
86     let mut payload = imp::payload();
87     if intrinsics::r#try(f, data, &mut payload as *mut _ as *mut _) == 0 {
88         0
89     } else {
90         let obj = mem::transmute::<_, raw::TraitObject>(imp::cleanup(payload));
91         *data_ptr = obj.data as usize;
92         *vtable_ptr = obj.vtable as usize;
93         1
94     }
95 }
96
97 // Entry point for raising an exception, just delegates to the platform-specific
98 // implementation.
99 #[no_mangle]
100 #[unwind(allowed)]
101 pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
102     let payload = payload as *mut &mut dyn BoxMeUp;
103     imp::panic(Box::from_raw((*payload).box_me_up()))
104 }