Skip to content

Commit 3793e5b

Browse files
committed
Auto merge of #121856 - ChrisDenton:abort, r=joboet
Cleanup windows `abort_internal` As the comments on the functions say, we define abort in both in panic_abort and in libstd. This PR makes the two implementation (mostly) the same. Additionally it: * uses `options(noreturn)` on the asm instead of using `core::intrinsics::unreachable`. * removed unnecessary allow lints * added `FAST_FAIL_FATAL_APP_EXIT` to our generated Windows API bindings instead of defining it manually (std only)
2 parents da02fff + ce26c78 commit 3793e5b

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

library/panic_abort/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,15 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
7575
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
7676
cfg_if::cfg_if! {
7777
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
78-
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
78+
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
7979
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
80-
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
80+
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
8181
} else if #[cfg(target_arch = "aarch64")] {
82-
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
82+
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
8383
} else {
8484
core::intrinsics::abort();
8585
}
8686
}
87-
core::intrinsics::unreachable();
8887
}
8988
} else if #[cfg(target_os = "teeos")] {
9089
mod teeos {

library/std/src/sys/pal/windows/c/bindings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2482,6 +2482,7 @@ Windows.Win32.System.SystemInformation.SYSTEM_INFO
24822482
Windows.Win32.System.SystemServices.DLL_PROCESS_DETACH
24832483
Windows.Win32.System.SystemServices.DLL_THREAD_DETACH
24842484
Windows.Win32.System.SystemServices.EXCEPTION_MAXIMUM_PARAMETERS
2485+
Windows.Win32.System.SystemServices.FAST_FAIL_FATAL_APP_EXIT
24852486
Windows.Win32.System.SystemServices.IO_REPARSE_TAG_MOUNT_POINT
24862487
Windows.Win32.System.SystemServices.IO_REPARSE_TAG_SYMLINK
24872488
Windows.Win32.System.Threading.ABOVE_NORMAL_PRIORITY_CLASS

library/std/src/sys/pal/windows/c/windows_sys.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,7 @@ pub type FACILITY_CODE = u32;
30903090
pub const FACILITY_NT_BIT: FACILITY_CODE = 268435456u32;
30913091
pub const FALSE: BOOL = 0i32;
30923092
pub type FARPROC = ::core::option::Option<unsafe extern "system" fn() -> isize>;
3093+
pub const FAST_FAIL_FATAL_APP_EXIT: u32 = 7u32;
30933094
#[repr(C)]
30943095
pub struct FD_SET {
30953096
pub fd_count: u32,

library/std/src/sys/pal/windows/mod.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,26 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD {
321321
///
322322
/// This is the same implementation as in libpanic_abort's `__rust_start_panic`. See
323323
/// that function for more information on `__fastfail`
324-
#[allow(unreachable_code)]
324+
#[cfg(not(miri))] // inline assembly does not work in Miri
325325
pub fn abort_internal() -> ! {
326-
#[allow(unused)]
327-
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
328-
#[cfg(not(miri))] // inline assembly does not work in Miri
329326
unsafe {
330327
cfg_if::cfg_if! {
331328
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
332-
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
333-
crate::intrinsics::unreachable();
329+
core::arch::asm!("int $$0x29", in("ecx") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
334330
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
335-
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
336-
crate::intrinsics::unreachable();
331+
core::arch::asm!(".inst 0xDEFB", in("r0") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
337332
} else if #[cfg(target_arch = "aarch64")] {
338-
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
339-
crate::intrinsics::unreachable();
333+
core::arch::asm!("brk 0xF003", in("x0") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
334+
} else {
335+
core::intrinsics::abort();
340336
}
341337
}
342338
}
339+
}
340+
341+
// miri is sensitive to changes here so check that miri is happy if touching this
342+
#[cfg(miri)]
343+
pub fn abort_internal() -> ! {
343344
crate::intrinsics::abort();
344345
}
345346

0 commit comments

Comments
 (0)