1const std = @import("std");
2const builtin = @import("builtin");
3const native_arch = builtin.target.cpu.arch;
4const assert = std.debug.assert;
5const AF = std.c.AF;
6const PROT = std.c.PROT;
7const caddr_t = std.c.caddr_t;
8const fd_t = std.c.fd_t;
9const iovec_const = std.posix.iovec_const;
10const mode_t = std.c.mode_t;
11const off_t = std.c.off_t;
12const pid_t = std.c.pid_t;
13const pthread_attr_t = std.c.pthread_attr_t;
14const timespec = std.c.timespec;
15const sf_hdtr = std.c.sf_hdtr;
16
17comptime {
18 assert(builtin.os.tag.isDarwin()); // Prevent access of std.c symbols on wrong OS.
19}
20
21// Grand Central Dispatch is exposed by libSystem.
22pub const dispatch = @import("darwin/dispatch.zig");
23
24pub const mach_port_t = c_uint;
25
26pub const EXC = enum(exception_type_t) {
27 NULL = 0,
28 /// Could not access memory
29 BAD_ACCESS = 1,
30 /// Instruction failed
31 BAD_INSTRUCTION = 2,
32 /// Arithmetic exception
33 ARITHMETIC = 3,
34 /// Emulation instruction
35 EMULATION = 4,
36 /// Software generated exception
37 SOFTWARE = 5,
38 /// Trace, breakpoint, etc.
39 BREAKPOINT = 6,
40 /// System calls.
41 SYSCALL = 7,
42 /// Mach system calls.
43 MACH_SYSCALL = 8,
44 /// RPC alert
45 RPC_ALERT = 9,
46 /// Abnormal process exit
47 CRASH = 10,
48 /// Hit resource consumption limit
49 RESOURCE = 11,
50 /// Violated guarded resource protections
51 GUARD = 12,
52 /// Abnormal process exited to corpse state
53 CORPSE_NOTIFY = 13,
54
55 _,
56
57 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".field_names.len;
58 pub const SOFT_SIGNAL = 0x10003;
59
60 pub const MASK = packed struct(u32) {
61 _0: u1 = 0,
62 BAD_ACCESS: bool = false,
63 BAD_INSTRUCTION: bool = false,
64 ARITHMETIC: bool = false,
65 EMULATION: bool = false,
66 SOFTWARE: bool = false,
67 BREAKPOINT: bool = false,
68 SYSCALL: bool = false,
69 MACH_SYSCALL: bool = false,
70 RPC_ALERT: bool = false,
71 CRASH: bool = false,
72 RESOURCE: bool = false,
73 GUARD: bool = false,
74 CORPSE_NOTIFY: bool = false,
75 _14: u18 = 0,
76
77 pub const MACHINE: MASK = @bitCast(@as(u32, 0));
78
79 pub const ALL: MASK = .{
80 .BAD_ACCESS = true,
81 .BAD_INSTRUCTION = true,
82 .ARITHMETIC = true,
83 .EMULATION = true,
84 .SOFTWARE = true,
85 .BREAKPOINT = true,
86 .SYSCALL = true,
87 .MACH_SYSCALL = true,
88 .RPC_ALERT = true,
89 .CRASH = true,
90 .RESOURCE = true,
91 .GUARD = true,
92 .CORPSE_NOTIFY = true,
93 };
94 };
95};
96
97pub const EXCEPTION = enum(u32) {
98 /// Send a catch_exception_raise message including the identity.
99 DEFAULT = 1,
100 /// Send a catch_exception_raise_state message including the
101 /// thread state.
102 STATE = 2,
103 /// Send a catch_exception_raise_state_identity message including
104 /// the thread identity and state.
105 STATE_IDENTITY = 3,
106 /// Send a catch_exception_raise_identity_protected message including protected task
107 /// and thread identity.
108 IDENTITY_PROTECTED = 4,
109
110 _,
111};
112
113pub const KEVENT = struct {
114 /// Used as the `flags` arg for `kevent64`.
115 pub const FLAG = packed struct(c_uint) {
116 /// immediate timeout
117 IMMEDIATE: bool = false,
118 /// output events only include change
119 ERROR_EVENTS: bool = false,
120 _: u30 = 0,
121
122 /// no flag value
123 pub const NONE: KEVENT.FLAG = .{
124 .IMMEDIATE = false,
125 .ERROR_EVENTS = false,
126 };
127 };
128};
129
130pub const MACH = struct {
131 pub const EXCEPTION = packed struct(exception_mask_t) {
132 _: u29 = 0,
133 /// Prefer sending a catch_exception_raice_backtrace message, if applicable.
134 BACKTRACE_PREFERRED: bool = false,
135 /// include additional exception specific errors, not used yet.
136 ERRORS: bool = false,
137 /// Send 64-bit code and subcode in the exception header */
138 CODES: bool = false,
139
140 pub const MASK: exception_mask_t = @bitCast(MACH.EXCEPTION{
141 .BACKTRACE_PREFERRED = true,
142 .ERRORS = true,
143 .CODES = true,
144 });
145 };
146
147 pub const MSG = packed struct(kern_return_t) {
148 _0: u10 = 0,
149 /// Kernel resource shortage handling an IPC capability.
150 VM_KERNEL: bool = false,
151 /// Kernel resource shortage handling out-of-line memory.
152 IPC_KERNEL: bool = false,
153 /// No room in VM address space for out-of-line memory.
154 VM_SPACE: bool = false,
155 /// No room in IPC name space for another capability name.
156 IPC_SPACE: bool = false,
157 _14: u18 = 0,
158
159 pub const MASK: kern_return_t = @bitCast(MACH.MSG{
160 .VM_KERNEL = true,
161 .IPC_KERNEL = true,
162 .VM_SPACE = true,
163 .IPC_SPACE = true,
164 });
165
166 pub const TIMEOUT_NONE: mach_msg_timeout_t = .NONE;
167 pub const OPTION_NONE: mach_msg_option_t = .NONE;
168 pub const STRICT_REPLY = @compileError("use MACH.RCV.STRICT_REPLY and/or MACH.SEND.STRICT_REPLY");
169
170 pub const TYPE = mach_msg_type_name_t;
171 };
172
173 pub const PORT = struct {
174 pub const NULL: mach_port_t = 0;
175 pub const RIGHT = mach_port_right_t;
176 };
177
178 pub const RCV = packed struct(integer_t) {
179 _0: u1 = 0,
180 /// Other flags are only valid if this one is set.
181 MSG: bool = true,
182 LARGE: bool = false,
183 LARGE_IDENTITY: bool = false,
184 _4: u4 = 0,
185 TIMEOUT: bool = false,
186 /// Shared between `RCV` and `SEND`. Used to be `MACH_RCV_NOTIFY`.
187 STRICT_REPLY: bool = false,
188 INTERRUPT: bool = false,
189 VOUCHER: bool = false,
190 GUARDED_DESC: bool = false,
191 _13: u1 = 0,
192 SYNC_WAIT: bool = false,
193 SYNC_PEEK: bool = false,
194 _16: u16 = 0,
195 };
196
197 pub const SEND = packed struct(integer_t) {
198 /// Other flags are only valid if this one is set.
199 MSG: bool = true,
200 _1: u3 = 0,
201 TIMEOUT: bool = false,
202 OVERRIDE: bool = false,
203 INTERRUPT: bool = false,
204 NOTIFY: bool = false,
205 _8: u1 = 0,
206 /// Shared between `RCV` and `SEND`.
207 STRICT_REPLY: bool = false,
208 _10: u6 = 0,
209 /// User-only. If you're the kernel, this bit is `MACH_SEND_ALWAYS`.
210 FILTER_NONFATAL: bool = false,
211 TRAILER: bool = false,
212 /// Synonymous to `MACH_SEND_NODENAP`.
213 NOIMPORTANCE: bool = false,
214 /// Kernel-only.
215 IMPORTANCE: bool = false,
216 SYNC_OVERRIDE: bool = false,
217 /// Synonymous to `MACH_SEND_SYNC_USE_THRPRI`.
218 PROPAGATE_QOS: bool = false,
219 /// Kernel-only.
220 KERNEL: bool = false,
221 SYNC_BOOTSTRAP_CHECKIN: bool = false,
222 _24: u8 = 0,
223 };
224
225 pub const TASK = struct {
226 pub const BASIC = struct {
227 pub const INFO = 20;
228 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t);
229 };
230 };
231};
232
233pub const MACH_MSG_TYPE = @compileError("use MACH.MSG.TYPE");
234pub const MACH_PORT_RIGHT = @compileError("use MACH.PORT.RIGHT");
235pub const MACH_TASK_BASIC_INFO = @compileError("use MACH.TASK.BASIC.INFO");
236pub const MACH_TASK_BASIC_INFO_COUNT = @compileError("use MACH.TASK.BASIC.INFO_COUNT");
237
238pub const MATTR = struct {
239 /// Cachability
240 pub const CACHE: vm_machine_attribute_t = 1;
241 /// Migrability
242 pub const MIGRATE: vm_machine_attribute_t = 2;
243 /// Replicability
244 pub const REPLICATE: vm_machine_attribute_t = 4;
245 /// (Generic) turn attribute off
246 pub const VAL_OFF: vm_machine_attribute_t = 0;
247 /// (Generic) turn attribute on
248 pub const VAL_ON: vm_machine_attribute_t = 1;
249 /// (Generic) return current value
250 pub const VAL_GET: vm_machine_attribute_t = 2;
251 /// Flush from all caches
252 pub const VAL_CACHE_FLUSH: vm_machine_attribute_t = 6;
253 /// Flush from data caches
254 pub const VAL_DCACHE_FLUSH: vm_machine_attribute_t = 7;
255 /// Flush from instruction caches
256 pub const VAL_ICACHE_FLUSH: vm_machine_attribute_t = 8;
257 /// Sync I+D caches
258 pub const VAL_CACHE_SYNC: vm_machine_attribute_t = 9;
259 /// Get page info (stats)
260 pub const VAL_GET_INFO: vm_machine_attribute_t = 10;
261};
262
263pub const OS = struct {
264 pub const LOG_CATEGORY = struct {
265 pub const POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
266 pub const DYNAMIC_TRACING: *const u8 = "DynamicTracing";
267 pub const DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
268 };
269};
270
271pub const TASK = struct {
272 pub const NULL: task_t = 0;
273
274 pub const VM = struct {
275 pub const INFO = 22;
276 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t);
277 };
278};
279
280pub const TASK_NULL = @compileError("use TASK.NULL");
281pub const TASK_VM_INFO = @compileError("use TASK.VM.INFO");
282pub const TASK_VM_INFO_COUNT = @compileError("use TASK.VM.INFO_COUNT");
283
284pub const THREAD = struct {
285 pub const NULL: thread_t = 0;
286
287 pub const BASIC = struct {
288 pub const INFO = 3;
289 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t);
290 };
291
292 pub const IDENTIFIER = struct {
293 pub const INFO = 4;
294 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t);
295 };
296
297 pub const STATE = struct {
298 pub const NONE = switch (native_arch) {
299 .aarch64 => 5,
300 .x86_64 => 13,
301 else => @compileError("unsupported arch"),
302 };
303 };
304};
305
306pub const THREAD_NULL = @compileError("use THREAD.NULL");
307pub const THREAD_BASIC_INFO = @compileError("use THREAD.BASIC.INFO");
308pub const THREAD_BASIC_INFO_COUNT = @compileError("use THREAD.BASIC.INFO_COUNT");
309pub const THREAD_IDENTIFIER_INFO_COUNT = @compileError("use THREAD.IDENTIFIER.INFO_COUNT");
310pub const THREAD_STATE_NONE = @compileError("use THREAD.STATE.NONE");
311
312pub const VM = struct {
313 pub const INHERIT = struct {
314 pub const SHARE: vm_inherit_t = 0;
315 pub const COPY: vm_inherit_t = 1;
316 pub const NONE: vm_inherit_t = 2;
317 pub const DONATE_COPY: vm_inherit_t = 3;
318 pub const DEFAULT = VM.INHERIT.COPY;
319 };
320
321 pub const BEHAVIOR = struct {
322 pub const DEFAULT: vm_behavior_t = 0;
323 pub const RANDOM: vm_behavior_t = 1;
324 pub const SEQUENTIAL: vm_behavior_t = 2;
325 pub const RSEQNTL: vm_behavior_t = 3;
326 pub const WILLNEED: vm_behavior_t = 4;
327 pub const DONTNEED: vm_behavior_t = 5;
328 pub const FREE: vm_behavior_t = 6;
329 pub const ZERO_WIRED_PAGES: vm_behavior_t = 7;
330 pub const REUSABLE: vm_behavior_t = 8;
331 pub const REUSE: vm_behavior_t = 9;
332 pub const CAN_REUSE: vm_behavior_t = 10;
333 pub const PAGEOUT: vm_behavior_t = 11;
334 };
335
336 pub const REGION = struct {
337 pub const BASIC_INFO_64 = 9;
338 pub const EXTENDED_INFO = 13;
339 pub const TOP_INFO = 12;
340 pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t);
341 pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t);
342 pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int);
343 pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t);
344 pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t);
345 };
346
347 pub fn MAKE_TAG(tag: u8) u32 {
348 return @as(u32, tag) << 24;
349 }
350};
351
352pub const exception_type_t = c_int;
353
354pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
355pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
356pub extern "c" fn _dyld_image_count() u32;
357pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
358pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
359pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
360pub extern "c" fn _dyld_get_image_header_containing_address(address: *const anyopaque) ?*mach_header;
361pub extern "c" fn dyld_image_path_containing_address(address: *const anyopaque) ?[*:0]const u8;
362pub extern "c" fn dladdr(addr: *const anyopaque, info: *dl_info) c_int;
363
364pub const dl_info = extern struct {
365 fname: [*:0]const u8,
366 fbase: *anyopaque,
367 sname: ?[*:0]const u8,
368 saddr: ?*anyopaque,
369};
370
371pub const COPYFILE = packed struct(u32) {
372 ACL: bool = false,
373 STAT: bool = false,
374 XATTR: bool = false,
375 DATA: bool = false,
376 _: u28 = 0,
377};
378
379pub const copyfile_state_t = *opaque {};
380pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: COPYFILE) c_int;
381pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
382
383pub const RENAME = packed struct(u32) {
384 SECLUDE: bool = false,
385 SWAP: bool = false,
386 EXCL: bool = false,
387 RESERVED1: bool = false,
388 NOFOLLOW_ANY: bool = false,
389 RESOLVE_BENEATH: bool = false,
390 _: u26 = 0,
391};
392
393pub extern "c" fn renameatx_np(fromfd: c_int, from: [*:0]const u8, tofd: c_int, to: [*:0]const u8, flags: RENAME) c_int;
394
395pub extern "c" fn mach_absolute_time() u64;
396pub extern "c" fn mach_continuous_time() u64;
397pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) kern_return_t;
398
399pub extern "c" fn kevent64(
400 kq: c_int,
401 changelist: [*]const kevent64_s,
402 nchanges: c_int,
403 eventlist: [*]kevent64_s,
404 nevents: c_int,
405 flags: KEVENT.FLAG,
406 timeout: ?*const timespec,
407) c_int;
408
409pub const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
410
411pub const mach_header_64 = std.macho.mach_header_64;
412pub const mach_header = std.macho.mach_header;
413
414pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
415pub extern "c" fn mach_host_self() mach_port_t;
416pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
417pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, ...) c_int;
418
419pub const exception_data_type_t = integer_t;
420pub const exception_data_t = ?*mach_exception_data_type_t;
421pub const mach_exception_data_type_t = i64;
422pub const mach_exception_data_t = ?*mach_exception_data_type_t;
423pub const vm_map_t = mach_port_t;
424pub const vm_map_read_t = mach_port_t;
425pub const vm_region_flavor_t = c_int;
426pub const vm_region_info_t = *c_int;
427pub const vm_region_recurse_info_t = *c_int;
428pub const mach_vm_address_t = usize;
429pub const vm_offset_t = usize;
430pub const mach_vm_size_t = u64;
431pub const mach_msg_bits_t = c_uint;
432pub const mach_msg_id_t = integer_t;
433pub const mach_msg_type_number_t = natural_t;
434pub const mach_msg_size_t = natural_t;
435pub const task_t = mach_port_t;
436pub const thread_port_t = task_t;
437pub const thread_t = thread_port_t;
438pub const exception_mask_t = c_uint;
439pub const exception_mask_array_t = [*]exception_mask_t;
440pub const exception_handler_t = mach_port_t;
441pub const exception_handler_array_t = [*]exception_handler_t;
442pub const exception_port_t = exception_handler_t;
443pub const exception_port_array_t = exception_handler_array_t;
444pub const exception_flavor_array_t = [*]thread_state_flavor_t;
445pub const exception_behavior_t = c_uint;
446pub const exception_behavior_array_t = [*]exception_behavior_t;
447pub const thread_state_flavor_t = c_int;
448pub const ipc_space_t = mach_port_t;
449pub const ipc_space_port_t = ipc_space_t;
450
451pub const mach_msg_option_t = packed union(integer_t) {
452 RCV: MACH.RCV,
453 SEND: MACH.SEND,
454
455 pub const NONE: mach_msg_option_t = @bitCast(@as(integer_t, 0));
456
457 pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t {
458 return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv)));
459 }
460};
461
462pub const mach_msg_timeout_t = enum(natural_t) {
463 NONE = 0,
464 _,
465};
466
467pub const mach_msg_type_name_t = enum(c_uint) {
468 /// Must hold receive right
469 MOVE_RECEIVE = 16,
470 /// Must hold send right(s)
471 MOVE_SEND = 17,
472 /// Must hold sendonce right
473 MOVE_SEND_ONCE = 18,
474 /// Must hold send right(s)
475 COPY_SEND = 19,
476 /// Must hold receive right
477 MAKE_SEND = 20,
478 /// Must hold receive right
479 MAKE_SEND_ONCE = 21,
480 /// NOT VALID
481 COPY_RECEIVE = 22,
482 /// Must hold receive right
483 DISPOSE_RECEIVE = 24,
484 /// Must hold send right(s)
485 DISPOSE_SEND = 25,
486 /// Must hold sendonce right
487 DISPOSE_SEND_ONCE = 26,
488
489 _,
490};
491
492pub const mach_port_right_t = enum(natural_t) {
493 SEND = 0,
494 RECEIVE = 1,
495 SEND_ONCE = 2,
496 PORT_SET = 3,
497 DEAD_NAME = 4,
498 /// Obsolete right
499 LABELH = 5,
500 /// Right not implemented
501 NUMBER = 6,
502
503 _,
504};
505
506extern "c" var mach_task_self_: mach_port_t;
507pub fn mach_task_self() callconv(.c) mach_port_t {
508 return mach_task_self_;
509}
510
511pub extern "c" fn mach_msg(
512 msg: ?*mach_msg_header_t,
513 option: mach_msg_option_t,
514 send_size: mach_msg_size_t,
515 rcv_size: mach_msg_size_t,
516 rcv_name: mach_port_name_t,
517 timeout: mach_msg_timeout_t,
518 notify: mach_port_name_t,
519) mach_msg_return_t;
520
521pub const mach_msg_header_t = extern struct {
522 msgh_bits: mach_msg_bits_t,
523 msgh_size: mach_msg_size_t,
524 msgh_remote_port: mach_port_t,
525 msgh_local_port: mach_port_t,
526 msgh_voucher_port: mach_port_name_t,
527 msgh_id: mach_msg_id_t,
528};
529
530pub extern "c" fn task_get_exception_ports(
531 task: task_t,
532 exception_mask: exception_mask_t,
533 masks: exception_mask_array_t,
534 masks_cnt: *mach_msg_type_number_t,
535 old_handlers: exception_handler_array_t,
536 old_behaviors: exception_behavior_array_t,
537 old_flavors: exception_flavor_array_t,
538) kern_return_t;
539pub extern "c" fn task_set_exception_ports(
540 task: task_t,
541 exception_mask: exception_mask_t,
542 new_port: mach_port_t,
543 behavior: exception_behavior_t,
544 new_flavor: thread_state_flavor_t,
545) kern_return_t;
546
547pub const task_read_t = mach_port_t;
548
549pub extern "c" fn task_resume(target_task: task_read_t) kern_return_t;
550pub extern "c" fn task_suspend(target_task: task_read_t) kern_return_t;
551
552pub extern "c" fn task_for_pid(target_tport: mach_port_name_t, pid: pid_t, t: *mach_port_name_t) kern_return_t;
553pub extern "c" fn pid_for_task(target_tport: mach_port_name_t, pid: *pid_t) kern_return_t;
554pub extern "c" fn mach_vm_read(
555 target_task: vm_map_read_t,
556 address: mach_vm_address_t,
557 size: mach_vm_size_t,
558 data: *vm_offset_t,
559 data_cnt: *mach_msg_type_number_t,
560) kern_return_t;
561pub extern "c" fn mach_vm_read_overwrite(
562 target_task: vm_map_read_t,
563 address: mach_vm_address_t,
564 size: mach_vm_size_t,
565 data: mach_vm_address_t,
566 outsize: *mach_vm_size_t,
567) kern_return_t;
568pub extern "c" fn mach_vm_write(
569 target_task: vm_map_t,
570 address: mach_vm_address_t,
571 data: vm_offset_t,
572 data_cnt: mach_msg_type_number_t,
573) kern_return_t;
574pub extern "c" fn mach_vm_region(
575 target_task: vm_map_t,
576 address: *mach_vm_address_t,
577 size: *mach_vm_size_t,
578 flavor: vm_region_flavor_t,
579 info: vm_region_info_t,
580 info_cnt: *mach_msg_type_number_t,
581 object_name: *mach_port_t,
582) kern_return_t;
583pub extern "c" fn mach_vm_region_recurse(
584 target_task: vm_map_t,
585 address: *mach_vm_address_t,
586 size: *mach_vm_size_t,
587 nesting_depth: *natural_t,
588 info: vm_region_recurse_info_t,
589 info_cnt: *mach_msg_type_number_t,
590) kern_return_t;
591
592pub const vm_inherit_t = u32;
593pub const memory_object_offset_t = u64;
594pub const vm_behavior_t = i32;
595pub const vm32_object_id_t = u32;
596pub const vm_object_id_t = u64;
597
598pub const vm_region_basic_info_64 = extern struct {
599 protection: vm_prot_t,
600 max_protection: vm_prot_t,
601 inheritance: vm_inherit_t,
602 shared: boolean_t,
603 reserved: boolean_t,
604 offset: memory_object_offset_t,
605 behavior: vm_behavior_t,
606 user_wired_count: u16,
607};
608
609pub const vm_region_extended_info = extern struct {
610 protection: vm_prot_t,
611 user_tag: u32,
612 pages_resident: u32,
613 pages_shared_now_private: u32,
614 pages_swapped_out: u32,
615 pages_dirtied: u32,
616 ref_count: u32,
617 shadow_depth: u16,
618 external_pager: u8,
619 share_mode: u8,
620 pages_reusable: u32,
621};
622
623pub const vm_region_top_info = extern struct {
624 obj_id: u32,
625 ref_count: u32,
626 private_pages_resident: u32,
627 shared_pages_resident: u32,
628 share_mode: u8,
629};
630
631pub const vm_region_submap_info_64 = extern struct {
632 // present across protection
633 protection: vm_prot_t,
634 // max avail through vm_prot
635 max_protection: vm_prot_t,
636 // behavior of map/obj on fork
637 inheritance: vm_inherit_t,
638 // offset into object/map
639 offset: memory_object_offset_t,
640 // user tag on map entry
641 user_tag: u32,
642 // only valid for objects
643 pages_resident: u32,
644 // only for objects
645 pages_shared_now_private: u32,
646 // only for objects
647 pages_swapped_out: u32,
648 // only for objects
649 pages_dirtied: u32,
650 // obj/map mappers, etc.
651 ref_count: u32,
652 // only for obj
653 shadow_depth: u16,
654 // only for obj
655 external_pager: u8,
656 // see enumeration
657 share_mode: u8,
658 // submap vs obj
659 is_submap: boolean_t,
660 // access behavior hint
661 behavior: vm_behavior_t,
662 // obj/map name, not a handle
663 object_id: vm32_object_id_t,
664 user_wired_count: u16,
665 pages_reusable: u32,
666 object_id_full: vm_object_id_t,
667};
668
669pub const vm_region_submap_short_info_64 = extern struct {
670 // present access protection
671 protection: vm_prot_t,
672 // max avail through vm_prot
673 max_protection: vm_prot_t,
674 // behavior of map/obj on fork
675 inheritance: vm_inherit_t,
676 // offset into object/map
677 offset: memory_object_offset_t,
678 // user tag on map entry
679 user_tag: u32,
680 // obj/map mappers, etc
681 ref_count: u32,
682 // only for obj
683 shadow_depth: u16,
684 // only for obj
685 external_pager: u8,
686 // see enumeration
687 share_mode: u8,
688 // submap vs obj
689 is_submap: boolean_t,
690 // access behavior hint
691 behavior: vm_behavior_t,
692 // obj/map name, not a handle
693 object_id: vm32_object_id_t,
694 user_wired_count: u16,
695};
696
697pub const thread_act_t = mach_port_t;
698pub const thread_state_t = *natural_t;
699pub const mach_port_array_t = [*]mach_port_t;
700
701pub extern "c" fn task_threads(
702 target_task: mach_port_t,
703 init_port_set: *mach_port_array_t,
704 init_port_count: *mach_msg_type_number_t,
705) kern_return_t;
706pub extern "c" fn thread_get_state(
707 thread: thread_act_t,
708 flavor: thread_flavor_t,
709 state: thread_state_t,
710 count: *mach_msg_type_number_t,
711) kern_return_t;
712pub extern "c" fn thread_set_state(
713 thread: thread_act_t,
714 flavor: thread_flavor_t,
715 new_state: thread_state_t,
716 count: mach_msg_type_number_t,
717) kern_return_t;
718pub extern "c" fn thread_info(
719 thread: thread_act_t,
720 flavor: thread_flavor_t,
721 info: thread_info_t,
722 count: *mach_msg_type_number_t,
723) kern_return_t;
724pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t;
725
726pub const thread_flavor_t = natural_t;
727pub const thread_info_t = *integer_t;
728pub const time_value_t = time_value;
729pub const task_policy_flavor_t = natural_t;
730pub const task_policy_t = *integer_t;
731pub const policy_t = c_int;
732
733pub const time_value = extern struct {
734 seconds: integer_t,
735 microseconds: integer_t,
736};
737
738pub const thread_basic_info = extern struct {
739 // user run time
740 user_time: time_value_t,
741 // system run time
742 system_time: time_value_t,
743 // scaled cpu usage percentage
744 cpu_usage: integer_t,
745 // scheduling policy in effect
746 policy: policy_t,
747 // run state
748 run_state: integer_t,
749 // various flags
750 flags: integer_t,
751 // suspend count for thread
752 suspend_count: integer_t,
753 // number of seconds that thread has been sleeping
754 sleep_time: integer_t,
755};
756
757pub const thread_identifier_info = extern struct {
758 /// System-wide unique 64-bit thread id
759 thread_id: u64,
760
761 /// Handle to be used by libproc
762 thread_handle: u64,
763
764 /// libdispatch queue address
765 dispatch_qaddr: u64,
766};
767
768pub const task_vm_info = extern struct {
769 // virtual memory size (bytes)
770 virtual_size: mach_vm_size_t,
771 // number of memory regions
772 region_count: integer_t,
773 page_size: integer_t,
774 // resident memory size (bytes)
775 resident_size: mach_vm_size_t,
776 // peak resident size (bytes)
777 resident_size_peak: mach_vm_size_t,
778
779 device: mach_vm_size_t,
780 device_peak: mach_vm_size_t,
781 internal: mach_vm_size_t,
782 internal_peak: mach_vm_size_t,
783 external: mach_vm_size_t,
784 external_peak: mach_vm_size_t,
785 reusable: mach_vm_size_t,
786 reusable_peak: mach_vm_size_t,
787 purgeable_volatile_pmap: mach_vm_size_t,
788 purgeable_volatile_resident: mach_vm_size_t,
789 purgeable_volatile_virtual: mach_vm_size_t,
790 compressed: mach_vm_size_t,
791 compressed_peak: mach_vm_size_t,
792 compressed_lifetime: mach_vm_size_t,
793
794 // added for rev1
795 phys_footprint: mach_vm_size_t,
796
797 // added for rev2
798 min_address: mach_vm_address_t,
799 max_address: mach_vm_address_t,
800
801 // added for rev3
802 ledger_phys_footprint_peak: i64,
803 ledger_purgeable_nonvolatile: i64,
804 ledger_purgeable_novolatile_compressed: i64,
805 ledger_purgeable_volatile: i64,
806 ledger_purgeable_volatile_compressed: i64,
807 ledger_tag_network_nonvolatile: i64,
808 ledger_tag_network_nonvolatile_compressed: i64,
809 ledger_tag_network_volatile: i64,
810 ledger_tag_network_volatile_compressed: i64,
811 ledger_tag_media_footprint: i64,
812 ledger_tag_media_footprint_compressed: i64,
813 ledger_tag_media_nofootprint: i64,
814 ledger_tag_media_nofootprint_compressed: i64,
815 ledger_tag_graphics_footprint: i64,
816 ledger_tag_graphics_footprint_compressed: i64,
817 ledger_tag_graphics_nofootprint: i64,
818 ledger_tag_graphics_nofootprint_compressed: i64,
819 ledger_tag_neural_footprint: i64,
820 ledger_tag_neural_footprint_compressed: i64,
821 ledger_tag_neural_nofootprint: i64,
822 ledger_tag_neural_nofootprint_compressed: i64,
823
824 // added for rev4
825 limit_bytes_remaining: u64,
826
827 // added for rev5
828 decompressions: integer_t,
829};
830
831pub const task_vm_info_data_t = task_vm_info;
832
833pub const vm_prot_t = std.macho.vm_prot_t;
834pub const boolean_t = c_int;
835
836pub extern "c" fn mach_vm_protect(
837 target_task: vm_map_t,
838 address: mach_vm_address_t,
839 size: mach_vm_size_t,
840 set_maximum: boolean_t,
841 new_protection: vm_prot_t,
842) kern_return_t;
843
844pub extern "c" fn mach_port_allocate(
845 task: ipc_space_t,
846 right: mach_port_right_t,
847 name: *mach_port_name_t,
848) kern_return_t;
849pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
850pub extern "c" fn mach_port_insert_right(
851 task: ipc_space_t,
852 name: mach_port_name_t,
853 right: mach_port_t,
854 right_type: mach_msg_type_name_t,
855) kern_return_t;
856
857pub extern "c" fn task_info(
858 target_task: task_name_t,
859 flavor: task_flavor_t,
860 task_info_out: task_info_t,
861 task_info_outCnt: *mach_msg_type_number_t,
862) kern_return_t;
863
864pub const mach_task_basic_info = extern struct {
865 /// Virtual memory size (bytes)
866 virtual_size: mach_vm_size_t,
867 /// Resident memory size (bytes)
868 resident_size: mach_vm_size_t,
869 /// Total user run time for terminated threads
870 user_time: time_value_t,
871 /// Total system run time for terminated threads
872 system_time: time_value_t,
873 /// Default policy for new threads
874 policy: policy_t,
875 /// Suspend count for task
876 suspend_count: mach_vm_size_t,
877};
878
879pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;
880pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t;
881pub extern "c" fn vm_machine_attribute(
882 target_task: vm_map_t,
883 address: vm_address_t,
884 size: vm_size_t,
885 attribute: vm_machine_attribute_t,
886 value: *vm_machine_attribute_val_t,
887) kern_return_t;
888
889pub extern "c" fn sendfile(
890 in_fd: fd_t,
891 out_fd: fd_t,
892 offset: off_t,
893 len: *off_t,
894 sf_hdtr: ?*sf_hdtr,
895 flags: u32,
896) c_int;
897
898// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/_types.h#L74
899pub const sigset_t = u32;
900
901// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/signal.h#L76
902pub const NSIG = 32;
903
904pub const qos_class_t = enum(c_uint) {
905 /// highest priority QOS class for critical tasks
906 USER_INTERACTIVE = 0x21,
907 /// slightly more moderate priority QOS class
908 USER_INITIATED = 0x19,
909 /// default QOS class when none is set
910 DEFAULT = 0x15,
911 /// more energy efficient QOS class than default
912 UTILITY = 0x11,
913 /// QOS class more appropriate for background tasks
914 BACKGROUND = 0x09,
915 /// QOS class as a return value
916 UNSPECIFIED = 0x00,
917
918 _,
919};
920
921/// Undocumented futex-like API available on darwin 16+
922/// (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).
923///
924/// [ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h
925/// [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c
926pub const UL = packed struct(u32) {
927 op: Op,
928 WAKE_ALL: bool = false,
929 WAKE_THREAD: bool = false,
930 _10: u6 = 0,
931 WAIT_WORKQ_DATA_CONTENTION: bool = false,
932 WAIT_CANCEL_POINT: bool = false,
933 WAIT_ADAPTIVE_SPIN: bool = false,
934 _19: u5 = 0,
935 NO_ERRNO: bool = false,
936 _: u7 = 0,
937
938 pub const Op = enum(u8) {
939 COMPARE_AND_WAIT = 1,
940 UNFAIR_LOCK = 2,
941 COMPARE_AND_WAIT_SHARED = 3,
942 UNFAIR_LOCK64_SHARED = 4,
943 COMPARE_AND_WAIT64 = 5,
944 COMPARE_AND_WAIT64_SHARED = 6,
945 _,
946 };
947};
948
949pub extern "c" fn __ulock_wait2(op: UL, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int;
950pub extern "c" fn __ulock_wait(op: UL, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int;
951pub extern "c" fn __ulock_wake(op: UL, addr: ?*const anyopaque, val: u64) c_int;
952
953pub const os_unfair_lock_t = *os_unfair_lock;
954pub const os_unfair_lock = extern struct {
955 _os_unfair_lock_opaque: u32 = 0,
956};
957
958pub extern "c" fn os_unfair_lock_lock(o: os_unfair_lock_t) void;
959pub extern "c" fn os_unfair_lock_unlock(o: os_unfair_lock_t) void;
960pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
961pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
962pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
963
964pub const os_signpost_id_t = enum(u64) {
965 NULL = 0,
966 INVALID = !0,
967 EXCLUSIVE = 0xeeeeb0b5b2b2eeee,
968 _,
969};
970
971pub const os_log_t = *opaque {};
972pub const os_log_type_t = enum(u8) {
973 /// default messages always captures
974 DEFAULT = 0x00,
975 /// messages with additional infos
976 INFO = 0x01,
977 /// debug messages
978 DEBUG = 0x02,
979 /// error messages
980 ERROR = 0x10,
981 /// unexpected conditions messages
982 FAULT = 0x11,
983
984 _,
985};
986
987pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
988pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
989pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t;
990pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
991pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
992pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
993pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
994
995pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
996pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
997pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
998pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
999pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
1000
1001pub const mach_timebase_info_data = extern struct {
1002 numer: u32,
1003 denom: u32,
1004};
1005
1006pub const kevent64_s = extern struct {
1007 ident: u64,
1008 filter: i16,
1009 flags: u16,
1010 fflags: u32,
1011 data: i64,
1012 udata: u64,
1013 ext: [2]u64,
1014};
1015
1016// sys/types.h on macos uses #pragma pack() so these checks are
1017// to make sure the struct is laid out the same. These values were
1018// produced from C code using the offsetof macro.
1019comptime {
1020 if (builtin.target.os.tag.isDarwin()) {
1021 assert(@offsetOf(kevent64_s, "ident") == 0);
1022 assert(@offsetOf(kevent64_s, "filter") == 8);
1023 assert(@offsetOf(kevent64_s, "flags") == 10);
1024 assert(@offsetOf(kevent64_s, "fflags") == 12);
1025 assert(@offsetOf(kevent64_s, "data") == 16);
1026 assert(@offsetOf(kevent64_s, "udata") == 24);
1027 assert(@offsetOf(kevent64_s, "ext") == 32);
1028 }
1029}
1030
1031pub const clock_serv_t = mach_port_t;
1032pub const clock_res_t = c_int;
1033pub const mach_port_name_t = natural_t;
1034pub const natural_t = c_uint;
1035pub const mach_timespec_t = extern struct {
1036 sec: c_uint,
1037 nsec: clock_res_t,
1038};
1039pub const kern_return_t = c_int;
1040pub const host_t = mach_port_t;
1041pub const integer_t = c_int;
1042pub const task_flavor_t = natural_t;
1043pub const task_info_t = *integer_t;
1044pub const task_name_t = mach_port_name_t;
1045pub const vm_address_t = vm_offset_t;
1046pub const vm_size_t = mach_vm_size_t;
1047pub const vm_machine_attribute_t = usize;
1048pub const vm_machine_attribute_val_t = isize;
1049
1050pub const CALENDAR_CLOCK = 1;
1051
1052pub const SYSPROTO_EVENT = 1;
1053pub const SYSPROTO_CONTROL = 2;
1054
1055/// Mach msg return values
1056pub const mach_msg_return_t = enum(kern_return_t) {
1057 SUCCESS = 0x00000000,
1058
1059 /// Thread is waiting to send. (Internal use only.)
1060 SEND_IN_PROGRESS = 0x10000001,
1061 /// Bogus in-line data.
1062 SEND_INVALID_DATA = 0x10000002,
1063 /// Bogus destination port.
1064 SEND_INVALID_DEST = 0x10000003,
1065 /// Message not sent before timeout expired.
1066 SEND_TIMED_OUT = 0x10000004,
1067 /// Bogus voucher port.
1068 SEND_INVALID_VOUCHER = 0x10000005,
1069 /// Software interrupt.
1070 SEND_INTERRUPTED = 0x10000007,
1071 /// Data doesn't contain a complete message.
1072 SEND_MSG_TOO_SMALL = 0x10000008,
1073 /// Bogus reply port.
1074 SEND_INVALID_REPLY = 0x10000009,
1075 /// Bogus port rights in the message body.
1076 SEND_INVALID_RIGHT = 0x1000000a,
1077 /// Bogus notify port argument.
1078 SEND_INVALID_NOTIFY = 0x1000000b,
1079 /// Invalid out-of-line memory pointer.
1080 SEND_INVALID_MEMORY = 0x1000000c,
1081 /// No message buffer is available.
1082 SEND_NO_BUFFER = 0x1000000d,
1083 /// Send is too large for port
1084 SEND_TOO_LARGE = 0x1000000e,
1085 /// Invalid msg-type specification.
1086 SEND_INVALID_TYPE = 0x1000000f,
1087 /// A field in the header had a bad value.
1088 SEND_INVALID_HEADER = 0x10000010,
1089 /// The trailer to be sent does not match kernel format.
1090 SEND_INVALID_TRAILER = 0x10000011,
1091 /// The sending thread context did not match the context on the dest port
1092 SEND_INVALID_CONTEXT = 0x10000012,
1093 /// compatibility: no longer a returned error
1094 SEND_INVALID_RT_OOL_SIZE = 0x10000015,
1095 /// The destination port doesn't accept ports in body
1096 SEND_NO_GRANT_DEST = 0x10000016,
1097 /// Message send was rejected by message filter
1098 SEND_MSG_FILTERED = 0x10000017,
1099
1100 /// Thread is waiting for receive. (Internal use only.)
1101 RCV_IN_PROGRESS = 0x10004001,
1102 /// Bogus name for receive port/port-set.
1103 RCV_INVALID_NAME = 0x10004002,
1104 /// Didn't get a message within the timeout value.
1105 RCV_TIMED_OUT = 0x10004003,
1106 /// Message buffer is not large enough for inline data.
1107 RCV_TOO_LARGE = 0x10004004,
1108 /// Software interrupt.
1109 RCV_INTERRUPTED = 0x10004005,
1110 /// compatibility: no longer a returned error
1111 RCV_PORT_CHANGED = 0x10004006,
1112 /// Bogus notify port argument.
1113 RCV_INVALID_NOTIFY = 0x10004007,
1114 /// Bogus message buffer for inline data.
1115 RCV_INVALID_DATA = 0x10004008,
1116 /// Port/set was sent away/died during receive.
1117 RCV_PORT_DIED = 0x10004009,
1118 /// compatibility: no longer a returned error
1119 RCV_IN_SET = 0x1000400a,
1120 /// Error receiving message header. See special bits (use `extractResourceError`).
1121 RCV_HEADER_ERROR = 0x1000400b,
1122 /// Error receiving message body. See special bits (use `extractResourceError`).
1123 RCV_BODY_ERROR = 0x1000400c,
1124 /// Invalid msg-type specification in scatter list.
1125 RCV_INVALID_TYPE = 0x1000400d,
1126 /// Out-of-line overwrite region is not large enough
1127 RCV_SCATTER_SMALL = 0x1000400e,
1128 /// trailer type or number of trailer elements not supported
1129 RCV_INVALID_TRAILER = 0x1000400f,
1130 /// Waiting for receive with timeout. (Internal use only.)
1131 RCV_IN_PROGRESS_TIMED = 0x10004011,
1132 /// invalid reply port used in a STRICT_REPLY message
1133 RCV_INVALID_REPLY = 0x10004012,
1134
1135 _,
1136
1137 pub fn extractResourceError(ret: mach_msg_return_t) struct {
1138 error_code: mach_msg_return_t,
1139 resource_error: ?MACH.MSG,
1140 } {
1141 const return_code: mach_msg_return_t = @fromBackingInt(@intCast(@backingInt(ret) & ~MACH.MSG.MASK));
1142 switch (return_code) {
1143 .RCV_HEADER_ERROR, .RCV_BODY_ERROR => {
1144 const resource_error: MACH.MSG = @bitCast(@backingInt(ret) & MACH.MSG.MASK);
1145 return .{
1146 .error_code = return_code,
1147 .resource_error = resource_error,
1148 };
1149 },
1150 else => return .{
1151 .error_code = ret,
1152 .resource_error = null,
1153 },
1154 }
1155 }
1156};
1157
1158pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
1159
1160/// Max open files per process
1161/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
1162pub const OPEN_MAX = 10240;
1163
1164// CPU families mapping
1165pub const CPUFAMILY = enum(u32) {
1166 UNKNOWN = 0,
1167 POWERPC_G3 = 0xcee41549,
1168 POWERPC_G4 = 0x77c184ae,
1169 POWERPC_G5 = 0xed76d8aa,
1170 INTEL_6_13 = 0xaa33392b,
1171 INTEL_PENRYN = 0x78ea4fbc,
1172 INTEL_NEHALEM = 0x6b5a4cd2,
1173 INTEL_WESTMERE = 0x573b5eec,
1174 INTEL_SANDYBRIDGE = 0x5490b78c,
1175 INTEL_IVYBRIDGE = 0x1f65e835,
1176 INTEL_HASWELL = 0x10b282dc,
1177 INTEL_BROADWELL = 0x582ed09c,
1178 INTEL_SKYLAKE = 0x37fc219f,
1179 INTEL_KABYLAKE = 0x0f817246,
1180 ARM_9 = 0xe73283ae,
1181 ARM_11 = 0x8ff620d8,
1182 ARM_XSCALE = 0x53b005f5,
1183 ARM_12 = 0xbd1b0ae9,
1184 ARM_13 = 0x0cc90e64,
1185 ARM_14 = 0x96077ef1,
1186 ARM_15 = 0xa8511bca,
1187 ARM_SWIFT = 0x1e2d6381,
1188 ARM_CYCLONE = 0x37a09642,
1189 ARM_TYPHOON = 0x2c91a47e,
1190 ARM_TWISTER = 0x92fb37c8,
1191 ARM_HURRICANE = 0x67ceee93,
1192 ARM_MONSOON_MISTRAL = 0xe81e7ef6,
1193 ARM_VORTEX_TEMPEST = 0x07d34b9f,
1194 ARM_LIGHTNING_THUNDER = 0x462504d2,
1195 ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
1196 ARM_BLIZZARD_AVALANCHE = 0xda33d83d,
1197 ARM_EVEREST_SAWTOOTH = 0x8765edea,
1198 ARM_COLL = 0x2876f5b5,
1199 ARM_IBIZA = 0xfa33415e,
1200 ARM_LOBOS = 0x5f4dea93,
1201 ARM_PALMA = 0x72015832,
1202 ARM_DONAN = 0x6f5129ac,
1203 ARM_BRAVA = 0x17d5b93a,
1204 ARM_TAHITI = 0x75d4acb9,
1205 ARM_TUPAI = 0x204526d0,
1206 ARM_HIDRA = 0x1d5a87e8,
1207 ARM_SOTRA = 0xf76c5b1a,
1208 ARM_THERA = 0xab345f09,
1209 ARM_TILOS = 0x01d7a72b,
1210 _,
1211};
1212
1213pub const PT = enum(c_int) {
1214 TRACE_ME = 0,
1215 READ_I = 1,
1216 READ_D = 2,
1217 READ_U = 3,
1218 WRITE_I = 4,
1219 WRITE_D = 5,
1220 WRITE_U = 6,
1221 CONTINUE = 7,
1222 KILL = 8,
1223 STEP = 9,
1224 DETACH = 11,
1225 SIGEXC = 12,
1226 THUPDATE = 13,
1227 ATTACHEXC = 14,
1228 FORCEQUOTA = 30,
1229 DENY_ATTACH = 31,
1230 _,
1231};
1232
1233pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int;
1234
1235pub const POSIX_SPAWN = packed struct(c_short) {
1236 RESETIDS: bool = false,
1237 SETPGROUP: bool = false,
1238 SETSIGDEF: bool = false,
1239 SETSIGMASK: bool = false,
1240 _4: u2 = 0,
1241 SETEXEC: bool = false,
1242 START_SUSPENDED: bool = false,
1243 DISABLE_ASLR: bool = false,
1244 _9: u1 = 0,
1245 SETSID: bool = false,
1246 RESLIDE: bool = false,
1247 _12: u2 = 0,
1248 CLOEXEC_DEFAULT: bool = false,
1249 _15: u1 = 0,
1250};
1251
1252pub const posix_spawnattr_t = *opaque {};
1253pub const posix_spawn_file_actions_t = *opaque {};
1254pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
1255pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
1256pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int;
1257pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int;
1258pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
1259pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
1260pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
1261pub extern "c" fn posix_spawn_file_actions_addopen(
1262 actions: *posix_spawn_file_actions_t,
1263 filedes: fd_t,
1264 path: [*:0]const u8,
1265 oflag: c_int,
1266 mode: mode_t,
1267) c_int;
1268pub extern "c" fn posix_spawn_file_actions_adddup2(
1269 actions: *posix_spawn_file_actions_t,
1270 filedes: fd_t,
1271 newfiledes: fd_t,
1272) c_int;
1273pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
1274pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
1275pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
1276pub extern "c" fn posix_spawn(
1277 pid: *pid_t,
1278 path: [*:0]const u8,
1279 actions: ?*const posix_spawn_file_actions_t,
1280 attr: ?*const posix_spawnattr_t,
1281 argv: [*:null]const ?[*:0]const u8,
1282 env: [*:null]const ?[*:0]const u8,
1283) c_int;
1284pub extern "c" fn posix_spawnp(
1285 pid: *pid_t,
1286 path: [*:0]const u8,
1287 actions: ?*const posix_spawn_file_actions_t,
1288 attr: ?*const posix_spawnattr_t,
1289 argv: [*:null]const ?[*:0]const u8,
1290 env: [*:null]const ?[*:0]const u8,
1291) c_int;
1292
1293pub const E = enum(u16) {
1294 /// No error occurred.
1295 SUCCESS = 0,
1296 /// Operation not permitted
1297 PERM = 1,
1298 /// No such file or directory
1299 NOENT = 2,
1300 /// No such process
1301 SRCH = 3,
1302 /// Interrupted system call
1303 INTR = 4,
1304 /// Input/output error
1305 IO = 5,
1306 /// Device not configured
1307 NXIO = 6,
1308 /// Argument list too long
1309 @"2BIG" = 7,
1310 /// Exec format error
1311 NOEXEC = 8,
1312 /// Bad file descriptor
1313 BADF = 9,
1314 /// No child processes
1315 CHILD = 10,
1316 /// Resource deadlock avoided
1317 DEADLK = 11,
1318 /// Cannot allocate memory
1319 NOMEM = 12,
1320 /// Permission denied
1321 ACCES = 13,
1322 /// Bad address
1323 FAULT = 14,
1324 /// Block device required
1325 NOTBLK = 15,
1326 /// Device / Resource busy
1327 BUSY = 16,
1328 /// File exists
1329 EXIST = 17,
1330 /// Cross-device link
1331 XDEV = 18,
1332 /// Operation not supported by device
1333 NODEV = 19,
1334 /// Not a directory
1335 NOTDIR = 20,
1336 /// Is a directory
1337 ISDIR = 21,
1338 /// Invalid argument
1339 INVAL = 22,
1340 /// Too many open files in system
1341 NFILE = 23,
1342 /// Too many open files
1343 MFILE = 24,
1344 /// Inappropriate ioctl for device
1345 NOTTY = 25,
1346 /// Text file busy
1347 TXTBSY = 26,
1348 /// File too large
1349 FBIG = 27,
1350 /// No space left on device
1351 NOSPC = 28,
1352 /// Illegal seek
1353 SPIPE = 29,
1354 /// Read-only file system
1355 ROFS = 30,
1356 /// Too many links
1357 MLINK = 31,
1358 /// Broken pipe
1359 PIPE = 32,
1360 // math software
1361 /// Numerical argument out of domain
1362 DOM = 33,
1363 /// Result too large
1364 RANGE = 34,
1365 // non-blocking and interrupt i/o
1366 /// Resource temporarily unavailable
1367 /// This is the same code used for `WOULDBLOCK`.
1368 AGAIN = 35,
1369 /// Operation now in progress
1370 INPROGRESS = 36,
1371 /// Operation already in progress
1372 ALREADY = 37,
1373 // ipc/network software -- argument errors
1374 /// Socket operation on non-socket
1375 NOTSOCK = 38,
1376 /// Destination address required
1377 DESTADDRREQ = 39,
1378 /// Message too long
1379 MSGSIZE = 40,
1380 /// Protocol wrong type for socket
1381 PROTOTYPE = 41,
1382 /// Protocol not available
1383 NOPROTOOPT = 42,
1384 /// Protocol not supported
1385 PROTONOSUPPORT = 43,
1386 /// Socket type not supported
1387 SOCKTNOSUPPORT = 44,
1388 /// Operation not supported
1389 /// The same code is used for `NOTSUP`.
1390 OPNOTSUPP = 45,
1391 /// Protocol family not supported
1392 PFNOSUPPORT = 46,
1393 /// Address family not supported by protocol family
1394 AFNOSUPPORT = 47,
1395 /// Address already in use
1396 ADDRINUSE = 48,
1397 /// Can't assign requested address
1398 // ipc/network software -- operational errors
1399 ADDRNOTAVAIL = 49,
1400 /// Network is down
1401 NETDOWN = 50,
1402 /// Network is unreachable
1403 NETUNREACH = 51,
1404 /// Network dropped connection on reset
1405 NETRESET = 52,
1406 /// Software caused connection abort
1407 CONNABORTED = 53,
1408 /// Connection reset by peer
1409 CONNRESET = 54,
1410 /// No buffer space available
1411 NOBUFS = 55,
1412 /// Socket is already connected
1413 ISCONN = 56,
1414 /// Socket is not connected
1415 NOTCONN = 57,
1416 /// Can't send after socket shutdown
1417 SHUTDOWN = 58,
1418 /// Too many references: can't splice
1419 TOOMANYREFS = 59,
1420 /// Operation timed out
1421 TIMEDOUT = 60,
1422 /// Connection refused
1423 CONNREFUSED = 61,
1424 /// Too many levels of symbolic links
1425 LOOP = 62,
1426 /// File name too long
1427 NAMETOOLONG = 63,
1428 /// Host is down
1429 HOSTDOWN = 64,
1430 /// No route to host
1431 HOSTUNREACH = 65,
1432 /// Directory not empty
1433 // quotas & mush
1434 NOTEMPTY = 66,
1435 /// Too many processes
1436 PROCLIM = 67,
1437 /// Too many users
1438 USERS = 68,
1439 /// Disc quota exceeded
1440 // Network File System
1441 DQUOT = 69,
1442 /// Stale NFS file handle
1443 STALE = 70,
1444 /// Too many levels of remote in path
1445 REMOTE = 71,
1446 /// RPC struct is bad
1447 BADRPC = 72,
1448 /// RPC version wrong
1449 RPCMISMATCH = 73,
1450 /// RPC prog. not avail
1451 PROGUNAVAIL = 74,
1452 /// Program version wrong
1453 PROGMISMATCH = 75,
1454 /// Bad procedure for program
1455 PROCUNAVAIL = 76,
1456 /// No locks available
1457 NOLCK = 77,
1458 /// Function not implemented
1459 NOSYS = 78,
1460 /// Inappropriate file type or format
1461 FTYPE = 79,
1462 /// Authentication error
1463 AUTH = 80,
1464 /// Need authenticator
1465 NEEDAUTH = 81,
1466 // Intelligent device errors
1467 /// Device power is off
1468 PWROFF = 82,
1469 /// Device error, e.g. paper out
1470 DEVERR = 83,
1471 /// Value too large to be stored in data type
1472 OVERFLOW = 84,
1473 // Program loading errors
1474 /// Bad executable
1475 BADEXEC = 85,
1476 /// Bad CPU type in executable
1477 BADARCH = 86,
1478 /// Shared library version mismatch
1479 SHLIBVERS = 87,
1480 /// Malformed Macho file
1481 BADMACHO = 88,
1482 /// Operation canceled
1483 CANCELED = 89,
1484 /// Identifier removed
1485 IDRM = 90,
1486 /// No message of desired type
1487 NOMSG = 91,
1488 /// Illegal byte sequence
1489 ILSEQ = 92,
1490 /// Attribute not found
1491 NOATTR = 93,
1492 /// Bad message
1493 BADMSG = 94,
1494 /// Reserved
1495 MULTIHOP = 95,
1496 /// No message available on STREAM
1497 NODATA = 96,
1498 /// Reserved
1499 NOLINK = 97,
1500 /// No STREAM resources
1501 NOSR = 98,
1502 /// Not a STREAM
1503 NOSTR = 99,
1504 /// Protocol error
1505 PROTO = 100,
1506 /// STREAM ioctl timeout
1507 TIME = 101,
1508 /// No such policy registered
1509 NOPOLICY = 103,
1510 /// State not recoverable
1511 NOTRECOVERABLE = 104,
1512 /// Previous owner died
1513 OWNERDEAD = 105,
1514 /// Interface output queue is full
1515 QFULL = 106,
1516 /// Capabilities insufficient
1517 NOTCAPABLE = 107,
1518 _,
1519};
1520
1521/// From Common Security Services Manager
1522/// Security.framework/Headers/cssm*.h
1523pub const DB_RECORDTYPE = enum(u32) {
1524 // Record Types defined in the Schema Management Name Space
1525 SCHEMA_INFO = SCHEMA_START + 0,
1526 SCHEMA_INDEXES = SCHEMA_START + 1,
1527 SCHEMA_ATTRIBUTES = SCHEMA_START + 2,
1528 SCHEMA_PARSING_MODULE = SCHEMA_START + 3,
1529
1530 // Record Types defined in the Open Group Application Name Space
1531 ANY = OPEN_GROUP_START + 0,
1532 CERT = OPEN_GROUP_START + 1,
1533 CRL = OPEN_GROUP_START + 2,
1534 POLICY = OPEN_GROUP_START + 3,
1535 GENERIC = OPEN_GROUP_START + 4,
1536 PUBLIC_KEY = OPEN_GROUP_START + 5,
1537 PRIVATE_KEY = OPEN_GROUP_START + 6,
1538 SYMMETRIC_KEY = OPEN_GROUP_START + 7,
1539 ALL_KEYS = OPEN_GROUP_START + 8,
1540
1541 // AppleFileDL record types
1542 GENERIC_PASSWORD = APP_DEFINED_START + 0,
1543 INTERNET_PASSWORD = APP_DEFINED_START + 1,
1544 APPLESHARE_PASSWORD = APP_DEFINED_START + 2,
1545
1546 X509_CERTIFICATE = APP_DEFINED_START + 0x1000,
1547 USER_TRUST,
1548 X509_CRL,
1549 UNLOCK_REFERRAL,
1550 EXTENDED_ATTRIBUTE,
1551 METADATA = APP_DEFINED_START + 0x8000,
1552
1553 _,
1554
1555 // Schema Management Name Space Range Definition
1556 pub const SCHEMA_START = 0x00000000;
1557 pub const SCHEMA_END = SCHEMA_START + 4;
1558
1559 // Open Group Application Name Space Range Definition
1560 pub const OPEN_GROUP_START = 0x0000000A;
1561 pub const OPEN_GROUP_END = OPEN_GROUP_START + 8;
1562
1563 // Industry At Large Application Name Space Range Definition
1564 pub const APP_DEFINED_START = 0x80000000;
1565 pub const APP_DEFINED_END = 0xffffffff;
1566};
1567
1568pub const TCP = struct {
1569 /// Turn off Nagle's algorithm
1570 pub const NODELAY = 0x01;
1571 /// Limit MSS
1572 pub const MAXSEG = 0x02;
1573 /// Don't push last block of write
1574 pub const NOPUSH = 0x04;
1575 /// Don't use TCP options
1576 pub const NOOPT = 0x08;
1577 /// Idle time used when SO_KEEPALIVE is enabled
1578 pub const KEEPALIVE = 0x10;
1579 /// Connection timeout
1580 pub const CONNECTIONTIMEOUT = 0x20;
1581 /// Time after which a conection in persist timeout will terminate.
1582 pub const PERSIST_TIMEOUT = 0x40;
1583 /// Time after which TCP retransmissions will be stopped and the connection will be dropped.
1584 pub const RXT_CONNDROPTIME = 0x80;
1585 /// Drop a connection after retransmitting the FIN 3 times.
1586 pub const RXT_FINDROP = 0x100;
1587 /// Interval between keepalives
1588 pub const KEEPINTVL = 0x101;
1589 /// Number of keepalives before clsoe
1590 pub const KEEPCNT = 0x102;
1591 /// Always ack every other packet
1592 pub const SENDMOREACKS = 0x103;
1593 /// Enable ECN on a connection
1594 pub const ENABLE_ECN = 0x104;
1595 /// Enable/Disable TCP Fastopen on this socket
1596 pub const FASTOPEN = 0x105;
1597 /// State of the TCP connection
1598 pub const CONNECTION_INFO = 0x106;
1599};
1600
1601pub const MSG = struct {
1602 /// process out-of-band data
1603 pub const OOB = 0x1;
1604 /// peek at incoming message
1605 pub const PEEK = 0x2;
1606 /// send without using routing tables
1607 pub const DONTROUTE = 0x4;
1608 /// data completes record
1609 pub const EOR = 0x8;
1610 /// data discarded before delivery
1611 pub const TRUNC = 0x10;
1612 /// control data lost before delivery
1613 pub const CTRUNC = 0x20;
1614 /// wait for full request or error
1615 pub const WAITALL = 0x40;
1616 /// this message should be nonblocking
1617 pub const DONTWAIT = 0x80;
1618 /// data completes connection
1619 pub const EOF = 0x100;
1620 /// wait up to full request, may return partial
1621 pub const WAITSTREAM = 0x200;
1622 /// Start of 'hold' seq; dump so_temp, deprecated
1623 pub const FLUSH = 0x400;
1624 /// Hold frag in so_temp, deprecated
1625 pub const HOLD = 0x800;
1626 /// Send the packet in so_temp, deprecated
1627 pub const SEND = 0x1000;
1628 /// Data ready to be read
1629 pub const HAVEMORE = 0x2000;
1630 /// Data remains in current pkt
1631 pub const RCVMORE = 0x4000;
1632 /// Fail receive if socket address cannot be allocated
1633 pub const NEEDSA = 0x10000;
1634 /// do not generate SIGPIPE on EOF
1635 pub const NOSIGNAL = 0x80000;
1636 /// Inherit upcall in sock_accept
1637 pub const USEUPCALL = 0x80000000;
1638};
1639
1640// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/in.h#L454
1641pub const IP = struct {
1642 pub const OPTIONS = 1;
1643 pub const HDRINCL = 2;
1644 pub const TOS = 3;
1645 pub const TTL = 4;
1646 pub const RECVOPTS = 5;
1647 pub const RECVRETOPTS = 6;
1648 pub const RECVDSTADDR = 7;
1649 pub const RETOPTS = 8;
1650 pub const MULTICAST_IF = 9;
1651 pub const MULTICAST_TTL = 10;
1652 pub const MULTICAST_LOOP = 11;
1653 pub const ADD_MEMBERSHIP = 12;
1654 pub const DROP_MEMBERSHIP = 13;
1655 pub const MULTICAST_VIF = 14;
1656 pub const RSVP_ON = 15;
1657 pub const RSVP_OFF = 16;
1658 pub const RSVP_VIF_ON = 17;
1659 pub const RSVP_VIF_OFF = 18;
1660 pub const PORTRANGE = 19;
1661 pub const RECVIF = 20;
1662 pub const IPSEC_POLICY = 21;
1663 pub const FAITH = 22;
1664 pub const STRIPHDR = 23;
1665 pub const RECVTTL = 24;
1666 pub const BOUND_IF = 25;
1667 pub const PKTINFO = 26;
1668 pub const RECVPKTINFO = PKTINFO;
1669 pub const RECVTOS = 27;
1670 pub const DONTFRAG = 28;
1671 pub const FW_ADD = 40;
1672 pub const FW_DEL = 41;
1673 pub const FW_FLUSH = 42;
1674 pub const FW_ZERO = 43;
1675 pub const FW_GET = 44;
1676 pub const FW_RESETLOG = 45;
1677 pub const OLD_FW_ADD = 50;
1678 pub const OLD_FW_DEL = 51;
1679 pub const OLD_FW_FLUSH = 52;
1680 pub const OLD_FW_ZERO = 53;
1681 pub const OLD_FW_GET = 54;
1682 pub const OLD_FW_RESETLOG = 56;
1683 pub const DUMMYNET_CONFIGURE = 60;
1684 pub const DUMMYNET_DEL = 61;
1685 pub const DUMMYNET_FLUSH = 62;
1686 pub const DUMMYNET_GET = 64;
1687 pub const TRAFFIC_MGT_BACKGROUND = 65;
1688 pub const MULTICAST_IFINDEX = 66;
1689 pub const ADD_SOURCE_MEMBERSHIP = 70;
1690 pub const DROP_SOURCE_MEMBERSHIP = 71;
1691 pub const BLOCK_SOURCE = 72;
1692 pub const UNBLOCK_SOURCE = 73;
1693 pub const MSFILTER = 74;
1694 // Same namespace, but these are arguments rather than option names
1695 pub const DEFAULT_MULTICAST_TTL = 1;
1696 pub const DEFAULT_MULTICAST_LOOP = 1;
1697 pub const MIN_MEMBERSHIPS = 31;
1698 pub const MAX_MEMBERSHIPS = 4095;
1699 pub const MAX_GROUP_SRC_FILTER = 512;
1700 pub const MAX_SOCK_SRC_FILTER = 128;
1701 pub const MAX_SOCK_MUTE_FILTER = 128;
1702 pub const PORTRANGE_DEFAULT = 0;
1703 pub const PORTRANGE_HIGH = 1;
1704 pub const PORTRANGE_LOW = 2;
1705};
1706
1707// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet6/in6.h#L521
1708pub const IPV6 = struct {
1709 pub const UNICAST_HOPS = 4;
1710 pub const MULTICAST_IF = 9;
1711 pub const MULTICAST_HOPS = 10;
1712 pub const MULTICAST_LOOP = 11;
1713 pub const JOIN_GROUP = 12;
1714 pub const LEAVE_GROUP = 13;
1715 pub const PORTRANGE = 14;
1716 pub const @"2292PKTINFO" = 19;
1717 pub const @"2292HOPLIMIT" = 20;
1718 pub const @"2292NEXTHOP" = 21;
1719 pub const @"2292HOPOPTS" = 22;
1720 pub const @"2292DSTOPTS" = 23;
1721 pub const @"2292RTHDR" = 24;
1722 pub const @"2292PKTOPTIONS" = 25;
1723 pub const CHECKSUM = 26;
1724 pub const V6ONLY = 27;
1725 pub const BINDV6ONLY = V6ONLY;
1726 pub const IPSEC_POLICY = 28;
1727 pub const FAITH = 29;
1728 pub const FW_ADD = 30;
1729 pub const FW_DEL = 31;
1730 pub const FW_FLUSH = 32;
1731 pub const FW_ZERO = 33;
1732 pub const FW_GET = 34;
1733 pub const RECVTCLASS = 35;
1734 pub const TCLASS = 36;
1735 pub const RTHDRDSTOPTS = 57;
1736 pub const RECVPKTINFO = 61;
1737 pub const RECVHOPLIMIT = 37;
1738 pub const RECVRTHDR = 38;
1739 pub const RECVHOPOPTS = 39;
1740 pub const RECVDSTOPTS = 40;
1741 pub const RECVRTHDRDSTOPTS = 41;
1742 pub const USE_MIN_MTU = 42;
1743 pub const RECVPATHMTU = 43;
1744 pub const PATHMTU = 44;
1745 pub const REACHCONF = 45;
1746 pub const @"3542PKTINFO" = 46;
1747 pub const @"3542HOPLIMIT" = 47;
1748 pub const @"3542NEXTHOP" = 48;
1749 pub const @"3542HOPOPTS" = 49;
1750 pub const @"3542DSTOPTS" = 50;
1751 pub const @"3542RTHDR" = 51;
1752 pub const PKTINFO = @"3542PKTINFO";
1753 pub const HOPLIMIT = @"3542HOPLIMIT";
1754 pub const NEXTHOP = @"3542NEXTHOP";
1755 pub const HOPOPTS = @"3542HOPOPTS";
1756 pub const DSTOPTS = @"3542DSTOPTS";
1757 pub const RTHDR = @"3542RTHDR";
1758 pub const AUTOFLOWLABEL = 59;
1759 pub const DONTFRAG = 62;
1760 pub const PREFER_TEMPADDR = 63;
1761 pub const MSFILTER = 74;
1762 pub const BOUND_IF = 125;
1763 // Same namespace, but these are arguments rather than option names
1764 pub const RTHDR_LOOSE = 0;
1765 pub const RTHDR_STRICT = 1;
1766 pub const RTHDR_TYPE_0 = 0;
1767 pub const DEFAULT_MULTICAST_HOPS = 1;
1768 pub const DEFAULT_MULTICAST_LOOP = 1;
1769 pub const MIN_MEMBERSHIPS = 31;
1770 pub const MAX_MEMBERSHIPS = 4095;
1771 pub const MAX_GROUP_SRC_FILTER = 512;
1772 pub const MAX_SOCK_SRC_FILTER = 128;
1773 pub const PORTRANGE_DEFAULT = 0;
1774 pub const PORTRANGE_HIGH = 1;
1775 pub const PORTRANGE_LOW = 2;
1776};
1777
1778// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/ip.h#L129
1779pub const IPTOS = struct {
1780 pub const LOWDELAY = 0x10;
1781 pub const THROUGHPUT = 0x08;
1782 pub const RELIABILITY = 0x04;
1783 pub const MINCOST = 0x02;
1784 pub const CE = 0x01;
1785 pub const ECT = 0x02;
1786 pub const DSCP_SHIFT = 2;
1787 pub const ECN_NOTECT = 0x00;
1788 pub const ECN_ECT1 = 0x01;
1789 pub const ECN_ECT0 = 0x02;
1790 pub const ECN_CE = 0x03;
1791 pub const ECN_MASK = 0x03;
1792 pub const PREC_NETCONTROL = 0xe0;
1793 pub const PREC_INTERNETCONTROL = 0xc0;
1794 pub const PREC_CRITIC_ECP = 0xa0;
1795 pub const PREC_FLASHOVERRIDE = 0x80;
1796 pub const PREC_FLASH = 0x60;
1797 pub const PREC_IMMEDIATE = 0x40;
1798 pub const PREC_PRIORITY = 0x20;
1799 pub const PREC_ROUTINE = 0x00;
1800};