Skip to content

Commit 2efd0eb

Browse files
committed
darwin: wrap task_threads mach syscall
1 parent 6f5eb99 commit 2efd0eb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/std/c/darwin.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pub const vm_region_submap_short_info_64 = extern struct {
573573

574574
pub const thread_act_t = mach_port_t;
575575
pub const thread_state_t = *natural_t;
576-
pub const mach_port_array_t = *mach_port_t;
576+
pub const mach_port_array_t = [*]mach_port_t;
577577

578578
pub extern "c" fn task_threads(
579579
target_task: mach_port_t,

lib/std/os/darwin.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,18 @@ const mach_task = if (builtin.target.isDarwin()) struct {
438438
},
439439
}
440440
}
441+
442+
pub fn getThreads(task: MachTask) MachError![]std.c.mach_port_t {
443+
var thread_list: std.c.mach_port_array_t = undefined;
444+
var thread_count: std.c.mach_msg_type_number_t = undefined;
445+
switch (std.c.getKernError(std.c.task_threads(task.port, &thread_list, &thread_count))) {
446+
.SUCCESS => return thread_list[0..thread_count],
447+
else => |err| {
448+
log.err("task_threads kernel call failed with error code: {s}", .{@tagName(err)});
449+
return error.Unexpected;
450+
},
451+
}
452+
}
441453
};
442454

443455
pub fn machTaskForPid(pid: std.os.pid_t) MachError!MachTask {

0 commit comments

Comments
 (0)