mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
darwin: wrap allocating and deallocating mach ports for a task
This commit is contained in:
parent
35e3069ab7
commit
2a65971eb0
@ -164,6 +164,21 @@ pub const mach_vm_address_t = usize;
|
||||
pub const vm_offset_t = usize;
|
||||
pub const mach_vm_size_t = u64;
|
||||
pub const mach_msg_type_number_t = natural_t;
|
||||
pub const mach_port_right_t = natural_t;
|
||||
pub const ipc_space_t = mach_port_t;
|
||||
pub const ipc_space_port_t = ipc_space_t;
|
||||
|
||||
pub const MACH_PORT_RIGHT = enum(mach_port_right_t) {
|
||||
SEND = 0,
|
||||
RECEIVE = 1,
|
||||
SEND_ONCE = 2,
|
||||
PORT_SET = 3,
|
||||
DEAD_NAME = 4,
|
||||
/// Obsolete right
|
||||
LABELH = 5,
|
||||
/// Right not implemented
|
||||
NUMBER = 6,
|
||||
};
|
||||
|
||||
extern "c" var mach_task_self_: mach_port_t;
|
||||
pub fn mach_task_self() callconv(.C) mach_port_t {
|
||||
@ -506,7 +521,12 @@ pub extern "c" fn mach_vm_protect(
|
||||
new_protection: vm_prot_t,
|
||||
) kern_return_t;
|
||||
|
||||
pub extern "c" fn mach_port_deallocate(target_tport: mach_port_name_t, task: mach_port_name_t) kern_return_t;
|
||||
pub extern "c" fn mach_port_allocate(
|
||||
task: ipc_space_t,
|
||||
right: mach_port_right_t,
|
||||
name: *mach_port_name_t,
|
||||
) kern_return_t;
|
||||
pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
|
||||
|
||||
pub extern "c" fn task_info(
|
||||
target_task: task_name_t,
|
||||
|
@ -24,6 +24,26 @@ const mach_task = if (builtin.target.isDarwin()) struct {
|
||||
return self.port != 0;
|
||||
}
|
||||
|
||||
pub fn allocatePort(self: MachTask, right: std.c.MACH_PORT_RIGHT) MachError!MachTask {
|
||||
var out_port: std.c.mach_port_name_t = undefined;
|
||||
switch (std.c.getKernError(std.c.mach_port_allocate(
|
||||
self.port,
|
||||
@enumToInt(right),
|
||||
&out_port,
|
||||
))) {
|
||||
.SUCCESS => return .{ .port = out_port },
|
||||
.FAILURE => return error.PermissionDenied,
|
||||
else => |err| {
|
||||
log.err("mach_task_allocate kernel call failed with error code: {s}", .{@tagName(err)});
|
||||
return error.Unexpected;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deallocatePort(self: MachTask, port: MachTask) void {
|
||||
_ = std.c.getKernError(std.c.mach_port_deallocate(self.port, port.port));
|
||||
}
|
||||
|
||||
pub const RegionInfo = struct {
|
||||
pub const Tag = enum {
|
||||
basic,
|
||||
|
Loading…
Reference in New Issue
Block a user