|
| 1 | +//! Platform-specific extensions to `core` for Windows platforms. |
| 2 | +
|
| 3 | +#![unstable(issue = "none", feature = "std_internals")] |
| 4 | + |
| 5 | +use crate::cfg_select; |
| 6 | + |
| 7 | +const FAST_FAIL_FATAL_APP_EXIT: u32 = 7u32; |
| 8 | + |
| 9 | +/// Use `__fastfail` to abort the process |
| 10 | +/// |
| 11 | +/// In Windows 8 and later, this will terminate the process immediately without |
| 12 | +/// running any in-process exception handlers. In earlier versions of Windows, |
| 13 | +/// this sequence of instructions will be treated as an access violation, which |
| 14 | +/// will still terminate the process but might run some exception handlers. |
| 15 | +/// |
| 16 | +/// https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail |
| 17 | +#[cfg(all( |
| 18 | + not(miri), |
| 19 | + any( |
| 20 | + any(target_arch = "x86", target_arch = "x86_64"), |
| 21 | + all(target_arch = "arm", target_feature = "thumb-mode"), |
| 22 | + any(target_arch = "aarch64", target_arch = "arm64ec") |
| 23 | + ) |
| 24 | +))] |
| 25 | +pub fn fastfail() -> ! { |
| 26 | + // SAFETY: These assembly instructions are always safe to call and will result in the documented behavior. |
| 27 | + unsafe { |
| 28 | + cfg_select! { |
| 29 | + any(target_arch = "x86", target_arch = "x86_64") => { |
| 30 | + core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); |
| 31 | + } |
| 32 | + all(target_arch = "arm", target_feature = "thumb-mode") => { |
| 33 | + core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); |
| 34 | + } |
| 35 | + any(target_arch = "aarch64", target_arch = "arm64ec") => { |
| 36 | + core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack)); |
| 37 | + } |
| 38 | + _ => {} |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments