Other/User defined WIndows Exceptions (#402)
* other exceptions * add * 46th * fix * fmt
This commit is contained in:
parent
b0019ae4a9
commit
d697554810
@ -18,7 +18,7 @@ use core::{
|
||||
sync::atomic::{compiler_fence, Ordering},
|
||||
};
|
||||
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use num_enum::TryFromPrimitive;
|
||||
|
||||
//const EXCEPTION_CONTINUE_EXECUTION: c_long = -1;
|
||||
//const EXCEPTION_CONTINUE_SEARCH: c_long = 0;
|
||||
@ -83,7 +83,7 @@ pub const STATUS_ASSERTION_FAILURE: u32 = 0xC0000420;
|
||||
pub const STATUS_SXS_EARLY_DEACTIVATION: u32 = 0xC015000F;
|
||||
pub const STATUS_SXS_INVALID_DEACTIVATION: u32 = 0xC0150010;
|
||||
|
||||
#[derive(IntoPrimitive, TryFromPrimitive, Clone, Copy)]
|
||||
#[derive(TryFromPrimitive, Clone, Copy)]
|
||||
#[repr(u32)]
|
||||
pub enum ExceptionCode {
|
||||
// From https://docs.microsoft.com/en-us/windows/win32/debug/getexceptioncode
|
||||
@ -133,6 +133,8 @@ pub enum ExceptionCode {
|
||||
AssertionFailure = STATUS_ASSERTION_FAILURE,
|
||||
SXSEarlyDeactivation = STATUS_SXS_EARLY_DEACTIVATION,
|
||||
SXSInvalidDeactivation = STATUS_SXS_INVALID_DEACTIVATION,
|
||||
#[num_enum(default)]
|
||||
Other,
|
||||
}
|
||||
|
||||
pub static CRASH_EXCEPTIONS: &[ExceptionCode] = &[
|
||||
@ -150,6 +152,7 @@ pub static CRASH_EXCEPTIONS: &[ExceptionCode] = &[
|
||||
ExceptionCode::HeapCorruption,
|
||||
ExceptionCode::StackBufferOverrun,
|
||||
ExceptionCode::AssertionFailure,
|
||||
ExceptionCode::Other,
|
||||
];
|
||||
|
||||
impl PartialEq for ExceptionCode {
|
||||
@ -212,13 +215,14 @@ impl Display for ExceptionCode {
|
||||
ExceptionCode::AssertionFailure => write!(f, "STATUS_ASSERTION_FAILURE")?,
|
||||
ExceptionCode::SXSEarlyDeactivation => write!(f, "STATUS_SXS_EARLY_DEACTIVATION")?,
|
||||
ExceptionCode::SXSInvalidDeactivation => write!(f, "STATUS_SXS_INVALID_DEACTIVATION")?,
|
||||
ExceptionCode::Other => write!(f, "Other/User defined exception")?,
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub static EXCEPTION_CODES_MAPPING: [ExceptionCode; 45] = [
|
||||
pub static EXCEPTION_CODES_MAPPING: [ExceptionCode; 46] = [
|
||||
ExceptionCode::AccessViolation,
|
||||
ExceptionCode::ArrayBoundsExceeded,
|
||||
ExceptionCode::Breakpoint,
|
||||
@ -264,6 +268,7 @@ pub static EXCEPTION_CODES_MAPPING: [ExceptionCode; 45] = [
|
||||
ExceptionCode::AssertionFailure,
|
||||
ExceptionCode::SXSEarlyDeactivation,
|
||||
ExceptionCode::SXSInvalidDeactivation,
|
||||
ExceptionCode::Other,
|
||||
];
|
||||
|
||||
pub trait Handler {
|
||||
|
@ -686,8 +686,7 @@ mod windows_exception_handler {
|
||||
use core::sync::atomic::{compiler_fence, Ordering};
|
||||
use windows::Win32::System::Threading::ExitProcess;
|
||||
|
||||
pub type HandlerFuncPtr =
|
||||
unsafe fn(ExceptionCode, *mut EXCEPTION_POINTERS, &mut InProcessExecutorHandlerData);
|
||||
pub type HandlerFuncPtr = unsafe fn(*mut EXCEPTION_POINTERS, &mut InProcessExecutorHandlerData);
|
||||
|
||||
/*pub unsafe fn nop_handler(
|
||||
_code: ExceptionCode,
|
||||
@ -703,7 +702,7 @@ mod windows_exception_handler {
|
||||
let data = &mut GLOBAL_STATE;
|
||||
if !data.crash_handler.is_null() {
|
||||
let func: HandlerFuncPtr = transmute(data.crash_handler);
|
||||
(func)(code, exception_pointers, data);
|
||||
(func)(exception_pointers, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -817,7 +816,6 @@ mod windows_exception_handler {
|
||||
}
|
||||
|
||||
pub unsafe fn inproc_crash_handler<E, EM, I, OC, OF, OT, S, Z>(
|
||||
code: ExceptionCode,
|
||||
exception_pointers: *mut EXCEPTION_POINTERS,
|
||||
data: &mut InProcessExecutorHandlerData,
|
||||
) where
|
||||
@ -851,6 +849,18 @@ mod windows_exception_handler {
|
||||
data.tp_timer = ptr::null_mut();
|
||||
}
|
||||
|
||||
let code = ExceptionCode::try_from(
|
||||
exception_pointers
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.ExceptionRecord
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.ExceptionCode
|
||||
.0,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
eprintln!("Crashed with {}", code);
|
||||
if data.current_input_ptr.is_null() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user