Skip to content

Commit

Permalink
darwin: not every process should be in running state (#1611)
Browse files Browse the repository at this point in the history
This deduces the RUNNING state from the proc_taskinfo structure
by using the number of running threads.
  • Loading branch information
aestriplex authored and BenBE committed Feb 25, 2025
1 parent fe73c2f commit 3c825d3
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable* dpt, double timeIntervalNS) {
struct proc_taskinfo pti;

if (sizeof(pti) != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
if (PROC_PIDTASKINFO_SIZE != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, PROC_PIDTASKINFO_SIZE)) {
proc->taskAccess = false;
return;
}

Expand All @@ -390,6 +391,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable
}
Process_updateCPUFieldWidths(proc->super.percent_cpu);

proc->super.state = pti.pti_numrunning > 0 ? RUNNING : SLEEPING;
proc->super.time = nanosecondsToCentiseconds(total_current_time_ns);
proc->super.nlwp = pti.pti_threadnum;
proc->super.m_virt = pti.pti_virtual_size / ONE_K;
Expand Down Expand Up @@ -435,18 +437,6 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
return;
}

{
task_info_data_t tinfo;
mach_msg_type_number_t task_info_count = TASK_INFO_MAX;
ret = task_info(task, TASK_BASIC_INFO, (task_info_t) &tinfo, &task_info_count);
if (ret != KERN_SUCCESS) {
CRT_debug("task_info(%d) failed: %s", pid, mach_error_string(ret));
dp->taskAccess = false;
mach_port_deallocate(mach_task_self(), task);
return;
}
}

thread_array_t thread_list;
mach_msg_type_number_t thread_count;
ret = task_threads(task, &thread_list, &thread_count);
Expand Down

0 comments on commit 3c825d3

Please sign in to comment.