authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-20 15:56:49+02:00
committergravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-20 18:21:32+02:00
log590d264bdf340fa1e6549ce1988f9ccb7418f4d7
treeb9ef97ae19c737d2b883b51fd82919c6a10cd0ea
parentd748cc9c12ba852ac02edf55eb418b06086d211c

std.c.darwin: cleanup, expose everything in std.c

This mainly just moves stuff around. Justifications for other changes: * `KEVENT.FLAGS` is backed by `c_uint` because that's what the `kevent64` flags param takes (according to the 'latest' manpage from 2008) * `MACH_RCV_NOTIFY` is a legacy name and `MACH_RCV_OVERWRITE` is deprecated (xnu/osfmk/mach/message.h), so I removed them. They were 0 anyway and thus couldn't be represented as a packed struct field. * `MACH.RCV` and `MACH.SEND` are technically the same 'type' because they can both be supplied at the same time to `mach_msg`. I decided to still keep them separate because naming works out better that way and all flags except for `MACH_MSG_STRICT_REPLY` aren't shared anyway. Both are part of a packed union `mach_msg_option_t` which supplies a helper function to combine the two types. * `PT` is backed by `c_int` because that's what `ptrace` takes as a request arg (according to the latest manpage from 2015)

5 files changed, 406 insertions(+), 248 deletions(-)

