1use std::ffi::{c_int, c_short, c_void};
5
6#[non_exhaustive]
7#[repr(C)]
8#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub enum SigillCode {
11 ILLOPC,
13 ILLOPN,
15 ILLADR,
17 ILLTRP,
19 PRVOPC,
21 PRVREG,
23 CORPOC,
25 BADSTK,
27}
28
29#[non_exhaustive]
30#[repr(C)]
31#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
32pub enum SigfpeCode {
34 INTDIV,
36 INTOVF,
38 FLTDIV,
40 FLTOVF,
42 FLTUND,
44 FLTRES,
46 FLTINV,
48 FLTSUB,
50}
51
52#[non_exhaustive]
53#[repr(C)]
54#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
55pub enum SigsegvCode {
57 MAPERR,
59 ACCERR,
61 BNDERR,
63 PKUERR,
65}
66
67#[non_exhaustive]
68#[repr(C)]
69#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
70#[allow(non_camel_case_types)]
71pub enum SigbusCode {
73 ADRALN,
75 ADDERR,
77 OBJERR,
79 MCEERR_AR,
81 MCEERR_AO,
83}
84
85#[non_exhaustive]
86#[repr(C)]
87#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
88pub enum SigtrapCode {
90 BRKPT,
92 TRACE,
94 BRANCH,
96 HWBKPT,
98}
99
100extern "C" {
101 pub(crate) fn hwexception_catch(
102 callback: unsafe extern "C" fn(*mut c_void),
103 context: *mut c_void,
104 exception: *mut c_void,
105 jmp_buf_ptr: *mut *mut c_void,
106 err_buf_ptr: *mut *mut c_void,
107 ) -> c_int;
108
109 pub(crate) fn hwexception_throw(
110 exception: *const c_void,
111 exception_len: usize,
112 jmp_buf_ptr: *mut *mut c_void,
113 err_buf_ptr: *mut *mut c_void,
114 );
115
116 pub(crate) fn hwexception_translate_sigill_code(
117 out: *mut SigillCode,
118 code: c_int,
119 ) -> c_int;
120 pub(crate) fn hwexception_translate_sigfpe_code(
121 out: *mut SigfpeCode,
122 code: c_int,
123 ) -> c_int;
124 pub(crate) fn hwexception_translate_sigsegv_code(
125 out: *mut SigsegvCode,
126 code: c_int,
127 ) -> c_int;
128 pub(crate) fn hwexception_translate_sigbus_code(
129 out: *mut SigbusCode,
130 code: c_int,
131 ) -> c_int;
132 pub(crate) fn hwexception_translate_sigtrap_code(
133 out: *mut SigtrapCode,
134 code: c_int,
135 ) -> c_int;
136
137 pub(crate) fn hwexception_get_ip(context: *const c_void) -> *mut c_void;
138 pub(crate) fn hwexception_get_sp(context: *const c_void) -> *mut c_void;
139 pub(crate) fn hwexception_get_symbol_address(context: *const c_void) -> *mut c_void;
140
141 pub(crate) fn hwexception_get_addr_lsb(info: *const libc::siginfo_t) -> c_short;
142 pub(crate) fn hwexception_get_lower(info: *const libc::siginfo_t) -> *mut c_void;
143 pub(crate) fn hwexception_get_upper(info: *const libc::siginfo_t) -> *mut c_void;
144 pub(crate) fn hwexception_get_pkey(info: *const libc::siginfo_t) -> c_int;
145}