Skip to content

Commit

Permalink
Use libc::abort, not intrinsics::abort, in rtabort!
Browse files Browse the repository at this point in the history
intrinsics::abort compiles down to an illegal instruction, which on
Unix-like platforms causes the process to be killed with SIGILL.  A more
appropriate way to kill the process would be SIGABRT; this indicates
better that the runtime has explicitly aborted, rather than some kind of
compiler bug or architecture mismatch that SIGILL might indicate.

For rtassert!, replace this with libc::abort.  libc::abort raises
SIGABRT, but is defined to do so in such a way that it will terminate
the process even if SIGABRT is currently masked or caught by a signal
handler that returns.

On non-Unix platforms, retain the existing behavior.  On Windows we
prefer to avoid depending on the C runtime, and we need a fallback for
any other platforms that may be defined.  An alternative on Windows
would be to call TerminateProcess, but this seems less essential than
switching to using SIGABRT on Unix-like platforms, where it is common
for the process-killing signal to be printed out or logged.

This is a [breaking-change] for any code that depends on the exact
signal raised to abort a process via rtabort!

cc rust-lang#31273
cc rust-lang#31333
  • Loading branch information
lambda committed Feb 6, 2016
1 parent be2ffdd commit de250e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/libstd/sys/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use env;
use fmt;
use intrinsics;
use io::prelude::*;
use sync::atomic::{self, Ordering};
use sys::stdio::Stderr;
Expand All @@ -34,7 +33,16 @@ pub fn dumb_print(args: fmt::Arguments) {
let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
}

#[cfg(unix)]
pub fn abort(args: fmt::Arguments) -> ! {
use libc;
dumb_print(format_args!("fatal runtime error: {}\n", args));
unsafe { libc::abort(); }
}

#[cfg(not(unix))]
pub fn abort(args: fmt::Arguments) -> ! {
use intrinsics;
dumb_print(format_args!("fatal runtime error: {}\n", args));
unsafe { intrinsics::abort(); }
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/run-pass/out-of-stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ fn check_status(status: std::process::ExitStatus)
use std::os::unix::process::ExitStatusExt;

assert!(!status.success());
assert!(status.signal() != Some(libc::SIGSEGV)
&& status.signal() != Some(libc::SIGBUS));
assert_eq!(status.signal(), Some(libc::SIGABRT));
}

#[cfg(not(unix))]
Expand Down

0 comments on commit de250e5

Please sign in to comment.