authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-11 18:27:10+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-11 18:27:10+01:00
log402dfb5fd3272fafd5d13a3065e44ad6b0b28a8b
tree445ce5244e15de3966204bf1efa5055e371f12b5
parent2a65971eb07e649ae8072c274a5a8817b0e1ca1e

darwin: wrap mach_port_insert_right kernel call


2 files changed, 55 insertions(+), 0 deletions(-)

lib/std/c/darwin.zig+39
......@@ -164,6 +164,7 @@ pub const mach_vm_address_t = usize;
164164pub const vm_offset_t = usize;
165165pub const mach_vm_size_t = u64;
166166pub const mach_msg_type_number_t = natural_t;
167pub const mach_msg_type_name_t = u32;
167168pub const mach_port_right_t = natural_t;
168169pub const ipc_space_t = mach_port_t;
169170pub const ipc_space_port_t = ipc_space_t;
......@@ -180,6 +181,38 @@ pub const MACH_PORT_RIGHT = enum(mach_port_right_t) {
180181 NUMBER = 6,
181182};
182183
184pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
185 /// Must hold receive right
186 MOVE_RECEIVE = 16,
187
188 /// Must hold send right(s)
189 MOVE_SEND = 17,
190
191 /// Must hold sendonce right
192 MOVE_SEND_ONCE = 18,
193
194 /// Must hold send right(s)
195 COPY_SEND = 19,
196
197 /// Must hold receive right
198 MAKE_SEND = 20,
199
200 /// Must hold receive right
201 MAKE_SEND_ONCE = 21,
202
203 /// NOT VALID
204 COPY_RECEIVE = 22,
205
206 /// Must hold receive right
207 DISPOSE_RECEIVE = 24,
208
209 /// Must hold send right(s)
210 DISPOSE_SEND = 25,
211
212 /// Must hold sendonce right
213 DISPOSE_SEND_ONCE = 26,
214};
215
183216extern "c" var mach_task_self_: mach_port_t;
184217pub fn mach_task_self() callconv(.C) mach_port_t {
185218 return mach_task_self_;
......@@ -527,6 +560,12 @@ pub extern "c" fn mach_port_allocate(
527560 name: *mach_port_name_t,
528561) kern_return_t;
529562pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
563pub extern "c" fn mach_port_insert_right(
564 task: ipc_space_t,
565 name: mach_port_name_t,
566 poly: mach_port_t,
567 poly_poly: mach_msg_type_name_t,
568) kern_return_t;
530569
531570pub extern "c" fn task_info(
532571 target_task: task_name_t,
lib/std/os/darwin.zig+16
......@@ -44,6 +44,22 @@ const mach_task = if (builtin.target.isDarwin()) struct {
4444 _ = std.c.getKernError(std.c.mach_port_deallocate(self.port, port.port));
4545 }
4646
47 pub fn insertRight(self: MachTask, port: MachTask, msg: std.c.MACH_MSG_TYPE) !void {
48 switch (std.c.getKernError(std.c.mach_port_insert_right(
49 self.port,
50 port.port,
51 port.port,
52 @enumToInt(msg),
53 ))) {
54 .SUCCESS => return,
55 .FAILURE => return error.PermissionDenied,
56 else => |err| {
57 log.err("mach_port_insert_right kernel call failed with error code: {s}", .{@tagName(err)});
58 return error.Unexpected;
59 },
60 }
61 }
62
4763 pub const RegionInfo = struct {
4864 pub const Tag = enum {
4965 basic,