Skip to content

Commit f3a709d

Browse files
committed
std: Move platform-specific out of sys_common::util
1 parent 219c018 commit f3a709d

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

src/libstd/sys/common/util.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,14 @@ pub fn dumb_print(args: fmt::Arguments) {
3333
let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
3434
}
3535

36-
// On Unix-like platforms, libc::abort will unregister signal handlers
37-
// including the SIGABRT handler, preventing the abort from being blocked, and
38-
// fclose streams, with the side effect of flushing them so libc bufferred
39-
// output will be printed. Additionally the shell will generally print a more
40-
// understandable error message like "Abort trap" rather than "Illegal
41-
// instruction" that intrinsics::abort would cause, as intrinsics::abort is
42-
// implemented as an illegal instruction.
43-
#[cfg(unix)]
44-
unsafe fn abort_internal() -> ! {
45-
::libc::abort()
46-
}
47-
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")))]
57-
unsafe fn abort_internal() -> ! {
58-
asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
59-
::intrinsics::unreachable();
60-
}
61-
6236
// Other platforms should use the appropriate platform-specific mechanism for
6337
// aborting the process. If no platform-specific mechanism is available,
6438
// ::intrinsics::abort() may be used instead. The above implementations cover
6539
// all targets currently supported by libstd.
6640

6741
pub fn abort(args: fmt::Arguments) -> ! {
6842
dumb_print(format_args!("fatal runtime error: {}\n", args));
69-
unsafe { abort_internal(); }
43+
unsafe { ::sys::abort_internal(); }
7044
}
7145

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

src/libstd/sys/unix/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,14 @@ pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
163163
}
164164
}
165165
}
166+
167+
// On Unix-like platforms, libc::abort will unregister signal handlers
168+
// including the SIGABRT handler, preventing the abort from being blocked, and
169+
// fclose streams, with the side effect of flushing them so libc bufferred
170+
// output will be printed. Additionally the shell will generally print a more
171+
// understandable error message like "Abort trap" rather than "Illegal
172+
// instruction" that intrinsics::abort would cause, as intrinsics::abort is
173+
// implemented as an illegal instruction.
174+
pub unsafe fn abort_internal() -> ! {
175+
::libc::abort()
176+
}

src/libstd/sys/windows/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,17 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD {
221221
}
222222
}).unwrap_or(c::INFINITE)
223223
}
224+
225+
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
226+
// and later, this will terminate the process immediately without running any
227+
// in-process exception handlers. In earlier versions of Windows, this
228+
// sequence of instructions will be treated as an access violation,
229+
// terminating the process but without necessarily bypassing all exception
230+
// handlers.
231+
//
232+
// https://msdn.microsoft.com/en-us/library/dn774154.aspx
233+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
234+
pub unsafe fn abort_internal() -> ! {
235+
asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
236+
::intrinsics::unreachable();
237+
}

src/tools/tidy/src/pal.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const EXCEPTION_PATHS: &'static [&'static str] = &[
7070
"src/libstd/num/f64.rs",
7171
"src/libstd/sys/common/mod.rs",
7272
"src/libstd/sys/common/net.rs",
73-
"src/libstd/sys/common/util.rs",
7473
"src/libterm", // Not sure how to make this crate portable, but test needs it
7574
"src/libtest", // Probably should defer to unstable std::sys APIs
7675

0 commit comments

Comments
 (0)