Commit 2efd0eb884
Changed files (2)
lib
std
lib/std/c/darwin.zig
@@ -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,
lib/std/os/darwin.zig
@@ -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 {