+ thread_t thact;
+ int err=0;
+ mach_msg_type_number_t count;
+ thread_basic_info_data_t basic_info;
+ kern_return_t kret;
+ uint64_t addr = 0;
+
+ task_lock(task);
+
+ for (thact = (thread_t)(void *)queue_first(&task->threads);
+ !queue_end(&task->threads, (queue_entry_t)thact); ) {
+ addr = (thuniqueid==0)?thact->machine.cthread_self: thact->thread_id;
+ if (addr == thaddr)
+ {
+
+ count = THREAD_BASIC_INFO_COUNT;
+ if ((kret = thread_info_internal(thact, THREAD_BASIC_INFO, (thread_info_t)&basic_info, &count)) != KERN_SUCCESS) {
+ err = 1;
+ goto out;
+ }
+ ptinfo->pth_user_time = ((basic_info.user_time.seconds * (integer_t)NSEC_PER_SEC) + (basic_info.user_time.microseconds * (integer_t)NSEC_PER_USEC));
+ ptinfo->pth_system_time = ((basic_info.system_time.seconds * (integer_t)NSEC_PER_SEC) + (basic_info.system_time.microseconds * (integer_t)NSEC_PER_USEC));
+
+ ptinfo->pth_cpu_usage = basic_info.cpu_usage;
+ ptinfo->pth_policy = basic_info.policy;
+ ptinfo->pth_run_state = basic_info.run_state;
+ ptinfo->pth_flags = basic_info.flags;
+ ptinfo->pth_sleep_time = basic_info.sleep_time;
+ ptinfo->pth_curpri = thact->sched_pri;
+ ptinfo->pth_priority = thact->priority;
+ ptinfo->pth_maxpriority = thact->max_priority;
+
+ if ((vpp != NULL) && (thact->uthread != NULL))
+ bsd_threadcdir(thact->uthread, vpp, vidp);
+ bsd_getthreadname(thact->uthread,ptinfo->pth_name);
+ err = 0;
+ goto out;
+ }
+ thact = (thread_t)(void *)queue_next(&thact->task_threads);
+ }
+ err = 1;
+
+out:
+ task_unlock(task);
+ return(err);
+}
+
+int
+fill_taskthreadlist(task_t task, void * buffer, int thcount)
+{
+ int numthr=0;
+ thread_t thact;
+ uint64_t * uptr;
+ uint64_t thaddr;
+
+ uptr = (uint64_t *)buffer;
+
+ task_lock(task);
+
+ for (thact = (thread_t)(void *)queue_first(&task->threads);
+ !queue_end(&task->threads, (queue_entry_t)thact); ) {
+ thaddr = thact->machine.cthread_self;
+ *uptr++ = thaddr;
+ numthr++;
+ if (numthr >= thcount)
+ goto out;
+ thact = (thread_t)(void *)queue_next(&thact->task_threads);
+ }
+
+out:
+ task_unlock(task);
+ return (int)(numthr * sizeof(uint64_t));
+
+}
+
+int
+get_numthreads(task_t task)
+{
+ return(task->thread_count);
+}
+
+/*
+ * Gather the various pieces of info about the designated task,
+ * and collect it all into a single rusage_info.
+ */
+int
+fill_task_rusage(task_t task, rusage_info_current *ri)
+{
+ struct task_power_info powerinfo;
+
+ assert(task != TASK_NULL);
+ task_lock(task);
+
+ task_power_info_locked(task, &powerinfo, NULL);
+ ri->ri_pkg_idle_wkups = powerinfo.task_platform_idle_wakeups;
+ ri->ri_interrupt_wkups = powerinfo.task_interrupt_wakeups;
+ ri->ri_user_time = powerinfo.total_user;
+ ri->ri_system_time = powerinfo.total_system;
+
+ ledger_get_balance(task->ledger, task_ledgers.phys_footprint,
+ (ledger_amount_t *)&ri->ri_phys_footprint);
+ ledger_get_balance(task->ledger, task_ledgers.phys_mem,
+ (ledger_amount_t *)&ri->ri_resident_size);
+ ledger_get_balance(task->ledger, task_ledgers.wired_mem,
+ (ledger_amount_t *)&ri->ri_wired_size);
+
+ ri->ri_pageins = task->pageins;
+
+ task_unlock(task);
+ return (0);