lib/std/c.zig+31
...@@ -11062,12 +11062,15 @@ pub const fsfilcnt_t = freebsd.fsfilcnt_t;...@@ -11062,12 +11062,15 @@ pub const fsfilcnt_t = freebsd.fsfilcnt_t;
11062pub const kinfo_file = freebsd.kinfo_file;11062pub const kinfo_file = freebsd.kinfo_file;
11063pub const kinfo_getfile = freebsd.kinfo_getfile;11063pub const kinfo_getfile = freebsd.kinfo_getfile;
1106411064
11065pub const CALENDAR_CLOCK = darwin.CALENDAR_CLOCK;
11065pub const COPYFILE = darwin.COPYFILE;11066pub const COPYFILE = darwin.COPYFILE;
11066pub const CPUFAMILY = darwin.CPUFAMILY;11067pub const CPUFAMILY = darwin.CPUFAMILY;
11067pub const PT = darwin.PT;11068pub const PT = darwin.PT;
11068pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;11069pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
11069pub const EXC = darwin.EXC;11070pub const EXC = darwin.EXC;
11070pub const EXCEPTION = darwin.EXCEPTION;11071pub const EXCEPTION = darwin.EXCEPTION;
11072pub const KEVENT = darwin.KEVENT;
11073pub const MACH = darwin.MACH;
11071pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;11074pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;
11072pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;11075pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;
11073pub const MACH_TASK_BASIC_INFO = darwin.MACH_TASK_BASIC_INFO;11076pub const MACH_TASK_BASIC_INFO = darwin.MACH_TASK_BASIC_INFO;
...@@ -11075,10 +11078,15 @@ pub const MACH_TASK_BASIC_INFO_COUNT = darwin.MACH_TASK_BASIC_INFO_COUNT;...@@ -11075,10 +11078,15 @@ pub const MACH_TASK_BASIC_INFO_COUNT = darwin.MACH_TASK_BASIC_INFO_COUNT;
11075pub const MATTR = darwin.MATTR;11078pub const MATTR = darwin.MATTR;
11076pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;11079pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
11077pub const OPEN_MAX = darwin.OPEN_MAX;11080pub const OPEN_MAX = darwin.OPEN_MAX;
11081pub const OS = darwin.OS;
11078pub const POSIX_SPAWN = darwin.POSIX_SPAWN;11082pub const POSIX_SPAWN = darwin.POSIX_SPAWN;
11083pub const SYSPROTO_EVENT = darwin.SYSPROTO_EVENT;
11084pub const SYSPROTO_CONTROL = darwin.SYSPROTO_CONTROL;
11085pub const TASK = darwin.TASK;
11079pub const TASK_NULL = darwin.TASK_NULL;11086pub const TASK_NULL = darwin.TASK_NULL;
11080pub const TASK_VM_INFO = darwin.TASK_VM_INFO;11087pub const TASK_VM_INFO = darwin.TASK_VM_INFO;
11081pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;11088pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;
11089pub const THREAD = darwin.THREAD;
11082pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;11090pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;
11083pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;11091pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;
11084pub const THREAD_IDENTIFIER_INFO_COUNT = darwin.THREAD_IDENTIFIER_INFO_COUNT;11092pub const THREAD_IDENTIFIER_INFO_COUNT = darwin.THREAD_IDENTIFIER_INFO_COUNT;
...@@ -11096,15 +11104,24 @@ pub const _dyld_get_image_name = darwin._dyld_get_image_name;...@@ -11096,15 +11104,24 @@ pub const _dyld_get_image_name = darwin._dyld_get_image_name;
11096pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;11104pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
11097pub const _dyld_image_count = darwin._dyld_image_count;11105pub const _dyld_image_count = darwin._dyld_image_count;
11098pub const _host_page_size = darwin._host_page_size;11106pub const _host_page_size = darwin._host_page_size;
11107pub const boolean_t = darwin.boolean_t;
11099pub const clock_get_time = darwin.clock_get_time;11108pub const clock_get_time = darwin.clock_get_time;
11109pub const clock_serv_t = darwin.clock_serv_t;
11110pub const clock_res_t = darwin.clock_res_t;
11100pub const @"close$NOCANCEL" = darwin.@"close$NOCANCEL";11111pub const @"close$NOCANCEL" = darwin.@"close$NOCANCEL";
11112pub const dispatch_function_t = darwin.dispatch_function_t;
11113pub const dispatch_once_f = darwin.dispatch_once_f;
11114pub const dispatch_once_t = darwin.dispatch_once_t;
11101pub const dispatch_release = darwin.dispatch_release;11115pub const dispatch_release = darwin.dispatch_release;
11102pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;11116pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;
11103pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;11117pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;
11118pub const dispatch_semaphore_t = darwin.dispatch_semaphore_t;
11104pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;11119pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;
11105pub const dispatch_time = darwin.dispatch_time;11120pub const dispatch_time = darwin.dispatch_time;
11121pub const dispatch_time_t = darwin.dispatch_time_t;
11106pub const fcopyfile = darwin.fcopyfile;11122pub const fcopyfile = darwin.fcopyfile;
11107pub const host_t = darwin.host_t;11123pub const host_t = darwin.host_t;
11124pub const integer_t = darwin.integer_t;
11108pub const ipc_space_t = darwin.ipc_space_t;11125pub const ipc_space_t = darwin.ipc_space_t;
11109pub const ipc_space_port_t = darwin.ipc_space_port_t;11126pub const ipc_space_port_t = darwin.ipc_space_port_t;
11110pub const kern_return_t = darwin.kern_return_t;11127pub const kern_return_t = darwin.kern_return_t;
...@@ -11116,6 +11133,7 @@ pub const mach_continuous_time = darwin.mach_continuous_time;...@@ -11116,6 +11133,7 @@ pub const mach_continuous_time = darwin.mach_continuous_time;
11116pub const mach_hdr = darwin.mach_hdr;11133pub const mach_hdr = darwin.mach_hdr;
11117pub const mach_host_self = darwin.mach_host_self;11134pub const mach_host_self = darwin.mach_host_self;
11118pub const mach_msg = darwin.mach_msg;11135pub const mach_msg = darwin.mach_msg;
11136pub const mach_msg_return_t = darwin.mach_msg_return_t;
11119pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;11137pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;
11120pub const mach_port_allocate = darwin.mach_port_allocate;11138pub const mach_port_allocate = darwin.mach_port_allocate;
11121pub const mach_port_array_t = darwin.mach_port_array_t;11139pub const mach_port_array_t = darwin.mach_port_array_t;
...@@ -11127,6 +11145,7 @@ pub const mach_task_basic_info = darwin.mach_task_basic_info;...@@ -11127,6 +11145,7 @@ pub const mach_task_basic_info = darwin.mach_task_basic_info;
11127pub const mach_task_self = darwin.mach_task_self;11145pub const mach_task_self = darwin.mach_task_self;
11128pub const mach_timebase_info = darwin.mach_timebase_info;11146pub const mach_timebase_info = darwin.mach_timebase_info;
11129pub const mach_timebase_info_data = darwin.mach_timebase_info_data;11147pub const mach_timebase_info_data = darwin.mach_timebase_info_data;
11148pub const mach_timespec_t = darwin.mach_timespec_t;
11130pub const mach_vm_address_t = darwin.mach_vm_address_t;11149pub const mach_vm_address_t = darwin.mach_vm_address_t;
11131pub const mach_vm_protect = darwin.mach_vm_protect;11150pub const mach_vm_protect = darwin.mach_vm_protect;
11132pub const mach_vm_read = darwin.mach_vm_read;11151pub const mach_vm_read = darwin.mach_vm_read;
...@@ -11136,16 +11155,20 @@ pub const mach_vm_size_t = darwin.mach_vm_size_t;...@@ -11136,16 +11155,20 @@ pub const mach_vm_size_t = darwin.mach_vm_size_t;
11136pub const mach_vm_write = darwin.mach_vm_write;11155pub const mach_vm_write = darwin.mach_vm_write;
11137pub const natural_t = darwin.natural_t;11156pub const natural_t = darwin.natural_t;
11138pub const os_log_create = darwin.os_log_create;11157pub const os_log_create = darwin.os_log_create;
11158pub const os_log_t = darwin.os_log_t;
11139pub const os_log_type_enabled = darwin.os_log_type_enabled;11159pub const os_log_type_enabled = darwin.os_log_type_enabled;
11160pub const os_log_type_t = darwin.os_log_type_t;
11140pub const os_signpost_enabled = darwin.os_signpost_enabled;11161pub const os_signpost_enabled = darwin.os_signpost_enabled;
11141pub const os_signpost_id_generate = darwin.os_signpost_id_generate;11162pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
11142pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;11163pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;
11164pub const os_signpost_id_t = darwin.os_signpost_id_t;
11143pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;11165pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
11144pub const os_signpost_interval_end = darwin.os_signpost_interval_end;11166pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
11145pub const os_unfair_lock = darwin.os_unfair_lock;11167pub const os_unfair_lock = darwin.os_unfair_lock;
11146pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;11168pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
11147pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;11169pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
11148pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;11170pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
11171pub const os_unfair_lock_t = darwin.os_unfair_lock_t;
11149pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;11172pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
11150pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;11173pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
11151pub const pid_for_task = darwin.pid_for_task;11174pub const pid_for_task = darwin.pid_for_task;
...@@ -11170,10 +11193,13 @@ pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;...@@ -11170,10 +11193,13 @@ pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;
11170pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;11193pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
11171pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;11194pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
11172pub const ptrace = darwin.ptrace;11195pub const ptrace = darwin.ptrace;
11196pub const qos_class_t = darwin.qos_class_t;
11197pub const task_flavor_t = darwin.task_flavor_t;
11173pub const task_for_pid = darwin.task_for_pid;11198pub const task_for_pid = darwin.task_for_pid;
11174pub const task_get_exception_ports = darwin.task_get_exception_ports;11199pub const task_get_exception_ports = darwin.task_get_exception_ports;
11175pub const task_info = darwin.task_info;11200pub const task_info = darwin.task_info;
11176pub const task_info_t = darwin.task_info_t;11201pub const task_info_t = darwin.task_info_t;
11202pub const task_name_t = darwin.task_name_t;
11177pub const task_resume = darwin.task_resume;11203pub const task_resume = darwin.task_resume;
11178pub const task_set_exception_ports = darwin.task_set_exception_ports;11204pub const task_set_exception_ports = darwin.task_set_exception_ports;
11179pub const task_suspend = darwin.task_suspend;11205pub const task_suspend = darwin.task_suspend;
...@@ -11186,8 +11212,10 @@ pub const thread_info = darwin.thread_info;...@@ -11186,8 +11212,10 @@ pub const thread_info = darwin.thread_info;
11186pub const thread_info_t = darwin.thread_info_t;11212pub const thread_info_t = darwin.thread_info_t;
11187pub const thread_resume = darwin.thread_resume;11213pub const thread_resume = darwin.thread_resume;
11188pub const thread_set_state = darwin.thread_set_state;11214pub const thread_set_state = darwin.thread_set_state;
11215pub const vm_address_t = darwin.vm_address_t;
11189pub const vm_deallocate = darwin.vm_deallocate;11216pub const vm_deallocate = darwin.vm_deallocate;
11190pub const vm_machine_attribute = darwin.vm_machine_attribute;11217pub const vm_machine_attribute = darwin.vm_machine_attribute;
11218pub const vm_machine_attribute_t = darwin.vm_machine_attribute_t;
11191pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;11219pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;
11192pub const vm_map_t = darwin.vm_map_t;11220pub const vm_map_t = darwin.vm_map_t;
11193pub const vm_offset_t = darwin.vm_offset_t;11221pub const vm_offset_t = darwin.vm_offset_t;
...@@ -11212,10 +11240,12 @@ pub const exception_mask_array_t = darwin.exception_mask_array_t;...@@ -11212,10 +11240,12 @@ pub const exception_mask_array_t = darwin.exception_mask_array_t;
11212pub const exception_mask_t = darwin.exception_mask_t;11240pub const exception_mask_t = darwin.exception_mask_t;
11213pub const exception_port_array_t = darwin.exception_port_array_t;11241pub const exception_port_array_t = darwin.exception_port_array_t;
11214pub const exception_port_t = darwin.exception_port_t;11242pub const exception_port_t = darwin.exception_port_t;
11243pub const exception_type_t = darwin.exception_type_t;
11215pub const mach_exception_data_t = darwin.mach_exception_data_t;11244pub const mach_exception_data_t = darwin.mach_exception_data_t;
11216pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;11245pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;
11217pub const mach_msg_bits_t = darwin.mach_msg_bits_t;11246pub const mach_msg_bits_t = darwin.mach_msg_bits_t;
11218pub const mach_msg_id_t = darwin.mach_msg_id_t;11247pub const mach_msg_id_t = darwin.mach_msg_id_t;
11248pub const mach_msg_header_t = darwin.mach_msg_header_t;
11219pub const mach_msg_option_t = darwin.mach_msg_option_t;11249pub const mach_msg_option_t = darwin.mach_msg_option_t;
11220pub const mach_msg_size_t = darwin.mach_msg_size_t;11250pub const mach_msg_size_t = darwin.mach_msg_size_t;
11221pub const mach_msg_timeout_t = darwin.mach_msg_timeout_t;11251pub const mach_msg_timeout_t = darwin.mach_msg_timeout_t;
...@@ -11225,6 +11255,7 @@ pub const memory_object_offset_t = darwin.memory_object_offset_t;...@@ -11225,6 +11255,7 @@ pub const memory_object_offset_t = darwin.memory_object_offset_t;
11225pub const policy_t = darwin.policy_t;11255pub const policy_t = darwin.policy_t;
11226pub const task_policy_flavor_t = darwin.task_policy_flavor_t;11256pub const task_policy_flavor_t = darwin.task_policy_flavor_t;
11227pub const task_policy_t = darwin.task_policy_t;11257pub const task_policy_t = darwin.task_policy_t;
11258pub const task_read_t = darwin.task_read_t;
11228pub const task_t = darwin.task_t;11259pub const task_t = darwin.task_t;
11229pub const thread_act_t = darwin.thread_act_t;11260pub const thread_act_t = darwin.thread_act_t;
11230pub const thread_flavor_t = darwin.thread_flavor_t;11261pub const thread_flavor_t = darwin.thread_flavor_t;
lib/std/c/darwin.zig+362-236
...@@ -19,12 +19,6 @@ comptime {...@@ -19,12 +19,6 @@ comptime {
1919
20pub const mach_port_t = c_uint;20pub const mach_port_t = c_uint;
2121
22pub const THREAD_STATE_NONE = switch (native_arch) {
23 .aarch64 => 5,
24 .x86_64 => 13,
25 else => @compileError("unsupported arch"),
26};
27
28pub const EXC = enum(exception_type_t) {22pub const EXC = enum(exception_type_t) {
29 NULL = 0,23 NULL = 0,
30 /// Could not access memory24 /// Could not access memory
...@@ -54,6 +48,8 @@ pub const EXC = enum(exception_type_t) {...@@ -54,6 +48,8 @@ pub const EXC = enum(exception_type_t) {
54 /// Abnormal process exited to corpse state48 /// Abnormal process exited to corpse state
55 CORPSE_NOTIFY = 13,49 CORPSE_NOTIFY = 13,
5650
51 _,
52
57 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len;53 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len;
58 pub const SOFT_SIGNAL = 0x10003;54 pub const SOFT_SIGNAL = 0x10003;
5955
...@@ -110,56 +106,240 @@ pub const EXCEPTION = enum(u32) {...@@ -110,56 +106,240 @@ pub const EXCEPTION = enum(u32) {
110 _,106 _,
111};107};
112108
113/// Prefer sending a catch_exception_raice_backtrace message, if applicable.109pub const KEVENT = struct {
114pub const MACH_EXCEPTION_BACKTRACE_PREFERRED = 0x20000000;110 /// Used as the `flags` arg for `kevent64`.
115/// include additional exception specific errors, not used yet.111 pub const FLAG = packed struct(c_uint) {
116pub const MACH_EXCEPTION_ERRORS = 0x40000000;112 /// immediate timeout
117/// Send 64-bit code and subcode in the exception header */113 IMMEDIATE: bool = false,
118pub const MACH_EXCEPTION_CODES = 0x80000000;114 /// output events only include change
119115 ERROR_EVENTS: bool = false,
120pub const MACH_EXCEPTION_MASK = MACH_EXCEPTION_CODES |116 _: u30 = 0,
121 MACH_EXCEPTION_ERRORS |117
122 MACH_EXCEPTION_BACKTRACE_PREFERRED;118 /// no flag value
123119 pub const NONE: KEVENT.FLAG = .{
124pub const TASK_NULL: task_t = 0;120 .IMMEDIATE = false,
125pub const THREAD_NULL: thread_t = 0;121 .ERROR_EVENTS = false,
126pub const MACH_PORT_NULL: mach_port_t = 0;122 };
127pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0;123 };
128124};
129pub const MACH_MSG_OPTION_NONE = 0x00000000;125
130126pub const MACH = struct {
131pub const MACH_SEND_MSG = 0x00000001;127 pub const EXCEPTION = packed struct(exception_mask_t) {
132pub const MACH_RCV_MSG = 0x00000002;128 _: u29 = 0,
133129 /// Prefer sending a catch_exception_raice_backtrace message, if applicable.
134pub const MACH_RCV_LARGE = 0x00000004;130 BACKTRACE_PREFERRED: bool = false,
135pub const MACH_RCV_LARGE_IDENTITY = 0x00000008;131 /// include additional exception specific errors, not used yet.
136132 ERRORS: bool = false,
137pub const MACH_SEND_TIMEOUT = 0x00000010;133 /// Send 64-bit code and subcode in the exception header */
138pub const MACH_SEND_OVERRIDE = 0x00000020;134 CODES: bool = false,
139pub const MACH_SEND_INTERRUPT = 0x00000040;135
140pub const MACH_SEND_NOTIFY = 0x00000080;136 pub const MASK = @compileError("use MACH.EXCEPTION and set/check all named fields");
141pub const MACH_SEND_ALWAYS = 0x00010000;137 };
142pub const MACH_SEND_FILTER_NONFATAL = 0x00010000;138
143pub const MACH_SEND_TRAILER = 0x00020000;139 pub const MSG = packed struct(kern_return_t) {
144pub const MACH_SEND_NOIMPORTANCE = 0x00040000;140 _0: u10 = 0,
145pub const MACH_SEND_NODENAP = MACH_SEND_NOIMPORTANCE;141 /// Kernel resource shortage handling an IPC capability.
146pub const MACH_SEND_IMPORTANCE = 0x00080000;142 VM_KERNEL: bool = false,
147pub const MACH_SEND_SYNC_OVERRIDE = 0x00100000;143 /// Kernel resource shortage handling out-of-line memory.
148pub const MACH_SEND_PROPAGATE_QOS = 0x00200000;144 IPC_KERNEL: bool = false,
149pub const MACH_SEND_SYNC_USE_THRPRI = MACH_SEND_PROPAGATE_QOS;145 /// No room in VM address space for out-of-line memory.
150pub const MACH_SEND_KERNEL = 0x00400000;146 VM_SPACE: bool = false,
151pub const MACH_SEND_SYNC_BOOTSTRAP_CHECKIN = 0x00800000;147 /// No room in IPC name space for another capability name.
152148 IPC_SPACE: bool = false,
153pub const MACH_RCV_TIMEOUT = 0x00000100;149 _14: u18 = 0,
154pub const MACH_RCV_NOTIFY = 0x00000000;150
155pub const MACH_RCV_INTERRUPT = 0x00000400;151 pub const MASK: kern_return_t = @bitCast(MACH.MSG{
156pub const MACH_RCV_VOUCHER = 0x00000800;152 .VM_KERNEL = true,
157pub const MACH_RCV_OVERWRITE = 0x00000000;153 .IPC_KERNEL = true,
158pub const MACH_RCV_GUARDED_DESC = 0x00001000;154 .VM_SPACE = true,
159pub const MACH_RCV_SYNC_WAIT = 0x00004000;155 .IPC_SPACE = true,
160pub const MACH_RCV_SYNC_PEEK = 0x00008000;156 });
161157
162pub const MACH_MSG_STRICT_REPLY = 0x00000200;158 pub const TIMEOUT_NONE = @compileError("use mach_msg_timeout_t.NONE");
159 pub const OPTION_NONE = @compileError("use MACH.RCV and/or MACH.SEND with their default values");
160 pub const STRICT_REPLY = @compileError("use MACH.RCV.STRICT_REPLY and/or MACH.SEND.STRICT_REPLY");
161
162 pub const TYPE = @compileError("use mach_msg_type_name_t members");
163 };
164
165 pub const PORT = struct {
166 pub const NULL: mach_port_t = 0;
167 pub const RIGHT = @compileError("use mach_port_right_t members");
168 };
169
170 pub const RCV = packed struct(integer_t) {
171 _0: u1 = 0,
172 /// Other flags are only valid if this one is set.
173 MSG: bool = true,
174 LARGE: bool = false,
175 LARGE_IDENTITY: bool = false,
176 _4: u4 = 0,
177 TIMEOUT: bool = false,
178 /// Shared between `RCV` and `SEND`. Used to be `MACH_RCV_NOTIFY`.
179 STRICT_REPLY: bool = false,
180 INTERRUPT: bool = false,
181 VOUCHER: bool = false,
182 GUARDED_DESC: bool = false,
183 _13: u1 = 0,
184 SYNC_WAIT: bool = false,
185 SYNC_PEEK: bool = false,
186 _16: u16 = 0,
187 };
188
189 pub const SEND = packed struct(integer_t) {
190 /// Other flags are only valid if this one is set.
191 MSG: bool = true,
192 _1: u3 = 0,
193 TIMEOUT: bool = false,
194 OVERRIDE: bool = false,
195 INTERRUPT: bool = false,
196 NOTIFY: bool = false,
197 _8: u1 = 0,
198 /// Shared between `RCV` and `SEND`.
199 STRICT_REPLY: bool = false,
200 _10: u6 = 0,
201 /// User-only. If you're the kernel, this bit is `MACH_SEND_ALWAYS`.
202 FILTER_NONFATAL: bool = false,
203 TRAILER: bool = false,
204 /// Synonymous to `MACH_SEND_NODENAP`.
205 NOIMPORTANCE: bool = false,
206 /// Kernel-only.
207 IMPORTANCE: bool = false,
208 SYNC_OVERRIDE: bool = false,
209 /// Synonymous to `MACH_SEND_SYNC_USE_THRPRI`.
210 PROPAGATE_QOS: bool = false,
211 /// Kernel-only.
212 KERNEL: bool = false,
213 SYNC_BOOTSTRAP_CHECKIN: bool = false,
214 _24: u8 = 0,
215 };
216
217 pub const TASK = struct {
218 pub const BASIC = struct {
219 pub const INFO = 20;
220 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t);
221 };
222 };
223};
224
225pub const MACH_MSG_TYPE = @compileError("use use mach_msg_type_name_t members");
226pub const MACH_PORT_RIGHT = @compileError("use mach_port_right_t members");
227pub const MACH_TASK_BASIC_INFO = @compileError("use MACH.TASK.BASIC.INFO");
228pub const MACH_TASK_BASIC_INFO_COUNT = @compileError("use MACH.TASK.BASIC.INFO_COUNT");
229
230pub const MATTR = struct {
231 /// Cachability
232 pub const CACHE: vm_machine_attribute_t = 1;
233 /// Migrability
234 pub const MIGRATE: vm_machine_attribute_t = 2;
235 /// Replicability
236 pub const REPLICATE: vm_machine_attribute_t = 4;
237 /// (Generic) turn attribute off
238 pub const VAL_OFF: vm_machine_attribute_t = 0;
239 /// (Generic) turn attribute on
240 pub const VAL_ON: vm_machine_attribute_t = 1;
241 /// (Generic) return current value
242 pub const VAL_GET: vm_machine_attribute_t = 2;
243 /// Flush from all caches
244 pub const VAL_CACHE_FLUSH: vm_machine_attribute_t = 6;
245 /// Flush from data caches
246 pub const VAL_DCACHE_FLUSH: vm_machine_attribute_t = 7;
247 /// Flush from instruction caches
248 pub const VAL_ICACHE_FLUSH: vm_machine_attribute_t = 8;
249 /// Sync I+D caches
250 pub const VAL_CACHE_SYNC: vm_machine_attribute_t = 9;
251 /// Get page info (stats)
252 pub const VAL_GET_INFO: vm_machine_attribute_t = 10;
253};
254
255pub const OS = struct {
256 pub const LOG_CATEGORY = struct {
257 pub const POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
258 pub const DYNAMIC_TRACING: *const u8 = "DynamicTracing";
259 pub const DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
260 };
261};
262
263pub const TASK = struct {
264 pub const NULL: task_t = 0;
265
266 pub const VM = struct {
267 pub const INFO = 22;
268 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t);
269 };
270};
271
272pub const TASK_NULL = @compileError("use TASK.NULL");
273pub const TASK_VM_INFO = @compileError("use TASK.VM.INFO");
274pub const TASK_VM_INFO_COUNT = @compileError("use TASK.VM.INFO_COUNT");
275
276pub const THREAD = struct {
277 pub const NULL: thread_t = 0;
278
279 pub const BASIC = struct {
280 pub const INFO = 3;
281 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t);
282 };
283
284 pub const IDENTIFIER = struct {
285 pub const INFO = 4;
286 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t);
287 };
288
289 pub const STATE = struct {
290 pub const NONE = switch (native_arch) {
291 .aarch64 => 5,
292 .x86_64 => 13,
293 else => @compileError("unsupported arch"),
294 };
295 };
296};
297
298pub const THREAD_NULL = @compileError("use THREAD.NULL");
299pub const THREAD_BASIC_INFO = @compileError("use THREAD.BASIC.INFO");
300pub const THREAD_BASIC_INFO_COUNT = @compileError("use THREAD.BASIC.INFO_COUNT");
301pub const THREAD_IDENTIFIER_INFO_COUNT = @compileError("use THREAD.IDENTIFIER.INFO_COUNT");
302pub const THREAD_STATE_NONE = @compileError("use THREAD.STATE.NONE");
303
304pub const VM = struct {
305 pub const INHERIT = struct {
306 pub const SHARE: vm_inherit_t = 0;
307 pub const COPY: vm_inherit_t = 1;
308 pub const NONE: vm_inherit_t = 2;
309 pub const DONATE_COPY: vm_inherit_t = 3;
310 pub const DEFAULT = VM.INHERIT.COPY;
311 };
312
313 pub const BEHAVIOR = struct {
314 pub const DEFAULT: vm_behavior_t = 0;
315 pub const RANDOM: vm_behavior_t = 1;
316 pub const SEQUENTIAL: vm_behavior_t = 2;
317 pub const RSEQNTL: vm_behavior_t = 3;
318 pub const WILLNEED: vm_behavior_t = 4;
319 pub const DONTNEED: vm_behavior_t = 5;
320 pub const FREE: vm_behavior_t = 6;
321 pub const ZERO_WIRED_PAGES: vm_behavior_t = 7;
322 pub const REUSABLE: vm_behavior_t = 8;
323 pub const REUSE: vm_behavior_t = 9;
324 pub const CAN_REUSE: vm_behavior_t = 10;
325 pub const PAGEOUT: vm_behavior_t = 11;
326 };
327
328 pub const REGION = struct {
329 pub const BASIC_INFO_64 = 9;
330 pub const EXTENDED_INFO = 13;
331 pub const TOP_INFO = 12;
332 pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t);
333 pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t);
334 pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int);
335 pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t);
336 pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t);
337 };
338
339 pub fn MAKE_TAG(tag: u8) u32 {
340 return @as(u32, tag) << 24;
341 }
342};
163343
164pub const exception_type_t = c_int;344pub const exception_type_t = c_int;
165345
...@@ -293,7 +473,7 @@ pub extern "c" fn kevent64(...@@ -293,7 +473,7 @@ pub extern "c" fn kevent64(
293 nchanges: c_int,473 nchanges: c_int,
294 eventlist: [*]kevent64_s,474 eventlist: [*]kevent64_s,
295 nevents: c_int,475 nevents: c_int,
296 flags: c_uint,476 flags: KEVENT.FLAG,
297 timeout: ?*const timespec,477 timeout: ?*const timespec,
298) c_int;478) c_int;
299479
...@@ -321,11 +501,7 @@ pub const mach_vm_size_t = u64;...@@ -321,11 +501,7 @@ pub const mach_vm_size_t = u64;
321pub const mach_msg_bits_t = c_uint;501pub const mach_msg_bits_t = c_uint;
322pub const mach_msg_id_t = integer_t;502pub const mach_msg_id_t = integer_t;
323pub const mach_msg_type_number_t = natural_t;503pub const mach_msg_type_number_t = natural_t;
324pub const mach_msg_type_name_t = c_uint;
325pub const mach_msg_option_t = integer_t;
326pub const mach_msg_size_t = natural_t;504pub const mach_msg_size_t = natural_t;
327pub const mach_msg_timeout_t = natural_t;
328pub const mach_port_right_t = natural_t;
329pub const task_t = mach_port_t;505pub const task_t = mach_port_t;
330pub const thread_port_t = task_t;506pub const thread_port_t = task_t;
331pub const thread_t = thread_port_t;507pub const thread_t = thread_port_t;
...@@ -342,19 +518,21 @@ pub const thread_state_flavor_t = c_int;...@@ -342,19 +518,21 @@ pub const thread_state_flavor_t = c_int;
342pub const ipc_space_t = mach_port_t;518pub const ipc_space_t = mach_port_t;
343pub const ipc_space_port_t = ipc_space_t;519pub const ipc_space_port_t = ipc_space_t;
344520
345pub const MACH_PORT_RIGHT = enum(mach_port_right_t) {521pub const mach_msg_option_t = packed union {
346 SEND = 0,522 RCV: MACH.RCV,
347 RECEIVE = 1,523 SEND: MACH.SEND,
348 SEND_ONCE = 2,524
349 PORT_SET = 3,525 pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t {
350 DEAD_NAME = 4,526 return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv)));
351 /// Obsolete right527 }
352 LABELH = 5,
353 /// Right not implemented
354 NUMBER = 6,
355};528};
356529
357pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {530pub const mach_msg_timeout_t = enum(natural_t) {
531 NONE = 0,
532 _,
533};
534
535pub const mach_msg_type_name_t = enum(c_uint) {
358 /// Must hold receive right536 /// Must hold receive right
359 MOVE_RECEIVE = 16,537 MOVE_RECEIVE = 16,
360 /// Must hold send right(s)538 /// Must hold send right(s)
...@@ -375,6 +553,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {...@@ -375,6 +553,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
375 DISPOSE_SEND = 25,553 DISPOSE_SEND = 25,
376 /// Must hold sendonce right554 /// Must hold sendonce right
377 DISPOSE_SEND_ONCE = 26,555 DISPOSE_SEND_ONCE = 26,
556
557 _,
558};
559
560pub const mach_port_right_t = enum(natural_t) {
561 SEND = 0,
562 RECEIVE = 1,
563 SEND_ONCE = 2,
564 PORT_SET = 3,
565 DEAD_NAME = 4,
566 /// Obsolete right
567 LABELH = 5,
568 /// Right not implemented
569 NUMBER = 6,
570
571 _,
378};572};
379573
380extern "c" var mach_task_self_: mach_port_t;574extern "c" var mach_task_self_: mach_port_t;
...@@ -390,7 +584,7 @@ pub extern "c" fn mach_msg(...@@ -390,7 +584,7 @@ pub extern "c" fn mach_msg(
390 rcv_name: mach_port_name_t,584 rcv_name: mach_port_name_t,
391 timeout: mach_msg_timeout_t,585 timeout: mach_msg_timeout_t,
392 notify: mach_port_name_t,586 notify: mach_port_name_t,
393) kern_return_t;587) mach_msg_return_t;
394588
395pub const mach_msg_header_t = extern struct {589pub const mach_msg_header_t = extern struct {
396 msgh_bits: mach_msg_bits_t,590 msgh_bits: mach_msg_bits_t,
...@@ -462,46 +656,6 @@ pub const vm_behavior_t = i32;...@@ -462,46 +656,6 @@ pub const vm_behavior_t = i32;
462pub const vm32_object_id_t = u32;656pub const vm32_object_id_t = u32;
463pub const vm_object_id_t = u64;657pub const vm_object_id_t = u64;
464658
465pub const VM = struct {
466 pub const INHERIT = struct {
467 pub const SHARE: vm_inherit_t = 0;
468 pub const COPY: vm_inherit_t = 1;
469 pub const NONE: vm_inherit_t = 2;
470 pub const DONATE_COPY: vm_inherit_t = 3;
471 pub const DEFAULT = COPY;
472 };
473
474 pub const BEHAVIOR = struct {
475 pub const DEFAULT: vm_behavior_t = 0;
476 pub const RANDOM: vm_behavior_t = 1;
477 pub const SEQUENTIAL: vm_behavior_t = 2;
478 pub const RSEQNTL: vm_behavior_t = 3;
479 pub const WILLNEED: vm_behavior_t = 4;
480 pub const DONTNEED: vm_behavior_t = 5;
481 pub const FREE: vm_behavior_t = 6;
482 pub const ZERO_WIRED_PAGES: vm_behavior_t = 7;
483 pub const REUSABLE: vm_behavior_t = 8;
484 pub const REUSE: vm_behavior_t = 9;
485 pub const CAN_REUSE: vm_behavior_t = 10;
486 pub const PAGEOUT: vm_behavior_t = 11;
487 };
488
489 pub const REGION = struct {
490 pub const BASIC_INFO_64 = 9;
491 pub const EXTENDED_INFO = 13;
492 pub const TOP_INFO = 12;
493 pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t);
494 pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t);
495 pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int);
496 pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t);
497 pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t);
498 };
499
500 pub fn MAKE_TAG(tag: u8) u32 {
501 return @as(u32, tag) << 24;
502 }
503};
504
505pub const vm_region_basic_info_64 = extern struct {659pub const vm_region_basic_info_64 = extern struct {
506 protection: vm_prot_t,660 protection: vm_prot_t,
507 max_protection: vm_prot_t,661 max_protection: vm_prot_t,
...@@ -630,12 +784,6 @@ pub extern "c" fn thread_info(...@@ -630,12 +784,6 @@ pub extern "c" fn thread_info(
630) kern_return_t;784) kern_return_t;
631pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t;785pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t;
632786
633pub const THREAD_BASIC_INFO = 3;
634pub const THREAD_BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t);
635
636pub const THREAD_IDENTIFIER_INFO = 4;
637pub const THREAD_IDENTIFIER_INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t);
638
639pub const thread_flavor_t = natural_t;787pub const thread_flavor_t = natural_t;
640pub const thread_info_t = *integer_t;788pub const thread_info_t = *integer_t;
641pub const time_value_t = time_value;789pub const time_value_t = time_value;
...@@ -678,34 +826,6 @@ pub const thread_identifier_info = extern struct {...@@ -678,34 +826,6 @@ pub const thread_identifier_info = extern struct {
678 dispatch_qaddr: u64,826 dispatch_qaddr: u64,
679};827};
680828
681pub const MATTR = struct {
682 /// Cachability
683 pub const CACHE = 1;
684 /// Migrability
685 pub const MIGRATE = 2;
686 /// Replicability
687 pub const REPLICATE = 4;
688 /// (Generic) turn attribute off
689 pub const VAL_OFF = 0;
690 /// (Generic) turn attribute on
691 pub const VAL_ON = 1;
692 /// (Generic) return current value
693 pub const VAL_GET = 2;
694 /// Flush from all caches
695 pub const VAL_CACHE_FLUSH = 6;
696 /// Flush from data caches
697 pub const VAL_DCACHE_FLUSH = 7;
698 /// Flush from instruction caches
699 pub const VAL_ICACHE_FLUSH = 8;
700 /// Sync I+D caches
701 pub const VAL_CACHE_SYNC = 9;
702 /// Get page info (stats)
703 pub const VAL_GET_INFO = 10;
704};
705
706pub const TASK_VM_INFO = 22;
707pub const TASK_VM_INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t);
708
709pub const task_vm_info = extern struct {829pub const task_vm_info = extern struct {
710 // virtual memory size (bytes)830 // virtual memory size (bytes)
711 virtual_size: mach_vm_size_t,831 virtual_size: mach_vm_size_t,
...@@ -791,8 +911,8 @@ pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t...@@ -791,8 +911,8 @@ pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t
791pub extern "c" fn mach_port_insert_right(911pub extern "c" fn mach_port_insert_right(
792 task: ipc_space_t,912 task: ipc_space_t,
793 name: mach_port_name_t,913 name: mach_port_name_t,
794 poly: mach_port_t,914 right: mach_port_t,
795 poly_poly: mach_msg_type_name_t,915 right_type: mach_msg_type_name_t,
796) kern_return_t;916) kern_return_t;
797917
798pub extern "c" fn task_info(918pub extern "c" fn task_info(
...@@ -817,9 +937,6 @@ pub const mach_task_basic_info = extern struct {...@@ -817,9 +937,6 @@ pub const mach_task_basic_info = extern struct {
817 suspend_count: mach_vm_size_t,937 suspend_count: mach_vm_size_t,
818};938};
819939
820pub const MACH_TASK_BASIC_INFO = 20;
821pub const MACH_TASK_BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t);
822
823pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;940pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;
824pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t;941pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t;
825pub extern "c" fn vm_machine_attribute(942pub extern "c" fn vm_machine_attribute(
...@@ -847,17 +964,19 @@ pub const NSIG = 32;...@@ -847,17 +964,19 @@ pub const NSIG = 32;
847964
848pub const qos_class_t = enum(c_uint) {965pub const qos_class_t = enum(c_uint) {
849 /// highest priority QOS class for critical tasks966 /// highest priority QOS class for critical tasks
850 QOS_CLASS_USER_INTERACTIVE = 0x21,967 USER_INTERACTIVE = 0x21,
851 /// slightly more moderate priority QOS class968 /// slightly more moderate priority QOS class
852 QOS_CLASS_USER_INITIATED = 0x19,969 USER_INITIATED = 0x19,
853 /// default QOS class when none is set970 /// default QOS class when none is set
854 QOS_CLASS_DEFAULT = 0x15,971 DEFAULT = 0x15,
855 /// more energy efficient QOS class than default972 /// more energy efficient QOS class than default
856 QOS_CLASS_UTILITY = 0x11,973 UTILITY = 0x11,
857 /// QOS class more appropriate for background tasks974 /// QOS class more appropriate for background tasks
858 QOS_CLASS_BACKGROUND = 0x09,975 BACKGROUND = 0x09,
859 /// QOS class as a return value976 /// QOS class as a return value
860 QOS_CLASS_UNSPECIFIED = 0x00,977 UNSPECIFIED = 0x00,
978
979 _,
861};980};
862981
863// Grand Central Dispatch is exposed by libSystem.982// Grand Central Dispatch is exposed by libSystem.
...@@ -868,13 +987,17 @@ pub extern "c" fn dispatch_semaphore_create(value: isize) ?dispatch_semaphore_t;...@@ -868,13 +987,17 @@ pub extern "c" fn dispatch_semaphore_create(value: isize) ?dispatch_semaphore_t;
868pub extern "c" fn dispatch_semaphore_wait(dsema: dispatch_semaphore_t, timeout: dispatch_time_t) isize;987pub extern "c" fn dispatch_semaphore_wait(dsema: dispatch_semaphore_t, timeout: dispatch_time_t) isize;
869pub extern "c" fn dispatch_semaphore_signal(dsema: dispatch_semaphore_t) isize;988pub extern "c" fn dispatch_semaphore_signal(dsema: dispatch_semaphore_t) isize;
870989
871pub const dispatch_time_t = u64;990pub const DISPATCH_TIME_NOW = @compileError("use dispatch_time_t.NOW");
872pub const DISPATCH_TIME_NOW = @as(dispatch_time_t, 0);991pub const DISPATCH_TIME_FOREVER = @compileError("use dispatch_time_t.FOREVER");
873pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0);992pub const dispatch_time_t = enum(u64) {
993 NOW = 0,
994 FOREVER = ~0,
995 _,
996};
874pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;997pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;
875998
876const dispatch_once_t = usize;999pub const dispatch_once_t = usize;
877const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;1000pub const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
878pub extern fn dispatch_once_f(1001pub extern fn dispatch_once_f(
879 predicate: *dispatch_once_t,1002 predicate: *dispatch_once_t,
880 context: ?*anyopaque,1003 context: ?*anyopaque,
...@@ -905,6 +1028,7 @@ pub const UL = packed struct(u32) {...@@ -905,6 +1028,7 @@ pub const UL = packed struct(u32) {
905 UNFAIR_LOCK64_SHARED = 4,1028 UNFAIR_LOCK64_SHARED = 4,
906 COMPARE_AND_WAIT64 = 5,1029 COMPARE_AND_WAIT64 = 5,
907 COMPARE_AND_WAIT64_SHARED = 6,1030 COMPARE_AND_WAIT64_SHARED = 6,
1031 _,
908 };1032 };
909};1033};
9101034
...@@ -923,29 +1047,28 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;...@@ -923,29 +1047,28 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
923pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;1047pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
924pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;1048pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
9251049
926pub const os_signpost_id_t = u64;1050pub const os_signpost_id_t = enum(u64) {
9271051 NULL = 0,
928pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;1052 INVALID = !0,
929pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;1053 EXCLUSIVE = 0xeeeeb0b5b2b2eeee,
930pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;1054 _,
1055};
9311056
932pub const os_log_t = *opaque {};1057pub const os_log_t = *opaque {};
933pub const os_log_type_t = enum(u8) {1058pub const os_log_type_t = enum(u8) {
934 /// default messages always captures1059 /// default messages always captures
935 OS_LOG_TYPE_DEFAULT = 0x00,1060 DEFAULT = 0x00,
936 /// messages with additional infos1061 /// messages with additional infos
937 OS_LOG_TYPE_INFO = 0x01,1062 INFO = 0x01,
938 /// debug messages1063 /// debug messages
939 OS_LOG_TYPE_DEBUG = 0x02,1064 DEBUG = 0x02,
940 /// error messages1065 /// error messages
941 OS_LOG_TYPE_ERROR = 0x10,1066 ERROR = 0x10,
942 /// unexpected conditions messages1067 /// unexpected conditions messages
943 OS_LOG_TYPE_FAULT = 0x11,1068 FAULT = 0x11,
944};
9451069
946pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";1070 _,
947pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";1071};
948pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
9491072
950pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;1073pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
951pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;1074pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
...@@ -1012,35 +1135,11 @@ pub const vm_machine_attribute_val_t = isize;...@@ -1012,35 +1135,11 @@ pub const vm_machine_attribute_val_t = isize;
10121135
1013pub const CALENDAR_CLOCK = 1;1136pub const CALENDAR_CLOCK = 1;
10141137
1015/// no flag value
1016pub const KEVENT_FLAG_NONE = 0x000;
1017/// immediate timeout
1018pub const KEVENT_FLAG_IMMEDIATE = 0x001;
1019/// output events only include change
1020pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
1021
1022pub const SYSPROTO_EVENT = 1;1138pub const SYSPROTO_EVENT = 1;
1023pub const SYSPROTO_CONTROL = 2;1139pub const SYSPROTO_CONTROL = 2;
10241140
1025pub const mach_msg_return_t = kern_return_t;
1026
1027pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
1028 return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
1029}
1030
1031/// All special error code bits defined below.
1032pub const MACH_MSG_MASK: u32 = 0x3e00;
1033/// No room in IPC name space for another capability name.
1034pub const MACH_MSG_IPC_SPACE: u32 = 0x2000;
1035/// No room in VM address space for out-of-line memory.
1036pub const MACH_MSG_VM_SPACE: u32 = 0x1000;
1037/// Kernel resource shortage handling out-of-line memory.
1038pub const MACH_MSG_IPC_KERNEL: u32 = 0x800;
1039/// Kernel resource shortage handling an IPC capability.
1040pub const MACH_MSG_VM_KERNEL: u32 = 0x400;
1041
1042/// Mach msg return values1141/// Mach msg return values
1043pub const MachMsgE = enum(u32) {1142pub const mach_msg_return_t = enum(kern_return_t) {
1044 SUCCESS = 0x00000000,1143 SUCCESS = 0x00000000,
10451144
1046 /// Thread is waiting to send. (Internal use only.)1145 /// Thread is waiting to send. (Internal use only.)
...@@ -1104,9 +1203,9 @@ pub const MachMsgE = enum(u32) {...@@ -1104,9 +1203,9 @@ pub const MachMsgE = enum(u32) {
1104 RCV_PORT_DIED = 0x10004009,1203 RCV_PORT_DIED = 0x10004009,
1105 /// compatibility: no longer a returned error1204 /// compatibility: no longer a returned error
1106 RCV_IN_SET = 0x1000400a,1205 RCV_IN_SET = 0x1000400a,
1107 /// Error receiving message header. See special bits.1206 /// Error receiving message header. See special bits (use `extractResourceError`).
1108 RCV_HEADER_ERROR = 0x1000400b,1207 RCV_HEADER_ERROR = 0x1000400b,
1109 /// Error receiving message body. See special bits.1208 /// Error receiving message body. See special bits (use `extractResourceError`).
1110 RCV_BODY_ERROR = 0x1000400c,1209 RCV_BODY_ERROR = 0x1000400c,
1111 /// Invalid msg-type specification in scatter list.1210 /// Invalid msg-type specification in scatter list.
1112 RCV_INVALID_TYPE = 0x1000400d,1211 RCV_INVALID_TYPE = 0x1000400d,
...@@ -1118,6 +1217,28 @@ pub const MachMsgE = enum(u32) {...@@ -1118,6 +1217,28 @@ pub const MachMsgE = enum(u32) {
1118 RCV_IN_PROGRESS_TIMED = 0x10004011,1217 RCV_IN_PROGRESS_TIMED = 0x10004011,
1119 /// invalid reply port used in a STRICT_REPLY message1218 /// invalid reply port used in a STRICT_REPLY message
1120 RCV_INVALID_REPLY = 0x10004012,1219 RCV_INVALID_REPLY = 0x10004012,
1220
1221 _,
1222
1223 pub fn extractResourceError(ret: mach_msg_return_t) struct {
1224 error_code: mach_msg_return_t,
1225 resource_error: ?MACH.MSG,
1226 } {
1227 const return_code: mach_msg_return_t = @enumFromInt(@intFromEnum(ret) & ~MACH.MSG.MASK);
1228 switch (return_code) {
1229 .RCV_HEADER_ERROR, .RCV_BODY_ERROR => {
1230 const resource_error: MACH.MSG = @bitCast(@intFromEnum(ret) & MACH.MSG.MASK);
1231 return .{
1232 .error_code = return_code,
1233 .resource_error = resource_error,
1234 };
1235 },
1236 else => return .{
1237 .error_code = ret,
1238 .resource_error = null,
1239 },
1240 }
1241 }
1121};1242};
11221243
1123pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;1244pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
...@@ -1171,48 +1292,53 @@ pub const CPUFAMILY = enum(u32) {...@@ -1171,48 +1292,53 @@ pub const CPUFAMILY = enum(u32) {
1171 _,1292 _,
1172};1293};
11731294
1174pub const PT = struct {1295pub const PT = enum(c_int) {
1175 pub const TRACE_ME = 0;1296 TRACE_ME = 0,
1176 pub const READ_I = 1;1297 READ_I = 1,
1177 pub const READ_D = 2;1298 READ_D = 2,
1178 pub const READ_U = 3;1299 READ_U = 3,
1179 pub const WRITE_I = 4;1300 WRITE_I = 4,
1180 pub const WRITE_D = 5;1301 WRITE_D = 5,
1181 pub const WRITE_U = 6;1302 WRITE_U = 6,
1182 pub const CONTINUE = 7;1303 CONTINUE = 7,
1183 pub const KILL = 8;1304 KILL = 8,
1184 pub const STEP = 9;1305 STEP = 9,
1185 pub const DETACH = 11;1306 DETACH = 11,
1186 pub const SIGEXC = 12;1307 SIGEXC = 12,
1187 pub const THUPDATE = 13;1308 THUPDATE = 13,
1188 pub const ATTACHEXC = 14;1309 ATTACHEXC = 14,
1189 pub const FORCEQUOTA = 30;1310 FORCEQUOTA = 30,
1190 pub const DENY_ATTACH = 31;1311 DENY_ATTACH = 31,
1312 _,
1191};1313};
11921314
1193pub const caddr_t = ?[*]u8;1315pub const caddr_t = ?[*]u8;
11941316
1195pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;1317pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int;
11961318
1197pub const POSIX_SPAWN = struct {1319pub const POSIX_SPAWN = packed struct(c_short) {
1198 pub const RESETIDS = 0x0001;1320 RESETIDS: bool = false,
1199 pub const SETPGROUP = 0x0002;1321 SETPGROUP: bool = false,
1200 pub const SETSIGDEF = 0x0004;1322 SETSIGDEF: bool = false,
1201 pub const SETSIGMASK = 0x0008;1323 SETSIGMASK: bool = false,
1202 pub const SETEXEC = 0x0040;1324 _4: u2 = 0,
1203 pub const START_SUSPENDED = 0x0080;1325 SETEXEC: bool = false,
1204 pub const DISABLE_ASLR = 0x0100;1326 START_SUSPENDED: bool = false,
1205 pub const SETSID = 0x0400;1327 DISABLE_ASLR: bool = false,
1206 pub const RESLIDE = 0x0800;1328 _9: u1 = 0,
1207 pub const CLOEXEC_DEFAULT = 0x4000;1329 SETSID: bool = false,
1330 RESLIDE: bool = false,
1331 _12: u2 = 0,
1332 CLOEXEC_DEFAULT: bool = false,
1333 _15: u1 = 0,
1208};1334};
12091335
1210pub const posix_spawnattr_t = *opaque {};1336pub const posix_spawnattr_t = *opaque {};
1211pub const posix_spawn_file_actions_t = *opaque {};1337pub const posix_spawn_file_actions_t = *opaque {};
1212pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;1338pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
1213pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;1339pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
1214pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;1340pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int;
1215pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;1341pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int;
1216pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;1342pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
1217pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;1343pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
1218pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;1344pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
lib/std/heap.zig+3-3
...@@ -83,14 +83,14 @@ pub fn defaultQueryPageSize() usize {...@@ -83,14 +83,14 @@ pub fn defaultQueryPageSize() usize {
83 .driverkit, .ios, .macos, .tvos, .visionos, .watchos => blk: {83 .driverkit, .ios, .macos, .tvos, .visionos, .watchos => blk: {
84 const task_port = std.c.mach_task_self();84 const task_port = std.c.mach_task_self();
85 // mach_task_self may fail "if there are any resource failures or other errors".85 // mach_task_self may fail "if there are any resource failures or other errors".
86 if (task_port == std.c.TASK_NULL)86 if (task_port == std.c.TASK.NULL)
87 break :blk 0;87 break :blk 0;
88 var info_count = std.c.TASK_VM_INFO_COUNT;88 var info_count = std.c.TASK.VM.INFO_COUNT;
89 var vm_info: std.c.task_vm_info_data_t = undefined;89 var vm_info: std.c.task_vm_info_data_t = undefined;
90 vm_info.page_size = 0;90 vm_info.page_size = 0;
91 _ = std.c.task_info(91 _ = std.c.task_info(
92 task_port,92 task_port,
93 std.c.TASK_VM_INFO,93 std.c.TASK.VM.INFO,
94 @as(std.c.task_info_t, @ptrCast(&vm_info)),94 @as(std.c.task_info_t, @ptrCast(&vm_info)),
95 &info_count,95 &info_count,
96 );96 );
src/DarwinPosixSpawn.zig+5-5
...@@ -41,17 +41,17 @@ pub const Attr = struct {...@@ -41,17 +41,17 @@ pub const Attr = struct {
41 }41 }
42 }42 }
4343
44 pub fn get(self: Attr) Error!u16 {44 pub fn get(self: Attr) Error!std.c.POSIX_SPAWN {
45 var flags: c_short = undefined;45 var flags: std.c.POSIX_SPAWN = undefined;
46 switch (errno(std.c.posix_spawnattr_getflags(&self.attr, &flags))) {46 switch (errno(std.c.posix_spawnattr_getflags(&self.attr, &flags))) {
47 .SUCCESS => return @as(u16, @bitCast(flags)),47 .SUCCESS => return flags,
48 .INVAL => unreachable,48 .INVAL => unreachable,
49 else => |err| return unexpectedErrno(err),49 else => |err| return unexpectedErrno(err),
50 }50 }
51 }51 }
5252
53 pub fn set(self: *Attr, flags: u16) Error!void {53 pub fn set(self: *Attr, flags: std.c.POSIX_SPAWN) Error!void {
54 switch (errno(std.c.posix_spawnattr_setflags(&self.attr, @as(c_short, @bitCast(flags))))) {54 switch (errno(std.c.posix_spawnattr_setflags(&self.attr, flags))) {
55 .SUCCESS => return,55 .SUCCESS => return,
56 .INVAL => unreachable,56 .INVAL => unreachable,
57 else => |err| return unexpectedErrno(err),57 else => |err| return unexpectedErrno(err),
src/main.zig+5-4
...@@ -4490,10 +4490,11 @@ fn runOrTestHotSwap(...@@ -4490,10 +4490,11 @@ fn runOrTestHotSwap(
44904490
4491 // ASLR is probably a good default for better debugging experience/programming4491 // ASLR is probably a good default for better debugging experience/programming
4492 // with hot-code updates in mind. However, we can also make it work with ASLR on.4492 // with hot-code updates in mind. However, we can also make it work with ASLR on.
4493 const flags: u16 = std.c.POSIX_SPAWN.SETSIGDEF |4493 try attr.set(.{
4494 std.c.POSIX_SPAWN.SETSIGMASK |4494 .SETSIGDEF = true,
4495 std.c.POSIX_SPAWN.DISABLE_ASLR;4495 .SETSIGMASK = true,
4496 try attr.set(flags);4496 .DISABLE_ASLR = true,
4497 });
44974498
4498 var arena_allocator = std.heap.ArenaAllocator.init(gpa);4499 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
4499 defer arena_allocator.deinit();4500 defer arena_allocator.deinit();