Skip to content
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
25 changes: 23 additions & 2 deletions 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,9 +33,31 @@ 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 { intrinsics::abort(); }
unsafe { libc::abort(); }
}

// On windows, use the processor-specific __fastfail mechanism
// https://msdn.microsoft.com/en-us/library/dn774154.aspx
#[cfg(all(windows, target_arch = "x86"))]
pub fn abort(args: fmt::Arguments) -> ! {
dumb_print(format_args!("fatal runtime error: {}\n", args));
unsafe {
asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
::intrinsics::unreachable();
}
}

#[cfg(all(windows, target_arch = "x86_64"))]
pub fn abort(args: fmt::Arguments) -> ! {
dumb_print(format_args!("fatal runtime error: {}\n", args));
unsafe {
asm!("int $$0x29" :: "{rcx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
::intrinsics::unreachable();
}
}

#[allow(dead_code)] // stack overflow detection not enabled on all platforms
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