Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion library/std/src/sys/pal/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ mod imp {

let mut guard_page_range = unsafe { install_main_guard() };

// Even for panic=immediate-abort, installing the guard pages is important for soundness.
// That said, we do not care about giving nice stackoverflow messages via our custom
// signal handler, just exit early and let the user enjoy the segfault.
if cfg!(panic = "immediate-abort") {
return;
}

// SAFETY: assuming all platforms define struct sigaction as "zero-initializable"
let mut action: sigaction = unsafe { mem::zeroed() };
for &signal in &[SIGSEGV, SIGBUS] {
Expand Down Expand Up @@ -179,6 +186,9 @@ mod imp {
/// Must be called only once
#[forbid(unsafe_op_in_unsafe_fn)]
pub unsafe fn cleanup() {
if cfg!(panic = "immediate-abort") {
return;
}
// FIXME: I probably cause more bugs than I'm worth!
// see https://github.com/rust-lang/rust/issues/111272
unsafe { drop_handler(MAIN_ALTSTACK.load(Ordering::Relaxed)) };
Expand Down Expand Up @@ -230,7 +240,7 @@ mod imp {
/// Mutates the alternate signal stack
#[forbid(unsafe_op_in_unsafe_fn)]
pub unsafe fn make_handler(main_thread: bool, thread_name: Option<Box<str>>) -> Handler {
if !NEED_ALTSTACK.load(Ordering::Acquire) {
if cfg!(panic = "immediate-abort") || !NEED_ALTSTACK.load(Ordering::Acquire) {
return Handler::null();
}

Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/pal/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub mod os;
pub mod pipe;
pub mod time;
cfg_select! {
not(target_vendor = "uwp") => {
// We don't care about printing nice error messages for panic=immediate-abort
all(not(target_vendor = "uwp"), not(panic = "immediate-abort")) => {
pub mod stack_overflow;
}
_ => {
Expand Down
Loading