Skip to main content

core/
process.rs

1//! A module for working with processes.
2//!
3//! Most process-related functionality requires std, but [`abort_immediate`]
4//! is available on all targets.
5
6/// Terminates the process in a violent fashion.
7///
8/// The function will never return and will immediately terminate the current
9/// process in a platform specific "abnormal" manner. As a consequence,
10/// no destructors on the current stack or any other thread's stack
11/// will be run, Rust IO buffers (eg, from `BufWriter`) will not be flushed,
12/// and C stdio buffers will not be flushed.
13///
14/// Unlike [`abort`](../../std/process/fn.abort.html), `abort_immediate` does
15/// not attempt to match C `abort()` or otherwise perform a "clean" abort.
16/// Instead, it emits code that will crash the process with as little overhead
17/// as possible, such as a "halt and catch fire" style instruction. You should
18/// generally prefer using `abort` instead except where the absolute minimum
19/// overhead is required.
20///
21/// # Platform-specific behavior
22///
23/// `abort_immediate` lowers to a trap instruction on *most* architectures; on
24/// some architectures it simply lowers to call the unmangled `abort` function.
25/// The exact behavior is architecture and system dependent.
26///
27/// On bare-metal (no OS) systems the trap instruction usually causes a
28/// *hardware* exception to be raised in a *synchronous* fashion; hardware
29/// exceptions have nothing to do with C++ exceptions and are closer in
30/// semantics to POSIX signals.
31///
32/// On hosted applications (applications running under an OS), the trap
33/// instruction *usually* terminates the whole process with an exit code that
34/// corresponds to `SIGILL` or equivalent, *unless* this signal is handled.
35/// Other signals such as `SIGABRT`, `SIGTRAP`, `SIGSEGV`, and `SIGBUS` may be
36/// produced instead, depending on specifics. This is not an exhaustive list.
37#[unstable(feature = "abort_immediate", issue = "154601")]
38#[cold]
39#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
40#[doc(alias = "halt")]
41pub fn abort_immediate() -> ! {
42    crate::intrinsics::abort()
43}