authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-21 11:52:22-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-21 11:52:22-07:00
log595c9d2353b137485ae37313239bc5495ab75721
tree18070c630281391db4d7780fa4c8f28f1c60c0f9
parent1594c8055500c595e1b47c3985c035142b824280
parentda4c9af354b1bca2fb05ef2757c7f9ad11728ac6
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #24921 from Justus2308/messy-mach

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

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

lib/std/c.zig+31
......@@ -11106,12 +11106,15 @@ pub const fsfilcnt_t = freebsd.fsfilcnt_t;
1110611106pub const kinfo_file = freebsd.kinfo_file;
1110711107pub const kinfo_getfile = freebsd.kinfo_getfile;
1110811108
11109pub const CALENDAR_CLOCK = darwin.CALENDAR_CLOCK;
1110911110pub const COPYFILE = darwin.COPYFILE;
1111011111pub const CPUFAMILY = darwin.CPUFAMILY;
1111111112pub const PT = darwin.PT;
1111211113pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
1111311114pub const EXC = darwin.EXC;
1111411115pub const EXCEPTION = darwin.EXCEPTION;
11116pub const KEVENT = darwin.KEVENT;
11117pub const MACH = darwin.MACH;
1111511118pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;
1111611119pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;
1111711120pub const MACH_TASK_BASIC_INFO = darwin.MACH_TASK_BASIC_INFO;
......@@ -11119,10 +11122,15 @@ pub const MACH_TASK_BASIC_INFO_COUNT = darwin.MACH_TASK_BASIC_INFO_COUNT;
1111911122pub const MATTR = darwin.MATTR;
1112011123pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
1112111124pub const OPEN_MAX = darwin.OPEN_MAX;
11125pub const OS = darwin.OS;
1112211126pub const POSIX_SPAWN = darwin.POSIX_SPAWN;
11127pub const SYSPROTO_EVENT = darwin.SYSPROTO_EVENT;
11128pub const SYSPROTO_CONTROL = darwin.SYSPROTO_CONTROL;
11129pub const TASK = darwin.TASK;
1112311130pub const TASK_NULL = darwin.TASK_NULL;
1112411131pub const TASK_VM_INFO = darwin.TASK_VM_INFO;
1112511132pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;
11133pub const THREAD = darwin.THREAD;
1112611134pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;
1112711135pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;
1112811136pub const THREAD_IDENTIFIER_INFO_COUNT = darwin.THREAD_IDENTIFIER_INFO_COUNT;
......@@ -11140,15 +11148,24 @@ pub const _dyld_get_image_name = darwin._dyld_get_image_name;
1114011148pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
1114111149pub const _dyld_image_count = darwin._dyld_image_count;
1114211150pub const _host_page_size = darwin._host_page_size;
11151pub const boolean_t = darwin.boolean_t;
1114311152pub const clock_get_time = darwin.clock_get_time;
11153pub const clock_serv_t = darwin.clock_serv_t;
11154pub const clock_res_t = darwin.clock_res_t;
1114411155pub const @"close$NOCANCEL" = darwin.@"close$NOCANCEL";
11156pub const dispatch_function_t = darwin.dispatch_function_t;
11157pub const dispatch_once_f = darwin.dispatch_once_f;
11158pub const dispatch_once_t = darwin.dispatch_once_t;
1114511159pub const dispatch_release = darwin.dispatch_release;
1114611160pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;
1114711161pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;
11162pub const dispatch_semaphore_t = darwin.dispatch_semaphore_t;
1114811163pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;
1114911164pub const dispatch_time = darwin.dispatch_time;
11165pub const dispatch_time_t = darwin.dispatch_time_t;
1115011166pub const fcopyfile = darwin.fcopyfile;
1115111167pub const host_t = darwin.host_t;
11168pub const integer_t = darwin.integer_t;
1115211169pub const ipc_space_t = darwin.ipc_space_t;
1115311170pub const ipc_space_port_t = darwin.ipc_space_port_t;
1115411171pub const kern_return_t = darwin.kern_return_t;
......@@ -11160,6 +11177,7 @@ pub const mach_continuous_time = darwin.mach_continuous_time;
1116011177pub const mach_hdr = darwin.mach_hdr;
1116111178pub const mach_host_self = darwin.mach_host_self;
1116211179pub const mach_msg = darwin.mach_msg;
11180pub const mach_msg_return_t = darwin.mach_msg_return_t;
1116311181pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;
1116411182pub const mach_port_allocate = darwin.mach_port_allocate;
1116511183pub const mach_port_array_t = darwin.mach_port_array_t;
......@@ -11171,6 +11189,7 @@ pub const mach_task_basic_info = darwin.mach_task_basic_info;
1117111189pub const mach_task_self = darwin.mach_task_self;
1117211190pub const mach_timebase_info = darwin.mach_timebase_info;
1117311191pub const mach_timebase_info_data = darwin.mach_timebase_info_data;
11192pub const mach_timespec_t = darwin.mach_timespec_t;
1117411193pub const mach_vm_address_t = darwin.mach_vm_address_t;
1117511194pub const mach_vm_protect = darwin.mach_vm_protect;
1117611195pub const mach_vm_read = darwin.mach_vm_read;
......@@ -11180,16 +11199,20 @@ pub const mach_vm_size_t = darwin.mach_vm_size_t;
1118011199pub const mach_vm_write = darwin.mach_vm_write;
1118111200pub const natural_t = darwin.natural_t;
1118211201pub const os_log_create = darwin.os_log_create;
11202pub const os_log_t = darwin.os_log_t;
1118311203pub const os_log_type_enabled = darwin.os_log_type_enabled;
11204pub const os_log_type_t = darwin.os_log_type_t;
1118411205pub const os_signpost_enabled = darwin.os_signpost_enabled;
1118511206pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
1118611207pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;
11208pub const os_signpost_id_t = darwin.os_signpost_id_t;
1118711209pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
1118811210pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
1118911211pub const os_unfair_lock = darwin.os_unfair_lock;
1119011212pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
1119111213pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
1119211214pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
11215pub const os_unfair_lock_t = darwin.os_unfair_lock_t;
1119311216pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
1119411217pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
1119511218pub const pid_for_task = darwin.pid_for_task;
......@@ -11214,10 +11237,13 @@ pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;
1121411237pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
1121511238pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
1121611239pub const ptrace = darwin.ptrace;
11240pub const qos_class_t = darwin.qos_class_t;
11241pub const task_flavor_t = darwin.task_flavor_t;
1121711242pub const task_for_pid = darwin.task_for_pid;
1121811243pub const task_get_exception_ports = darwin.task_get_exception_ports;
1121911244pub const task_info = darwin.task_info;
1122011245pub const task_info_t = darwin.task_info_t;
11246pub const task_name_t = darwin.task_name_t;
1122111247pub const task_resume = darwin.task_resume;
1122211248pub const task_set_exception_ports = darwin.task_set_exception_ports;
1122311249pub const task_suspend = darwin.task_suspend;
......@@ -11230,8 +11256,10 @@ pub const thread_info = darwin.thread_info;
1123011256pub const thread_info_t = darwin.thread_info_t;
1123111257pub const thread_resume = darwin.thread_resume;
1123211258pub const thread_set_state = darwin.thread_set_state;
11259pub const vm_address_t = darwin.vm_address_t;
1123311260pub const vm_deallocate = darwin.vm_deallocate;
1123411261pub const vm_machine_attribute = darwin.vm_machine_attribute;
11262pub const vm_machine_attribute_t = darwin.vm_machine_attribute_t;
1123511263pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;
1123611264pub const vm_map_t = darwin.vm_map_t;
1123711265pub const vm_offset_t = darwin.vm_offset_t;
......@@ -11256,10 +11284,12 @@ pub const exception_mask_array_t = darwin.exception_mask_array_t;
1125611284pub const exception_mask_t = darwin.exception_mask_t;
1125711285pub const exception_port_array_t = darwin.exception_port_array_t;
1125811286pub const exception_port_t = darwin.exception_port_t;
11287pub const exception_type_t = darwin.exception_type_t;
1125911288pub const mach_exception_data_t = darwin.mach_exception_data_t;
1126011289pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;
1126111290pub const mach_msg_bits_t = darwin.mach_msg_bits_t;
1126211291pub const mach_msg_id_t = darwin.mach_msg_id_t;
11292pub const mach_msg_header_t = darwin.mach_msg_header_t;
1126311293pub const mach_msg_option_t = darwin.mach_msg_option_t;
1126411294pub const mach_msg_size_t = darwin.mach_msg_size_t;
1126511295pub const mach_msg_timeout_t = darwin.mach_msg_timeout_t;
......@@ -11269,6 +11299,7 @@ pub const memory_object_offset_t = darwin.memory_object_offset_t;
1126911299pub const policy_t = darwin.policy_t;
1127011300pub const task_policy_flavor_t = darwin.task_policy_flavor_t;
1127111301pub const task_policy_t = darwin.task_policy_t;
11302pub const task_read_t = darwin.task_read_t;
1127211303pub const task_t = darwin.task_t;
1127311304pub const thread_act_t = darwin.thread_act_t;
1127411305pub const thread_flavor_t = darwin.thread_flavor_t;
lib/std/c/darwin.zig+368-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,244 @@ 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: exception_mask_t = @bitCast(MACH.EXCEPTION{
137 .BACKTRACE_PREFERRED = true,
138 .ERRORS = true,
139 .CODES = true,
140 });
141 };
142
143 pub const MSG = packed struct(kern_return_t) {
144 _0: u10 = 0,
145 /// Kernel resource shortage handling an IPC capability.
146 VM_KERNEL: bool = false,
147 /// Kernel resource shortage handling out-of-line memory.
148 IPC_KERNEL: bool = false,
149 /// No room in VM address space for out-of-line memory.
150 VM_SPACE: bool = false,
151 /// No room in IPC name space for another capability name.
152 IPC_SPACE: bool = false,
153 _14: u18 = 0,
154
155 pub const MASK: kern_return_t = @bitCast(MACH.MSG{
156 .VM_KERNEL = true,
157 .IPC_KERNEL = true,
158 .VM_SPACE = true,
159 .IPC_SPACE = true,
160 });
161
162 pub const TIMEOUT_NONE: mach_msg_timeout_t = .NONE;
163 pub const OPTION_NONE: mach_msg_option_t = .NONE;
164 pub const STRICT_REPLY = @compileError("use MACH.RCV.STRICT_REPLY and/or MACH.SEND.STRICT_REPLY");
165
166 pub const TYPE = mach_msg_type_name_t;
167 };
168
169 pub const PORT = struct {
170 pub const NULL: mach_port_t = 0;
171 pub const RIGHT = mach_port_right_t;
172 };
173
174 pub const RCV = packed struct(integer_t) {
175 _0: u1 = 0,
176 /// Other flags are only valid if this one is set.
177 MSG: bool = true,
178 LARGE: bool = false,
179 LARGE_IDENTITY: bool = false,
180 _4: u4 = 0,
181 TIMEOUT: bool = false,
182 /// Shared between `RCV` and `SEND`. Used to be `MACH_RCV_NOTIFY`.
183 STRICT_REPLY: bool = false,
184 INTERRUPT: bool = false,
185 VOUCHER: bool = false,
186 GUARDED_DESC: bool = false,
187 _13: u1 = 0,
188 SYNC_WAIT: bool = false,
189 SYNC_PEEK: bool = false,
190 _16: u16 = 0,
191 };
192
193 pub const SEND = packed struct(integer_t) {
194 /// Other flags are only valid if this one is set.
195 MSG: bool = true,
196 _1: u3 = 0,
197 TIMEOUT: bool = false,
198 OVERRIDE: bool = false,
199 INTERRUPT: bool = false,
200 NOTIFY: bool = false,
201 _8: u1 = 0,
202 /// Shared between `RCV` and `SEND`.
203 STRICT_REPLY: bool = false,
204 _10: u6 = 0,
205 /// User-only. If you're the kernel, this bit is `MACH_SEND_ALWAYS`.
206 FILTER_NONFATAL: bool = false,
207 TRAILER: bool = false,
208 /// Synonymous to `MACH_SEND_NODENAP`.
209 NOIMPORTANCE: bool = false,
210 /// Kernel-only.
211 IMPORTANCE: bool = false,
212 SYNC_OVERRIDE: bool = false,
213 /// Synonymous to `MACH_SEND_SYNC_USE_THRPRI`.
214 PROPAGATE_QOS: bool = false,
215 /// Kernel-only.
216 KERNEL: bool = false,
217 SYNC_BOOTSTRAP_CHECKIN: bool = false,
218 _24: u8 = 0,
219 };
220
221 pub const TASK = struct {
222 pub const BASIC = struct {
223 pub const INFO = 20;
224 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t);
225 };
226 };
227};
228
229pub const MACH_MSG_TYPE = @compileError("use MACH.MSG.TYPE");
230pub const MACH_PORT_RIGHT = @compileError("use MACH.PORT.RIGHT");
231pub const MACH_TASK_BASIC_INFO = @compileError("use MACH.TASK.BASIC.INFO");
232pub const MACH_TASK_BASIC_INFO_COUNT = @compileError("use MACH.TASK.BASIC.INFO_COUNT");
233
234pub const MATTR = struct {
235 /// Cachability
236 pub const CACHE: vm_machine_attribute_t = 1;
237 /// Migrability
238 pub const MIGRATE: vm_machine_attribute_t = 2;
239 /// Replicability
240 pub const REPLICATE: vm_machine_attribute_t = 4;
241 /// (Generic) turn attribute off
242 pub const VAL_OFF: vm_machine_attribute_t = 0;
243 /// (Generic) turn attribute on
244 pub const VAL_ON: vm_machine_attribute_t = 1;
245 /// (Generic) return current value
246 pub const VAL_GET: vm_machine_attribute_t = 2;
247 /// Flush from all caches
248 pub const VAL_CACHE_FLUSH: vm_machine_attribute_t = 6;
249 /// Flush from data caches
250 pub const VAL_DCACHE_FLUSH: vm_machine_attribute_t = 7;
251 /// Flush from instruction caches
252 pub const VAL_ICACHE_FLUSH: vm_machine_attribute_t = 8;
253 /// Sync I+D caches
254 pub const VAL_CACHE_SYNC: vm_machine_attribute_t = 9;
255 /// Get page info (stats)
256 pub const VAL_GET_INFO: vm_machine_attribute_t = 10;
257};
258
259pub const OS = struct {
260 pub const LOG_CATEGORY = struct {
261 pub const POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
262 pub const DYNAMIC_TRACING: *const u8 = "DynamicTracing";
263 pub const DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
264 };
265};
266
267pub const TASK = struct {
268 pub const NULL: task_t = 0;
269
270 pub const VM = struct {
271 pub const INFO = 22;
272 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t);
273 };
274};
275
276pub const TASK_NULL = @compileError("use TASK.NULL");
277pub const TASK_VM_INFO = @compileError("use TASK.VM.INFO");
278pub const TASK_VM_INFO_COUNT = @compileError("use TASK.VM.INFO_COUNT");
279
280pub const THREAD = struct {
281 pub const NULL: thread_t = 0;
282
283 pub const BASIC = struct {
284 pub const INFO = 3;
285 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t);
286 };
287
288 pub const IDENTIFIER = struct {
289 pub const INFO = 4;
290 pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t);
291 };
292
293 pub const STATE = struct {
294 pub const NONE = switch (native_arch) {
295 .aarch64 => 5,
296 .x86_64 => 13,
297 else => @compileError("unsupported arch"),
298 };
299 };
300};
301
302pub const THREAD_NULL = @compileError("use THREAD.NULL");
303pub const THREAD_BASIC_INFO = @compileError("use THREAD.BASIC.INFO");
304pub const THREAD_BASIC_INFO_COUNT = @compileError("use THREAD.BASIC.INFO_COUNT");
305pub const THREAD_IDENTIFIER_INFO_COUNT = @compileError("use THREAD.IDENTIFIER.INFO_COUNT");
306pub const THREAD_STATE_NONE = @compileError("use THREAD.STATE.NONE");
307
308pub const VM = struct {
309 pub const INHERIT = struct {
310 pub const SHARE: vm_inherit_t = 0;
311 pub const COPY: vm_inherit_t = 1;
312 pub const NONE: vm_inherit_t = 2;
313 pub const DONATE_COPY: vm_inherit_t = 3;
314 pub const DEFAULT = VM.INHERIT.COPY;
315 };
316
317 pub const BEHAVIOR = struct {
318 pub const DEFAULT: vm_behavior_t = 0;
319 pub const RANDOM: vm_behavior_t = 1;
320 pub const SEQUENTIAL: vm_behavior_t = 2;
321 pub const RSEQNTL: vm_behavior_t = 3;
322 pub const WILLNEED: vm_behavior_t = 4;
323 pub const DONTNEED: vm_behavior_t = 5;
324 pub const FREE: vm_behavior_t = 6;
325 pub const ZERO_WIRED_PAGES: vm_behavior_t = 7;
326 pub const REUSABLE: vm_behavior_t = 8;
327 pub const REUSE: vm_behavior_t = 9;
328 pub const CAN_REUSE: vm_behavior_t = 10;
329 pub const PAGEOUT: vm_behavior_t = 11;
330 };
331
332 pub const REGION = struct {
333 pub const BASIC_INFO_64 = 9;
334 pub const EXTENDED_INFO = 13;
335 pub const TOP_INFO = 12;
336 pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t);
337 pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t);
338 pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int);
339 pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t);
340 pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t);
341 };
342
343 pub fn MAKE_TAG(tag: u8) u32 {
344 return @as(u32, tag) << 24;
345 }
346};
163347
164348pub const exception_type_t = c_int;
165349
......@@ -293,7 +477,7 @@ pub extern "c" fn kevent64(
293477 nchanges: c_int,
294478 eventlist: [*]kevent64_s,
295479 nevents: c_int,
296 flags: c_uint,
480 flags: KEVENT.FLAG,
297481 timeout: ?*const timespec,
298482) c_int;
299483
......@@ -321,11 +505,7 @@ pub const mach_vm_size_t = u64;
321505pub const mach_msg_bits_t = c_uint;
322506pub const mach_msg_id_t = integer_t;
323507pub 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;
326508pub const mach_msg_size_t = natural_t;
327pub const mach_msg_timeout_t = natural_t;
328pub const mach_port_right_t = natural_t;
329509pub const task_t = mach_port_t;
330510pub const thread_port_t = task_t;
331511pub const thread_t = thread_port_t;
......@@ -342,19 +522,23 @@ pub const thread_state_flavor_t = c_int;
342522pub const ipc_space_t = mach_port_t;
343523pub const ipc_space_port_t = ipc_space_t;
344524
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,
525pub const mach_msg_option_t = packed union {
526 RCV: MACH.RCV,
527 SEND: MACH.SEND,
528
529 pub const NONE: mach_msg_option_t = @bitCast(@as(integer_t, 0));
530
531 pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t {
532 return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv)));
533 }
355534};
356535
357pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
536pub const mach_msg_timeout_t = enum(natural_t) {
537 NONE = 0,
538 _,
539};
540
541pub const mach_msg_type_name_t = enum(c_uint) {
358542 /// Must hold receive right
359543 MOVE_RECEIVE = 16,
360544 /// Must hold send right(s)
......@@ -375,6 +559,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
375559 DISPOSE_SEND = 25,
376560 /// Must hold sendonce right
377561 DISPOSE_SEND_ONCE = 26,
562
563 _,
564};
565
566pub const mach_port_right_t = enum(natural_t) {
567 SEND = 0,
568 RECEIVE = 1,
569 SEND_ONCE = 2,
570 PORT_SET = 3,
571 DEAD_NAME = 4,
572 /// Obsolete right
573 LABELH = 5,
574 /// Right not implemented
575 NUMBER = 6,
576
577 _,
378578};
379579
380580extern "c" var mach_task_self_: mach_port_t;
......@@ -390,7 +590,7 @@ pub extern "c" fn mach_msg(
390590 rcv_name: mach_port_name_t,
391591 timeout: mach_msg_timeout_t,
392592 notify: mach_port_name_t,
393) kern_return_t;
593) mach_msg_return_t;
394594
395595pub const mach_msg_header_t = extern struct {
396596 msgh_bits: mach_msg_bits_t,
......@@ -462,46 +662,6 @@ pub const vm_behavior_t = i32;
462662pub const vm32_object_id_t = u32;
463663pub const vm_object_id_t = u64;
464664
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
505665pub const vm_region_basic_info_64 = extern struct {
506666 protection: vm_prot_t,
507667 max_protection: vm_prot_t,
......@@ -630,12 +790,6 @@ pub extern "c" fn thread_info(
630790) kern_return_t;
631791pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t;
632792
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
639793pub const thread_flavor_t = natural_t;
640794pub const thread_info_t = *integer_t;
641795pub const time_value_t = time_value;
......@@ -678,34 +832,6 @@ pub const thread_identifier_info = extern struct {
678832 dispatch_qaddr: u64,
679833};
680834
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
709835pub const task_vm_info = extern struct {
710836 // virtual memory size (bytes)
711837 virtual_size: mach_vm_size_t,
......@@ -791,8 +917,8 @@ pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t
791917pub extern "c" fn mach_port_insert_right(
792918 task: ipc_space_t,
793919 name: mach_port_name_t,
794 poly: mach_port_t,
795 poly_poly: mach_msg_type_name_t,
920 right: mach_port_t,
921 right_type: mach_msg_type_name_t,
796922) kern_return_t;
797923
798924pub extern "c" fn task_info(
......@@ -817,9 +943,6 @@ pub const mach_task_basic_info = extern struct {
817943 suspend_count: mach_vm_size_t,
818944};
819945
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
823946pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;
824947pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t;
825948pub extern "c" fn vm_machine_attribute(
......@@ -847,17 +970,19 @@ pub const NSIG = 32;
847970
848971pub const qos_class_t = enum(c_uint) {
849972 /// highest priority QOS class for critical tasks
850 QOS_CLASS_USER_INTERACTIVE = 0x21,
973 USER_INTERACTIVE = 0x21,
851974 /// slightly more moderate priority QOS class
852 QOS_CLASS_USER_INITIATED = 0x19,
975 USER_INITIATED = 0x19,
853976 /// default QOS class when none is set
854 QOS_CLASS_DEFAULT = 0x15,
977 DEFAULT = 0x15,
855978 /// more energy efficient QOS class than default
856 QOS_CLASS_UTILITY = 0x11,
979 UTILITY = 0x11,
857980 /// QOS class more appropriate for background tasks
858 QOS_CLASS_BACKGROUND = 0x09,
981 BACKGROUND = 0x09,
859982 /// QOS class as a return value
860 QOS_CLASS_UNSPECIFIED = 0x00,
983 UNSPECIFIED = 0x00,
984
985 _,
861986};
862987
863988// Grand Central Dispatch is exposed by libSystem.
......@@ -868,13 +993,17 @@ pub extern "c" fn dispatch_semaphore_create(value: isize) ?dispatch_semaphore_t;
868993pub extern "c" fn dispatch_semaphore_wait(dsema: dispatch_semaphore_t, timeout: dispatch_time_t) isize;
869994pub extern "c" fn dispatch_semaphore_signal(dsema: dispatch_semaphore_t) isize;
870995
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);
996pub const DISPATCH_TIME_NOW = @compileError("use dispatch_time_t.NOW");
997pub const DISPATCH_TIME_FOREVER = @compileError("use dispatch_time_t.FOREVER");
998pub const dispatch_time_t = enum(u64) {
999 NOW = 0,
1000 FOREVER = ~0,
1001 _,
1002};
8741003pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;
8751004
876const dispatch_once_t = usize;
877const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
1005pub const dispatch_once_t = usize;
1006pub const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
8781007pub extern fn dispatch_once_f(
8791008 predicate: *dispatch_once_t,
8801009 context: ?*anyopaque,
......@@ -905,6 +1034,7 @@ pub const UL = packed struct(u32) {
9051034 UNFAIR_LOCK64_SHARED = 4,
9061035 COMPARE_AND_WAIT64 = 5,
9071036 COMPARE_AND_WAIT64_SHARED = 6,
1037 _,
9081038 };
9091039};
9101040
......@@ -923,29 +1053,28 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
9231053pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
9241054pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
9251055
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;
1056pub const os_signpost_id_t = enum(u64) {
1057 NULL = 0,
1058 INVALID = !0,
1059 EXCLUSIVE = 0xeeeeb0b5b2b2eeee,
1060 _,
1061};
9311062
9321063pub const os_log_t = *opaque {};
9331064pub const os_log_type_t = enum(u8) {
9341065 /// default messages always captures
935 OS_LOG_TYPE_DEFAULT = 0x00,
1066 DEFAULT = 0x00,
9361067 /// messages with additional infos
937 OS_LOG_TYPE_INFO = 0x01,
1068 INFO = 0x01,
9381069 /// debug messages
939 OS_LOG_TYPE_DEBUG = 0x02,
1070 DEBUG = 0x02,
9401071 /// error messages
941 OS_LOG_TYPE_ERROR = 0x10,
1072 ERROR = 0x10,
9421073 /// unexpected conditions messages
943 OS_LOG_TYPE_FAULT = 0x11,
944};
1074 FAULT = 0x11,
9451075
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";
1076 _,
1077};
9491078
9501079pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
9511080pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
......@@ -1012,35 +1141,11 @@ pub const vm_machine_attribute_val_t = isize;
10121141
10131142pub const CALENDAR_CLOCK = 1;
10141143
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
10221144pub const SYSPROTO_EVENT = 1;
10231145pub const SYSPROTO_CONTROL = 2;
10241146
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
10421147/// Mach msg return values
1043pub const MachMsgE = enum(u32) {
1148pub const mach_msg_return_t = enum(kern_return_t) {
10441149 SUCCESS = 0x00000000,
10451150
10461151 /// Thread is waiting to send. (Internal use only.)
......@@ -1104,9 +1209,9 @@ pub const MachMsgE = enum(u32) {
11041209 RCV_PORT_DIED = 0x10004009,
11051210 /// compatibility: no longer a returned error
11061211 RCV_IN_SET = 0x1000400a,
1107 /// Error receiving message header. See special bits.
1212 /// Error receiving message header. See special bits (use `extractResourceError`).
11081213 RCV_HEADER_ERROR = 0x1000400b,
1109 /// Error receiving message body. See special bits.
1214 /// Error receiving message body. See special bits (use `extractResourceError`).
11101215 RCV_BODY_ERROR = 0x1000400c,
11111216 /// Invalid msg-type specification in scatter list.
11121217 RCV_INVALID_TYPE = 0x1000400d,
......@@ -1118,6 +1223,28 @@ pub const MachMsgE = enum(u32) {
11181223 RCV_IN_PROGRESS_TIMED = 0x10004011,
11191224 /// invalid reply port used in a STRICT_REPLY message
11201225 RCV_INVALID_REPLY = 0x10004012,
1226
1227 _,
1228
1229 pub fn extractResourceError(ret: mach_msg_return_t) struct {
1230 error_code: mach_msg_return_t,
1231 resource_error: ?MACH.MSG,
1232 } {
1233 const return_code: mach_msg_return_t = @enumFromInt(@intFromEnum(ret) & ~MACH.MSG.MASK);
1234 switch (return_code) {
1235 .RCV_HEADER_ERROR, .RCV_BODY_ERROR => {
1236 const resource_error: MACH.MSG = @bitCast(@intFromEnum(ret) & MACH.MSG.MASK);
1237 return .{
1238 .error_code = return_code,
1239 .resource_error = resource_error,
1240 };
1241 },
1242 else => return .{
1243 .error_code = ret,
1244 .resource_error = null,
1245 },
1246 }
1247 }
11211248};
11221249
11231250pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
......@@ -1171,48 +1298,53 @@ pub const CPUFAMILY = enum(u32) {
11711298 _,
11721299};
11731300
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;
1301pub const PT = enum(c_int) {
1302 TRACE_ME = 0,
1303 READ_I = 1,
1304 READ_D = 2,
1305 READ_U = 3,
1306 WRITE_I = 4,
1307 WRITE_D = 5,
1308 WRITE_U = 6,
1309 CONTINUE = 7,
1310 KILL = 8,
1311 STEP = 9,
1312 DETACH = 11,
1313 SIGEXC = 12,
1314 THUPDATE = 13,
1315 ATTACHEXC = 14,
1316 FORCEQUOTA = 30,
1317 DENY_ATTACH = 31,
1318 _,
11911319};
11921320
11931321pub const caddr_t = ?[*]u8;
11941322
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;
1323pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int;
1324
1325pub const POSIX_SPAWN = packed struct(c_short) {
1326 RESETIDS: bool = false,
1327 SETPGROUP: bool = false,
1328 SETSIGDEF: bool = false,
1329 SETSIGMASK: bool = false,
1330 _4: u2 = 0,
1331 SETEXEC: bool = false,
1332 START_SUSPENDED: bool = false,
1333 DISABLE_ASLR: bool = false,
1334 _9: u1 = 0,
1335 SETSID: bool = false,
1336 RESLIDE: bool = false,
1337 _12: u2 = 0,
1338 CLOEXEC_DEFAULT: bool = false,
1339 _15: u1 = 0,
12081340};
12091341
12101342pub const posix_spawnattr_t = *opaque {};
12111343pub const posix_spawn_file_actions_t = *opaque {};
12121344pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
12131345pub 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;
1346pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int;
1347pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int;
12161348pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
12171349pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
12181350pub 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();