| ... | ... | @@ -18,46 +18,51 @@ const arch_bits = switch (native_arch) { |
| 18 | 18 | pub const EXC_TYPES_COUNT = arch_bits.EXC_TYPES_COUNT; |
| 19 | 19 | pub const THREAD_STATE_NONE = arch_bits.THREAD_STATE_NONE; |
| 20 | 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; |
| 21 | pub const EXC = enum(exception_type_t) { |
| 22 | NULL = 0, |
| 23 | /// Could not access memory |
| 24 | BAD_ACCESS = 1, |
| 25 | /// Instruction failed |
| 26 | BAD_INSTRUCTION = 2, |
| 27 | /// Arithmetic exception |
| 28 | ARITHMETIC = 3, |
| 29 | /// Emulation instruction |
| 30 | EMULATION = 4, |
| 31 | /// Software generated exception |
| 32 | SOFTWARE = 5, |
| 33 | /// Trace, breakpoint, etc. |
| 34 | BREAKPOINT = 6, |
| 35 | /// System calls. |
| 36 | SYSCALL = 7, |
| 37 | /// Mach system calls. |
| 38 | MACH_SYSCALL = 8, |
| 39 | /// RPC alert |
| 40 | RPC_ALERT = 9, |
| 41 | /// Abnormal process exit |
| 42 | CRASH = 10, |
| 43 | /// Hit resource consumption limit |
| 44 | RESOURCE = 11, |
| 45 | /// Violated guarded resource protections |
| 46 | GUARD = 12, |
| 47 | /// Abnormal process exited to corpse state |
| 48 | CORPSE_NOTIFY = 13, |
| 49 | }; |
| 50 | |
| 51 | pub const EXC_SOFT_SIGNAL = 0x10003; |
| 52 | |
| 53 | pub const EXC_MASK_BAD_ACCESS = 1 << @enumToInt(EXC.BAD_ACCESS); |
| 54 | pub const EXC_MASK_BAD_INSTRUCTION = 1 << @enumToInt(EXC.BAD_INSTRUCTION); |
| 55 | pub const EXC_MASK_ARITHMETIC = 1 << @enumToInt(EXC.ARITHMETIC); |
| 56 | pub const EXC_MASK_EMULATION = 1 << @enumToInt(EXC.EMULATION); |
| 57 | pub const EXC_MASK_SOFTWARE = 1 << @enumToInt(EXC.SOFTWARE); |
| 58 | pub const EXC_MASK_BREAKPOINT = 1 << @enumToInt(EXC.BREAKPOINT); |
| 59 | pub const EXC_MASK_SYSCALL = 1 << @enumToInt(EXC.SYSCALL); |
| 60 | pub const EXC_MASK_MACH_SYSCALL = 1 << @enumToInt(EXC.MACH_SYSCALL); |
| 61 | pub const EXC_MASK_RPC_ALERT = 1 << @enumToInt(EXC.RPC_ALERT); |
| 62 | pub const EXC_MASK_CRASH = 1 << @enumToInt(EXC.CRASH); |
| 63 | pub const EXC_MASK_RESOURCE = 1 << @enumToInt(EXC.RESOURCE); |
| 64 | pub const EXC_MASK_GUARD = 1 << @enumToInt(EXC.GUARD); |
| 65 | pub const EXC_MASK_CORPSE_NOTIFY = 1 << @enumToInt(EXC.CORPSE_NOTIFY); |
| 61 | 66 | pub const EXC_MASK_MACHINE = arch_bits.EXC_MASK_MACHINE; |
| 62 | 67 | |
| 63 | 68 | pub const EXC_MASK_ALL = EXC_MASK_BAD_ACCESS | |
| ... | ... | @@ -95,6 +100,44 @@ pub const MACH_EXCEPTION_MASK = MACH_EXCEPTION_CODES | |
| 95 | 100 | MACH_EXCEPTION_ERRORS | |
| 96 | 101 | MACH_EXCEPTION_BACKTRACE_PREFERRED; |
| 97 | 102 | |
| 103 | pub const TASK_NULL: task_t = 0; |
| 104 | pub const THREAD_NULL: thread_t = 0; |
| 105 | |
| 106 | pub const MACH_MSG_OPTION_NONE = 0x00000000; |
| 107 | |
| 108 | pub const MACH_SEND_MSG = 0x00000001; |
| 109 | pub const MACH_RCV_MSG = 0x00000002; |
| 110 | |
| 111 | pub const MACH_RCV_LARGE = 0x00000004; |
| 112 | pub const MACH_RCV_LARGE_IDENTITY = 0x00000008; |
| 113 | |
| 114 | pub const MACH_SEND_TIMEOUT = 0x00000010; |
| 115 | pub const MACH_SEND_OVERRIDE = 0x00000020; |
| 116 | pub const MACH_SEND_INTERRUPT = 0x00000040; |
| 117 | pub const MACH_SEND_NOTIFY = 0x00000080; |
| 118 | pub const MACH_SEND_ALWAYS = 0x00010000; |
| 119 | pub const MACH_SEND_FILTER_NONFATAL = 0x00010000; |
| 120 | pub const MACH_SEND_TRAILER = 0x00020000; |
| 121 | pub const MACH_SEND_NOIMPORTANCE = 0x00040000; |
| 122 | pub const MACH_SEND_NODENAP = MACH_SEND_NOIMPORTANCE; |
| 123 | pub const MACH_SEND_IMPORTANCE = 0x00080000; |
| 124 | pub const MACH_SEND_SYNC_OVERRIDE = 0x00100000; |
| 125 | pub const MACH_SEND_PROPAGATE_QOS = 0x00200000; |
| 126 | pub const MACH_SEND_SYNC_USE_THRPRI = MACH_SEND_PROPAGATE_QOS; |
| 127 | pub const MACH_SEND_KERNEL = 0x00400000; |
| 128 | pub const MACH_SEND_SYNC_BOOTSTRAP_CHECKIN = 0x00800000; |
| 129 | |
| 130 | pub const MACH_RCV_TIMEOUT = 0x00000100; |
| 131 | pub const MACH_RCV_NOTIFY = 0x00000000; |
| 132 | pub const MACH_RCV_INTERRUPT = 0x00000400; |
| 133 | pub const MACH_RCV_VOUCHER = 0x00000800; |
| 134 | pub const MACH_RCV_OVERWRITE = 0x00000000; |
| 135 | pub const MACH_RCV_GUARDED_DESC = 0x00001000; |
| 136 | pub const MACH_RCV_SYNC_WAIT = 0x00004000; |
| 137 | pub const MACH_RCV_SYNC_PEEK = 0x00008000; |
| 138 | |
| 139 | pub const MACH_MSG_STRICT_REPLY = 0x00000200; |
| 140 | |
| 98 | 141 | pub const ucontext_t = extern struct { |
| 99 | 142 | onstack: c_int, |
| 100 | 143 | sigmask: sigset_t, |
| ... | ... | @@ -235,6 +278,11 @@ pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int; |
| 235 | 278 | pub extern "c" fn mach_host_self() mach_port_t; |
| 236 | 279 | pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t; |
| 237 | 280 | |
| 281 | pub const exception_type_t = c_int; |
| 282 | pub const exception_data_type_t = integer_t; |
| 283 | pub const exception_data_t = ?*mach_exception_data_type_t; |
| 284 | pub const mach_exception_data_type_t = i64; |
| 285 | pub const mach_exception_data_t = ?*mach_exception_data_type_t; |
| 238 | 286 | pub const vm_map_t = mach_port_t; |
| 239 | 287 | pub const vm_map_read_t = mach_port_t; |
| 240 | 288 | pub const vm_region_flavor_t = c_int; |
| ... | ... | @@ -243,20 +291,27 @@ pub const vm_region_recurse_info_t = *c_int; |
| 243 | 291 | pub const mach_vm_address_t = usize; |
| 244 | 292 | pub const vm_offset_t = usize; |
| 245 | 293 | pub const mach_vm_size_t = u64; |
| 294 | pub const mach_msg_bits_t = c_uint; |
| 295 | pub const mach_msg_id_t = integer_t; |
| 246 | 296 | pub const mach_msg_type_number_t = natural_t; |
| 247 | | pub const mach_msg_type_name_t = u32; |
| 297 | pub const mach_msg_type_name_t = c_uint; |
| 298 | pub const mach_msg_option_t = integer_t; |
| 299 | pub const mach_msg_size_t = natural_t; |
| 300 | pub const mach_msg_timeout_t = natural_t; |
| 248 | 301 | pub const mach_port_right_t = natural_t; |
| 249 | 302 | pub const task_t = mach_port_t; |
| 250 | | pub const exception_mask_t = u32; |
| 303 | pub const thread_port_t = task_t; |
| 304 | pub const thread_t = thread_port_t; |
| 305 | pub const exception_mask_t = c_uint; |
| 251 | 306 | pub const exception_mask_array_t = [*]exception_mask_t; |
| 252 | 307 | pub const exception_handler_t = mach_port_t; |
| 253 | 308 | pub const exception_handler_array_t = [*]exception_handler_t; |
| 254 | 309 | pub const exception_port_t = exception_handler_t; |
| 255 | 310 | pub const exception_port_array_t = exception_handler_array_t; |
| 256 | 311 | pub const exception_flavor_array_t = [*]thread_state_flavor_t; |
| 257 | | pub const exception_behavior_t = i32; |
| 312 | pub const exception_behavior_t = c_uint; |
| 258 | 313 | pub const exception_behavior_array_t = [*]exception_behavior_t; |
| 259 | | pub const thread_state_flavor_t = i32; |
| 314 | pub const thread_state_flavor_t = c_int; |
| 260 | 315 | pub const ipc_space_t = mach_port_t; |
| 261 | 316 | pub const ipc_space_port_t = ipc_space_t; |
| 262 | 317 | |
| ... | ... | @@ -309,6 +364,25 @@ pub fn mach_task_self() callconv(.C) mach_port_t { |
| 309 | 364 | return mach_task_self_; |
| 310 | 365 | } |
| 311 | 366 | |
| 367 | pub extern "c" fn mach_msg( |
| 368 | msg: ?*mach_msg_header_t, |
| 369 | option: mach_msg_option_t, |
| 370 | send_size: mach_msg_size_t, |
| 371 | rcv_size: mach_msg_size_t, |
| 372 | rcv_name: mach_port_name_t, |
| 373 | timeout: mach_msg_timeout_t, |
| 374 | notify: mach_port_name_t, |
| 375 | ) kern_return_t; |
| 376 | |
| 377 | pub const mach_msg_header_t = extern struct { |
| 378 | msgh_bits: mach_msg_bits_t, |
| 379 | msgh_size: mach_msg_size_t, |
| 380 | msgh_remote_port: mach_port_t, |
| 381 | msgh_local_port: mach_port_t, |
| 382 | msgh_voucher_port: mach_port_name_t, |
| 383 | msgh_id: mach_msg_id_t, |
| 384 | }; |
| 385 | |
| 312 | 386 | pub extern "c" fn task_get_exception_ports( |
| 313 | 387 | task: task_t, |
| 314 | 388 | exception_mask: exception_mask_t, |
| ... | ... | @@ -681,6 +755,30 @@ pub extern "c" fn task_info( |
| 681 | 755 | task_info_out: task_info_t, |
| 682 | 756 | task_info_outCnt: *mach_msg_type_number_t, |
| 683 | 757 | ) kern_return_t; |
| 758 | |
| 759 | pub const mach_task_basic_info = extern struct { |
| 760 | /// Virtual memory size (bytes) |
| 761 | virtual_size: mach_vm_size_t, |
| 762 | |
| 763 | /// Resident memory size (bytes) |
| 764 | resident_size: mach_vm_size_t, |
| 765 | |
| 766 | /// Total user run time for terminated threads |
| 767 | user_time: time_value_t, |
| 768 | |
| 769 | /// Total system run time for terminated threads |
| 770 | system_time: time_value_t, |
| 771 | |
| 772 | /// Default policy for new threads |
| 773 | policy: policy_t, |
| 774 | |
| 775 | /// Suspend count for task |
| 776 | suspend_count: mach_vm_size_t, |
| 777 | }; |
| 778 | |
| 779 | pub const MACH_TASK_BASIC_INFO = 20; |
| 780 | pub const MACH_TASK_BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t); |
| 781 | |
| 684 | 782 | pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t; |
| 685 | 783 | pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t; |
| 686 | 784 | pub extern "c" fn vm_machine_attribute( |
| ... | ... | @@ -2052,11 +2150,11 @@ pub const E = enum(u16) { |
| 2052 | 2150 | }; |
| 2053 | 2151 | |
| 2054 | 2152 | pub fn getKernError(err: kern_return_t) KernE { |
| 2055 | | return @intToEnum(KernE, @truncate(u8, @intCast(usize, err))); |
| 2153 | return @intToEnum(KernE, @truncate(u32, @intCast(usize, err))); |
| 2056 | 2154 | } |
| 2057 | 2155 | |
| 2058 | 2156 | /// Kernel return values |
| 2059 | | pub const KernE = enum(u8) { |
| 2157 | pub const KernE = enum(u32) { |
| 2060 | 2158 | SUCCESS = 0, |
| 2061 | 2159 | |
| 2062 | 2160 | /// Specified address is not currently valid |
| ... | ... | @@ -2275,6 +2373,104 @@ pub const KernE = enum(u8) { |
| 2275 | 2373 | _, |
| 2276 | 2374 | }; |
| 2277 | 2375 | |
| 2376 | pub const mach_msg_return_t = kern_return_t; |
| 2377 | |
| 2378 | pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE { |
| 2379 | return @intToEnum(MachMsgE, @truncate(u32, @intCast(usize, err))); |
| 2380 | } |
| 2381 | |
| 2382 | /// All special error code bits defined below. |
| 2383 | pub const MACH_MSG_MASK: u32 = 0x3e00; |
| 2384 | /// No room in IPC name space for another capability name. |
| 2385 | pub const MACH_MSG_IPC_SPACE: u32 = 0x2000; |
| 2386 | /// No room in VM address space for out-of-line memory. |
| 2387 | pub const MACH_MSG_VM_SPACE: u32 = 0x1000; |
| 2388 | /// Kernel resource shortage handling out-of-line memory. |
| 2389 | pub const MACH_MSG_IPC_KERNEL: u32 = 0x800; |
| 2390 | /// Kernel resource shortage handling an IPC capability. |
| 2391 | pub const MACH_MSG_VM_KERNEL: u32 = 0x400; |
| 2392 | |
| 2393 | /// Mach msg return values |
| 2394 | pub const MachMsgE = enum(u32) { |
| 2395 | SUCCESS = 0x00000000, |
| 2396 | |
| 2397 | /// Thread is waiting to send. (Internal use only.) |
| 2398 | SEND_IN_PROGRESS = 0x10000001, |
| 2399 | /// Bogus in-line data. |
| 2400 | SEND_INVALID_DATA = 0x10000002, |
| 2401 | /// Bogus destination port. |
| 2402 | SEND_INVALID_DEST = 0x10000003, |
| 2403 | /// Message not sent before timeout expired. |
| 2404 | SEND_TIMED_OUT = 0x10000004, |
| 2405 | /// Bogus voucher port. |
| 2406 | SEND_INVALID_VOUCHER = 0x10000005, |
| 2407 | /// Software interrupt. |
| 2408 | SEND_INTERRUPTED = 0x10000007, |
| 2409 | /// Data doesn't contain a complete message. |
| 2410 | SEND_MSG_TOO_SMALL = 0x10000008, |
| 2411 | /// Bogus reply port. |
| 2412 | SEND_INVALID_REPLY = 0x10000009, |
| 2413 | /// Bogus port rights in the message body. |
| 2414 | SEND_INVALID_RIGHT = 0x1000000a, |
| 2415 | /// Bogus notify port argument. |
| 2416 | SEND_INVALID_NOTIFY = 0x1000000b, |
| 2417 | /// Invalid out-of-line memory pointer. |
| 2418 | SEND_INVALID_MEMORY = 0x1000000c, |
| 2419 | /// No message buffer is available. |
| 2420 | SEND_NO_BUFFER = 0x1000000d, |
| 2421 | /// Send is too large for port |
| 2422 | SEND_TOO_LARGE = 0x1000000e, |
| 2423 | /// Invalid msg-type specification. |
| 2424 | SEND_INVALID_TYPE = 0x1000000f, |
| 2425 | /// A field in the header had a bad value. |
| 2426 | SEND_INVALID_HEADER = 0x10000010, |
| 2427 | /// The trailer to be sent does not match kernel format. |
| 2428 | SEND_INVALID_TRAILER = 0x10000011, |
| 2429 | /// The sending thread context did not match the context on the dest port |
| 2430 | SEND_INVALID_CONTEXT = 0x10000012, |
| 2431 | /// compatibility: no longer a returned error |
| 2432 | SEND_INVALID_RT_OOL_SIZE = 0x10000015, |
| 2433 | /// The destination port doesn't accept ports in body |
| 2434 | SEND_NO_GRANT_DEST = 0x10000016, |
| 2435 | /// Message send was rejected by message filter |
| 2436 | SEND_MSG_FILTERED = 0x10000017, |
| 2437 | |
| 2438 | /// Thread is waiting for receive. (Internal use only.) |
| 2439 | RCV_IN_PROGRESS = 0x10004001, |
| 2440 | /// Bogus name for receive port/port-set. |
| 2441 | RCV_INVALID_NAME = 0x10004002, |
| 2442 | /// Didn't get a message within the timeout value. |
| 2443 | RCV_TIMED_OUT = 0x10004003, |
| 2444 | /// Message buffer is not large enough for inline data. |
| 2445 | RCV_TOO_LARGE = 0x10004004, |
| 2446 | /// Software interrupt. |
| 2447 | RCV_INTERRUPTED = 0x10004005, |
| 2448 | /// compatibility: no longer a returned error |
| 2449 | RCV_PORT_CHANGED = 0x10004006, |
| 2450 | /// Bogus notify port argument. |
| 2451 | RCV_INVALID_NOTIFY = 0x10004007, |
| 2452 | /// Bogus message buffer for inline data. |
| 2453 | RCV_INVALID_DATA = 0x10004008, |
| 2454 | /// Port/set was sent away/died during receive. |
| 2455 | RCV_PORT_DIED = 0x10004009, |
| 2456 | /// compatibility: no longer a returned error |
| 2457 | RCV_IN_SET = 0x1000400a, |
| 2458 | /// Error receiving message header. See special bits. |
| 2459 | RCV_HEADER_ERROR = 0x1000400b, |
| 2460 | /// Error receiving message body. See special bits. |
| 2461 | RCV_BODY_ERROR = 0x1000400c, |
| 2462 | /// Invalid msg-type specification in scatter list. |
| 2463 | RCV_INVALID_TYPE = 0x1000400d, |
| 2464 | /// Out-of-line overwrite region is not large enough |
| 2465 | RCV_SCATTER_SMALL = 0x1000400e, |
| 2466 | /// trailer type or number of trailer elements not supported |
| 2467 | RCV_INVALID_TRAILER = 0x1000400f, |
| 2468 | /// Waiting for receive with timeout. (Internal use only.) |
| 2469 | RCV_IN_PROGRESS_TIMED = 0x10004011, |
| 2470 | /// invalid reply port used in a STRICT_REPLY message |
| 2471 | RCV_INVALID_REPLY = 0x10004012, |
| 2472 | }; |
| 2473 | |
| 2278 | 2474 | pub const SIGSTKSZ = 131072; |
| 2279 | 2475 | pub const MINSIGSTKSZ = 32768; |
| 2280 | 2476 | |