authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-13 11:36:00+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-13 11:36:00+01:00
log2efd0eb884d69c967f8b0c7066d62a8b656f1fda
tree9716be5ac3cf7831b4c5bcaf95c9342868846ccb
parent6f5eb9927d5f7713ebc0d104c0590fb037afe275

darwin: wrap task_threads mach syscall


2 files changed, 13 insertions(+), 1 deletions(-)

lib/std/c/darwin.zig+1-1
...@@ -573,7 +573,7 @@ pub const vm_region_submap_short_info_64 = extern struct {...@@ -573,7 +573,7 @@ pub const vm_region_submap_short_info_64 = extern struct {
573573
574pub const thread_act_t = mach_port_t;574pub const thread_act_t = mach_port_t;
575pub const thread_state_t = *natural_t;575pub const thread_state_t = *natural_t;
576pub const mach_port_array_t = *mach_port_t;576pub const mach_port_array_t = [*]mach_port_t;
577577
578pub extern "c" fn task_threads(578pub extern "c" fn task_threads(
579 target_task: mach_port_t,579 target_task: mach_port_t,
lib/std/os/darwin.zig+12
...@@ -438,6 +438,18 @@ const mach_task = if (builtin.target.isDarwin()) struct {...@@ -438,6 +438,18 @@ const mach_task = if (builtin.target.isDarwin()) struct {
438 },438 },
439 }439 }
440 }440 }
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 }
441 };453 };
442454
443 pub fn machTaskForPid(pid: std.os.pid_t) MachError!MachTask {455 pub fn machTaskForPid(pid: std.os.pid_t) MachError!MachTask {