Skip to content

Commit 696a570

Browse files
Brian Andersonlambda
Brian Anderson
authored andcommittedMay 24, 2016
Open code the __fastfail intrinsic for rtabort! on windows
As described https://msdn.microsoft.com/en-us/library/dn774154.aspx This is a Windows 8+ mechanism for terminating the process quickly, which degrades to either an access violation or bugcheck in older versions. I'm not sure this is better the the current mechanism of terminating with an illegal instruction, but we recently converted unix to terminate more correctly with SIGABORT, and this *seems* more correct for windows. [breaking-change]
1 parent cfc3865 commit 696a570

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed
 

‎src/libstd/sys/common/util.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,28 @@ pub fn dumb_print(args: fmt::Arguments) {
4242
// implemented as an illegal instruction.
4343
#[cfg(unix)]
4444
unsafe fn abort_internal() -> ! {
45-
use libc;
46-
libc::abort()
45+
::libc::abort()
4746
}
4847

49-
// On Windows, we want to avoid using libc, and there isn't a direct
50-
// equivalent of libc::abort. The __failfast intrinsic may be a reasonable
51-
// substitute, but desireability of using it over the abort instrinsic is
52-
// debateable; see https://github.com/rust-lang/rust/pull/31519 for details.
53-
#[cfg(not(unix))]
48+
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
49+
// and later, this will terminate the process immediately without running any
50+
// in-process exception handlers. In earlier versions of Windows, this
51+
// sequence of instructions will be treated as an access violation,
52+
// terminating the process but without necessarily bypassing all exception
53+
// handlers.
54+
//
55+
// https://msdn.microsoft.com/en-us/library/dn774154.aspx
56+
#[cfg(all(windows, any(target_arch = "x86", target_arch = "x86_64")))]
5457
unsafe fn abort_internal() -> ! {
55-
use intrinsics;
56-
intrinsics::abort()
58+
asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
59+
::intrinsics::unreachable();
5760
}
5861

62+
// Other platforms should use the appropriate platform-specific mechanism for
63+
// aborting the process. If no platform-specific mechanism is available,
64+
// ::intrinsics::abort() may be used instead. The above implementations cover
65+
// all targets currently supported by libstd.
66+
5967
pub fn abort(args: fmt::Arguments) -> ! {
6068
dumb_print(format_args!("fatal runtime error: {}\n", args));
6169
unsafe { abort_internal(); }

0 commit comments

Comments
 (0)