From 3a311edc97b9c93b3384ce8ff8ef47306e22ca41 Mon Sep 17 00:00:00 2001 From: Crystal Durham Date: Mon, 30 Mar 2026 18:55:59 -0400 Subject: [PATCH 1/2] add abort_immediate --- library/core/src/intrinsics/mod.rs | 2 ++ library/core/src/lib.rs | 2 ++ library/core/src/process.rs | 38 ++++++++++++++++++++++++++++++ library/std/src/process.rs | 4 ++++ 4 files changed, 46 insertions(+) create mode 100644 library/core/src/process.rs diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 6f9d35130016..94d0c7eab922 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -364,6 +364,8 @@ pub const fn prefetch_write_instruction(data: *const T) /// On Unix, the /// process will probably terminate with a signal like `SIGABRT`, `SIGILL`, `SIGTRAP`, `SIGSEGV` or /// `SIGBUS`. The precise behavior is not guaranteed and not stable. +/// +/// The stabilization-track version of this intrinsic is [`core::process::abort_immediate`]. #[rustc_nounwind] #[rustc_intrinsic] pub fn abort() -> !; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 35f93d8fb33b..73ca7c599cad 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -305,6 +305,8 @@ pub mod autodiff { #[unstable(feature = "pattern_type_macro", issue = "123646")] pub mod pat; pub mod pin; +#[unstable(feature = "abort_immediate", issue = "154601")] +pub mod process; #[unstable(feature = "random", issue = "130703")] pub mod random; #[stable(feature = "new_range_inclusive_api", since = "1.95.0")] diff --git a/library/core/src/process.rs b/library/core/src/process.rs new file mode 100644 index 000000000000..4b94d7101520 --- /dev/null +++ b/library/core/src/process.rs @@ -0,0 +1,38 @@ +/// Terminates the process in a violent fashion. +/// +/// The function will never return and will immediately terminate the current +/// process in a platform specific "abnormal" manner. As a consequence, +/// no destructors on the current stack or any other thread's stack +/// will be run, Rust IO buffers (eg, from `BufWriter`) will not be flushed, +/// and C stdio buffers will not be flushed. +/// +/// Unlike [`abort`](../../std/process/fn.abort.html), `abort_immediate` does +/// not attempt to match C `abort()` or otherwise perform a "clean" abort. +/// Instead, it emits code that will crash the process with as little overhead +/// as possible, such as a "halt and catch fire" style instruction. You should +/// generally prefer using `abort` instead except where the absolute minimum +/// overhead is required. +/// +/// # Platform-specific behavior +/// +/// `abort_immediate` lowers to a trap instruction on *most* architectures; on +/// some architectures it simply lowers to call the unmangled `abort` function. +/// The exact behavior is architecture and system dependent. +/// +/// On bare-metal (no OS) systems the trap instruction usually causes a +/// *hardware* exception to be raised in a *synchronous* fashion; hardware +/// exceptions have nothing to do with C++ exceptions and are closer in +/// semantics to POSIX signals. +/// +/// On hosted applications (applications running under an OS), the trap +/// instruction *usually* terminates the whole process with an exit code that +/// corresponds to `SIGILL` or equivalent, *unless* this signal is handled. +/// Other signals such as `SIGABRT`, `SIGTRAP`, `SIGSEGV`, and `SIGBUS` may be +/// produced instead, depending on specifics. This is not an exhaustive list. +#[unstable(feature = "abort_immediate", issue = "154601")] +#[cold] +#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces +#[doc(alias = "halt")] +pub fn abort_immediate() -> ! { + crate::intrinsics::abort() +} diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 321b68b3225a..ebb07632d963 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2536,6 +2536,10 @@ pub fn abort() -> ! { crate::sys::abort_internal(); } +#[doc(inline)] +#[unstable(feature = "abort_immediate", issue = "154601")] +pub use core::process::abort_immediate; + /// Returns the OS-assigned process identifier associated with this process. /// /// # Examples From fb99fbec8486638f909700e2b0381186ffe1c384 Mon Sep 17 00:00:00 2001 From: Crystal Durham Date: Mon, 30 Mar 2026 19:05:26 -0400 Subject: [PATCH 2/2] add missing core::process module docs --- library/core/src/process.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/process.rs b/library/core/src/process.rs index 4b94d7101520..81481b2cba26 100644 --- a/library/core/src/process.rs +++ b/library/core/src/process.rs @@ -1,3 +1,8 @@ +//! A module for working with processes. +//! +//! Most process-related functionality requires std, but [`abort_immediate`] +//! is available on all targets. + /// Terminates the process in a violent fashion. /// /// The function will never return and will immediately terminate the current