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;
1106211062pub const kinfo_file = freebsd.kinfo_file;
1106311063pub const kinfo_getfile = freebsd.kinfo_getfile;
1106411064
11065pub const CALENDAR_CLOCK = darwin.CALENDAR_CLOCK;
1106511066pub const COPYFILE = darwin.COPYFILE;
1106611067pub const CPUFAMILY = darwin.CPUFAMILY;
1106711068pub const PT = darwin.PT;
1106811069pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
1106911070pub const EXC = darwin.EXC;
1107011071pub const EXCEPTION = darwin.EXCEPTION;
11072pub const KEVENT = darwin.KEVENT;
11073pub const MACH = darwin.MACH;
1107111074pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;
1107211075pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;
1107311076pub 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;
1107511078pub const MATTR = darwin.MATTR;
1107611079pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
1107711080pub const OPEN_MAX = darwin.OPEN_MAX;
11081pub const OS = darwin.OS;
1107811082pub 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;
1107911086pub const TASK_NULL = darwin.TASK_NULL;
1108011087pub const TASK_VM_INFO = darwin.TASK_VM_INFO;
1108111088pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;
11089pub const THREAD = darwin.THREAD;
1108211090pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;
1108311091pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;
1108411092pub 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;
1109611104pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
1109711105pub const _dyld_image_count = darwin._dyld_image_count;
1109811106pub const _host_page_size = darwin._host_page_size;
11107pub const boolean_t = darwin.boolean_t;
1109911108pub 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;
1110011111pub 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;
1110111115pub const dispatch_release = darwin.dispatch_release;
1110211116pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;
1110311117pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;
11118pub const dispatch_semaphore_t = darwin.dispatch_semaphore_t;
1110411119pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;
1110511120pub const dispatch_time = darwin.dispatch_time;
11121pub const dispatch_time_t = darwin.dispatch_time_t;
1110611122pub const fcopyfile = darwin.fcopyfile;
1110711123pub const host_t = darwin.host_t;
11124pub const integer_t = darwin.integer_t;
1110811125pub const ipc_space_t = darwin.ipc_space_t;
1110911126pub const ipc_space_port_t = darwin.ipc_space_port_t;
1111011127pub const kern_return_t = darwin.kern_return_t;
......@@ -11116,6 +11133,7 @@ pub const mach_continuous_time = darwin.mach_continuous_time;
1111611133pub const mach_hdr = darwin.mach_hdr;
1111711134pub const mach_host_self = darwin.mach_host_self;
1111811135pub const mach_msg = darwin.mach_msg;
11136pub const mach_msg_return_t = darwin.mach_msg_return_t;
1111911137pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;
1112011138pub const mach_port_allocate = darwin.mach_port_allocate;
1112111139pub 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;
1112711145pub const mach_task_self = darwin.mach_task_self;
1112811146pub const mach_timebase_info = darwin.mach_timebase_info;
1112911147pub const mach_timebase_info_data = darwin.mach_timebase_info_data;
11148pub const mach_timespec_t = darwin.mach_timespec_t;
1113011149pub const mach_vm_address_t = darwin.mach_vm_address_t;
1113111150pub const mach_vm_protect = darwin.mach_vm_protect;
1113211151pub const mach_vm_read = darwin.mach_vm_read;
......@@ -11136,16 +11155,20 @@ pub const mach_vm_size_t = darwin.mach_vm_size_t;
1113611155pub const mach_vm_write = darwin.mach_vm_write;
1113711156pub const natural_t = darwin.natural_t;
1113811157pub const os_log_create = darwin.os_log_create;
11158pub const os_log_t = darwin.os_log_t;
1113911159pub const os_log_type_enabled = darwin.os_log_type_enabled;
11160pub const os_log_type_t = darwin.os_log_type_t;
1114011161pub const os_signpost_enabled = darwin.os_signpost_enabled;
1114111162pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
1114211163pub 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;
1114311165pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
1114411166pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
1114511167pub const os_unfair_lock = darwin.os_unfair_lock;
1114611168pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
1114711169pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
1114811170pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
11171pub const os_unfair_lock_t = darwin.os_unfair_lock_t;
1114911172pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
1115011173pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
1115111174pub 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;
1117011193pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
1117111194pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
1117211195pub const ptrace = darwin.ptrace;
11196pub const qos_class_t = darwin.qos_class_t;
11197pub const task_flavor_t = darwin.task_flavor_t;
1117311198pub const task_for_pid = darwin.task_for_pid;
1117411199pub const task_get_exception_ports = darwin.task_get_exception_ports;
1117511200pub const task_info = darwin.task_info;
1117611201pub const task_info_t = darwin.task_info_t;
11202pub const task_name_t = darwin.task_name_t;
1117711203pub const task_resume = darwin.task_resume;
1117811204pub const task_set_exception_ports = darwin.task_set_exception_ports;
1117911205pub const task_suspend = darwin.task_suspend;
......@@ -11186,8 +11212,10 @@ pub const thread_info = darwin.thread_info;
1118611212pub const thread_info_t = darwin.thread_info_t;
1118711213pub const thread_resume = darwin.thread_resume;
1118811214pub const thread_set_state = darwin.thread_set_state;
11215pub const vm_address_t = darwin.vm_address_t;
1118911216pub const vm_deallocate = darwin.vm_deallocate;
1119011217pub const vm_machine_attribute = darwin.vm_machine_attribute;
11218pub const vm_machine_attribute_t = darwin.vm_machine_attribute_t;
1119111219pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;
1119211220pub const vm_map_t = darwin.vm_map_t;
1119311221pub const vm_offset_t = darwin.vm_offset_t;
......@@ -11212,10 +11240,12 @@ pub const exception_mask_array_t = darwin.exception_mask_array_t;
1121211240pub const exception_mask_t = darwin.exception_mask_t;
1121311241pub const exception_port_array_t = darwin.exception_port_array_t;
1121411242pub const exception_port_t = darwin.exception_port_t;
11243pub const exception_type_t = darwin.exception_type_t;
1121511244pub const mach_exception_data_t = darwin.mach_exception_data_t;
1121611245pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;
1121711246pub const mach_msg_bits_t = darwin.mach_msg_bits_t;
1121811247pub const mach_msg_id_t = darwin.mach_msg_id_t;
11248pub const mach_msg_header_t = darwin.mach_msg_header_t;
1121911249pub const mach_msg_option_t = darwin.mach_msg_option_t;
1122011250pub const mach_msg_size_t = darwin.mach_msg_size_t;
1122111251pub 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;
1122511255pub const policy_t = darwin.policy_t;
1122611256pub const task_policy_flavor_t = darwin.task_policy_flavor_t;
1122711257pub const task_policy_t = darwin.task_policy_t;
11258pub const task_read_t = darwin.task_read_t;
1122811259pub const task_t = darwin.task_t;
1122911260pub const thread_act_t = darwin.thread_act_t;
1123011261pub const thread_flavor_t = darwin.thread_flavor_t;
lib/std/c/darwin.zig+362-236
......@@ -19,12 +19,6 @@ comptime {
1919
2020pub 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
2822pub const EXC = enum(exception_type_t) {
2923 NULL = 0,
3024 /// Could not access memory
......@@ -54,6 +48,8 @@ pub const EXC = enum(exception_type_t) {
5448 /// Abnormal process exited to corpse state
5549 CORPSE_NOTIFY = 13,
5650
51 _,
52
5753 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len;
5854 pub const SOFT_SIGNAL = 0x10003;
5955
......@@ -110,56 +106,240 @@ pub const EXCEPTION = enum(u32) {
110106 _,
111107};
112108
113/// Prefer sending a catch_exception_raice_backtrace message, if applicable.
114pub const MACH_EXCEPTION_BACKTRACE_PREFERRED = 0x20000000;
115/// include additional exception specific errors, not used yet.
116pub const MACH_EXCEPTION_ERRORS = 0x40000000;
117/// Send 64-bit code and subcode in the exception header */
118pub const MACH_EXCEPTION_CODES = 0x80000000;
119
120pub const MACH_EXCEPTION_MASK = MACH_EXCEPTION_CODES |
121 MACH_EXCEPTION_ERRORS |
122 MACH_EXCEPTION_BACKTRACE_PREFERRED;
123
124pub const TASK_NULL: task_t = 0;
125pub const THREAD_NULL: thread_t = 0;
126pub const MACH_PORT_NULL: mach_port_t = 0;
127pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0;
128
129pub const MACH_MSG_OPTION_NONE = 0x00000000;
130
131pub const MACH_SEND_MSG = 0x00000001;
132pub const MACH_RCV_MSG = 0x00000002;
133
134pub const MACH_RCV_LARGE = 0x00000004;
135pub const MACH_RCV_LARGE_IDENTITY = 0x00000008;
136
137pub const MACH_SEND_TIMEOUT = 0x00000010;
138pub const MACH_SEND_OVERRIDE = 0x00000020;
139pub const MACH_SEND_INTERRUPT = 0x00000040;
140pub const MACH_SEND_NOTIFY = 0x00000080;
141pub const MACH_SEND_ALWAYS = 0x00010000;
142pub const MACH_SEND_FILTER_NONFATAL = 0x00010000;
143pub const MACH_SEND_TRAILER = 0x00020000;
144pub const MACH_SEND_NOIMPORTANCE = 0x00040000;
145pub const MACH_SEND_NODENAP = MACH_SEND_NOIMPORTANCE;
146pub const MACH_SEND_IMPORTANCE = 0x00080000;
147pub const MACH_SEND_SYNC_OVERRIDE = 0x00100000;
148pub const MACH_SEND_PROPAGATE_QOS = 0x00200000;
149pub const MACH_SEND_SYNC_USE_THRPRI = MACH_SEND_PROPAGATE_QOS;
150pub const MACH_SEND_KERNEL = 0x00400000;
151pub const MACH_SEND_SYNC_BOOTSTRAP_CHECKIN = 0x00800000;
152
153pub const MACH_RCV_TIMEOUT = 0x00000100;
154pub const MACH_RCV_NOTIFY = 0x00000000;
155pub const MACH_RCV_INTERRUPT = 0x00000400;
156pub const MACH_RCV_VOUCHER = 0x00000800;
157pub const MACH_RCV_OVERWRITE = 0x00000000;
158pub const MACH_RCV_GUARDED_DESC = 0x00001000;
159pub const MACH_RCV_SYNC_WAIT = 0x00004000;
160pub const MACH_RCV_SYNC_PEEK = 0x00008000;
161
162pub const MACH_MSG_STRICT_REPLY = 0x00000200;
109pub const KEVENT = struct {
110 /// Used as the `flags` arg for `kevent64`.
111 pub const FLAG = packed struct(c_uint) {
112 /// immediate timeout
113 IMMEDIATE: bool = false,
114 /// output events only include change
115 ERROR_EVENTS: bool = false,
116 _: u30 = 0,
117
118 /// no flag value
119 pub const NONE: KEVENT.FLAG = .{
120 .IMMEDIATE = false,
121 .ERROR_EVENTS = false,
122 };
123 };
124};
125
126pub const MACH = struct {
127 pub const EXCEPTION = packed struct(exception_mask_t) {
128 _: u29 = 0,
129 /// Prefer sending a catch_exception_raice_backtrace message, if applicable.
130 BACKTRACE_PREFERRED: bool = false,
131 /// include additional exception specific errors, not used yet.
132 ERRORS: bool = false,
133 /// Send 64-bit code and subcode in the exception header */
134 CODES: bool = false,
135
136 pub const MASK = @compileError("use MACH.EXCEPTION and set/check all named fields");
137 };
138
139 pub const MSG = packed struct(kern_return_t) {
140 _0: u10 = 0,
141 /// Kernel resource shortage handling an IPC capability.
142 VM_KERNEL: bool = false,
143 /// Kernel resource shortage handling out-of-line memory.
144 IPC_KERNEL: bool = false,
145 /// No room in VM address space for out-of-line memory.
146 VM_SPACE: bool = false,
147 /// No room in IPC name space for another capability name.
148 IPC_SPACE: bool = false,
149 _14: u18 = 0,
150
151 pub const MASK: kern_return_t = @bitCast(MACH.MSG{
152 .VM_KERNEL = true,
153 .IPC_KERNEL = true,
154 .VM_SPACE = true,
155 .IPC_SPACE = true,
156 });
157
158 pub const TIMEOUT_NONE = @compileError("use mach_msg_timeout_t.NONE");
159 pub const OPTION_NONE = @compileError("use MACH.RCV and/or MACH.SEND with their default values");
160 pub const STRICT_REPLY = @compileError("use MACH.RCV.STRICT_REPLY and/or MACH.SEND.STRICT_REPLY");
161
162 pub const TYPE = @compileError("use mach_msg_type_name_t members");
163 };
164
165 pub const PORT = struct {
166 pub const NULL: mach_port_t = 0;
167 pub const RIGHT = @compileError("use mach_port_right_t members");
168 };
169
170 pub const RCV = packed struct(integer_t) {
171 _0: u1 = 0,
172 /// Other flags are only valid if this one is set.
173 MSG: bool = true,
174 LARGE: bool = false,
175 LARGE_IDENTITY: bool = false,
176 _4: u4 = 0,
177 TIMEOUT: bool = false,
178 /// Shared between `RCV` and `SEND`. Used to be `MACH_RCV_NOTIFY`.
179 STRICT_REPLY: bool = false,
180 INTERRUPT: bool = false,
181 VOUCHER: bool = false,
182 GUARDED_DESC: bool = false,
183 _13: u1 = 0,
184 SYNC_WAIT: bool = false,
185 SYNC_PEEK: bool = false,
186 _16: u16 = 0,
187 };
188
189 pub const SEND = packed struct(integer_t) {
190 /// Other flags are only valid if this one is set.
191 MSG: bool = true,
192 _1: u3 = 0,
193 TIMEOUT: bool = false,
194 OVERRIDE: bool = false,
195 INTERRUPT: bool = false,
196 NOTIFY: bool = false,
197 _8: u1 = 0,
198 /// Shared between `RCV` and `SEND`.
199 STRICT_REPLY: bool = false,
200 _10: u6 = 0,
201 /// User-only. If you're the kernel, this bit is `MACH_SEND_ALWAYS`.
202 FILTER_NONFATAL: bool = false,
203 TRAILER: bool = false,
204 /// Synonymous to `MACH_SEND_NODENAP`.
205 NOIMPORTANCE: bool = false,
206 /// Kernel-only.
207 IMPORTANCE: bool = false,
208 SYNC_OVERRIDE: bool = false,
209 /// Synonymous to `MACH_SEND_SYNC_USE_THRPRI`.
210 PROPAGATE_QOS: bool = false,
211 /// Kernel-only.
212 KERNEL: bool = false,
213 SYNC_BOOTSTRAP_CHECKIN: bool = false,
214 _24: u8 = 0,
215 };
216
217 pub const TASK = struct {
218 pub const BASIC = struct {
219 pub const INFO = 20;
220 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t);
221 };
222 };
223};
224
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
164344pub const exception_type_t = c_int;
165345
......@@ -293,7 +473,7 @@ pub extern "c" fn kevent64(
293473 nchanges: c_int,
294474 eventlist: [*]kevent64_s,
295475 nevents: c_int,
296 flags: c_uint,
476 flags: KEVENT.FLAG,
297477 timeout: ?*const timespec,
298478) c_int;
299479
......@@ -321,11 +501,7 @@ pub const mach_vm_size_t = u64;
321501pub const mach_msg_bits_t = c_uint;
322502pub const mach_msg_id_t = integer_t;
323503pub 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;
326504pub const mach_msg_size_t = natural_t;
327pub const mach_msg_timeout_t = natural_t;
328pub const mach_port_right_t = natural_t;
329505pub const task_t = mach_port_t;
330506pub const thread_port_t = task_t;
331507pub const thread_t = thread_port_t;
......@@ -342,19 +518,21 @@ pub const thread_state_flavor_t = c_int;
342518pub const ipc_space_t = mach_port_t;
343519pub const ipc_space_port_t = ipc_space_t;
344520
345pub const MACH_PORT_RIGHT = enum(mach_port_right_t) {
346 SEND = 0,
347 RECEIVE = 1,
348 SEND_ONCE = 2,
349 PORT_SET = 3,
350 DEAD_NAME = 4,
351 /// Obsolete right
352 LABELH = 5,
353 /// Right not implemented
354 NUMBER = 6,
521pub const mach_msg_option_t = packed union {
522 RCV: MACH.RCV,
523 SEND: MACH.SEND,
524
525 pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t {
526 return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv)));
527 }
355528};
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) {
358536 /// Must hold receive right
359537 MOVE_RECEIVE = 16,
360538 /// Must hold send right(s)
......@@ -375,6 +553,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
375553 DISPOSE_SEND = 25,
376554 /// Must hold sendonce right
377555 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 _,
378572};
379573
380574extern "c" var mach_task_self_: mach_port_t;
......@@ -390,7 +584,7 @@ pub extern "c" fn mach_msg(
390584 rcv_name: mach_port_name_t,
391585 timeout: mach_msg_timeout_t,
392586 notify: mach_port_name_t,
393) kern_return_t;
587) mach_msg_return_t;
394588
395589pub const mach_msg_header_t = extern struct {
396590 msgh_bits: mach_msg_bits_t,
......@@ -462,46 +656,6 @@ pub const vm_behavior_t = i32;
462656pub const vm32_object_id_t = u32;
463657pub 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
505659pub const vm_region_basic_info_64 = extern struct {
506660 protection: vm_prot_t,
507661 max_protection: vm_prot_t,
......@@ -630,12 +784,6 @@ pub extern "c" fn thread_info(
630784) kern_return_t;
631785pub 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
639787pub const thread_flavor_t = natural_t;
640788pub const thread_info_t = *integer_t;
641789pub const time_value_t = time_value;
......@@ -678,34 +826,6 @@ pub const thread_identifier_info = extern struct {
678826 dispatch_qaddr: u64,
679827};
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
709829pub const task_vm_info = extern struct {
710830 // virtual memory size (bytes)
711831 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
791911pub extern "c" fn mach_port_insert_right(
792912 task: ipc_space_t,
793913 name: mach_port_name_t,
794 poly: mach_port_t,
795 poly_poly: mach_msg_type_name_t,
914 right: mach_port_t,
915 right_type: mach_msg_type_name_t,
796916) kern_return_t;
797917
798918pub extern "c" fn task_info(
......@@ -817,9 +937,6 @@ pub const mach_task_basic_info = extern struct {
817937 suspend_count: mach_vm_size_t,
818938};
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
823940pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;
824941pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t;
825942pub extern "c" fn vm_machine_attribute(
......@@ -847,17 +964,19 @@ pub const NSIG = 32;
847964
848965pub const qos_class_t = enum(c_uint) {
849966 /// highest priority QOS class for critical tasks
850 QOS_CLASS_USER_INTERACTIVE = 0x21,
967 USER_INTERACTIVE = 0x21,
851968 /// slightly more moderate priority QOS class
852 QOS_CLASS_USER_INITIATED = 0x19,
969 USER_INITIATED = 0x19,
853970 /// default QOS class when none is set
854 QOS_CLASS_DEFAULT = 0x15,
971 DEFAULT = 0x15,
855972 /// more energy efficient QOS class than default
856 QOS_CLASS_UTILITY = 0x11,
973 UTILITY = 0x11,
857974 /// QOS class more appropriate for background tasks
858 QOS_CLASS_BACKGROUND = 0x09,
975 BACKGROUND = 0x09,
859976 /// QOS class as a return value
860 QOS_CLASS_UNSPECIFIED = 0x00,
977 UNSPECIFIED = 0x00,
978
979 _,
861980};
862981
863982// Grand Central Dispatch is exposed by libSystem.
......@@ -868,13 +987,17 @@ pub extern "c" fn dispatch_semaphore_create(value: isize) ?dispatch_semaphore_t;
868987pub extern "c" fn dispatch_semaphore_wait(dsema: dispatch_semaphore_t, timeout: dispatch_time_t) isize;
869988pub extern "c" fn dispatch_semaphore_signal(dsema: dispatch_semaphore_t) isize;
870989
871pub const dispatch_time_t = u64;
872pub const DISPATCH_TIME_NOW = @as(dispatch_time_t, 0);
873pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0);
990pub const DISPATCH_TIME_NOW = @compileError("use dispatch_time_t.NOW");
991pub const DISPATCH_TIME_FOREVER = @compileError("use dispatch_time_t.FOREVER");
992pub const dispatch_time_t = enum(u64) {
993 NOW = 0,
994 FOREVER = ~0,
995 _,
996};
874997pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;
875998
876const dispatch_once_t = usize;
877const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
999pub const dispatch_once_t = usize;
1000pub const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
8781001pub extern fn dispatch_once_f(
8791002 predicate: *dispatch_once_t,
8801003 context: ?*anyopaque,
......@@ -905,6 +1028,7 @@ pub const UL = packed struct(u32) {
9051028 UNFAIR_LOCK64_SHARED = 4,
9061029 COMPARE_AND_WAIT64 = 5,
9071030 COMPARE_AND_WAIT64_SHARED = 6,
1031 _,
9081032 };
9091033};
9101034
......@@ -923,29 +1047,28 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
9231047pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
9241048pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
9251049
926pub const os_signpost_id_t = u64;
927
928pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;
929pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;
930pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;
1050pub const os_signpost_id_t = enum(u64) {
1051 NULL = 0,
1052 INVALID = !0,
1053 EXCLUSIVE = 0xeeeeb0b5b2b2eeee,
1054 _,
1055};
9311056
9321057pub const os_log_t = *opaque {};
9331058pub const os_log_type_t = enum(u8) {
9341059 /// default messages always captures
935 OS_LOG_TYPE_DEFAULT = 0x00,
1060 DEFAULT = 0x00,
9361061 /// messages with additional infos
937 OS_LOG_TYPE_INFO = 0x01,
1062 INFO = 0x01,
9381063 /// debug messages
939 OS_LOG_TYPE_DEBUG = 0x02,
1064 DEBUG = 0x02,
9401065 /// error messages
941 OS_LOG_TYPE_ERROR = 0x10,
1066 ERROR = 0x10,
9421067 /// unexpected conditions messages
943 OS_LOG_TYPE_FAULT = 0x11,
944};
1068 FAULT = 0x11,
9451069
946pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
947pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";
948pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
1070 _,
1071};
9491072
9501073pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
9511074pub 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;
10121135
10131136pub 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
10221138pub const SYSPROTO_EVENT = 1;
10231139pub 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
10421141/// Mach msg return values
1043pub const MachMsgE = enum(u32) {
1142pub const mach_msg_return_t = enum(kern_return_t) {
10441143 SUCCESS = 0x00000000,
10451144
10461145 /// Thread is waiting to send. (Internal use only.)
......@@ -1104,9 +1203,9 @@ pub const MachMsgE = enum(u32) {
11041203 RCV_PORT_DIED = 0x10004009,
11051204 /// compatibility: no longer a returned error
11061205 RCV_IN_SET = 0x1000400a,
1107 /// Error receiving message header. See special bits.
1206 /// Error receiving message header. See special bits (use `extractResourceError`).
11081207 RCV_HEADER_ERROR = 0x1000400b,
1109 /// Error receiving message body. See special bits.
1208 /// Error receiving message body. See special bits (use `extractResourceError`).
11101209 RCV_BODY_ERROR = 0x1000400c,
11111210 /// Invalid msg-type specification in scatter list.
11121211 RCV_INVALID_TYPE = 0x1000400d,
......@@ -1118,6 +1217,28 @@ pub const MachMsgE = enum(u32) {
11181217 RCV_IN_PROGRESS_TIMED = 0x10004011,
11191218 /// invalid reply port used in a STRICT_REPLY message
11201219 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 }
11211242};
11221243
11231244pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
......@@ -1171,48 +1292,53 @@ pub const CPUFAMILY = enum(u32) {
11711292 _,
11721293};
11731294
1174pub const PT = struct {
1175 pub const TRACE_ME = 0;
1176 pub const READ_I = 1;
1177 pub const READ_D = 2;
1178 pub const READ_U = 3;
1179 pub const WRITE_I = 4;
1180 pub const WRITE_D = 5;
1181 pub const WRITE_U = 6;
1182 pub const CONTINUE = 7;
1183 pub const KILL = 8;
1184 pub const STEP = 9;
1185 pub const DETACH = 11;
1186 pub const SIGEXC = 12;
1187 pub const THUPDATE = 13;
1188 pub const ATTACHEXC = 14;
1189 pub const FORCEQUOTA = 30;
1190 pub const DENY_ATTACH = 31;
1295pub const PT = enum(c_int) {
1296 TRACE_ME = 0,
1297 READ_I = 1,
1298 READ_D = 2,
1299 READ_U = 3,
1300 WRITE_I = 4,
1301 WRITE_D = 5,
1302 WRITE_U = 6,
1303 CONTINUE = 7,
1304 KILL = 8,
1305 STEP = 9,
1306 DETACH = 11,
1307 SIGEXC = 12,
1308 THUPDATE = 13,
1309 ATTACHEXC = 14,
1310 FORCEQUOTA = 30,
1311 DENY_ATTACH = 31,
1312 _,
11911313};
11921314
11931315pub const caddr_t = ?[*]u8;
11941316
1195pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;
1196
1197pub const POSIX_SPAWN = struct {
1198 pub const RESETIDS = 0x0001;
1199 pub const SETPGROUP = 0x0002;
1200 pub const SETSIGDEF = 0x0004;
1201 pub const SETSIGMASK = 0x0008;
1202 pub const SETEXEC = 0x0040;
1203 pub const START_SUSPENDED = 0x0080;
1204 pub const DISABLE_ASLR = 0x0100;
1205 pub const SETSID = 0x0400;
1206 pub const RESLIDE = 0x0800;
1207 pub const CLOEXEC_DEFAULT = 0x4000;
1317pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int;
1318
1319pub const POSIX_SPAWN = packed struct(c_short) {
1320 RESETIDS: bool = false,
1321 SETPGROUP: bool = false,
1322 SETSIGDEF: bool = false,
1323 SETSIGMASK: bool = false,
1324 _4: u2 = 0,
1325 SETEXEC: bool = false,
1326 START_SUSPENDED: bool = false,
1327 DISABLE_ASLR: bool = false,
1328 _9: u1 = 0,
1329 SETSID: bool = false,
1330 RESLIDE: bool = false,
1331 _12: u2 = 0,
1332 CLOEXEC_DEFAULT: bool = false,
1333 _15: u1 = 0,
12081334};
12091335
12101336pub const posix_spawnattr_t = *opaque {};
12111337pub const posix_spawn_file_actions_t = *opaque {};
12121338pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
12131339pub 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;
1215pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
1340pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int;
1341pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int;
12161342pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
12171343pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
12181344pub 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 {
8383 .driverkit, .ios, .macos, .tvos, .visionos, .watchos => blk: {
8484 const task_port = std.c.mach_task_self();
8585 // 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)
8787 break :blk 0;
88 var info_count = std.c.TASK_VM_INFO_COUNT;
88 var info_count = std.c.TASK.VM.INFO_COUNT;
8989 var vm_info: std.c.task_vm_info_data_t = undefined;
9090 vm_info.page_size = 0;
9191 _ = std.c.task_info(
9292 task_port,
93 std.c.TASK_VM_INFO,
93 std.c.TASK.VM.INFO,
9494 @as(std.c.task_info_t, @ptrCast(&vm_info)),
9595 &info_count,
9696 );
src/DarwinPosixSpawn.zig+5-5
......@@ -41,17 +41,17 @@ pub const Attr = struct {
4141 }
4242 }
4343
44 pub fn get(self: Attr) Error!u16 {
45 var flags: c_short = undefined;
44 pub fn get(self: Attr) Error!std.c.POSIX_SPAWN {
45 var flags: std.c.POSIX_SPAWN = undefined;
4646 switch (errno(std.c.posix_spawnattr_getflags(&self.attr, &flags))) {
47 .SUCCESS => return @as(u16, @bitCast(flags)),
47 .SUCCESS => return flags,
4848 .INVAL => unreachable,
4949 else => |err| return unexpectedErrno(err),
5050 }
5151 }
5252
53 pub fn set(self: *Attr, flags: u16) Error!void {
54 switch (errno(std.c.posix_spawnattr_setflags(&self.attr, @as(c_short, @bitCast(flags))))) {
53 pub fn set(self: *Attr, flags: std.c.POSIX_SPAWN) Error!void {
54 switch (errno(std.c.posix_spawnattr_setflags(&self.attr, flags))) {
5555 .SUCCESS => return,
5656 .INVAL => unreachable,
5757 else => |err| return unexpectedErrno(err),
src/main.zig+5-4
......@@ -4490,10 +4490,11 @@ fn runOrTestHotSwap(
44904490
44914491 // ASLR is probably a good default for better debugging experience/programming
44924492 // 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 |
4494 std.c.POSIX_SPAWN.SETSIGMASK |
4495 std.c.POSIX_SPAWN.DISABLE_ASLR;
4496 try attr.set(flags);
4493 try attr.set(.{
4494 .SETSIGDEF = true,
4495 .SETSIGMASK = true,
4496 .DISABLE_ASLR = true,
4497 });
44974498
44984499 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
44994500 defer arena_allocator.deinit();