| ... | ... | @@ -19,12 +19,6 @@ comptime { |
| 19 | 19 | |
| 20 | 20 | pub const mach_port_t = c_uint; |
| 21 | 21 | |
| 22 | | pub const THREAD_STATE_NONE = switch (native_arch) { |
| 23 | | .aarch64 => 5, |
| 24 | | .x86_64 => 13, |
| 25 | | else => @compileError("unsupported arch"), |
| 26 | | }; |
| 27 | | |
| 28 | 22 | pub const EXC = enum(exception_type_t) { |
| 29 | 23 | NULL = 0, |
| 30 | 24 | /// Could not access memory |
| ... | ... | @@ -54,6 +48,8 @@ pub const EXC = enum(exception_type_t) { |
| 54 | 48 | /// Abnormal process exited to corpse state |
| 55 | 49 | CORPSE_NOTIFY = 13, |
| 56 | 50 | |
| 51 | _, |
| 52 | |
| 57 | 53 | pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len; |
| 58 | 54 | pub const SOFT_SIGNAL = 0x10003; |
| 59 | 55 | |
| ... | ... | @@ -110,56 +106,240 @@ pub const EXCEPTION = enum(u32) { |
| 110 | 106 | _, |
| 111 | 107 | }; |
| 112 | 108 | |
| 113 | | /// Prefer sending a catch_exception_raice_backtrace message, if applicable. |
| 114 | | pub const MACH_EXCEPTION_BACKTRACE_PREFERRED = 0x20000000; |
| 115 | | /// include additional exception specific errors, not used yet. |
| 116 | | pub const MACH_EXCEPTION_ERRORS = 0x40000000; |
| 117 | | /// Send 64-bit code and subcode in the exception header */ |
| 118 | | pub const MACH_EXCEPTION_CODES = 0x80000000; |
| 119 | | |
| 120 | | pub const MACH_EXCEPTION_MASK = MACH_EXCEPTION_CODES | |
| 121 | | MACH_EXCEPTION_ERRORS | |
| 122 | | MACH_EXCEPTION_BACKTRACE_PREFERRED; |
| 123 | | |
| 124 | | pub const TASK_NULL: task_t = 0; |
| 125 | | pub const THREAD_NULL: thread_t = 0; |
| 126 | | pub const MACH_PORT_NULL: mach_port_t = 0; |
| 127 | | pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0; |
| 128 | | |
| 129 | | pub const MACH_MSG_OPTION_NONE = 0x00000000; |
| 130 | | |
| 131 | | pub const MACH_SEND_MSG = 0x00000001; |
| 132 | | pub const MACH_RCV_MSG = 0x00000002; |
| 133 | | |
| 134 | | pub const MACH_RCV_LARGE = 0x00000004; |
| 135 | | pub const MACH_RCV_LARGE_IDENTITY = 0x00000008; |
| 136 | | |
| 137 | | pub const MACH_SEND_TIMEOUT = 0x00000010; |
| 138 | | pub const MACH_SEND_OVERRIDE = 0x00000020; |
| 139 | | pub const MACH_SEND_INTERRUPT = 0x00000040; |
| 140 | | pub const MACH_SEND_NOTIFY = 0x00000080; |
| 141 | | pub const MACH_SEND_ALWAYS = 0x00010000; |
| 142 | | pub const MACH_SEND_FILTER_NONFATAL = 0x00010000; |
| 143 | | pub const MACH_SEND_TRAILER = 0x00020000; |
| 144 | | pub const MACH_SEND_NOIMPORTANCE = 0x00040000; |
| 145 | | pub const MACH_SEND_NODENAP = MACH_SEND_NOIMPORTANCE; |
| 146 | | pub const MACH_SEND_IMPORTANCE = 0x00080000; |
| 147 | | pub const MACH_SEND_SYNC_OVERRIDE = 0x00100000; |
| 148 | | pub const MACH_SEND_PROPAGATE_QOS = 0x00200000; |
| 149 | | pub const MACH_SEND_SYNC_USE_THRPRI = MACH_SEND_PROPAGATE_QOS; |
| 150 | | pub const MACH_SEND_KERNEL = 0x00400000; |
| 151 | | pub const MACH_SEND_SYNC_BOOTSTRAP_CHECKIN = 0x00800000; |
| 152 | | |
| 153 | | pub const MACH_RCV_TIMEOUT = 0x00000100; |
| 154 | | pub const MACH_RCV_NOTIFY = 0x00000000; |
| 155 | | pub const MACH_RCV_INTERRUPT = 0x00000400; |
| 156 | | pub const MACH_RCV_VOUCHER = 0x00000800; |
| 157 | | pub const MACH_RCV_OVERWRITE = 0x00000000; |
| 158 | | pub const MACH_RCV_GUARDED_DESC = 0x00001000; |
| 159 | | pub const MACH_RCV_SYNC_WAIT = 0x00004000; |
| 160 | | pub const MACH_RCV_SYNC_PEEK = 0x00008000; |
| 161 | | |
| 162 | | pub const MACH_MSG_STRICT_REPLY = 0x00000200; |
| 109 | pub const KEVENT = struct { |
| 110 | /// Used as the `flags` arg for `kevent64`. |
| 111 | pub const FLAG = packed struct(c_uint) { |
| 112 | /// immediate timeout |
| 113 | IMMEDIATE: bool = false, |
| 114 | /// output events only include change |
| 115 | ERROR_EVENTS: bool = false, |
| 116 | _: u30 = 0, |
| 117 | |
| 118 | /// no flag value |
| 119 | pub const NONE: KEVENT.FLAG = .{ |
| 120 | .IMMEDIATE = false, |
| 121 | .ERROR_EVENTS = false, |
| 122 | }; |
| 123 | }; |
| 124 | }; |
| 125 | |
| 126 | pub const MACH = struct { |
| 127 | pub const EXCEPTION = packed struct(exception_mask_t) { |
| 128 | _: u29 = 0, |
| 129 | /// Prefer sending a catch_exception_raice_backtrace message, if applicable. |
| 130 | BACKTRACE_PREFERRED: bool = false, |
| 131 | /// include additional exception specific errors, not used yet. |
| 132 | ERRORS: bool = false, |
| 133 | /// Send 64-bit code and subcode in the exception header */ |
| 134 | CODES: bool = false, |
| 135 | |
| 136 | pub const MASK = @compileError("use MACH.EXCEPTION and set/check all named fields"); |
| 137 | }; |
| 138 | |
| 139 | pub const MSG = packed struct(kern_return_t) { |
| 140 | _0: u10 = 0, |
| 141 | /// Kernel resource shortage handling an IPC capability. |
| 142 | VM_KERNEL: bool = false, |
| 143 | /// Kernel resource shortage handling out-of-line memory. |
| 144 | IPC_KERNEL: bool = false, |
| 145 | /// No room in VM address space for out-of-line memory. |
| 146 | VM_SPACE: bool = false, |
| 147 | /// No room in IPC name space for another capability name. |
| 148 | IPC_SPACE: bool = false, |
| 149 | _14: u18 = 0, |
| 150 | |
| 151 | pub const MASK: kern_return_t = @bitCast(MACH.MSG{ |
| 152 | .VM_KERNEL = true, |
| 153 | .IPC_KERNEL = true, |
| 154 | .VM_SPACE = true, |
| 155 | .IPC_SPACE = true, |
| 156 | }); |
| 157 | |
| 158 | pub const TIMEOUT_NONE = @compileError("use mach_msg_timeout_t.NONE"); |
| 159 | pub const OPTION_NONE = @compileError("use MACH.RCV and/or MACH.SEND with their default values"); |
| 160 | pub const STRICT_REPLY = @compileError("use MACH.RCV.STRICT_REPLY and/or MACH.SEND.STRICT_REPLY"); |
| 161 | |
| 162 | pub const TYPE = @compileError("use mach_msg_type_name_t members"); |
| 163 | }; |
| 164 | |
| 165 | pub const PORT = struct { |
| 166 | pub const NULL: mach_port_t = 0; |
| 167 | pub const RIGHT = @compileError("use mach_port_right_t members"); |
| 168 | }; |
| 169 | |
| 170 | pub const RCV = packed struct(integer_t) { |
| 171 | _0: u1 = 0, |
| 172 | /// Other flags are only valid if this one is set. |
| 173 | MSG: bool = true, |
| 174 | LARGE: bool = false, |
| 175 | LARGE_IDENTITY: bool = false, |
| 176 | _4: u4 = 0, |
| 177 | TIMEOUT: bool = false, |
| 178 | /// Shared between `RCV` and `SEND`. Used to be `MACH_RCV_NOTIFY`. |
| 179 | STRICT_REPLY: bool = false, |
| 180 | INTERRUPT: bool = false, |
| 181 | VOUCHER: bool = false, |
| 182 | GUARDED_DESC: bool = false, |
| 183 | _13: u1 = 0, |
| 184 | SYNC_WAIT: bool = false, |
| 185 | SYNC_PEEK: bool = false, |
| 186 | _16: u16 = 0, |
| 187 | }; |
| 188 | |
| 189 | pub const SEND = packed struct(integer_t) { |
| 190 | /// Other flags are only valid if this one is set. |
| 191 | MSG: bool = true, |
| 192 | _1: u3 = 0, |
| 193 | TIMEOUT: bool = false, |
| 194 | OVERRIDE: bool = false, |
| 195 | INTERRUPT: bool = false, |
| 196 | NOTIFY: bool = false, |
| 197 | _8: u1 = 0, |
| 198 | /// Shared between `RCV` and `SEND`. |
| 199 | STRICT_REPLY: bool = false, |
| 200 | _10: u6 = 0, |
| 201 | /// User-only. If you're the kernel, this bit is `MACH_SEND_ALWAYS`. |
| 202 | FILTER_NONFATAL: bool = false, |
| 203 | TRAILER: bool = false, |
| 204 | /// Synonymous to `MACH_SEND_NODENAP`. |
| 205 | NOIMPORTANCE: bool = false, |
| 206 | /// Kernel-only. |
| 207 | IMPORTANCE: bool = false, |
| 208 | SYNC_OVERRIDE: bool = false, |
| 209 | /// Synonymous to `MACH_SEND_SYNC_USE_THRPRI`. |
| 210 | PROPAGATE_QOS: bool = false, |
| 211 | /// Kernel-only. |
| 212 | KERNEL: bool = false, |
| 213 | SYNC_BOOTSTRAP_CHECKIN: bool = false, |
| 214 | _24: u8 = 0, |
| 215 | }; |
| 216 | |
| 217 | pub const TASK = struct { |
| 218 | pub const BASIC = struct { |
| 219 | pub const INFO = 20; |
| 220 | pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t); |
| 221 | }; |
| 222 | }; |
| 223 | }; |
| 224 | |
| 225 | pub const MACH_MSG_TYPE = @compileError("use use mach_msg_type_name_t members"); |
| 226 | pub const MACH_PORT_RIGHT = @compileError("use mach_port_right_t members"); |
| 227 | pub const MACH_TASK_BASIC_INFO = @compileError("use MACH.TASK.BASIC.INFO"); |
| 228 | pub const MACH_TASK_BASIC_INFO_COUNT = @compileError("use MACH.TASK.BASIC.INFO_COUNT"); |
| 229 | |
| 230 | pub const MATTR = struct { |
| 231 | /// Cachability |
| 232 | pub const CACHE: vm_machine_attribute_t = 1; |
| 233 | /// Migrability |
| 234 | pub const MIGRATE: vm_machine_attribute_t = 2; |
| 235 | /// Replicability |
| 236 | pub const REPLICATE: vm_machine_attribute_t = 4; |
| 237 | /// (Generic) turn attribute off |
| 238 | pub const VAL_OFF: vm_machine_attribute_t = 0; |
| 239 | /// (Generic) turn attribute on |
| 240 | pub const VAL_ON: vm_machine_attribute_t = 1; |
| 241 | /// (Generic) return current value |
| 242 | pub const VAL_GET: vm_machine_attribute_t = 2; |
| 243 | /// Flush from all caches |
| 244 | pub const VAL_CACHE_FLUSH: vm_machine_attribute_t = 6; |
| 245 | /// Flush from data caches |
| 246 | pub const VAL_DCACHE_FLUSH: vm_machine_attribute_t = 7; |
| 247 | /// Flush from instruction caches |
| 248 | pub const VAL_ICACHE_FLUSH: vm_machine_attribute_t = 8; |
| 249 | /// Sync I+D caches |
| 250 | pub const VAL_CACHE_SYNC: vm_machine_attribute_t = 9; |
| 251 | /// Get page info (stats) |
| 252 | pub const VAL_GET_INFO: vm_machine_attribute_t = 10; |
| 253 | }; |
| 254 | |
| 255 | pub const OS = struct { |
| 256 | pub const LOG_CATEGORY = struct { |
| 257 | pub const POINTS_OF_INTEREST: *const u8 = "PointsOfInterest"; |
| 258 | pub const DYNAMIC_TRACING: *const u8 = "DynamicTracing"; |
| 259 | pub const DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing"; |
| 260 | }; |
| 261 | }; |
| 262 | |
| 263 | pub const TASK = struct { |
| 264 | pub const NULL: task_t = 0; |
| 265 | |
| 266 | pub const VM = struct { |
| 267 | pub const INFO = 22; |
| 268 | pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t); |
| 269 | }; |
| 270 | }; |
| 271 | |
| 272 | pub const TASK_NULL = @compileError("use TASK.NULL"); |
| 273 | pub const TASK_VM_INFO = @compileError("use TASK.VM.INFO"); |
| 274 | pub const TASK_VM_INFO_COUNT = @compileError("use TASK.VM.INFO_COUNT"); |
| 275 | |
| 276 | pub const THREAD = struct { |
| 277 | pub const NULL: thread_t = 0; |
| 278 | |
| 279 | pub const BASIC = struct { |
| 280 | pub const INFO = 3; |
| 281 | pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t); |
| 282 | }; |
| 283 | |
| 284 | pub const IDENTIFIER = struct { |
| 285 | pub const INFO = 4; |
| 286 | pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t); |
| 287 | }; |
| 288 | |
| 289 | pub const STATE = struct { |
| 290 | pub const NONE = switch (native_arch) { |
| 291 | .aarch64 => 5, |
| 292 | .x86_64 => 13, |
| 293 | else => @compileError("unsupported arch"), |
| 294 | }; |
| 295 | }; |
| 296 | }; |
| 297 | |
| 298 | pub const THREAD_NULL = @compileError("use THREAD.NULL"); |
| 299 | pub const THREAD_BASIC_INFO = @compileError("use THREAD.BASIC.INFO"); |
| 300 | pub const THREAD_BASIC_INFO_COUNT = @compileError("use THREAD.BASIC.INFO_COUNT"); |
| 301 | pub const THREAD_IDENTIFIER_INFO_COUNT = @compileError("use THREAD.IDENTIFIER.INFO_COUNT"); |
| 302 | pub const THREAD_STATE_NONE = @compileError("use THREAD.STATE.NONE"); |
| 303 | |
| 304 | pub const VM = struct { |
| 305 | pub const INHERIT = struct { |
| 306 | pub const SHARE: vm_inherit_t = 0; |
| 307 | pub const COPY: vm_inherit_t = 1; |
| 308 | pub const NONE: vm_inherit_t = 2; |
| 309 | pub const DONATE_COPY: vm_inherit_t = 3; |
| 310 | pub const DEFAULT = VM.INHERIT.COPY; |
| 311 | }; |
| 312 | |
| 313 | pub const BEHAVIOR = struct { |
| 314 | pub const DEFAULT: vm_behavior_t = 0; |
| 315 | pub const RANDOM: vm_behavior_t = 1; |
| 316 | pub const SEQUENTIAL: vm_behavior_t = 2; |
| 317 | pub const RSEQNTL: vm_behavior_t = 3; |
| 318 | pub const WILLNEED: vm_behavior_t = 4; |
| 319 | pub const DONTNEED: vm_behavior_t = 5; |
| 320 | pub const FREE: vm_behavior_t = 6; |
| 321 | pub const ZERO_WIRED_PAGES: vm_behavior_t = 7; |
| 322 | pub const REUSABLE: vm_behavior_t = 8; |
| 323 | pub const REUSE: vm_behavior_t = 9; |
| 324 | pub const CAN_REUSE: vm_behavior_t = 10; |
| 325 | pub const PAGEOUT: vm_behavior_t = 11; |
| 326 | }; |
| 327 | |
| 328 | pub const REGION = struct { |
| 329 | pub const BASIC_INFO_64 = 9; |
| 330 | pub const EXTENDED_INFO = 13; |
| 331 | pub const TOP_INFO = 12; |
| 332 | pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t); |
| 333 | pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t); |
| 334 | pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int); |
| 335 | pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t); |
| 336 | pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t); |
| 337 | }; |
| 338 | |
| 339 | pub fn MAKE_TAG(tag: u8) u32 { |
| 340 | return @as(u32, tag) << 24; |
| 341 | } |
| 342 | }; |
| 163 | 343 | |
| 164 | 344 | pub const exception_type_t = c_int; |
| 165 | 345 | |
| ... | ... | @@ -293,7 +473,7 @@ pub extern "c" fn kevent64( |
| 293 | 473 | nchanges: c_int, |
| 294 | 474 | eventlist: [*]kevent64_s, |
| 295 | 475 | nevents: c_int, |
| 296 | | flags: c_uint, |
| 476 | flags: KEVENT.FLAG, |
| 297 | 477 | timeout: ?*const timespec, |
| 298 | 478 | ) c_int; |
| 299 | 479 | |
| ... | ... | @@ -321,11 +501,7 @@ pub const mach_vm_size_t = u64; |
| 321 | 501 | pub const mach_msg_bits_t = c_uint; |
| 322 | 502 | pub const mach_msg_id_t = integer_t; |
| 323 | 503 | pub const mach_msg_type_number_t = natural_t; |
| 324 | | pub const mach_msg_type_name_t = c_uint; |
| 325 | | pub const mach_msg_option_t = integer_t; |
| 326 | 504 | pub const mach_msg_size_t = natural_t; |
| 327 | | pub const mach_msg_timeout_t = natural_t; |
| 328 | | pub const mach_port_right_t = natural_t; |
| 329 | 505 | pub const task_t = mach_port_t; |
| 330 | 506 | pub const thread_port_t = task_t; |
| 331 | 507 | pub const thread_t = thread_port_t; |
| ... | ... | @@ -342,19 +518,21 @@ pub const thread_state_flavor_t = c_int; |
| 342 | 518 | pub const ipc_space_t = mach_port_t; |
| 343 | 519 | pub const ipc_space_port_t = ipc_space_t; |
| 344 | 520 | |
| 345 | | pub const MACH_PORT_RIGHT = enum(mach_port_right_t) { |
| 346 | | SEND = 0, |
| 347 | | RECEIVE = 1, |
| 348 | | SEND_ONCE = 2, |
| 349 | | PORT_SET = 3, |
| 350 | | DEAD_NAME = 4, |
| 351 | | /// Obsolete right |
| 352 | | LABELH = 5, |
| 353 | | /// Right not implemented |
| 354 | | NUMBER = 6, |
| 521 | pub const mach_msg_option_t = packed union { |
| 522 | RCV: MACH.RCV, |
| 523 | SEND: MACH.SEND, |
| 524 | |
| 525 | pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t { |
| 526 | return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv))); |
| 527 | } |
| 355 | 528 | }; |
| 356 | 529 | |
| 357 | | pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) { |
| 530 | pub const mach_msg_timeout_t = enum(natural_t) { |
| 531 | NONE = 0, |
| 532 | _, |
| 533 | }; |
| 534 | |
| 535 | pub const mach_msg_type_name_t = enum(c_uint) { |
| 358 | 536 | /// Must hold receive right |
| 359 | 537 | MOVE_RECEIVE = 16, |
| 360 | 538 | /// Must hold send right(s) |
| ... | ... | @@ -375,6 +553,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) { |
| 375 | 553 | DISPOSE_SEND = 25, |
| 376 | 554 | /// Must hold sendonce right |
| 377 | 555 | DISPOSE_SEND_ONCE = 26, |
| 556 | |
| 557 | _, |
| 558 | }; |
| 559 | |
| 560 | pub const mach_port_right_t = enum(natural_t) { |
| 561 | SEND = 0, |
| 562 | RECEIVE = 1, |
| 563 | SEND_ONCE = 2, |
| 564 | PORT_SET = 3, |
| 565 | DEAD_NAME = 4, |
| 566 | /// Obsolete right |
| 567 | LABELH = 5, |
| 568 | /// Right not implemented |
| 569 | NUMBER = 6, |
| 570 | |
| 571 | _, |
| 378 | 572 | }; |
| 379 | 573 | |
| 380 | 574 | extern "c" var mach_task_self_: mach_port_t; |
| ... | ... | @@ -390,7 +584,7 @@ pub extern "c" fn mach_msg( |
| 390 | 584 | rcv_name: mach_port_name_t, |
| 391 | 585 | timeout: mach_msg_timeout_t, |
| 392 | 586 | notify: mach_port_name_t, |
| 393 | | ) kern_return_t; |
| 587 | ) mach_msg_return_t; |
| 394 | 588 | |
| 395 | 589 | pub const mach_msg_header_t = extern struct { |
| 396 | 590 | msgh_bits: mach_msg_bits_t, |
| ... | ... | @@ -462,46 +656,6 @@ pub const vm_behavior_t = i32; |
| 462 | 656 | pub const vm32_object_id_t = u32; |
| 463 | 657 | pub const vm_object_id_t = u64; |
| 464 | 658 | |
| 465 | | pub const VM = struct { |
| 466 | | pub const INHERIT = struct { |
| 467 | | pub const SHARE: vm_inherit_t = 0; |
| 468 | | pub const COPY: vm_inherit_t = 1; |
| 469 | | pub const NONE: vm_inherit_t = 2; |
| 470 | | pub const DONATE_COPY: vm_inherit_t = 3; |
| 471 | | pub const DEFAULT = COPY; |
| 472 | | }; |
| 473 | | |
| 474 | | pub const BEHAVIOR = struct { |
| 475 | | pub const DEFAULT: vm_behavior_t = 0; |
| 476 | | pub const RANDOM: vm_behavior_t = 1; |
| 477 | | pub const SEQUENTIAL: vm_behavior_t = 2; |
| 478 | | pub const RSEQNTL: vm_behavior_t = 3; |
| 479 | | pub const WILLNEED: vm_behavior_t = 4; |
| 480 | | pub const DONTNEED: vm_behavior_t = 5; |
| 481 | | pub const FREE: vm_behavior_t = 6; |
| 482 | | pub const ZERO_WIRED_PAGES: vm_behavior_t = 7; |
| 483 | | pub const REUSABLE: vm_behavior_t = 8; |
| 484 | | pub const REUSE: vm_behavior_t = 9; |
| 485 | | pub const CAN_REUSE: vm_behavior_t = 10; |
| 486 | | pub const PAGEOUT: vm_behavior_t = 11; |
| 487 | | }; |
| 488 | | |
| 489 | | pub const REGION = struct { |
| 490 | | pub const BASIC_INFO_64 = 9; |
| 491 | | pub const EXTENDED_INFO = 13; |
| 492 | | pub const TOP_INFO = 12; |
| 493 | | pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t); |
| 494 | | pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t); |
| 495 | | pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int); |
| 496 | | pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t); |
| 497 | | pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t); |
| 498 | | }; |
| 499 | | |
| 500 | | pub fn MAKE_TAG(tag: u8) u32 { |
| 501 | | return @as(u32, tag) << 24; |
| 502 | | } |
| 503 | | }; |
| 504 | | |
| 505 | 659 | pub const vm_region_basic_info_64 = extern struct { |
| 506 | 660 | protection: vm_prot_t, |
| 507 | 661 | max_protection: vm_prot_t, |
| ... | ... | @@ -630,12 +784,6 @@ pub extern "c" fn thread_info( |
| 630 | 784 | ) kern_return_t; |
| 631 | 785 | pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t; |
| 632 | 786 | |
| 633 | | pub const THREAD_BASIC_INFO = 3; |
| 634 | | pub const THREAD_BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t); |
| 635 | | |
| 636 | | pub const THREAD_IDENTIFIER_INFO = 4; |
| 637 | | pub const THREAD_IDENTIFIER_INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t); |
| 638 | | |
| 639 | 787 | pub const thread_flavor_t = natural_t; |
| 640 | 788 | pub const thread_info_t = *integer_t; |
| 641 | 789 | pub const time_value_t = time_value; |
| ... | ... | @@ -678,34 +826,6 @@ pub const thread_identifier_info = extern struct { |
| 678 | 826 | dispatch_qaddr: u64, |
| 679 | 827 | }; |
| 680 | 828 | |
| 681 | | pub const MATTR = struct { |
| 682 | | /// Cachability |
| 683 | | pub const CACHE = 1; |
| 684 | | /// Migrability |
| 685 | | pub const MIGRATE = 2; |
| 686 | | /// Replicability |
| 687 | | pub const REPLICATE = 4; |
| 688 | | /// (Generic) turn attribute off |
| 689 | | pub const VAL_OFF = 0; |
| 690 | | /// (Generic) turn attribute on |
| 691 | | pub const VAL_ON = 1; |
| 692 | | /// (Generic) return current value |
| 693 | | pub const VAL_GET = 2; |
| 694 | | /// Flush from all caches |
| 695 | | pub const VAL_CACHE_FLUSH = 6; |
| 696 | | /// Flush from data caches |
| 697 | | pub const VAL_DCACHE_FLUSH = 7; |
| 698 | | /// Flush from instruction caches |
| 699 | | pub const VAL_ICACHE_FLUSH = 8; |
| 700 | | /// Sync I+D caches |
| 701 | | pub const VAL_CACHE_SYNC = 9; |
| 702 | | /// Get page info (stats) |
| 703 | | pub const VAL_GET_INFO = 10; |
| 704 | | }; |
| 705 | | |
| 706 | | pub const TASK_VM_INFO = 22; |
| 707 | | pub const TASK_VM_INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t); |
| 708 | | |
| 709 | 829 | pub const task_vm_info = extern struct { |
| 710 | 830 | // virtual memory size (bytes) |
| 711 | 831 | virtual_size: mach_vm_size_t, |
| ... | ... | @@ -791,8 +911,8 @@ pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t |
| 791 | 911 | pub extern "c" fn mach_port_insert_right( |
| 792 | 912 | task: ipc_space_t, |
| 793 | 913 | name: mach_port_name_t, |
| 794 | | poly: mach_port_t, |
| 795 | | poly_poly: mach_msg_type_name_t, |
| 914 | right: mach_port_t, |
| 915 | right_type: mach_msg_type_name_t, |
| 796 | 916 | ) kern_return_t; |
| 797 | 917 | |
| 798 | 918 | pub extern "c" fn task_info( |
| ... | ... | @@ -817,9 +937,6 @@ pub const mach_task_basic_info = extern struct { |
| 817 | 937 | suspend_count: mach_vm_size_t, |
| 818 | 938 | }; |
| 819 | 939 | |
| 820 | | pub const MACH_TASK_BASIC_INFO = 20; |
| 821 | | pub const MACH_TASK_BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t); |
| 822 | | |
| 823 | 940 | pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t; |
| 824 | 941 | pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t; |
| 825 | 942 | pub extern "c" fn vm_machine_attribute( |
| ... | ... | @@ -847,17 +964,19 @@ pub const NSIG = 32; |
| 847 | 964 | |
| 848 | 965 | pub const qos_class_t = enum(c_uint) { |
| 849 | 966 | /// highest priority QOS class for critical tasks |
| 850 | | QOS_CLASS_USER_INTERACTIVE = 0x21, |
| 967 | USER_INTERACTIVE = 0x21, |
| 851 | 968 | /// slightly more moderate priority QOS class |
| 852 | | QOS_CLASS_USER_INITIATED = 0x19, |
| 969 | USER_INITIATED = 0x19, |
| 853 | 970 | /// default QOS class when none is set |
| 854 | | QOS_CLASS_DEFAULT = 0x15, |
| 971 | DEFAULT = 0x15, |
| 855 | 972 | /// more energy efficient QOS class than default |
| 856 | | QOS_CLASS_UTILITY = 0x11, |
| 973 | UTILITY = 0x11, |
| 857 | 974 | /// QOS class more appropriate for background tasks |
| 858 | | QOS_CLASS_BACKGROUND = 0x09, |
| 975 | BACKGROUND = 0x09, |
| 859 | 976 | /// QOS class as a return value |
| 860 | | QOS_CLASS_UNSPECIFIED = 0x00, |
| 977 | UNSPECIFIED = 0x00, |
| 978 | |
| 979 | _, |
| 861 | 980 | }; |
| 862 | 981 | |
| 863 | 982 | // Grand Central Dispatch is exposed by libSystem. |
| ... | ... | @@ -868,13 +987,17 @@ pub extern "c" fn dispatch_semaphore_create(value: isize) ?dispatch_semaphore_t; |
| 868 | 987 | pub extern "c" fn dispatch_semaphore_wait(dsema: dispatch_semaphore_t, timeout: dispatch_time_t) isize; |
| 869 | 988 | pub extern "c" fn dispatch_semaphore_signal(dsema: dispatch_semaphore_t) isize; |
| 870 | 989 | |
| 871 | | pub const dispatch_time_t = u64; |
| 872 | | pub const DISPATCH_TIME_NOW = @as(dispatch_time_t, 0); |
| 873 | | pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0); |
| 990 | pub const DISPATCH_TIME_NOW = @compileError("use dispatch_time_t.NOW"); |
| 991 | pub const DISPATCH_TIME_FOREVER = @compileError("use dispatch_time_t.FOREVER"); |
| 992 | pub const dispatch_time_t = enum(u64) { |
| 993 | NOW = 0, |
| 994 | FOREVER = ~0, |
| 995 | _, |
| 996 | }; |
| 874 | 997 | pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t; |
| 875 | 998 | |
| 876 | | const dispatch_once_t = usize; |
| 877 | | const dispatch_function_t = fn (?*anyopaque) callconv(.c) void; |
| 999 | pub const dispatch_once_t = usize; |
| 1000 | pub const dispatch_function_t = fn (?*anyopaque) callconv(.c) void; |
| 878 | 1001 | pub extern fn dispatch_once_f( |
| 879 | 1002 | predicate: *dispatch_once_t, |
| 880 | 1003 | context: ?*anyopaque, |
| ... | ... | @@ -905,6 +1028,7 @@ pub const UL = packed struct(u32) { |
| 905 | 1028 | UNFAIR_LOCK64_SHARED = 4, |
| 906 | 1029 | COMPARE_AND_WAIT64 = 5, |
| 907 | 1030 | COMPARE_AND_WAIT64_SHARED = 6, |
| 1031 | _, |
| 908 | 1032 | }; |
| 909 | 1033 | }; |
| 910 | 1034 | |
| ... | ... | @@ -923,29 +1047,28 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool; |
| 923 | 1047 | pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void; |
| 924 | 1048 | pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void; |
| 925 | 1049 | |
| 926 | | pub const os_signpost_id_t = u64; |
| 927 | | |
| 928 | | pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0; |
| 929 | | pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0; |
| 930 | | pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee; |
| 1050 | pub const os_signpost_id_t = enum(u64) { |
| 1051 | NULL = 0, |
| 1052 | INVALID = !0, |
| 1053 | EXCLUSIVE = 0xeeeeb0b5b2b2eeee, |
| 1054 | _, |
| 1055 | }; |
| 931 | 1056 | |
| 932 | 1057 | pub const os_log_t = *opaque {}; |
| 933 | 1058 | pub const os_log_type_t = enum(u8) { |
| 934 | 1059 | /// default messages always captures |
| 935 | | OS_LOG_TYPE_DEFAULT = 0x00, |
| 1060 | DEFAULT = 0x00, |
| 936 | 1061 | /// messages with additional infos |
| 937 | | OS_LOG_TYPE_INFO = 0x01, |
| 1062 | INFO = 0x01, |
| 938 | 1063 | /// debug messages |
| 939 | | OS_LOG_TYPE_DEBUG = 0x02, |
| 1064 | DEBUG = 0x02, |
| 940 | 1065 | /// error messages |
| 941 | | OS_LOG_TYPE_ERROR = 0x10, |
| 1066 | ERROR = 0x10, |
| 942 | 1067 | /// unexpected conditions messages |
| 943 | | OS_LOG_TYPE_FAULT = 0x11, |
| 944 | | }; |
| 1068 | FAULT = 0x11, |
| 945 | 1069 | |
| 946 | | pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest"; |
| 947 | | pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing"; |
| 948 | | pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing"; |
| 1070 | _, |
| 1071 | }; |
| 949 | 1072 | |
| 950 | 1073 | pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t; |
| 951 | 1074 | pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool; |
| ... | ... | @@ -1012,35 +1135,11 @@ pub const vm_machine_attribute_val_t = isize; |
| 1012 | 1135 | |
| 1013 | 1136 | pub const CALENDAR_CLOCK = 1; |
| 1014 | 1137 | |
| 1015 | | /// no flag value |
| 1016 | | pub const KEVENT_FLAG_NONE = 0x000; |
| 1017 | | /// immediate timeout |
| 1018 | | pub const KEVENT_FLAG_IMMEDIATE = 0x001; |
| 1019 | | /// output events only include change |
| 1020 | | pub const KEVENT_FLAG_ERROR_EVENTS = 0x002; |
| 1021 | | |
| 1022 | 1138 | pub const SYSPROTO_EVENT = 1; |
| 1023 | 1139 | pub const SYSPROTO_CONTROL = 2; |
| 1024 | 1140 | |
| 1025 | | pub const mach_msg_return_t = kern_return_t; |
| 1026 | | |
| 1027 | | pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE { |
| 1028 | | return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err)))))); |
| 1029 | | } |
| 1030 | | |
| 1031 | | /// All special error code bits defined below. |
| 1032 | | pub const MACH_MSG_MASK: u32 = 0x3e00; |
| 1033 | | /// No room in IPC name space for another capability name. |
| 1034 | | pub const MACH_MSG_IPC_SPACE: u32 = 0x2000; |
| 1035 | | /// No room in VM address space for out-of-line memory. |
| 1036 | | pub const MACH_MSG_VM_SPACE: u32 = 0x1000; |
| 1037 | | /// Kernel resource shortage handling out-of-line memory. |
| 1038 | | pub const MACH_MSG_IPC_KERNEL: u32 = 0x800; |
| 1039 | | /// Kernel resource shortage handling an IPC capability. |
| 1040 | | pub const MACH_MSG_VM_KERNEL: u32 = 0x400; |
| 1041 | | |
| 1042 | 1141 | /// Mach msg return values |
| 1043 | | pub const MachMsgE = enum(u32) { |
| 1142 | pub const mach_msg_return_t = enum(kern_return_t) { |
| 1044 | 1143 | SUCCESS = 0x00000000, |
| 1045 | 1144 | |
| 1046 | 1145 | /// Thread is waiting to send. (Internal use only.) |
| ... | ... | @@ -1104,9 +1203,9 @@ pub const MachMsgE = enum(u32) { |
| 1104 | 1203 | RCV_PORT_DIED = 0x10004009, |
| 1105 | 1204 | /// compatibility: no longer a returned error |
| 1106 | 1205 | RCV_IN_SET = 0x1000400a, |
| 1107 | | /// Error receiving message header. See special bits. |
| 1206 | /// Error receiving message header. See special bits (use `extractResourceError`). |
| 1108 | 1207 | RCV_HEADER_ERROR = 0x1000400b, |
| 1109 | | /// Error receiving message body. See special bits. |
| 1208 | /// Error receiving message body. See special bits (use `extractResourceError`). |
| 1110 | 1209 | RCV_BODY_ERROR = 0x1000400c, |
| 1111 | 1210 | /// Invalid msg-type specification in scatter list. |
| 1112 | 1211 | RCV_INVALID_TYPE = 0x1000400d, |
| ... | ... | @@ -1118,6 +1217,28 @@ pub const MachMsgE = enum(u32) { |
| 1118 | 1217 | RCV_IN_PROGRESS_TIMED = 0x10004011, |
| 1119 | 1218 | /// invalid reply port used in a STRICT_REPLY message |
| 1120 | 1219 | RCV_INVALID_REPLY = 0x10004012, |
| 1220 | |
| 1221 | _, |
| 1222 | |
| 1223 | pub fn extractResourceError(ret: mach_msg_return_t) struct { |
| 1224 | error_code: mach_msg_return_t, |
| 1225 | resource_error: ?MACH.MSG, |
| 1226 | } { |
| 1227 | const return_code: mach_msg_return_t = @enumFromInt(@intFromEnum(ret) & ~MACH.MSG.MASK); |
| 1228 | switch (return_code) { |
| 1229 | .RCV_HEADER_ERROR, .RCV_BODY_ERROR => { |
| 1230 | const resource_error: MACH.MSG = @bitCast(@intFromEnum(ret) & MACH.MSG.MASK); |
| 1231 | return .{ |
| 1232 | .error_code = return_code, |
| 1233 | .resource_error = resource_error, |
| 1234 | }; |
| 1235 | }, |
| 1236 | else => return .{ |
| 1237 | .error_code = ret, |
| 1238 | .resource_error = null, |
| 1239 | }, |
| 1240 | } |
| 1241 | } |
| 1121 | 1242 | }; |
| 1122 | 1243 | |
| 1123 | 1244 | pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000; |
| ... | ... | @@ -1171,48 +1292,53 @@ pub const CPUFAMILY = enum(u32) { |
| 1171 | 1292 | _, |
| 1172 | 1293 | }; |
| 1173 | 1294 | |
| 1174 | | pub const PT = struct { |
| 1175 | | pub const TRACE_ME = 0; |
| 1176 | | pub const READ_I = 1; |
| 1177 | | pub const READ_D = 2; |
| 1178 | | pub const READ_U = 3; |
| 1179 | | pub const WRITE_I = 4; |
| 1180 | | pub const WRITE_D = 5; |
| 1181 | | pub const WRITE_U = 6; |
| 1182 | | pub const CONTINUE = 7; |
| 1183 | | pub const KILL = 8; |
| 1184 | | pub const STEP = 9; |
| 1185 | | pub const DETACH = 11; |
| 1186 | | pub const SIGEXC = 12; |
| 1187 | | pub const THUPDATE = 13; |
| 1188 | | pub const ATTACHEXC = 14; |
| 1189 | | pub const FORCEQUOTA = 30; |
| 1190 | | pub const DENY_ATTACH = 31; |
| 1295 | pub const PT = enum(c_int) { |
| 1296 | TRACE_ME = 0, |
| 1297 | READ_I = 1, |
| 1298 | READ_D = 2, |
| 1299 | READ_U = 3, |
| 1300 | WRITE_I = 4, |
| 1301 | WRITE_D = 5, |
| 1302 | WRITE_U = 6, |
| 1303 | CONTINUE = 7, |
| 1304 | KILL = 8, |
| 1305 | STEP = 9, |
| 1306 | DETACH = 11, |
| 1307 | SIGEXC = 12, |
| 1308 | THUPDATE = 13, |
| 1309 | ATTACHEXC = 14, |
| 1310 | FORCEQUOTA = 30, |
| 1311 | DENY_ATTACH = 31, |
| 1312 | _, |
| 1191 | 1313 | }; |
| 1192 | 1314 | |
| 1193 | 1315 | pub const caddr_t = ?[*]u8; |
| 1194 | 1316 | |
| 1195 | | pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int; |
| 1196 | | |
| 1197 | | pub const POSIX_SPAWN = struct { |
| 1198 | | pub const RESETIDS = 0x0001; |
| 1199 | | pub const SETPGROUP = 0x0002; |
| 1200 | | pub const SETSIGDEF = 0x0004; |
| 1201 | | pub const SETSIGMASK = 0x0008; |
| 1202 | | pub const SETEXEC = 0x0040; |
| 1203 | | pub const START_SUSPENDED = 0x0080; |
| 1204 | | pub const DISABLE_ASLR = 0x0100; |
| 1205 | | pub const SETSID = 0x0400; |
| 1206 | | pub const RESLIDE = 0x0800; |
| 1207 | | pub const CLOEXEC_DEFAULT = 0x4000; |
| 1317 | pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int; |
| 1318 | |
| 1319 | pub const POSIX_SPAWN = packed struct(c_short) { |
| 1320 | RESETIDS: bool = false, |
| 1321 | SETPGROUP: bool = false, |
| 1322 | SETSIGDEF: bool = false, |
| 1323 | SETSIGMASK: bool = false, |
| 1324 | _4: u2 = 0, |
| 1325 | SETEXEC: bool = false, |
| 1326 | START_SUSPENDED: bool = false, |
| 1327 | DISABLE_ASLR: bool = false, |
| 1328 | _9: u1 = 0, |
| 1329 | SETSID: bool = false, |
| 1330 | RESLIDE: bool = false, |
| 1331 | _12: u2 = 0, |
| 1332 | CLOEXEC_DEFAULT: bool = false, |
| 1333 | _15: u1 = 0, |
| 1208 | 1334 | }; |
| 1209 | 1335 | |
| 1210 | 1336 | pub const posix_spawnattr_t = *opaque {}; |
| 1211 | 1337 | pub const posix_spawn_file_actions_t = *opaque {}; |
| 1212 | 1338 | pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int; |
| 1213 | 1339 | pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int; |
| 1214 | | pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int; |
| 1215 | | pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int; |
| 1340 | pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int; |
| 1341 | pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int; |
| 1216 | 1342 | pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int; |
| 1217 | 1343 | pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int; |
| 1218 | 1344 | pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int; |