Skip to content

Commit be07ab2

Browse files
committed
Open code the __failfast 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 de250e5 commit be07ab2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/libstd/sys/common/util.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,24 @@ pub fn abort(args: fmt::Arguments) -> ! {
4040
unsafe { libc::abort(); }
4141
}
4242

43-
#[cfg(not(unix))]
43+
// On windows, use the processor-specific __fastfail mechanism
44+
// https://msdn.microsoft.com/en-us/library/dn774154.aspx
45+
#[cfg(all(windows, target_arch = "x86"))]
4446
pub fn abort(args: fmt::Arguments) -> ! {
45-
use intrinsics;
4647
dumb_print(format_args!("fatal runtime error: {}\n", args));
47-
unsafe { intrinsics::abort(); }
48+
unsafe {
49+
asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
50+
::intrinsics::unreachable();
51+
}
52+
}
53+
54+
#[cfg(all(windows, target_arch = "x86_64"))]
55+
pub fn abort(args: fmt::Arguments) -> ! {
56+
dumb_print(format_args!("fatal runtime error: {}\n", args));
57+
unsafe {
58+
asm!("int $$0x29" :: "{rcx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
59+
::intrinsics::unreachable();
60+
}
4861
}
4962

5063
#[allow(dead_code)] // stack overflow detection not enabled on all platforms

0 commit comments

Comments
 (0)