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;...@@ -11106,12 +11106,15 @@ pub const fsfilcnt_t = freebsd.fsfilcnt_t;
11106pub const kinfo_file = freebsd.kinfo_file;11106pub const kinfo_file = freebsd.kinfo_file;
11107pub const kinfo_getfile = freebsd.kinfo_getfile;11107pub const kinfo_getfile = freebsd.kinfo_getfile;
1110811108
11109pub const CALENDAR_CLOCK = darwin.CALENDAR_CLOCK;
11109pub const COPYFILE = darwin.COPYFILE;11110pub const COPYFILE = darwin.COPYFILE;
11110pub const CPUFAMILY = darwin.CPUFAMILY;11111pub const CPUFAMILY = darwin.CPUFAMILY;
11111pub const PT = darwin.PT;11112pub const PT = darwin.PT;
11112pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;11113pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
11113pub const EXC = darwin.EXC;11114pub const EXC = darwin.EXC;
11114pub const EXCEPTION = darwin.EXCEPTION;11115pub const EXCEPTION = darwin.EXCEPTION;
11116pub const KEVENT = darwin.KEVENT;
11117pub const MACH = darwin.MACH;
11115pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;11118pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;
11116pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;11119pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;
11117pub const MACH_TASK_BASIC_INFO = darwin.MACH_TASK_BASIC_INFO;11120pub 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;...@@ -11119,10 +11122,15 @@ pub const MACH_TASK_BASIC_INFO_COUNT = darwin.MACH_TASK_BASIC_INFO_COUNT;
11119pub const MATTR = darwin.MATTR;11122pub const MATTR = darwin.MATTR;
11120pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;11123pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
11121pub const OPEN_MAX = darwin.OPEN_MAX;11124pub const OPEN_MAX = darwin.OPEN_MAX;
11125pub const OS = darwin.OS;
11122pub const POSIX_SPAWN = darwin.POSIX_SPAWN;11126pub 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;
11123pub const TASK_NULL = darwin.TASK_NULL;11130pub const TASK_NULL = darwin.TASK_NULL;
11124pub const TASK_VM_INFO = darwin.TASK_VM_INFO;11131pub const TASK_VM_INFO = darwin.TASK_VM_INFO;
11125pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;11132pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;
11133pub const THREAD = darwin.THREAD;
11126pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;11134pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;
11127pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;11135pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;
11128pub const THREAD_IDENTIFIER_INFO_COUNT = darwin.THREAD_IDENTIFIER_INFO_COUNT;11136pub 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;...@@ -11140,15 +11148,24 @@ pub const _dyld_get_image_name = darwin._dyld_get_image_name;
11140pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;11148pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
11141pub const _dyld_image_count = darwin._dyld_image_count;11149pub const _dyld_image_count = darwin._dyld_image_count;
11142pub const _host_page_size = darwin._host_page_size;11150pub const _host_page_size = darwin._host_page_size;
11151pub const boolean_t = darwin.boolean_t;
11143pub const clock_get_time = darwin.clock_get_time;11152pub 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;
11144pub const @"close$NOCANCEL" = darwin.@"close$NOCANCEL";11155pub 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;
11145pub const dispatch_release = darwin.dispatch_release;11159pub const dispatch_release = darwin.dispatch_release;
11146pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;11160pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;
11147pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;11161pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;
11162pub const dispatch_semaphore_t = darwin.dispatch_semaphore_t;
11148pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;11163pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;
11149pub const dispatch_time = darwin.dispatch_time;11164pub const dispatch_time = darwin.dispatch_time;
11165pub const dispatch_time_t = darwin.dispatch_time_t;
11150pub const fcopyfile = darwin.fcopyfile;11166pub const fcopyfile = darwin.fcopyfile;
11151pub const host_t = darwin.host_t;11167pub const host_t = darwin.host_t;
11168pub const integer_t = darwin.integer_t;
11152pub const ipc_space_t = darwin.ipc_space_t;11169pub const ipc_space_t = darwin.ipc_space_t;
11153pub const ipc_space_port_t = darwin.ipc_space_port_t;11170pub const ipc_space_port_t = darwin.ipc_space_port_t;
11154pub const kern_return_t = darwin.kern_return_t;11171pub const kern_return_t = darwin.kern_return_t;
...@@ -11160,6 +11177,7 @@ pub const mach_continuous_time = darwin.mach_continuous_time;...@@ -11160,6 +11177,7 @@ pub const mach_continuous_time = darwin.mach_continuous_time;
11160pub const mach_hdr = darwin.mach_hdr;11177pub const mach_hdr = darwin.mach_hdr;
11161pub const mach_host_self = darwin.mach_host_self;11178pub const mach_host_self = darwin.mach_host_self;
11162pub const mach_msg = darwin.mach_msg;11179pub const mach_msg = darwin.mach_msg;
11180pub const mach_msg_return_t = darwin.mach_msg_return_t;
11163pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;11181pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;
11164pub const mach_port_allocate = darwin.mach_port_allocate;11182pub const mach_port_allocate = darwin.mach_port_allocate;
11165pub const mach_port_array_t = darwin.mach_port_array_t;11183pub 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;...@@ -11171,6 +11189,7 @@ pub const mach_task_basic_info = darwin.mach_task_basic_info;
11171pub const mach_task_self = darwin.mach_task_self;11189pub const mach_task_self = darwin.mach_task_self;
11172pub const mach_timebase_info = darwin.mach_timebase_info;11190pub const mach_timebase_info = darwin.mach_timebase_info;
11173pub const mach_timebase_info_data = darwin.mach_timebase_info_data;11191pub const mach_timebase_info_data = darwin.mach_timebase_info_data;
11192pub const mach_timespec_t = darwin.mach_timespec_t;
11174pub const mach_vm_address_t = darwin.mach_vm_address_t;11193pub const mach_vm_address_t = darwin.mach_vm_address_t;
11175pub const mach_vm_protect = darwin.mach_vm_protect;11194pub const mach_vm_protect = darwin.mach_vm_protect;
11176pub const mach_vm_read = darwin.mach_vm_read;11195pub const mach_vm_read = darwin.mach_vm_read;
...@@ -11180,16 +11199,20 @@ pub const mach_vm_size_t = darwin.mach_vm_size_t;...@@ -11180,16 +11199,20 @@ pub const mach_vm_size_t = darwin.mach_vm_size_t;
11180pub const mach_vm_write = darwin.mach_vm_write;11199pub const mach_vm_write = darwin.mach_vm_write;
11181pub const natural_t = darwin.natural_t;11200pub const natural_t = darwin.natural_t;
11182pub const os_log_create = darwin.os_log_create;11201pub const os_log_create = darwin.os_log_create;
11202pub const os_log_t = darwin.os_log_t;
11183pub const os_log_type_enabled = darwin.os_log_type_enabled;11203pub const os_log_type_enabled = darwin.os_log_type_enabled;
11204pub const os_log_type_t = darwin.os_log_type_t;
11184pub const os_signpost_enabled = darwin.os_signpost_enabled;11205pub const os_signpost_enabled = darwin.os_signpost_enabled;
11185pub const os_signpost_id_generate = darwin.os_signpost_id_generate;11206pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
11186pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;11207pub 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;
11187pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;11209pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
11188pub const os_signpost_interval_end = darwin.os_signpost_interval_end;11210pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
11189pub const os_unfair_lock = darwin.os_unfair_lock;11211pub const os_unfair_lock = darwin.os_unfair_lock;
11190pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;11212pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
11191pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;11213pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
11192pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;11214pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
11215pub const os_unfair_lock_t = darwin.os_unfair_lock_t;
11193pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;11216pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
11194pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;11217pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
11195pub const pid_for_task = darwin.pid_for_task;11218pub 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;...@@ -11214,10 +11237,13 @@ pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;
11214pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;11237pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
11215pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;11238pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
11216pub const ptrace = darwin.ptrace;11239pub const ptrace = darwin.ptrace;
11240pub const qos_class_t = darwin.qos_class_t;
11241pub const task_flavor_t = darwin.task_flavor_t;
11217pub const task_for_pid = darwin.task_for_pid;11242pub const task_for_pid = darwin.task_for_pid;
11218pub const task_get_exception_ports = darwin.task_get_exception_ports;11243pub const task_get_exception_ports = darwin.task_get_exception_ports;
11219pub const task_info = darwin.task_info;11244pub const task_info = darwin.task_info;
11220pub const task_info_t = darwin.task_info_t;11245pub const task_info_t = darwin.task_info_t;
11246pub const task_name_t = darwin.task_name_t;
11221pub const task_resume = darwin.task_resume;11247pub const task_resume = darwin.task_resume;
11222pub const task_set_exception_ports = darwin.task_set_exception_ports;11248pub const task_set_exception_ports = darwin.task_set_exception_ports;
11223pub const task_suspend = darwin.task_suspend;11249pub const task_suspend = darwin.task_suspend;
...@@ -11230,8 +11256,10 @@ pub const thread_info = darwin.thread_info;...@@ -11230,8 +11256,10 @@ pub const thread_info = darwin.thread_info;
11230pub const thread_info_t = darwin.thread_info_t;11256pub const thread_info_t = darwin.thread_info_t;
11231pub const thread_resume = darwin.thread_resume;11257pub const thread_resume = darwin.thread_resume;
11232pub const thread_set_state = darwin.thread_set_state;11258pub const thread_set_state = darwin.thread_set_state;
11259pub const vm_address_t = darwin.vm_address_t;
11233pub const vm_deallocate = darwin.vm_deallocate;11260pub const vm_deallocate = darwin.vm_deallocate;
11234pub const vm_machine_attribute = darwin.vm_machine_attribute;11261pub const vm_machine_attribute = darwin.vm_machine_attribute;
11262pub const vm_machine_attribute_t = darwin.vm_machine_attribute_t;
11235pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;11263pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;
11236pub const vm_map_t = darwin.vm_map_t;11264pub const vm_map_t = darwin.vm_map_t;
11237pub const vm_offset_t = darwin.vm_offset_t;11265pub const vm_offset_t = darwin.vm_offset_t;
...@@ -11256,10 +11284,12 @@ pub const exception_mask_array_t = darwin.exception_mask_array_t;...@@ -11256,10 +11284,12 @@ pub const exception_mask_array_t = darwin.exception_mask_array_t;
11256pub const exception_mask_t = darwin.exception_mask_t;11284pub const exception_mask_t = darwin.exception_mask_t;
11257pub const exception_port_array_t = darwin.exception_port_array_t;11285pub const exception_port_array_t = darwin.exception_port_array_t;
11258pub const exception_port_t = darwin.exception_port_t;11286pub const exception_port_t = darwin.exception_port_t;
11287pub const exception_type_t = darwin.exception_type_t;
11259pub const mach_exception_data_t = darwin.mach_exception_data_t;11288pub const mach_exception_data_t = darwin.mach_exception_data_t;
11260pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;11289pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;
11261pub const mach_msg_bits_t = darwin.mach_msg_bits_t;11290pub const mach_msg_bits_t = darwin.mach_msg_bits_t;
11262pub const mach_msg_id_t = darwin.mach_msg_id_t;11291pub const mach_msg_id_t = darwin.mach_msg_id_t;
11292pub const mach_msg_header_t = darwin.mach_msg_header_t;
11263pub const mach_msg_option_t = darwin.mach_msg_option_t;11293pub const mach_msg_option_t = darwin.mach_msg_option_t;
11264pub const mach_msg_size_t = darwin.mach_msg_size_t;11294pub const mach_msg_size_t = darwin.mach_msg_size_t;
11265pub const mach_msg_timeout_t = darwin.mach_msg_timeout_t;11295pub 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;...@@ -11269,6 +11299,7 @@ pub const memory_object_offset_t = darwin.memory_object_offset_t;
11269pub const policy_t = darwin.policy_t;11299pub const policy_t = darwin.policy_t;
11270pub const task_policy_flavor_t = darwin.task_policy_flavor_t;11300pub const task_policy_flavor_t = darwin.task_policy_flavor_t;
11271pub const task_policy_t = darwin.task_policy_t;11301pub const task_policy_t = darwin.task_policy_t;
11302pub const task_read_t = darwin.task_read_t;
11272pub const task_t = darwin.task_t;11303pub const task_t = darwin.task_t;
11273pub const thread_act_t = darwin.thread_act_t;11304pub const thread_act_t = darwin.thread_act_t;
11274pub const thread_flavor_t = darwin.thread_flavor_t;11305pub const thread_flavor_t = darwin.thread_flavor_t;
lib/std/c/darwin.zig+368-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,244 @@ pub const EXCEPTION = enum(u32) {...@@ -110,56 +106,244 @@ 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: exception_mask_t = @bitCast(MACH.EXCEPTION{
141pub const MACH_SEND_ALWAYS = 0x00010000;137 .BACKTRACE_PREFERRED = true,
142pub const MACH_SEND_FILTER_NONFATAL = 0x00010000;138 .ERRORS = true,
143pub const MACH_SEND_TRAILER = 0x00020000;139 .CODES = true,
144pub const MACH_SEND_NOIMPORTANCE = 0x00040000;140 });
145pub const MACH_SEND_NODENAP = MACH_SEND_NOIMPORTANCE;141 };
146pub const MACH_SEND_IMPORTANCE = 0x00080000;142
147pub const MACH_SEND_SYNC_OVERRIDE = 0x00100000;143 pub const MSG = packed struct(kern_return_t) {
148pub const MACH_SEND_PROPAGATE_QOS = 0x00200000;144 _0: u10 = 0,
149pub const MACH_SEND_SYNC_USE_THRPRI = MACH_SEND_PROPAGATE_QOS;145 /// Kernel resource shortage handling an IPC capability.
150pub const MACH_SEND_KERNEL = 0x00400000;146 VM_KERNEL: bool = false,
151pub const MACH_SEND_SYNC_BOOTSTRAP_CHECKIN = 0x00800000;147 /// Kernel resource shortage handling out-of-line memory.
152148 IPC_KERNEL: bool = false,
153pub const MACH_RCV_TIMEOUT = 0x00000100;149 /// No room in VM address space for out-of-line memory.
154pub const MACH_RCV_NOTIFY = 0x00000000;150 VM_SPACE: bool = false,
155pub const MACH_RCV_INTERRUPT = 0x00000400;151 /// No room in IPC name space for another capability name.
156pub const MACH_RCV_VOUCHER = 0x00000800;152 IPC_SPACE: bool = false,
157pub const MACH_RCV_OVERWRITE = 0x00000000;153 _14: u18 = 0,
158pub const MACH_RCV_GUARDED_DESC = 0x00001000;154
159pub const MACH_RCV_SYNC_WAIT = 0x00004000;155 pub const MASK: kern_return_t = @bitCast(MACH.MSG{
160pub const MACH_RCV_SYNC_PEEK = 0x00008000;156 .VM_KERNEL = true,
161157 .IPC_KERNEL = true,
162pub const MACH_MSG_STRICT_REPLY = 0x00000200;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
164pub const exception_type_t = c_int;348pub const exception_type_t = c_int;
165349
...@@ -293,7 +477,7 @@ pub extern "c" fn kevent64(...@@ -293,7 +477,7 @@ pub extern "c" fn kevent64(
293 nchanges: c_int,477 nchanges: c_int,
294 eventlist: [*]kevent64_s,478 eventlist: [*]kevent64_s,
295 nevents: c_int,479 nevents: c_int,
296 flags: c_uint,480 flags: KEVENT.FLAG,
297 timeout: ?*const timespec,481 timeout: ?*const timespec,
298) c_int;482) c_int;
299483
...@@ -321,11 +505,7 @@ pub const mach_vm_size_t = u64;...@@ -321,11 +505,7 @@ pub const mach_vm_size_t = u64;
321pub const mach_msg_bits_t = c_uint;505pub const mach_msg_bits_t = c_uint;
322pub const mach_msg_id_t = integer_t;506pub const mach_msg_id_t = integer_t;
323pub const mach_msg_type_number_t = natural_t;507pub 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;508pub 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;509pub const task_t = mach_port_t;
330pub const thread_port_t = task_t;510pub const thread_port_t = task_t;
331pub const thread_t = thread_port_t;511pub const thread_t = thread_port_t;
...@@ -342,19 +522,23 @@ pub const thread_state_flavor_t = c_int;...@@ -342,19 +522,23 @@ pub const thread_state_flavor_t = c_int;
342pub const ipc_space_t = mach_port_t;522pub const ipc_space_t = mach_port_t;
343pub const ipc_space_port_t = ipc_space_t;523pub const ipc_space_port_t = ipc_space_t;
344524
345pub const MACH_PORT_RIGHT = enum(mach_port_right_t) {525pub const mach_msg_option_t = packed union {
346 SEND = 0,526 RCV: MACH.RCV,
347 RECEIVE = 1,527 SEND: MACH.SEND,
348 SEND_ONCE = 2,528
349 PORT_SET = 3,529 pub const NONE: mach_msg_option_t = @bitCast(@as(integer_t, 0));
350 DEAD_NAME = 4,530
351 /// Obsolete right531 pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t {
352 LABELH = 5,532 return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv)));
353 /// Right not implemented533 }
354 NUMBER = 6,
355};534};
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) {
358 /// Must hold receive right542 /// Must hold receive right
359 MOVE_RECEIVE = 16,543 MOVE_RECEIVE = 16,
360 /// Must hold send right(s)544 /// Must hold send right(s)
...@@ -375,6 +559,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {...@@ -375,6 +559,22 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
375 DISPOSE_SEND = 25,559 DISPOSE_SEND = 25,
376 /// Must hold sendonce right560 /// Must hold sendonce right
377 DISPOSE_SEND_ONCE = 26,561 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 _,
378};578};
379579
380extern "c" var mach_task_self_: mach_port_t;580extern "c" var mach_task_self_: mach_port_t;
...@@ -390,7 +590,7 @@ pub extern "c" fn mach_msg(...@@ -390,7 +590,7 @@ pub extern "c" fn mach_msg(
390 rcv_name: mach_port_name_t,590 rcv_name: mach_port_name_t,
391 timeout: mach_msg_timeout_t,591 timeout: mach_msg_timeout_t,
392 notify: mach_port_name_t,592 notify: mach_port_name_t,
393) kern_return_t;593) mach_msg_return_t;
394594
395pub const mach_msg_header_t = extern struct {595pub const mach_msg_header_t = extern struct {
396 msgh_bits: mach_msg_bits_t,596 msgh_bits: mach_msg_bits_t,
...@@ -462,46 +662,6 @@ pub const vm_behavior_t = i32;...@@ -462,46 +662,6 @@ pub const vm_behavior_t = i32;
462pub const vm32_object_id_t = u32;662pub const vm32_object_id_t = u32;
463pub const vm_object_id_t = u64;663pub 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
505pub const vm_region_basic_info_64 = extern struct {665pub const vm_region_basic_info_64 = extern struct {
506 protection: vm_prot_t,666 protection: vm_prot_t,
507 max_protection: vm_prot_t,667 max_protection: vm_prot_t,
...@@ -630,12 +790,6 @@ pub extern "c" fn thread_info(...@@ -630,12 +790,6 @@ pub extern "c" fn thread_info(
630) kern_return_t;790) kern_return_t;
631pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t;791pub 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
639pub const thread_flavor_t = natural_t;793pub const thread_flavor_t = natural_t;
640pub const thread_info_t = *integer_t;794pub const thread_info_t = *integer_t;
641pub const time_value_t = time_value;795pub const time_value_t = time_value;
...@@ -678,34 +832,6 @@ pub const thread_identifier_info = extern struct {...@@ -678,34 +832,6 @@ pub const thread_identifier_info = extern struct {
678 dispatch_qaddr: u64,832 dispatch_qaddr: u64,
679};833};
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
709pub const task_vm_info = extern struct {835pub const task_vm_info = extern struct {
710 // virtual memory size (bytes)836 // virtual memory size (bytes)
711 virtual_size: mach_vm_size_t,837 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...@@ -791,8 +917,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(917pub extern "c" fn mach_port_insert_right(
792 task: ipc_space_t,918 task: ipc_space_t,
793 name: mach_port_name_t,919 name: mach_port_name_t,
794 poly: mach_port_t,920 right: mach_port_t,
795 poly_poly: mach_msg_type_name_t,921 right_type: mach_msg_type_name_t,
796) kern_return_t;922) kern_return_t;
797923
798pub extern "c" fn task_info(924pub extern "c" fn task_info(
...@@ -817,9 +943,6 @@ pub const mach_task_basic_info = extern struct {...@@ -817,9 +943,6 @@ pub const mach_task_basic_info = extern struct {
817 suspend_count: mach_vm_size_t,943 suspend_count: mach_vm_size_t,
818};944};
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
823pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;946pub 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;947pub 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(948pub extern "c" fn vm_machine_attribute(
...@@ -847,17 +970,19 @@ pub const NSIG = 32;...@@ -847,17 +970,19 @@ pub const NSIG = 32;
847970
848pub const qos_class_t = enum(c_uint) {971pub const qos_class_t = enum(c_uint) {
849 /// highest priority QOS class for critical tasks972 /// highest priority QOS class for critical tasks
850 QOS_CLASS_USER_INTERACTIVE = 0x21,973 USER_INTERACTIVE = 0x21,
851 /// slightly more moderate priority QOS class974 /// slightly more moderate priority QOS class
852 QOS_CLASS_USER_INITIATED = 0x19,975 USER_INITIATED = 0x19,
853 /// default QOS class when none is set976 /// default QOS class when none is set
854 QOS_CLASS_DEFAULT = 0x15,977 DEFAULT = 0x15,
855 /// more energy efficient QOS class than default978 /// more energy efficient QOS class than default
856 QOS_CLASS_UTILITY = 0x11,979 UTILITY = 0x11,
857 /// QOS class more appropriate for background tasks980 /// QOS class more appropriate for background tasks
858 QOS_CLASS_BACKGROUND = 0x09,981 BACKGROUND = 0x09,
859 /// QOS class as a return value982 /// QOS class as a return value
860 QOS_CLASS_UNSPECIFIED = 0x00,983 UNSPECIFIED = 0x00,
984
985 _,
861};986};
862987
863// Grand Central Dispatch is exposed by libSystem.988// Grand Central Dispatch is exposed by libSystem.
...@@ -868,13 +993,17 @@ pub extern "c" fn dispatch_semaphore_create(value: isize) ?dispatch_semaphore_t;...@@ -868,13 +993,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;993pub 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;994pub extern "c" fn dispatch_semaphore_signal(dsema: dispatch_semaphore_t) isize;
870995
871pub const dispatch_time_t = u64;996pub const DISPATCH_TIME_NOW = @compileError("use dispatch_time_t.NOW");
872pub const DISPATCH_TIME_NOW = @as(dispatch_time_t, 0);997pub const DISPATCH_TIME_FOREVER = @compileError("use dispatch_time_t.FOREVER");
873pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0);998pub const dispatch_time_t = enum(u64) {
999 NOW = 0,
1000 FOREVER = ~0,
1001 _,
1002};
874pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;1003pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;
8751004
876const dispatch_once_t = usize;1005pub const dispatch_once_t = usize;
877const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;1006pub const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
878pub extern fn dispatch_once_f(1007pub extern fn dispatch_once_f(
879 predicate: *dispatch_once_t,1008 predicate: *dispatch_once_t,
880 context: ?*anyopaque,1009 context: ?*anyopaque,
...@@ -905,6 +1034,7 @@ pub const UL = packed struct(u32) {...@@ -905,6 +1034,7 @@ pub const UL = packed struct(u32) {
905 UNFAIR_LOCK64_SHARED = 4,1034 UNFAIR_LOCK64_SHARED = 4,
906 COMPARE_AND_WAIT64 = 5,1035 COMPARE_AND_WAIT64 = 5,
907 COMPARE_AND_WAIT64_SHARED = 6,1036 COMPARE_AND_WAIT64_SHARED = 6,
1037 _,
908 };1038 };
909};1039};
9101040
...@@ -923,29 +1053,28 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;...@@ -923,29 +1053,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;1053pub 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;1054pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
9251055
926pub const os_signpost_id_t = u64;1056pub const os_signpost_id_t = enum(u64) {
9271057 NULL = 0,
928pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;1058 INVALID = !0,
929pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;1059 EXCLUSIVE = 0xeeeeb0b5b2b2eeee,
930pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;1060 _,
1061};
9311062
932pub const os_log_t = *opaque {};1063pub const os_log_t = *opaque {};
933pub const os_log_type_t = enum(u8) {1064pub const os_log_type_t = enum(u8) {
934 /// default messages always captures1065 /// default messages always captures
935 OS_LOG_TYPE_DEFAULT = 0x00,1066 DEFAULT = 0x00,
936 /// messages with additional infos1067 /// messages with additional infos
937 OS_LOG_TYPE_INFO = 0x01,1068 INFO = 0x01,
938 /// debug messages1069 /// debug messages
939 OS_LOG_TYPE_DEBUG = 0x02,1070 DEBUG = 0x02,
940 /// error messages1071 /// error messages
941 OS_LOG_TYPE_ERROR = 0x10,1072 ERROR = 0x10,
942 /// unexpected conditions messages1073 /// unexpected conditions messages
943 OS_LOG_TYPE_FAULT = 0x11,1074 FAULT = 0x11,
944};
9451075
946pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";1076 _,
947pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";1077};
948pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
9491078
950pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;1079pub 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;1080pub 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;...@@ -1012,35 +1141,11 @@ pub const vm_machine_attribute_val_t = isize;
10121141
1013pub const CALENDAR_CLOCK = 1;1142pub 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
1022pub const SYSPROTO_EVENT = 1;1144pub const SYSPROTO_EVENT = 1;
1023pub const SYSPROTO_CONTROL = 2;1145pub 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
1042/// Mach msg return values1147/// Mach msg return values
1043pub const MachMsgE = enum(u32) {1148pub const mach_msg_return_t = enum(kern_return_t) {
1044 SUCCESS = 0x00000000,1149 SUCCESS = 0x00000000,
10451150
1046 /// Thread is waiting to send. (Internal use only.)1151 /// Thread is waiting to send. (Internal use only.)
...@@ -1104,9 +1209,9 @@ pub const MachMsgE = enum(u32) {...@@ -1104,9 +1209,9 @@ pub const MachMsgE = enum(u32) {
1104 RCV_PORT_DIED = 0x10004009,1209 RCV_PORT_DIED = 0x10004009,
1105 /// compatibility: no longer a returned error1210 /// compatibility: no longer a returned error
1106 RCV_IN_SET = 0x1000400a,1211 RCV_IN_SET = 0x1000400a,
1107 /// Error receiving message header. See special bits.1212 /// Error receiving message header. See special bits (use `extractResourceError`).
1108 RCV_HEADER_ERROR = 0x1000400b,1213 RCV_HEADER_ERROR = 0x1000400b,
1109 /// Error receiving message body. See special bits.1214 /// Error receiving message body. See special bits (use `extractResourceError`).
1110 RCV_BODY_ERROR = 0x1000400c,1215 RCV_BODY_ERROR = 0x1000400c,
1111 /// Invalid msg-type specification in scatter list.1216 /// Invalid msg-type specification in scatter list.
1112 RCV_INVALID_TYPE = 0x1000400d,1217 RCV_INVALID_TYPE = 0x1000400d,
...@@ -1118,6 +1223,28 @@ pub const MachMsgE = enum(u32) {...@@ -1118,6 +1223,28 @@ pub const MachMsgE = enum(u32) {
1118 RCV_IN_PROGRESS_TIMED = 0x10004011,1223 RCV_IN_PROGRESS_TIMED = 0x10004011,
1119 /// invalid reply port used in a STRICT_REPLY message1224 /// invalid reply port used in a STRICT_REPLY message
1120 RCV_INVALID_REPLY = 0x10004012,1225 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 }
1121};1248};
11221249
1123pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;1250pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
...@@ -1171,48 +1298,53 @@ pub const CPUFAMILY = enum(u32) {...@@ -1171,48 +1298,53 @@ pub const CPUFAMILY = enum(u32) {
1171 _,1298 _,
1172};1299};
11731300
1174pub const PT = struct {1301pub const PT = enum(c_int) {
1175 pub const TRACE_ME = 0;1302 TRACE_ME = 0,
1176 pub const READ_I = 1;1303 READ_I = 1,
1177 pub const READ_D = 2;1304 READ_D = 2,
1178 pub const READ_U = 3;1305 READ_U = 3,
1179 pub const WRITE_I = 4;1306 WRITE_I = 4,
1180 pub const WRITE_D = 5;1307 WRITE_D = 5,
1181 pub const WRITE_U = 6;1308 WRITE_U = 6,
1182 pub const CONTINUE = 7;1309 CONTINUE = 7,
1183 pub const KILL = 8;1310 KILL = 8,
1184 pub const STEP = 9;1311 STEP = 9,
1185 pub const DETACH = 11;1312 DETACH = 11,
1186 pub const SIGEXC = 12;1313 SIGEXC = 12,
1187 pub const THUPDATE = 13;1314 THUPDATE = 13,
1188 pub const ATTACHEXC = 14;1315 ATTACHEXC = 14,
1189 pub const FORCEQUOTA = 30;1316 FORCEQUOTA = 30,
1190 pub const DENY_ATTACH = 31;1317 DENY_ATTACH = 31,
1318 _,
1191};1319};
11921320
1193pub const caddr_t = ?[*]u8;1321pub const caddr_t = ?[*]u8;
11941322
1195pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;1323pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int;
11961324
1197pub const POSIX_SPAWN = struct {1325pub const POSIX_SPAWN = packed struct(c_short) {
1198 pub const RESETIDS = 0x0001;1326 RESETIDS: bool = false,
1199 pub const SETPGROUP = 0x0002;1327 SETPGROUP: bool = false,
1200 pub const SETSIGDEF = 0x0004;1328 SETSIGDEF: bool = false,
1201 pub const SETSIGMASK = 0x0008;1329 SETSIGMASK: bool = false,
1202 pub const SETEXEC = 0x0040;1330 _4: u2 = 0,
1203 pub const START_SUSPENDED = 0x0080;1331 SETEXEC: bool = false,
1204 pub const DISABLE_ASLR = 0x0100;1332 START_SUSPENDED: bool = false,
1205 pub const SETSID = 0x0400;1333 DISABLE_ASLR: bool = false,
1206 pub const RESLIDE = 0x0800;1334 _9: u1 = 0,
1207 pub const CLOEXEC_DEFAULT = 0x4000;1335 SETSID: bool = false,
1336 RESLIDE: bool = false,
1337 _12: u2 = 0,
1338 CLOEXEC_DEFAULT: bool = false,
1339 _15: u1 = 0,
1208};1340};
12091341
1210pub const posix_spawnattr_t = *opaque {};1342pub const posix_spawnattr_t = *opaque {};
1211pub const posix_spawn_file_actions_t = *opaque {};1343pub const posix_spawn_file_actions_t = *opaque {};
1212pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;1344pub 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;1345pub 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;1346pub 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;1347pub 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;1348pub 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;1349pub 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;1350pub 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();