about summary refs log tree commit diff
path: root/src/libstd/sys/common
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-06-01 10:21:55 -0700
committerbors <bors@rust-lang.org>2016-06-01 10:21:55 -0700
commit12d16599d84c25899f02a6e53110d1e70cdcbd8a (patch)
treee80bd1fa32678c202966526688236550e9bc10b4 /src/libstd/sys/common
parentc2cab1fd58d6373582da189bd2c20ed3f6a7042a (diff)
parent696a570a00db2528b7934be32da7d8334738a997 (diff)
downloadrust-12d16599d84c25899f02a6e53110d1e70cdcbd8a.tar.gz
rust-12d16599d84c25899f02a6e53110d1e70cdcbd8a.zip
Auto merge of #33814 - lambda:rtabort-use-platform-abort, r=alexcrichton
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]
Diffstat (limited to 'src/libstd/sys/common')
-rw-r--r--src/libstd/sys/common/util.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/libstd/sys/common/util.rs b/src/libstd/sys/common/util.rs
index 1df511a8818..b5d03576338 100644
--- a/src/libstd/sys/common/util.rs
+++ b/src/libstd/sys/common/util.rs
@@ -42,20 +42,28 @@ pub fn dumb_print(args: fmt::Arguments) {
 // implemented as an illegal instruction.
 #[cfg(unix)]
 unsafe fn abort_internal() -> ! {
-    use libc;
-    libc::abort()
+    ::libc::abort()
 }
 
-// On Windows, we want to avoid using libc, and there isn't a direct
-// equivalent of libc::abort.  The __failfast intrinsic may be a reasonable
-// substitute, but desireability of using it over the abort instrinsic is
-// debateable; see https://github.com/rust-lang/rust/pull/31519 for details.
-#[cfg(not(unix))]
+// On Windows, use the processor-specific __fastfail mechanism.  In Windows 8
+// and later, this will terminate the process immediately without running any
+// in-process exception handlers.  In earlier versions of Windows, this
+// sequence of instructions will be treated as an access violation,
+// terminating the process but without necessarily bypassing all exception
+// handlers.
+//
+// https://msdn.microsoft.com/en-us/library/dn774154.aspx
+#[cfg(all(windows, any(target_arch = "x86", target_arch = "x86_64")))]
 unsafe fn abort_internal() -> ! {
-    use intrinsics;
-    intrinsics::abort()
+    asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
+    ::intrinsics::unreachable();
 }
 
+// Other platforms should use the appropriate platform-specific mechanism for
+// aborting the process.  If no platform-specific mechanism is available,
+// ::intrinsics::abort() may be used instead.  The above implementations cover
+// all targets currently supported by libstd.
+
 pub fn abort(args: fmt::Arguments) -> ! {
     dumb_print(format_args!("fatal runtime error: {}\n", args));
     unsafe { abort_internal(); }