| ... | @@ -15,6 +15,86 @@ const arch_bits = switch (native_arch) { | ... | @@ -15,6 +15,86 @@ const arch_bits = switch (native_arch) { |
| 15 | else => struct {}, | 15 | else => struct {}, |
| 16 | }; | 16 | }; |
| 17 | | 17 | |
| | 18 | pub const EXC_TYPES_COUNT = arch_bits.EXC_TYPES_COUNT; |
| | 19 | pub const THREAD_STATE_NONE = arch_bits.THREAD_STATE_NONE; |
| | 20 | |
| | 21 | /// Could not access memory |
| | 22 | pub const EXC_BAD_ACCESS = 1; |
| | 23 | /// Instruction failed |
| | 24 | pub const EXC_BAD_INSTRUCTION = 2; |
| | 25 | /// Arithmetic exception |
| | 26 | pub const EXC_ARITHMETIC = 3; |
| | 27 | /// Emulation instruction |
| | 28 | pub const EXC_EMULATION = 4; |
| | 29 | /// Software generated exception |
| | 30 | pub const EXC_SOFTWARE = 5; |
| | 31 | /// Trace, breakpoint, etc. |
| | 32 | pub const EXC_BREAKPOINT = 6; |
| | 33 | /// System calls. |
| | 34 | pub const EXC_SYSCALL = 7; |
| | 35 | /// Mach system calls. |
| | 36 | pub const EXC_MACH_SYSCALL = 8; |
| | 37 | /// RPC alert |
| | 38 | pub const EXC_RPC_ALERT = 9; |
| | 39 | /// Abnormal process exit |
| | 40 | pub const EXC_CRASH = 10; |
| | 41 | /// Hit resource consumption limit |
| | 42 | pub const EXC_RESOURCE = 11; |
| | 43 | /// Violated guarded resource protections |
| | 44 | pub const EXC_GUARD = 12; |
| | 45 | /// Abnormal process exited to corpse state |
| | 46 | pub const EXC_CORPSE_NOTIFY = 13; |
| | 47 | |
| | 48 | pub const EXC_MASK_BAD_ACCESS = 1 << EXC_BAD_ACCESS; |
| | 49 | pub const EXC_MASK_BAD_INSTRUCTION = 1 << EXC_BAD_INSTRUCTION; |
| | 50 | pub const EXC_MASK_ARITHMETIC = 1 << EXC_ARITHMETIC; |
| | 51 | pub const EXC_MASK_EMULATION = 1 << EXC_EMULATION; |
| | 52 | pub const EXC_MASK_SOFTWARE = 1 << EXC_SOFTWARE; |
| | 53 | pub const EXC_MASK_BREAKPOINT = 1 << EXC_BREAKPOINT; |
| | 54 | pub const EXC_MASK_SYSCALL = 1 << EXC_SYSCALL; |
| | 55 | pub const EXC_MASK_MACH_SYSCALL = 1 << EXC_MACH_SYSCALL; |
| | 56 | pub const EXC_MASK_RPC_ALERT = 1 << EXC_RPC_ALERT; |
| | 57 | pub const EXC_MASK_CRASH = 1 << EXC_CRASH; |
| | 58 | pub const EXC_MASK_RESOURCE = 1 << EXC_RESOURCE; |
| | 59 | pub const EXC_MASK_GUARD = 1 << EXC_GUARD; |
| | 60 | pub const EXC_MASK_CORPSE_NOTIFY = 1 << EXC_CORPSE_NOTIFY; |
| | 61 | pub const EXC_MASK_MACHINE = arch_bits.EXC_MASK_MACHINE; |
| | 62 | |
| | 63 | pub const EXC_MASK_ALL = EXC_MASK_BAD_ACCESS | |
| | 64 | EXC_MASK_BAD_INSTRUCTION | |
| | 65 | EXC_MASK_ARITHMETIC | |
| | 66 | EXC_MASK_EMULATION | |
| | 67 | EXC_MASK_SOFTWARE | |
| | 68 | EXC_MASK_BREAKPOINT | |
| | 69 | EXC_MASK_SYSCALL | |
| | 70 | EXC_MASK_MACH_SYSCALL | |
| | 71 | EXC_MASK_RPC_ALERT | |
| | 72 | EXC_MASK_RESOURCE | |
| | 73 | EXC_MASK_GUARD | |
| | 74 | EXC_MASK_MACHINE; |
| | 75 | |
| | 76 | /// Send a catch_exception_raise message including the identity. |
| | 77 | pub const EXCEPTION_DEFAULT = 1; |
| | 78 | /// Send a catch_exception_raise_state message including the |
| | 79 | /// thread state. |
| | 80 | pub const EXCEPTION_STATE = 2; |
| | 81 | /// Send a catch_exception_raise_state_identity message including |
| | 82 | /// the thread identity and state. |
| | 83 | pub const EXCEPTION_STATE_IDENTITY = 3; |
| | 84 | /// Send a catch_exception_raise_identity_protected message including protected task |
| | 85 | /// and thread identity. |
| | 86 | pub const EXCEPTION_IDENTITY_PROTECTED = 4; |
| | 87 | /// Prefer sending a catch_exception_raice_backtrace message, if applicable. |
| | 88 | pub const MACH_EXCEPTION_BACKTRACE_PREFERRED = 0x20000000; |
| | 89 | /// include additional exception specific errors, not used yet. |
| | 90 | pub const MACH_EXCEPTION_ERRORS = 0x40000000; |
| | 91 | /// Send 64-bit code and subcode in the exception header */ |
| | 92 | pub const MACH_EXCEPTION_CODES = 0x80000000; |
| | 93 | |
| | 94 | pub const MACH_EXCEPTION_MASK = MACH_EXCEPTION_CODES | |
| | 95 | MACH_EXCEPTION_ERRORS | |
| | 96 | MACH_EXCEPTION_BACKTRACE_PREFERRED; |
| | 97 | |
| 18 | pub const ucontext_t = extern struct { | 98 | pub const ucontext_t = extern struct { |
| 19 | onstack: c_int, | 99 | onstack: c_int, |
| 20 | sigmask: sigset_t, | 100 | sigmask: sigset_t, |
| ... | @@ -166,6 +246,17 @@ pub const mach_vm_size_t = u64; | ... | @@ -166,6 +246,17 @@ pub const mach_vm_size_t = u64; |
| 166 | pub const mach_msg_type_number_t = natural_t; | 246 | pub const mach_msg_type_number_t = natural_t; |
| 167 | pub const mach_msg_type_name_t = u32; | 247 | pub const mach_msg_type_name_t = u32; |
| 168 | pub const mach_port_right_t = natural_t; | 248 | pub const mach_port_right_t = natural_t; |
| | 249 | pub const task_t = mach_port_t; |
| | 250 | pub const exception_mask_t = u32; |
| | 251 | pub const exception_mask_array_t = [*]exception_mask_t; |
| | 252 | pub const exception_handler_t = mach_port_t; |
| | 253 | pub const exception_handler_array_t = [*]exception_handler_t; |
| | 254 | pub const exception_port_t = exception_handler_t; |
| | 255 | pub const exception_port_array_t = exception_handler_array_t; |
| | 256 | pub const exception_flavor_array_t = [*]thread_state_flavor_t; |
| | 257 | pub const exception_behavior_t = i32; |
| | 258 | pub const exception_behavior_array_t = [*]exception_behavior_t; |
| | 259 | pub const thread_state_flavor_t = i32; |
| 169 | pub const ipc_space_t = mach_port_t; | 260 | pub const ipc_space_t = mach_port_t; |
| 170 | pub const ipc_space_port_t = ipc_space_t; | 261 | pub const ipc_space_port_t = ipc_space_t; |
| 171 | | 262 | |
| ... | @@ -218,6 +309,23 @@ pub fn mach_task_self() callconv(.C) mach_port_t { | ... | @@ -218,6 +309,23 @@ pub fn mach_task_self() callconv(.C) mach_port_t { |
| 218 | return mach_task_self_; | 309 | return mach_task_self_; |
| 219 | } | 310 | } |
| 220 | | 311 | |
| | 312 | pub extern "c" fn task_get_exception_ports( |
| | 313 | task: task_t, |
| | 314 | exception_mask: exception_mask_t, |
| | 315 | masks: exception_mask_array_t, |
| | 316 | masks_cnt: *mach_msg_type_number_t, |
| | 317 | old_handlers: exception_handler_array_t, |
| | 318 | old_behaviors: exception_behavior_array_t, |
| | 319 | old_flavors: exception_flavor_array_t, |
| | 320 | ) kern_return_t; |
| | 321 | pub extern "c" fn task_set_exception_ports( |
| | 322 | task: task_t, |
| | 323 | exception_mask: exception_mask_t, |
| | 324 | new_port: mach_port_t, |
| | 325 | behavior: exception_behavior_t, |
| | 326 | new_flavor: thread_state_flavor_t, |
| | 327 | ) kern_return_t; |
| | 328 | |
| 221 | pub const task_read_t = mach_port_t; | 329 | pub const task_read_t = mach_port_t; |
| 222 | | 330 | |
| 223 | pub extern "c" fn task_resume(target_task: task_read_t) kern_return_t; | 331 | pub extern "c" fn task_resume(target_task: task_read_t) kern_return_t; |