From ce26c7882024874bacf05bedf0e8de692e6f6d13 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Fri, 1 Mar 2024 11:42:42 -0300 Subject: [PATCH] Cleanup windows abort_internal --- library/panic_abort/src/lib.rs | 7 +++---- .../std/src/sys/pal/windows/c/bindings.txt | 1 + .../std/src/sys/pal/windows/c/windows_sys.rs | 1 + library/std/src/sys/pal/windows/mod.rs | 21 ++++++++++--------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/library/panic_abort/src/lib.rs b/library/panic_abort/src/lib.rs index c44f23eea80..a6d07fd1984 100644 --- a/library/panic_abort/src/lib.rs +++ b/library/panic_abort/src/lib.rs @@ -75,16 +75,15 @@ unsafe fn abort() -> ! { const FAST_FAIL_FATAL_APP_EXIT: usize = 7; cfg_if::cfg_if! { if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { - core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT); + core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); } else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] { - core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT); + core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); } else if #[cfg(target_arch = "aarch64")] { - core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT); + core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); } else { core::intrinsics::abort(); } } - core::intrinsics::unreachable(); } } else if #[cfg(target_os = "teeos")] { mod teeos { diff --git a/library/std/src/sys/pal/windows/c/bindings.txt b/library/std/src/sys/pal/windows/c/bindings.txt index ab2a8caf5df..e69a745cdd4 100644 --- a/library/std/src/sys/pal/windows/c/bindings.txt +++ b/library/std/src/sys/pal/windows/c/bindings.txt @@ -2481,6 +2481,7 @@ Windows.Win32.System.SystemInformation.SYSTEM_INFO Windows.Win32.System.SystemServices.DLL_PROCESS_DETACH Windows.Win32.System.SystemServices.DLL_THREAD_DETACH Windows.Win32.System.SystemServices.EXCEPTION_MAXIMUM_PARAMETERS +Windows.Win32.System.SystemServices.FAST_FAIL_FATAL_APP_EXIT Windows.Win32.System.SystemServices.IO_REPARSE_TAG_MOUNT_POINT Windows.Win32.System.SystemServices.IO_REPARSE_TAG_SYMLINK Windows.Win32.System.Threading.ABOVE_NORMAL_PRIORITY_CLASS diff --git a/library/std/src/sys/pal/windows/c/windows_sys.rs b/library/std/src/sys/pal/windows/c/windows_sys.rs index 8eb779373f7..a416fa183fe 100644 --- a/library/std/src/sys/pal/windows/c/windows_sys.rs +++ b/library/std/src/sys/pal/windows/c/windows_sys.rs @@ -3086,6 +3086,7 @@ fn clone(&self) -> Self { pub const FACILITY_NT_BIT: FACILITY_CODE = 268435456u32; pub const FALSE: BOOL = 0i32; pub type FARPROC = ::core::option::Option isize>; +pub const FAST_FAIL_FATAL_APP_EXIT: u32 = 7u32; #[repr(C)] pub struct FD_SET { pub fd_count: u32, diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs index 831cb04c566..a53c4034d06 100644 --- a/library/std/src/sys/pal/windows/mod.rs +++ b/library/std/src/sys/pal/windows/mod.rs @@ -321,25 +321,26 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD { /// /// This is the same implementation as in libpanic_abort's `__rust_start_panic`. See /// that function for more information on `__fastfail` -#[allow(unreachable_code)] +#[cfg(not(miri))] // inline assembly does not work in Miri pub fn abort_internal() -> ! { - #[allow(unused)] - const FAST_FAIL_FATAL_APP_EXIT: usize = 7; - #[cfg(not(miri))] // inline assembly does not work in Miri unsafe { cfg_if::cfg_if! { if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { - core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT); - crate::intrinsics::unreachable(); + core::arch::asm!("int $$0x29", in("ecx") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); } else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] { - core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT); - crate::intrinsics::unreachable(); + core::arch::asm!(".inst 0xDEFB", in("r0") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); } else if #[cfg(target_arch = "aarch64")] { - core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT); - crate::intrinsics::unreachable(); + core::arch::asm!("brk 0xF003", in("x0") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); + } else { + core::intrinsics::abort(); } } } +} + +// miri is sensitive to changes here so check that miri is happy if touching this +#[cfg(miri)] +pub fn abort_internal() -> ! { crate::intrinsics::abort(); }