Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Funnel all aborts through rtabort! cc #31519 #32832

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 4 additions & 7 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use io::prelude::*;
use any::Any;
use cell::Cell;
use cell::RefCell;
use intrinsics;
use sync::StaticRwLock;
use sync::atomic::{AtomicBool, Ordering};
use sys::stdio::Stderr;
Expand Down Expand Up @@ -208,9 +207,8 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: u32) {
// abort immediately to avoid infinite recursion, so that attaching a
// debugger provides a useable stacktrace.
if panics >= 3 {
util::dumb_print(format_args!("thread panicked while processing \
panic. aborting.\n"));
unsafe { intrinsics::abort() }
rtabort!("thread panicked while processing \
panic. aborting.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that these messages will now be prefixed with fatal runtime error: rather than being printed directly as-is. In the past I think we tried to avoid printing the "fatal runtime error" aspect?

}

let info = PanicInfo {
Expand All @@ -234,8 +232,7 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: u32) {
// have limited options. Currently our preference is to
// just abort. In the future we may consider resuming
// unwinding or otherwise exiting the thread cleanly.
util::dumb_print(format_args!("thread panicked while panicking. \
aborting.\n"));
unsafe { intrinsics::abort() }
rtabort!("thread panicked while panicking. \
aborting.");
}
}
2 changes: 1 addition & 1 deletion src/libstd/sys/common/unwind/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ mod imp {
#[lang = "eh_personality"]
#[cfg(not(test))]
fn rust_eh_personality() {
unsafe { ::intrinsics::abort() }
rtabort!()
}
3 changes: 1 addition & 2 deletions src/libstd/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ pub fn init() {
// errors are ignored while printing since there's nothing we can do about
// them and we are about to exit anyways.
fn oom_handler() -> ! {
use intrinsics;
let msg = "fatal runtime error: out of memory\n";
unsafe {
libc::write(libc::STDERR_FILENO,
msg.as_ptr() as *const libc::c_void,
msg.len() as libc::size_t);
intrinsics::abort();
rtabort!();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was somewhat intentionally done because as part of the OOM handler we want to be sure that no allocations happen here. Right now dumb_print (called by rtabort!) uses Stderr::new() which does a bunch of allocations on Windows (for random unicode tidbits), which may not be appropriate to call in an OOM situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

er, well this is more relevant for the code below, but you get the point

}
}

Expand Down
3 changes: 1 addition & 2 deletions src/libstd/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub fn init() {

// See comment in sys/unix/mod.rs
fn oom_handler() -> ! {
use intrinsics;
use ptr;
let msg = "fatal runtime error: out of memory\n";
unsafe {
Expand All @@ -59,7 +58,7 @@ pub fn init() {
msg.len() as c::DWORD,
ptr::null_mut(),
ptr::null_mut());
intrinsics::abort();
rtabort!();
}
}
}
Expand Down