panic_abort/
lib.rs

1//! Set the panicking behavior to abort
2//!
3//! This crate contains an implementation of `panic_fmt` that simply calls [`intrinsics::abort`].
4//!
5//! [`intrinsics::abort`]: https://doc.rust-lang.org/core/intrinsics/fn.abort.html
6//!
7//! # Behavior
8//!
9//! As of Rust 1.38.0, `intrinsics::abort` lowers to a trap instruction on *most* architectures; on
10//! some architectures it simply lowers to call to the `abort` function (unmangled name). The exact
11//! behavior of `intrinsics::abort` is architecture and system dependent.
12//!
13//! On bare-metal (no OS) systems the trap instruction usually causes a *hardware* exception to be
14//! raised in a *synchronous* fashion -- hardware exceptions have nothing to do with C++ exceptions
15//! and are closer in semantics to POSIX signals (see `man 7 signals` on UNIX-y systems).
16//!
17//! On hosted applications (applications running under an OS), the trap instruction *usually*
18//! terminates the whole process with an exit code that corresponds to SIGILL *unless* a signal
19//! handler that handles this particular signal was registered (again, see `man 7 signals` on UNIX-y
20//! systems).
21//!
22//! *HEADS UP* Because `intrinsics::abort` is an unstable API its semantics could change in any new
23//! Rust release (minor or patch release).
24//!
25//! # Usage
26//!
27//! ``` ignore
28//! #![no_std]
29//!
30//! extern crate panic_abort;
31//!
32//! fn main() {
33//!     panic!("argument is ignored");
34//! }
35//! ```
36
37#![allow(stable_features)]
38#![deny(missing_docs)]
39#![deny(warnings)]
40#![feature(core_intrinsics)]
41#![feature(panic_handler)]
42#![no_std]
43
44use core::intrinsics;
45use core::panic::PanicInfo;
46
47#[panic_handler]
48fn panic(_info: &PanicInfo) -> ! {
49    unsafe { intrinsics::abort() }
50}