darwin: wrap task_threads mach syscall

This commit is contained in:
Jakub Konka 2022-12-13 11:36:00 +01:00
parent 6f5eb9927d
commit 2efd0eb884
2 changed files with 13 additions and 1 deletions

View File

@ -573,7 +573,7 @@ pub const vm_region_submap_short_info_64 = extern struct {
pub const thread_act_t = mach_port_t;
pub const thread_state_t = *natural_t;
pub const mach_port_array_t = *mach_port_t;
pub const mach_port_array_t = [*]mach_port_t;
pub extern "c" fn task_threads(
target_task: mach_port_t,

View File

@ -438,6 +438,18 @@ const mach_task = if (builtin.target.isDarwin()) struct {
},
}
}
pub fn getThreads(task: MachTask) MachError![]std.c.mach_port_t {
var thread_list: std.c.mach_port_array_t = undefined;
var thread_count: std.c.mach_msg_type_number_t = undefined;
switch (std.c.getKernError(std.c.task_threads(task.port, &thread_list, &thread_count))) {
.SUCCESS => return thread_list[0..thread_count],
else => |err| {
log.err("task_threads kernel call failed with error code: {s}", .{@tagName(err)});
return error.Unexpected;
},
}
}
};
pub fn machTaskForPid(pid: std.os.pid_t) MachError!MachTask {