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