1*27b03b36SApple OSS Distributions /* 2*27b03b36SApple OSS Distributions * Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved. 3*27b03b36SApple OSS Distributions * 4*27b03b36SApple OSS Distributions * @APPLE_LICENSE_HEADER_START@ 5*27b03b36SApple OSS Distributions * 6*27b03b36SApple OSS Distributions * The contents of this file constitute Original Code as defined in and 7*27b03b36SApple OSS Distributions * are subject to the Apple Public Source License Version 1.1 (the 8*27b03b36SApple OSS Distributions * "License"). You may not use this file except in compliance with the 9*27b03b36SApple OSS Distributions * License. Please obtain a copy of the License at 10*27b03b36SApple OSS Distributions * http://www.apple.com/publicsource and read it before using this file. 11*27b03b36SApple OSS Distributions * 12*27b03b36SApple OSS Distributions * This Original Code and all software distributed under the License are 13*27b03b36SApple OSS Distributions * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14*27b03b36SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15*27b03b36SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16*27b03b36SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17*27b03b36SApple OSS Distributions * License for the specific language governing rights and limitations 18*27b03b36SApple OSS Distributions * under the License. 19*27b03b36SApple OSS Distributions * 20*27b03b36SApple OSS Distributions * @APPLE_LICENSE_HEADER_END@ 21*27b03b36SApple OSS Distributions */ 22*27b03b36SApple OSS Distributions 23*27b03b36SApple OSS Distributions inline int UT_VFORK = 0x02000000; /* thread has vfork children */ 24*27b03b36SApple OSS Distributions #pragma D binding "1.0" UT_VFORK 25*27b03b36SApple OSS Distributions 26*27b03b36SApple OSS Distributions inline uthread_t uthread = (mach_kernel`uthread_t)(&curthread[1]); /* ` */ 27*27b03b36SApple OSS Distributions #pragma D binding "1.0" uthread 28*27b03b36SApple OSS Distributions 29*27b03b36SApple OSS Distributions inline struct proc * curproc = 30*27b03b36SApple OSS Distributions ((struct proc *)(curthread->t_tro->tro_proc)) != NULL ? ((struct proc *)(curthread->t_tro->tro_proc)) : 31*27b03b36SApple OSS Distributions mach_kernel`kernproc; /* ` */ 32*27b03b36SApple OSS Distributions #pragma D binding "1.0" curproc 33*27b03b36SApple OSS Distributions 34*27b03b36SApple OSS Distributions /* 35*27b03b36SApple OSS Distributions * curthread->thread_tag will have this set if the thread is the main thread 36*27b03b36SApple OSS Distributions */ 37*27b03b36SApple OSS Distributions inline uint32_t THREAD_TAG_MAINTHREAD = 0x1; 38*27b03b36SApple OSS Distributions inline uint32_t THREAD_TAG_CALLOUT = 0x2; 39*27b03b36SApple OSS Distributions inline uint32_t THREAD_TAG_IOWORKLOOP = 0x4; 40*27b03b36SApple OSS Distributions 41*27b03b36SApple OSS Distributions /* 42*27b03b36SApple OSS Distributions * mach thread scheduler state 43*27b03b36SApple OSS Distributions */ 44*27b03b36SApple OSS Distributions inline int TH_WAIT = 0x01; 45*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_WAIT 46*27b03b36SApple OSS Distributions inline int TH_SUSP = 0x02; 47*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_SUSP 48*27b03b36SApple OSS Distributions inline int TH_RUN = 0x04; 49*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_RUN 50*27b03b36SApple OSS Distributions inline int TH_UNINT = 0x08; 51*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_UNINT 52*27b03b36SApple OSS Distributions inline int TH_TERMINATE = 0x10; 53*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_TERMINATE 54*27b03b36SApple OSS Distributions inline int TH_TERMINATE2 = 0x20; 55*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_TERMINATE2 56*27b03b36SApple OSS Distributions inline int TH_IDLE = 0x80; 57*27b03b36SApple OSS Distributions #pragma D binding "1.0" TH_IDLE 58*27b03b36SApple OSS Distributions 59*27b03b36SApple OSS Distributions /* 60*27b03b36SApple OSS Distributions * The following miscellaneous constants are used by the proc(4) translators 61*27b03b36SApple OSS Distributions * defined below. 62*27b03b36SApple OSS Distributions */ 63*27b03b36SApple OSS Distributions inline char SIDL = 1; 64*27b03b36SApple OSS Distributions #pragma D binding "1.0" SIDL 65*27b03b36SApple OSS Distributions inline char SRUN = 2; 66*27b03b36SApple OSS Distributions #pragma D binding "1.0" SRUN 67*27b03b36SApple OSS Distributions inline char SSLEEP = 3; 68*27b03b36SApple OSS Distributions #pragma D binding "1.0" SSLEEP 69*27b03b36SApple OSS Distributions inline char SSTOP = 4; 70*27b03b36SApple OSS Distributions #pragma D binding "1.0" SSTOP 71*27b03b36SApple OSS Distributions inline char SZOMB = 5; 72*27b03b36SApple OSS Distributions #pragma D binding "1.0" SZOMB 73*27b03b36SApple OSS Distributions /* 74*27b03b36SApple OSS Distributions * SONPROC defined here for compatability with ported scripts 75*27b03b36SApple OSS Distributions */ 76*27b03b36SApple OSS Distributions inline char SONPROC = 6; 77*27b03b36SApple OSS Distributions #pragma D binding "1.0" SONPROC 78*27b03b36SApple OSS Distributions 79*27b03b36SApple OSS Distributions inline char SOBJ_NONE = 0; 80*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_NONE 81*27b03b36SApple OSS Distributions /* 82*27b03b36SApple OSS Distributions * SOBJ_* defined here for compatability with ported scripts 83*27b03b36SApple OSS Distributions */ 84*27b03b36SApple OSS Distributions inline char SOBJ_MUTEX = 1; 85*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_MUTEX 86*27b03b36SApple OSS Distributions inline char SOBJ_RWLOCK = 2; 87*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_RWLOCK 88*27b03b36SApple OSS Distributions inline char SOBJ_CV = 3; 89*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_CV 90*27b03b36SApple OSS Distributions inline char SOBJ_SEMA = 4; 91*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_SEMA 92*27b03b36SApple OSS Distributions inline char SOBJ_USER = 5; 93*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_USER 94*27b03b36SApple OSS Distributions inline char SOBJ_USER_PI = 6; 95*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_USER_PI 96*27b03b36SApple OSS Distributions inline char SOBJ_SHUTTLE = 7; 97*27b03b36SApple OSS Distributions #pragma D binding "1.0" SOBJ_SHUTTLE 98*27b03b36SApple OSS Distributions 99*27b03b36SApple OSS Distributions inline char PR_MODEL_ILP32 = 1; 100*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_MODEL_ILP32 101*27b03b36SApple OSS Distributions inline char PR_MODEL_LP64 = 2; 102*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_MODEL_LP64 103*27b03b36SApple OSS Distributions 104*27b03b36SApple OSS Distributions /* 105*27b03b36SApple OSS Distributions * PR_* defined here for compatability with ported scripts 106*27b03b36SApple OSS Distributions */ 107*27b03b36SApple OSS Distributions inline int PR_STOPPED = 0x00000001; 108*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_STOPPED 109*27b03b36SApple OSS Distributions inline int PR_ISTOP = 0x00000002; 110*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_ISTOP 111*27b03b36SApple OSS Distributions inline int PR_DSTOP = 0x00000004; 112*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_DSTOP 113*27b03b36SApple OSS Distributions inline int PR_STEP = 0x00000008; 114*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_STEP 115*27b03b36SApple OSS Distributions inline int PR_ASLEEP = 0x00000010; 116*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_ASLEEP 117*27b03b36SApple OSS Distributions inline int PR_PCINVAL = 0x00000020; 118*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_PCINVAL 119*27b03b36SApple OSS Distributions inline int PR_ASLWP = 0x00000040; 120*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_ASLWP 121*27b03b36SApple OSS Distributions inline int PR_AGENT = 0x00000080; 122*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_AGENT 123*27b03b36SApple OSS Distributions inline int PR_DETACH = 0x00000100; 124*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_DETACH 125*27b03b36SApple OSS Distributions inline int PR_DAEMON = 0x00000200; 126*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_DAEMON 127*27b03b36SApple OSS Distributions inline int PR_ISSYS = 0x00001000; 128*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_ISSYS 129*27b03b36SApple OSS Distributions inline int PR_VFORKP = 0x00002000; 130*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_VFORKP 131*27b03b36SApple OSS Distributions inline int PR_ORPHAN = 0x00004000; 132*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_ORPHAN 133*27b03b36SApple OSS Distributions inline int PR_FORK = 0x00100000; 134*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_FORK 135*27b03b36SApple OSS Distributions inline int PR_RLC = 0x00200000; 136*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_RLC 137*27b03b36SApple OSS Distributions inline int PR_KLC = 0x00400000; 138*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_KLC 139*27b03b36SApple OSS Distributions inline int PR_ASYNC = 0x00800000; 140*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_ASYNC 141*27b03b36SApple OSS Distributions inline int PR_MSACCT = 0x01000000; 142*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_MSACCT 143*27b03b36SApple OSS Distributions inline int PR_BPTADJ = 0x02000000; 144*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_BPTADJ 145*27b03b36SApple OSS Distributions inline int PR_PTRACE = 0x04000000; 146*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_PTRACE 147*27b03b36SApple OSS Distributions inline int PR_MSFORK = 0x08000000; 148*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_MSFORK 149*27b03b36SApple OSS Distributions inline int PR_IDLE = 0x10000000; 150*27b03b36SApple OSS Distributions #pragma D binding "1.0" PR_IDLE 151*27b03b36SApple OSS Distributions 152*27b03b36SApple OSS Distributions /* 153*27b03b36SApple OSS Distributions * Translate from the kernel's proc_t structure to a proc(4) psinfo_t struct. 154*27b03b36SApple OSS Distributions * We do not provide support for pr_size, pr_rssize, pr_pctcpu, and pr_pctmem. 155*27b03b36SApple OSS Distributions * We also do not fill in pr_lwp (the lwpsinfo_t for the representative LWP) 156*27b03b36SApple OSS Distributions * because we do not have the ability to select and stop any representative. 157*27b03b36SApple OSS Distributions * Also, for the moment, pr_wstat, pr_time, and pr_ctime are not supported, 158*27b03b36SApple OSS Distributions * but these could be supported by DTrace in the future using subroutines. 159*27b03b36SApple OSS Distributions * Note that any member added to this translator should also be added to the 160*27b03b36SApple OSS Distributions * kthread_t-to-psinfo_t translator, below. 161*27b03b36SApple OSS Distributions */ 162*27b03b36SApple OSS Distributions typedef int taskid_t; 163*27b03b36SApple OSS Distributions typedef int projid_t; 164*27b03b36SApple OSS Distributions typedef int poolid_t; 165*27b03b36SApple OSS Distributions typedef struct timespec timestruc_t; /* (SECONDS, NANOSECONDS) */ 166*27b03b36SApple OSS Distributions 167*27b03b36SApple OSS Distributions typedef struct psinfo { 168*27b03b36SApple OSS Distributions int pr_nlwp; /* number of active lwps in the process */ 169*27b03b36SApple OSS Distributions pid_t pr_pid; /* unique process id */ 170*27b03b36SApple OSS Distributions pid_t pr_ppid; /* process id of parent */ 171*27b03b36SApple OSS Distributions pid_t pr_pgid; /* pid of process group leader */ 172*27b03b36SApple OSS Distributions pid_t pr_sid; /* session id */ 173*27b03b36SApple OSS Distributions uid_t pr_uid; /* real user id */ 174*27b03b36SApple OSS Distributions uid_t pr_euid; /* effective user id */ 175*27b03b36SApple OSS Distributions gid_t pr_gid; /* real group id */ 176*27b03b36SApple OSS Distributions gid_t pr_egid; /* effective group id */ 177*27b03b36SApple OSS Distributions uintptr_t pr_addr; /* address of process */ 178*27b03b36SApple OSS Distributions dev_t pr_ttydev; /* controlling tty device (or PRNODEV) */ 179*27b03b36SApple OSS Distributions timestruc_t pr_start;/* process start time, DEPRECATED, see pr_start_tv below */ 180*27b03b36SApple OSS Distributions char pr_fname[16]; /* name of execed file */ 181*27b03b36SApple OSS Distributions char pr_psargs[80]; /* initial characters of arg list */ 182*27b03b36SApple OSS Distributions int pr_argc; /* initial argument count */ 183*27b03b36SApple OSS Distributions user_addr_t pr_argv; /* address of initial argument vector */ 184*27b03b36SApple OSS Distributions user_addr_t pr_envp; /* address of initial environment vector */ 185*27b03b36SApple OSS Distributions char pr_dmodel; /* data model of the process */ 186*27b03b36SApple OSS Distributions taskid_t pr_taskid; /* task id */ 187*27b03b36SApple OSS Distributions projid_t pr_projid; /* project id */ 188*27b03b36SApple OSS Distributions poolid_t pr_poolid; /* pool id */ 189*27b03b36SApple OSS Distributions zoneid_t pr_zoneid; /* zone id */ 190*27b03b36SApple OSS Distributions 191*27b03b36SApple OSS Distributions struct timeval pr_start_tv; /* process start time, from the epoch (SECONDS, MICROSECONDS) */ 192*27b03b36SApple OSS Distributions } psinfo_t; 193*27b03b36SApple OSS Distributions 194*27b03b36SApple OSS Distributions inline int P_LP64 = 0x00000004; /* Process is LP64 */ 195*27b03b36SApple OSS Distributions #pragma D binding "1.0" P_LP64 196*27b03b36SApple OSS Distributions 197*27b03b36SApple OSS Distributions #pragma D binding "1.0" translator 198*27b03b36SApple OSS Distributions translator psinfo_t < struct proc * P > { 199*27b03b36SApple OSS Distributions pr_nlwp = ((struct task *)(P->task))->thread_count; 200*27b03b36SApple OSS Distributions pr_pid = P->p_pid; 201*27b03b36SApple OSS Distributions pr_ppid = P->p_ppid; 202*27b03b36SApple OSS Distributions pr_pgid = P->p_pgrp.__hazard_ptr->pg_id; 203*27b03b36SApple OSS Distributions pr_sid = P->p_pgrp.__hazard_ptr->pg_session->s_sid; 204*27b03b36SApple OSS Distributions pr_uid = P->p_proc_ro->p_ucred->cr_posix.cr_ruid; 205*27b03b36SApple OSS Distributions pr_euid = P->p_proc_ro->p_ucred->cr_posix.cr_uid; 206*27b03b36SApple OSS Distributions pr_gid = P->p_proc_ro->p_ucred->cr_posix.cr_rgid; 207*27b03b36SApple OSS Distributions pr_egid = P->p_proc_ro->p_ucred->cr_posix.cr_groups[0]; 208*27b03b36SApple OSS Distributions pr_addr = (uintptr_t)P; 209*27b03b36SApple OSS Distributions 210*27b03b36SApple OSS Distributions pr_ttydev = (P->p_pgrp.__hazard_ptr->pg_session->s_ttyvp == NULL) ? (dev_t)-1 : 211*27b03b36SApple OSS Distributions P->p_pgrp.__hazard_ptr->pg_session->s_ttyp->t_dev; 212*27b03b36SApple OSS Distributions 213*27b03b36SApple OSS Distributions /* 214*27b03b36SApple OSS Distributions * timestruct_t (SECONDS, NANOSECONDS) is not available directly nor can a further translation 215*27b03b36SApple OSS Distributions * be specified here. Zero the structure. Use pr_start_tv instead. 216*27b03b36SApple OSS Distributions */ 217*27b03b36SApple OSS Distributions pr_start = *((timestruc_t *)`dtrace_zero); /* ` */ 218*27b03b36SApple OSS Distributions 219*27b03b36SApple OSS Distributions pr_fname = P->p_comm; 220*27b03b36SApple OSS Distributions pr_psargs = P->p_comm; /* XXX omits command line arguments XXX */ 221*27b03b36SApple OSS Distributions pr_argc = P->p_argc; 222*27b03b36SApple OSS Distributions pr_argv = P->p_dtrace_argv; 223*27b03b36SApple OSS Distributions pr_envp = P->p_dtrace_envp; 224*27b03b36SApple OSS Distributions 225*27b03b36SApple OSS Distributions pr_dmodel = (P->p_flag & P_LP64) ? PR_MODEL_LP64 : PR_MODEL_ILP32; 226*27b03b36SApple OSS Distributions 227*27b03b36SApple OSS Distributions pr_taskid = 0; 228*27b03b36SApple OSS Distributions pr_projid = 0; 229*27b03b36SApple OSS Distributions pr_poolid = 0; 230*27b03b36SApple OSS Distributions pr_zoneid = 0; 231*27b03b36SApple OSS Distributions 232*27b03b36SApple OSS Distributions /* 233*27b03b36SApple OSS Distributions * pstats->pstart is a struct timeval: (SECONDS, MICROSECONDS). 234*27b03b36SApple OSS Distributions */ 235*27b03b36SApple OSS Distributions pr_start_tv = P->p_start; 236*27b03b36SApple OSS Distributions }; 237*27b03b36SApple OSS Distributions 238*27b03b36SApple OSS Distributions /* 239*27b03b36SApple OSS Distributions * Translate from the kernel's kthread_t structure to a proc(4) psinfo_t 240*27b03b36SApple OSS Distributions * struct. Lacking a facility to define one translator only in terms of 241*27b03b36SApple OSS Distributions * another, we explicitly define each member by using the proc_t-to-psinfo_t 242*27b03b36SApple OSS Distributions * translator, above; any members added to that translator should also be 243*27b03b36SApple OSS Distributions * added here. (The only exception to this is pr_start, which -- due to it 244*27b03b36SApple OSS Distributions * being a structure -- cannot be defined in terms of a translator at all.) 245*27b03b36SApple OSS Distributions */ 246*27b03b36SApple OSS Distributions #pragma D binding "1.0" translator 247*27b03b36SApple OSS Distributions translator psinfo_t < thread_t T > { 248*27b03b36SApple OSS Distributions pr_nlwp = xlate <psinfo_t> (T->t_tro->tro_proc).pr_nlwp; 249*27b03b36SApple OSS Distributions pr_pid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_pid; 250*27b03b36SApple OSS Distributions pr_ppid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_ppid; 251*27b03b36SApple OSS Distributions pr_pgid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_pgid; 252*27b03b36SApple OSS Distributions pr_sid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_sid; 253*27b03b36SApple OSS Distributions pr_uid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_uid; 254*27b03b36SApple OSS Distributions pr_euid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_euid; 255*27b03b36SApple OSS Distributions pr_gid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_gid; 256*27b03b36SApple OSS Distributions pr_egid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_egid; 257*27b03b36SApple OSS Distributions pr_addr = xlate <psinfo_t> (T->t_tro->tro_proc).pr_addr; 258*27b03b36SApple OSS Distributions pr_ttydev = xlate <psinfo_t> (T->t_tro->tro_proc).pr_ttydev; 259*27b03b36SApple OSS Distributions pr_start = xlate <psinfo_t> (T->t_tro->tro_proc).pr_start; 260*27b03b36SApple OSS Distributions pr_fname = xlate <psinfo_t> (T->t_tro->tro_proc).pr_fname; 261*27b03b36SApple OSS Distributions pr_psargs = xlate <psinfo_t> (T->t_tro->tro_proc).pr_psargs; /* XXX omits command line arguments XXX */ 262*27b03b36SApple OSS Distributions pr_argc = xlate <psinfo_t> (T->t_tro->tro_proc).pr_argc; 263*27b03b36SApple OSS Distributions pr_argv = xlate <psinfo_t> (T->t_tro->tro_proc).pr_argv; 264*27b03b36SApple OSS Distributions pr_envp = xlate <psinfo_t> (T->t_tro->tro_proc).pr_envp; 265*27b03b36SApple OSS Distributions pr_dmodel = xlate <psinfo_t> (T->t_tro->tro_proc).pr_dmodel; 266*27b03b36SApple OSS Distributions pr_taskid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_taskid; 267*27b03b36SApple OSS Distributions pr_projid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_projid; 268*27b03b36SApple OSS Distributions pr_poolid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_poolid; 269*27b03b36SApple OSS Distributions pr_zoneid = xlate <psinfo_t> (T->t_tro->tro_proc).pr_zoneid; 270*27b03b36SApple OSS Distributions 271*27b03b36SApple OSS Distributions pr_start_tv = xlate <psinfo_t> (T->t_tro->tro_proc).pr_start_tv; 272*27b03b36SApple OSS Distributions }; 273*27b03b36SApple OSS Distributions 274*27b03b36SApple OSS Distributions /* 275*27b03b36SApple OSS Distributions * Translate from the kernel's kthread_t structure to a proc(4) lwpsinfo_t. 276*27b03b36SApple OSS Distributions * We do not provide support for pr_nice, pr_oldpri, pr_cpu, or pr_pctcpu. 277*27b03b36SApple OSS Distributions * Also, for the moment, pr_start and pr_time are not supported, but these 278*27b03b36SApple OSS Distributions * could be supported by DTrace in the future using subroutines. 279*27b03b36SApple OSS Distributions */ 280*27b03b36SApple OSS Distributions 281*27b03b36SApple OSS Distributions inline processor_t PROCESSOR_NULL = ((processor_t) 0); 282*27b03b36SApple OSS Distributions #pragma D binding "1.0" PROCESSOR_NULL 283*27b03b36SApple OSS Distributions 284*27b03b36SApple OSS Distributions typedef int psetid_t; 285*27b03b36SApple OSS Distributions 286*27b03b36SApple OSS Distributions typedef struct lwpsinfo { 287*27b03b36SApple OSS Distributions int pr_flag; /* lwp flags (DEPRECATED; do not use) */ 288*27b03b36SApple OSS Distributions id_t pr_lwpid; /* lwp id */ 289*27b03b36SApple OSS Distributions uintptr_t pr_addr; /* internal address of lwp */ 290*27b03b36SApple OSS Distributions uintptr_t pr_wchan; /* wait addr for sleeping lwp */ 291*27b03b36SApple OSS Distributions char pr_stype; /* synchronization event type */ 292*27b03b36SApple OSS Distributions char pr_state; /* numeric lwp state */ 293*27b03b36SApple OSS Distributions char pr_sname; /* printable character for pr_state */ 294*27b03b36SApple OSS Distributions short pr_syscall; /* system call number (if in syscall) */ 295*27b03b36SApple OSS Distributions int pr_pri; /* priority, high value is high priority */ 296*27b03b36SApple OSS Distributions char pr_clname[8]; /* scheduling class name */ 297*27b03b36SApple OSS Distributions int pr_thstate; /* mach thread scheduler state */ 298*27b03b36SApple OSS Distributions processorid_t pr_onpro; /* processor which last ran this lwp */ 299*27b03b36SApple OSS Distributions processorid_t pr_bindpro; /* processor to which lwp is bound */ 300*27b03b36SApple OSS Distributions psetid_t pr_bindpset; /* processor set to which lwp is bound */ 301*27b03b36SApple OSS Distributions } lwpsinfo_t; 302*27b03b36SApple OSS Distributions 303*27b03b36SApple OSS Distributions #pragma D binding "1.0" translator 304*27b03b36SApple OSS Distributions translator lwpsinfo_t < thread_t T > { 305*27b03b36SApple OSS Distributions pr_flag = 0; /* lwp flags (DEPRECATED; do not use) */ 306*27b03b36SApple OSS Distributions pr_lwpid = (id_t)T->thread_id; 307*27b03b36SApple OSS Distributions pr_addr = (uintptr_t)T; 308*27b03b36SApple OSS Distributions pr_wchan = (uintptr_t)(((uthread_t)&T[1])->uu_wchan); 309*27b03b36SApple OSS Distributions 310*27b03b36SApple OSS Distributions pr_stype = SOBJ_NONE; /* XXX Undefined synch object (or none) XXX */ 311*27b03b36SApple OSS Distributions pr_state = curproc->p_stat; 312*27b03b36SApple OSS Distributions pr_sname = (curproc->p_stat == SIDL) ? 'I' : 313*27b03b36SApple OSS Distributions (curproc->p_stat == SRUN) ? 'R' : 314*27b03b36SApple OSS Distributions (curproc->p_stat == SSLEEP) ? 'S' : 315*27b03b36SApple OSS Distributions (curproc->p_stat == SSTOP) ? 'T' : 316*27b03b36SApple OSS Distributions (curproc->p_stat == SZOMB) ? 'Z' : '?'; 317*27b03b36SApple OSS Distributions 318*27b03b36SApple OSS Distributions pr_syscall = ((uthread_t)&T[1])->uu_code; 319*27b03b36SApple OSS Distributions pr_pri = T->sched_pri; 320*27b03b36SApple OSS Distributions 321*27b03b36SApple OSS Distributions pr_clname = (T->sched_mode & 0x0001) ? "RT" : 322*27b03b36SApple OSS Distributions (T->sched_mode & 0x0002) ? "TS" : "SYS"; 323*27b03b36SApple OSS Distributions 324*27b03b36SApple OSS Distributions pr_onpro = (T->last_processor == PROCESSOR_NULL) ? -1 : T->last_processor->cpu_id; 325*27b03b36SApple OSS Distributions pr_bindpro = -1; /* Darwin does not bind threads to processors. */ 326*27b03b36SApple OSS Distributions pr_bindpset = -1; /* Darwin does not partition processors. */ 327*27b03b36SApple OSS Distributions pr_thstate = T->state; 328*27b03b36SApple OSS Distributions }; 329*27b03b36SApple OSS Distributions 330*27b03b36SApple OSS Distributions inline psinfo_t *curpsinfo = xlate <psinfo_t *> (curproc); 331*27b03b36SApple OSS Distributions #pragma D attributes Stable/Stable/Common curpsinfo 332*27b03b36SApple OSS Distributions #pragma D binding "1.0" curpsinfo 333*27b03b36SApple OSS Distributions 334*27b03b36SApple OSS Distributions inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread); 335*27b03b36SApple OSS Distributions #pragma D attributes Stable/Stable/Common curlwpsinfo 336*27b03b36SApple OSS Distributions #pragma D binding "1.0" curlwpsinfo 337*27b03b36SApple OSS Distributions 338*27b03b36SApple OSS Distributions /* XXX Really want vn_getpath(curproc->p_fd.fd_cdir, , ) but that takes namecache_rw_lock XXX */ 339*27b03b36SApple OSS Distributions inline string cwd = curproc->p_fd.fd_cdir->v_name == NULL ? 340*27b03b36SApple OSS Distributions "<unknown>" : stringof(curproc->p_fd.fd_cdir->v_name); 341*27b03b36SApple OSS Distributions #pragma D attributes Stable/Stable/Common cwd 342*27b03b36SApple OSS Distributions #pragma D binding "1.0" cwd 343*27b03b36SApple OSS Distributions 344*27b03b36SApple OSS Distributions /* XXX Really want vn_getpath(curproc->p_fd.fd_rdir, , ) but that takes namecache_rw_lock XXX */ 345*27b03b36SApple OSS Distributions inline string root = curproc->p_fd.fd_rdir == NULL ? "/" : 346*27b03b36SApple OSS Distributions curproc->p_fd.fd_rdir->v_name == NULL ? "<unknown>" : 347*27b03b36SApple OSS Distributions stringof(curproc->p_fd.fd_rdir->v_name); 348*27b03b36SApple OSS Distributions #pragma D attributes Stable/Stable/Common root 349*27b03b36SApple OSS Distributions #pragma D binding "1.0" root 350*27b03b36SApple OSS Distributions 351*27b03b36SApple OSS Distributions /* Used with livedump. */ 352*27b03b36SApple OSS Distributions inline unsigned DT_HV = 0; 353*27b03b36SApple OSS Distributions #pragma D binding "1.19" DT_HV 354