Skip to content

Commit 993adf3

Browse files
authored
Rollup merge of rust-lang#75990 - rylev:arm-fastfail, r=alexcrichton
Add __fastfail for Windows on arm/aarch64 Fixes rust-lang#73215
2 parents d62a324 + 9e2228d commit 993adf3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

library/panic_abort/src/lib.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#![feature(panic_runtime)]
1818
#![feature(staged_api)]
1919
#![feature(rustc_attrs)]
20-
#![feature(llvm_asm)]
20+
#![feature(asm)]
2121

2222
use core::any::Any;
2323

@@ -47,7 +47,7 @@ pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 {
4747
}
4848
__rust_abort();
4949
}
50-
} else if #[cfg(all(windows, any(target_arch = "x86", target_arch = "x86_64")))] {
50+
} else if #[cfg(windows)] {
5151
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
5252
// and later, this will terminate the process immediately without running any
5353
// in-process exception handlers. In earlier versions of Windows, this
@@ -59,7 +59,18 @@ pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 {
5959
//
6060
// Note: this is the same implementation as in libstd's `abort_internal`
6161
unsafe fn abort() -> ! {
62-
llvm_asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
62+
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
63+
cfg_if::cfg_if! {
64+
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
65+
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
66+
} else if #[cfg(target_arch = "arm")] {
67+
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
68+
} else if #[cfg(target_arch = "aarch64")] {
69+
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
70+
} else {
71+
core::intrinsics::abort();
72+
}
73+
}
6374
core::intrinsics::unreachable();
6475
}
6576
} else {

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,20 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD {
306306
/// that function for more information on `__fastfail`
307307
#[allow(unreachable_code)]
308308
pub fn abort_internal() -> ! {
309-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
309+
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
310310
unsafe {
311-
llvm_asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT
312-
crate::intrinsics::unreachable();
311+
cfg_if::cfg_if! {
312+
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
313+
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
314+
crate::intrinsics::unreachable();
315+
} else if #[cfg(target_arch = "arm")] {
316+
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
317+
crate::intrinsics::unreachable();
318+
} else if #[cfg(target_arch = "aarch64")] {
319+
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
320+
crate::intrinsics::unreachable();
321+
}
322+
}
313323
}
314324
crate::intrinsics::abort();
315325
}

0 commit comments

Comments
 (0)