-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise noncontinuable exception when aborting on earlier Windows versions #76203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![allow(nonstandard_style)] | ||
|
||
use libc::{c_int, c_ulong, c_void}; | ||
|
||
pub type DWORD = c_ulong; | ||
pub type BOOL = c_int; | ||
|
||
pub type LPVOID = *mut c_void; | ||
|
||
pub const FALSE: BOOL = 0; | ||
|
||
pub const PF_FASTFAIL_AVAILABLE: DWORD = 23; | ||
|
||
pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15; | ||
|
||
#[repr(C)] | ||
pub struct EXCEPTION_RECORD { | ||
pub ExceptionCode: DWORD, | ||
pub ExceptionFlags: DWORD, | ||
pub ExceptionRecord: *mut EXCEPTION_RECORD, | ||
pub ExceptionAddress: LPVOID, | ||
pub NumberParameters: DWORD, | ||
pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS], | ||
} | ||
|
||
pub enum CONTEXT {} | ||
|
||
extern "system" { | ||
pub fn IsProcessorFeaturePresent(ProcessorFeature: DWORD) -> BOOL; | ||
pub fn RaiseFailFastException( | ||
pExceptionRecord: *const EXCEPTION_RECORD, | ||
pContextRecord: *const CONTEXT, | ||
dwFlags: DWORD, | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,26 +300,42 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD { | |
.unwrap_or(c::INFINITE) | ||
} | ||
|
||
/// Use `__fastfail` to abort the process | ||
/// On Windows 8 and later versions, use the processor-specific `__fastfail` | ||
/// mechanism. This will terminate the process immediately without running any | ||
/// in-process exception handlers. | ||
/// On Windows 7, use `RaiseFailFastException` to raise a noncontinuable exception | ||
/// `STATUS_FAIL_FAST_EXCEPTION`. | ||
/// On earlier versions of Windows, use `RaiseException` to raise the same | ||
/// noncontinuable exception. | ||
/// | ||
/// This is the same implementation as in libpanic_abort's `__rust_start_panic`. See | ||
/// that function for more information on `__fastfail` | ||
/// This is the same implementation as in libpanic_abort's `__rust_start_panic`. | ||
#[allow(unreachable_code)] | ||
pub fn abort_internal() -> ! { | ||
const FAST_FAIL_FATAL_APP_EXIT: usize = 7; | ||
unsafe { | ||
cfg_if::cfg_if! { | ||
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { | ||
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT); | ||
crate::intrinsics::unreachable(); | ||
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] { | ||
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT); | ||
crate::intrinsics::unreachable(); | ||
} else if #[cfg(target_arch = "aarch64")] { | ||
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT); | ||
crate::intrinsics::unreachable(); | ||
if c::IsProcessorFeaturePresent(c::PF_FASTFAIL_AVAILABLE) != c::FALSE { | ||
const FAST_FAIL_FATAL_APP_EXIT: usize = 7; | ||
cfg_if::cfg_if! { | ||
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { | ||
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT); | ||
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] { | ||
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT); | ||
} else if #[cfg(target_arch = "aarch64")] { | ||
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT); | ||
} else { | ||
crate::intrinsics::abort(); | ||
} | ||
} | ||
} else { | ||
match compat::lookup("kernel32", "RaiseFailFastException") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you put |
||
Some(..) => c::RaiseFailFastException(ptr::null(), ptr::null(), 0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will cause a runtime missing symbol error on older Windows versions here since you are directly linking to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
None => c::RaiseException( | ||
c::STATUS_FAIL_FAST_EXCEPTION, | ||
c::EXCEPTION_NONCONTINUABLE, | ||
0, | ||
ptr::null(), | ||
), | ||
}; | ||
} | ||
crate::intrinsics::unreachable(); | ||
} | ||
crate::intrinsics::abort(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there no fallback to
RaiseException
here?