1*0Sstevel@tonic-gate/* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate/* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate/* 30*0Sstevel@tonic-gate * This file defines the standard set of inlines and translators to be made 31*0Sstevel@tonic-gate * available for all D programs to use to examine process model state. 32*0Sstevel@tonic-gate */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate#pragma D depends_on module procfs 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gateinline int errno = curthread->t_lwp ? curthread->t_lwp->lwp_errno : 0; 37*0Sstevel@tonic-gate#pragma D binding "1.0" errno 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate/* 40*0Sstevel@tonic-gate * The following miscellaneous constants are used by the proc(4) translators 41*0Sstevel@tonic-gate * defined below. These are assigned the latest values from the system .h's. 42*0Sstevel@tonic-gate */ 43*0Sstevel@tonic-gateinline char SSLEEP = @SSLEEP@; 44*0Sstevel@tonic-gate#pragma D binding "1.0" SSLEEP 45*0Sstevel@tonic-gateinline char SRUN = @SRUN@; 46*0Sstevel@tonic-gate#pragma D binding "1.0" SRUN 47*0Sstevel@tonic-gateinline char SZOMB = @SZOMB@; 48*0Sstevel@tonic-gate#pragma D binding "1.0" SZOMB 49*0Sstevel@tonic-gateinline char SSTOP = @SSTOP@; 50*0Sstevel@tonic-gate#pragma D binding "1.0" SSTOP 51*0Sstevel@tonic-gateinline char SIDL = @SIDL@; 52*0Sstevel@tonic-gate#pragma D binding "1.0" SIDL 53*0Sstevel@tonic-gateinline char SONPROC = @SONPROC@; 54*0Sstevel@tonic-gate#pragma D binding "1.0" SONPROC 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gateinline int PR_STOPPED = @PR_STOPPED@; 57*0Sstevel@tonic-gate#pragma D binding "1.0" PR_STOPPED 58*0Sstevel@tonic-gateinline int PR_ISTOP = @PR_ISTOP@; 59*0Sstevel@tonic-gate#pragma D binding "1.0" PR_ISTOP 60*0Sstevel@tonic-gateinline int PR_DSTOP = @PR_DSTOP@; 61*0Sstevel@tonic-gate#pragma D binding "1.0" PR_DSTOP 62*0Sstevel@tonic-gateinline int PR_STEP = @PR_STEP@; 63*0Sstevel@tonic-gate#pragma D binding "1.0" PR_STEP 64*0Sstevel@tonic-gateinline int PR_ASLEEP = @PR_ASLEEP@; 65*0Sstevel@tonic-gate#pragma D binding "1.0" PR_ASLEEP 66*0Sstevel@tonic-gateinline int PR_PCINVAL = @PR_PCINVAL@; 67*0Sstevel@tonic-gate#pragma D binding "1.0" PR_PCINVAL 68*0Sstevel@tonic-gateinline int PR_ASLWP = @PR_ASLWP@; 69*0Sstevel@tonic-gate#pragma D binding "1.0" PR_ASLWP 70*0Sstevel@tonic-gateinline int PR_AGENT = @PR_AGENT@; 71*0Sstevel@tonic-gate#pragma D binding "1.0" PR_AGENT 72*0Sstevel@tonic-gateinline int PR_DETACH = @PR_DETACH@; 73*0Sstevel@tonic-gate#pragma D binding "1.0" PR_DETACH 74*0Sstevel@tonic-gateinline int PR_DAEMON = @PR_DAEMON@; 75*0Sstevel@tonic-gate#pragma D binding "1.0" PR_DAEMON 76*0Sstevel@tonic-gateinline int PR_ISSYS = @PR_ISSYS@; 77*0Sstevel@tonic-gate#pragma D binding "1.0" PR_ISSYS 78*0Sstevel@tonic-gateinline int PR_VFORKP = @PR_VFORKP@; 79*0Sstevel@tonic-gate#pragma D binding "1.0" PR_VFORKP 80*0Sstevel@tonic-gateinline int PR_ORPHAN = @PR_ORPHAN@; 81*0Sstevel@tonic-gate#pragma D binding "1.0" PR_ORPHAN 82*0Sstevel@tonic-gateinline int PR_FORK = @PR_FORK@; 83*0Sstevel@tonic-gate#pragma D binding "1.0" PR_FORK 84*0Sstevel@tonic-gateinline int PR_RLC = @PR_RLC@; 85*0Sstevel@tonic-gate#pragma D binding "1.0" PR_RLC 86*0Sstevel@tonic-gateinline int PR_KLC = @PR_KLC@; 87*0Sstevel@tonic-gate#pragma D binding "1.0" PR_KLC 88*0Sstevel@tonic-gateinline int PR_ASYNC = @PR_ASYNC@; 89*0Sstevel@tonic-gate#pragma D binding "1.0" PR_ASYNC 90*0Sstevel@tonic-gateinline int PR_MSACCT = @PR_MSACCT@; 91*0Sstevel@tonic-gate#pragma D binding "1.0" PR_MSACCT 92*0Sstevel@tonic-gateinline int PR_BPTADJ = @PR_BPTADJ@; 93*0Sstevel@tonic-gate#pragma D binding "1.0" PR_BPTADJ 94*0Sstevel@tonic-gateinline int PR_PTRACE = @PR_PTRACE@; 95*0Sstevel@tonic-gate#pragma D binding "1.0" PR_PTRACE 96*0Sstevel@tonic-gateinline int PR_MSFORK = @PR_MSFORK@; 97*0Sstevel@tonic-gate#pragma D binding "1.0" PR_MSFORK 98*0Sstevel@tonic-gateinline int PR_IDLE = @PR_IDLE@; 99*0Sstevel@tonic-gate#pragma D binding "1.0" PR_IDLE 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gateinline char PR_MODEL_ILP32 = @PR_MODEL_ILP32@; 102*0Sstevel@tonic-gate#pragma D binding "1.0" PR_MODEL_ILP32 103*0Sstevel@tonic-gateinline char PR_MODEL_LP64 = @PR_MODEL_LP64@; 104*0Sstevel@tonic-gate#pragma D binding "1.0" PR_MODEL_LP64 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gateinline char SOBJ_NONE = @SOBJ_NONE@; 107*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_NONE 108*0Sstevel@tonic-gateinline char SOBJ_MUTEX = @SOBJ_MUTEX@; 109*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_MUTEX 110*0Sstevel@tonic-gateinline char SOBJ_RWLOCK = @SOBJ_RWLOCK@; 111*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_RWLOCK 112*0Sstevel@tonic-gateinline char SOBJ_CV = @SOBJ_CV@; 113*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_CV 114*0Sstevel@tonic-gateinline char SOBJ_SEMA = @SOBJ_SEMA@; 115*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_SEMA 116*0Sstevel@tonic-gateinline char SOBJ_USER = @SOBJ_USER@; 117*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_USER 118*0Sstevel@tonic-gateinline char SOBJ_USER_PI = @SOBJ_USER_PI@; 119*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_USER_PI 120*0Sstevel@tonic-gateinline char SOBJ_SHUTTLE = @SOBJ_SHUTTLE@; 121*0Sstevel@tonic-gate#pragma D binding "1.0" SOBJ_SHUTTLE 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gateinline int SI_USER = @SI_USER@; 124*0Sstevel@tonic-gate#pragma D binding "1.0" SI_USER 125*0Sstevel@tonic-gateinline int SI_LWP = @SI_LWP@; 126*0Sstevel@tonic-gate#pragma D binding "1.0" SI_LWP 127*0Sstevel@tonic-gateinline int SI_QUEUE = @SI_QUEUE@; 128*0Sstevel@tonic-gate#pragma D binding "1.0" SI_QUEUE 129*0Sstevel@tonic-gateinline int SI_TIMER = @SI_TIMER@; 130*0Sstevel@tonic-gate#pragma D binding "1.0" SI_TIMER 131*0Sstevel@tonic-gateinline int SI_ASYNCIO = @SI_ASYNCIO@; 132*0Sstevel@tonic-gate#pragma D binding "1.0" SI_ASYNCIO 133*0Sstevel@tonic-gateinline int SI_MESGQ = @SI_MESGQ@; 134*0Sstevel@tonic-gate#pragma D binding "1.0" SI_MESGQ 135*0Sstevel@tonic-gateinline int SI_RCTL = @SI_RCTL@; 136*0Sstevel@tonic-gate#pragma D binding "1.0" SI_RCTL 137*0Sstevel@tonic-gateinline int ILL_ILLOPC = @ILL_ILLOPC@; 138*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_ILLOPC 139*0Sstevel@tonic-gateinline int ILL_ILLOPN = @ILL_ILLOPN@; 140*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_ILLOPN 141*0Sstevel@tonic-gateinline int ILL_ILLADR = @ILL_ILLADR@; 142*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_ILLADR 143*0Sstevel@tonic-gateinline int ILL_ILLTRP = @ILL_ILLTRP@; 144*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_ILLTRP 145*0Sstevel@tonic-gateinline int ILL_PRVOPC = @ILL_PRVOPC@; 146*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_PRVOPC 147*0Sstevel@tonic-gateinline int ILL_PRVREG = @ILL_PRVREG@; 148*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_PRVREG 149*0Sstevel@tonic-gateinline int ILL_COPROC = @ILL_COPROC@; 150*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_COPROC 151*0Sstevel@tonic-gateinline int ILL_BADSTK = @ILL_BADSTK@; 152*0Sstevel@tonic-gate#pragma D binding "1.0" ILL_BADSTK 153*0Sstevel@tonic-gateinline int FPE_INTDIV = @FPE_INTDIV@; 154*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_INTDIV 155*0Sstevel@tonic-gateinline int FPE_INTOVF = @FPE_INTOVF@; 156*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_INTOVF 157*0Sstevel@tonic-gateinline int FPE_FLTDIV = @FPE_FLTDIV@; 158*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_FLTDIV 159*0Sstevel@tonic-gateinline int FPE_FLTOVF = @FPE_FLTOVF@; 160*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_FLTOVF 161*0Sstevel@tonic-gateinline int FPE_FLTUND = @FPE_FLTUND@; 162*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_FLTUND 163*0Sstevel@tonic-gateinline int FPE_FLTRES = @FPE_FLTRES@; 164*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_FLTRES 165*0Sstevel@tonic-gateinline int FPE_FLTINV = @FPE_FLTINV@; 166*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_FLTINV 167*0Sstevel@tonic-gateinline int FPE_FLTSUB = @FPE_FLTSUB@; 168*0Sstevel@tonic-gate#pragma D binding "1.0" FPE_FLTSUB 169*0Sstevel@tonic-gateinline int SEGV_MAPERR = @SEGV_MAPERR@; 170*0Sstevel@tonic-gate#pragma D binding "1.0" SEGV_MAPERR 171*0Sstevel@tonic-gateinline int SEGV_ACCERR = @SEGV_ACCERR@; 172*0Sstevel@tonic-gate#pragma D binding "1.0" SEGV_ACCERR 173*0Sstevel@tonic-gateinline int BUS_ADRALN = @BUS_ADRALN@; 174*0Sstevel@tonic-gate#pragma D binding "1.0" BUS_ADRALN 175*0Sstevel@tonic-gateinline int BUS_ADRERR = @BUS_ADRERR@; 176*0Sstevel@tonic-gate#pragma D binding "1.0" BUS_ADRERR 177*0Sstevel@tonic-gateinline int BUS_OBJERR = @BUS_OBJERR@; 178*0Sstevel@tonic-gate#pragma D binding "1.0" BUS_OBJERR 179*0Sstevel@tonic-gateinline int TRAP_BRKPT = @TRAP_BRKPT@; 180*0Sstevel@tonic-gate#pragma D binding "1.0" TRAP_BRKPT 181*0Sstevel@tonic-gateinline int TRAP_TRACE = @TRAP_TRACE@; 182*0Sstevel@tonic-gate#pragma D binding "1.0" TRAP_TRACE 183*0Sstevel@tonic-gateinline int CLD_EXITED = @CLD_EXITED@; 184*0Sstevel@tonic-gate#pragma D binding "1.0" CLD_EXITED 185*0Sstevel@tonic-gateinline int CLD_KILLED = @CLD_KILLED@; 186*0Sstevel@tonic-gate#pragma D binding "1.0" CLD_KILLED 187*0Sstevel@tonic-gateinline int CLD_DUMPED = @CLD_DUMPED@; 188*0Sstevel@tonic-gate#pragma D binding "1.0" CLD_DUMPED 189*0Sstevel@tonic-gateinline int CLD_TRAPPED = @CLD_TRAPPED@; 190*0Sstevel@tonic-gate#pragma D binding "1.0" CLD_TRAPPED 191*0Sstevel@tonic-gateinline int CLD_STOPPED = @CLD_STOPPED@; 192*0Sstevel@tonic-gate#pragma D binding "1.0" CLD_STOPPED 193*0Sstevel@tonic-gateinline int CLD_CONTINUED = @CLD_CONTINUED@; 194*0Sstevel@tonic-gate#pragma D binding "1.0" CLD_CONTINUED 195*0Sstevel@tonic-gateinline int POLL_IN = @POLL_IN@; 196*0Sstevel@tonic-gate#pragma D binding "1.0" POLL_IN 197*0Sstevel@tonic-gateinline int POLL_OUT = @POLL_OUT@; 198*0Sstevel@tonic-gate#pragma D binding "1.0" POLL_OUT 199*0Sstevel@tonic-gateinline int POLL_MSG = @POLL_MSG@; 200*0Sstevel@tonic-gate#pragma D binding "1.0" POLL_MSG 201*0Sstevel@tonic-gateinline int POLL_ERR = @POLL_ERR@; 202*0Sstevel@tonic-gate#pragma D binding "1.0" POLL_ERR 203*0Sstevel@tonic-gateinline int POLL_PRI = @POLL_PRI@; 204*0Sstevel@tonic-gate#pragma D binding "1.0" POLL_PRI 205*0Sstevel@tonic-gateinline int POLL_HUP = @POLL_HUP@; 206*0Sstevel@tonic-gate#pragma D binding "1.0" POLL_HUP 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate/* 209*0Sstevel@tonic-gate * Translate from the kernel's proc_t structure to a proc(4) psinfo_t struct. 210*0Sstevel@tonic-gate * We do not provide support for pr_size, pr_rssize, pr_pctcpu, and pr_pctmem. 211*0Sstevel@tonic-gate * We also do not fill in pr_lwp (the lwpsinfo_t for the representative LWP) 212*0Sstevel@tonic-gate * because we do not have the ability to select and stop any representative. 213*0Sstevel@tonic-gate * Also, for the moment, pr_wstat, pr_time, and pr_ctime are not supported, 214*0Sstevel@tonic-gate * but these could be supported by DTrace in the future using subroutines. 215*0Sstevel@tonic-gate * Note that any member added to this translator should also be added to the 216*0Sstevel@tonic-gate * kthread_t-to-psinfo_t translator, below. 217*0Sstevel@tonic-gate */ 218*0Sstevel@tonic-gate#pragma D binding "1.0" translator 219*0Sstevel@tonic-gatetranslator psinfo_t < proc_t *T > { 220*0Sstevel@tonic-gate pr_nlwp = T->p_lwpcnt; 221*0Sstevel@tonic-gate pr_pid = T->p_pidp->pid_id; 222*0Sstevel@tonic-gate pr_ppid = T->p_ppid; 223*0Sstevel@tonic-gate pr_pgid = T->p_pgidp->pid_id; 224*0Sstevel@tonic-gate pr_sid = T->p_sessp->s_sidp->pid_id; 225*0Sstevel@tonic-gate pr_uid = T->p_cred->cr_ruid; 226*0Sstevel@tonic-gate pr_euid = T->p_cred->cr_uid; 227*0Sstevel@tonic-gate pr_gid = T->p_cred->cr_rgid; 228*0Sstevel@tonic-gate pr_egid = T->p_cred->cr_gid; 229*0Sstevel@tonic-gate pr_addr = (uintptr_t)T; 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate pr_ttydev = (T->p_sessp->s_vp == NULL) ? (dev_t)-1 : 232*0Sstevel@tonic-gate (T->p_sessp->s_dev == `rwsconsdev) ? `uconsdev : 233*0Sstevel@tonic-gate (T->p_sessp->s_dev == `rconsdev) ? `uconsdev : T->p_sessp->s_dev; 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate pr_start = T->p_user.u_start; 236*0Sstevel@tonic-gate pr_fname = T->p_user.u_comm; 237*0Sstevel@tonic-gate pr_psargs = T->p_user.u_psargs; 238*0Sstevel@tonic-gate pr_argc = T->p_user.u_argc; 239*0Sstevel@tonic-gate pr_argv = T->p_user.u_argv; 240*0Sstevel@tonic-gate pr_envp = T->p_user.u_envp; 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate pr_dmodel = (T->p_model == @DATAMODEL_ILP32@) ? 243*0Sstevel@tonic-gate PR_MODEL_ILP32 : PR_MODEL_LP64; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate pr_taskid = T->p_task->tk_tkid; 246*0Sstevel@tonic-gate pr_projid = T->p_task->tk_proj->kpj_id; 247*0Sstevel@tonic-gate pr_poolid = T->p_pool->pool_id; 248*0Sstevel@tonic-gate pr_zoneid = T->p_zone->zone_id; 249*0Sstevel@tonic-gate}; 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate/* 252*0Sstevel@tonic-gate * Translate from the kernel's kthread_t structure to a proc(4) psinfo_t 253*0Sstevel@tonic-gate * struct. Lacking a facility to define one translator only in terms of 254*0Sstevel@tonic-gate * another, we explicitly define each member by using the proc_t-to-psinfo_t 255*0Sstevel@tonic-gate * translator, above; any members added to that translator should also be 256*0Sstevel@tonic-gate * added here. (The only exception to this is pr_start, which -- due to it 257*0Sstevel@tonic-gate * being a structure -- cannot be defined in terms of a translator at all.) 258*0Sstevel@tonic-gate */ 259*0Sstevel@tonic-gate#pragma D binding "1.0" translator 260*0Sstevel@tonic-gatetranslator psinfo_t < kthread_t *T > { 261*0Sstevel@tonic-gate pr_nlwp = xlate <psinfo_t> (T->t_procp).pr_nlwp; 262*0Sstevel@tonic-gate pr_pid = xlate <psinfo_t> (T->t_procp).pr_pid; 263*0Sstevel@tonic-gate pr_ppid = xlate <psinfo_t> (T->t_procp).pr_ppid; 264*0Sstevel@tonic-gate pr_pgid = xlate <psinfo_t> (T->t_procp).pr_pgid; 265*0Sstevel@tonic-gate pr_sid = xlate <psinfo_t> (T->t_procp).pr_sid; 266*0Sstevel@tonic-gate pr_uid = xlate <psinfo_t> (T->t_procp).pr_uid; 267*0Sstevel@tonic-gate pr_euid = xlate <psinfo_t> (T->t_procp).pr_euid; 268*0Sstevel@tonic-gate pr_gid = xlate <psinfo_t> (T->t_procp).pr_gid; 269*0Sstevel@tonic-gate pr_egid = xlate <psinfo_t> (T->t_procp).pr_egid; 270*0Sstevel@tonic-gate pr_addr = xlate <psinfo_t> (T->t_procp).pr_addr; 271*0Sstevel@tonic-gate pr_ttydev = xlate <psinfo_t> (T->t_procp).pr_ttydev; 272*0Sstevel@tonic-gate pr_start = (timestruc_t)xlate <psinfo_t> (T->t_procp).pr_start; 273*0Sstevel@tonic-gate pr_fname = xlate <psinfo_t> (T->t_procp).pr_fname; 274*0Sstevel@tonic-gate pr_psargs = xlate <psinfo_t> (T->t_procp).pr_psargs; 275*0Sstevel@tonic-gate pr_argc = xlate <psinfo_t> (T->t_procp).pr_argc; 276*0Sstevel@tonic-gate pr_argv = xlate <psinfo_t> (T->t_procp).pr_argv; 277*0Sstevel@tonic-gate pr_envp = xlate <psinfo_t> (T->t_procp).pr_envp; 278*0Sstevel@tonic-gate pr_dmodel = xlate <psinfo_t> (T->t_procp).pr_dmodel; 279*0Sstevel@tonic-gate pr_taskid = xlate <psinfo_t> (T->t_procp).pr_taskid; 280*0Sstevel@tonic-gate pr_projid = xlate <psinfo_t> (T->t_procp).pr_projid; 281*0Sstevel@tonic-gate pr_poolid = xlate <psinfo_t> (T->t_procp).pr_poolid; 282*0Sstevel@tonic-gate pr_zoneid = xlate <psinfo_t> (T->t_procp).pr_zoneid; 283*0Sstevel@tonic-gate}; 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate/* 286*0Sstevel@tonic-gate * Translate from the kernel's kthread_t structure to a proc(4) lwpsinfo_t. 287*0Sstevel@tonic-gate * We do not provide support for pr_nice, pr_oldpri, pr_cpu, or pr_pctcpu. 288*0Sstevel@tonic-gate * Also, for the moment, pr_start and pr_time are not supported, but these 289*0Sstevel@tonic-gate * could be supported by DTrace in the future using subroutines. 290*0Sstevel@tonic-gate */ 291*0Sstevel@tonic-gate#pragma D binding "1.0" translator 292*0Sstevel@tonic-gatetranslator lwpsinfo_t < kthread_t *T > { 293*0Sstevel@tonic-gate pr_flag = ((T->t_state == @TS_STOPPED@) ? (PR_STOPPED | 294*0Sstevel@tonic-gate ((!(T->t_schedflag & @TS_PSTART@)) ? PR_ISTOP : 0)) : 295*0Sstevel@tonic-gate ((T->t_proc_flag & @TP_PRVSTOP@) ? PR_STOPPED | PR_ISTOP : 0)) | 296*0Sstevel@tonic-gate ((T == T->t_procp->p_agenttp) ? PR_AGENT : 0) | 297*0Sstevel@tonic-gate ((!(T->t_proc_flag & @TP_TWAIT@)) ? PR_DETACH : 0) | 298*0Sstevel@tonic-gate ((T->t_proc_flag & @TP_DAEMON@) ? PR_DAEMON : 0) | 299*0Sstevel@tonic-gate ((T->t_procp->p_proc_flag & @P_PR_FORK@) ? PR_FORK : 0) | 300*0Sstevel@tonic-gate ((T->t_procp->p_proc_flag & @P_PR_RUNLCL@) ? PR_RLC : 0) | 301*0Sstevel@tonic-gate ((T->t_procp->p_proc_flag & @P_PR_KILLCL@) ? PR_KLC : 0) | 302*0Sstevel@tonic-gate ((T->t_procp->p_proc_flag & @P_PR_ASYNC@) ? PR_ASYNC : 0) | 303*0Sstevel@tonic-gate ((T->t_procp->p_proc_flag & @P_PR_BPTADJ@) ? PR_BPTADJ : 0) | 304*0Sstevel@tonic-gate ((T->t_procp->p_proc_flag & @P_PR_PTRACE@) ? PR_PTRACE : 0) | 305*0Sstevel@tonic-gate ((T->t_procp->p_flag & @SMSACCT@) ? PR_MSACCT : 0) | 306*0Sstevel@tonic-gate ((T->t_procp->p_flag & @SMSFORK@) ? PR_MSFORK : 0) | 307*0Sstevel@tonic-gate ((T->t_procp->p_flag & @SVFWAIT@) ? PR_VFORKP : 0) | 308*0Sstevel@tonic-gate (((T->t_procp->p_flag & @SSYS@) || 309*0Sstevel@tonic-gate (T->t_procp->p_as == &`kas)) ? PR_ISSYS : 0) | 310*0Sstevel@tonic-gate ((T == T->t_cpu->cpu_idle_thread) ? PR_IDLE : 0); 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gate pr_lwpid = T->t_tid; 313*0Sstevel@tonic-gate pr_addr = (uintptr_t)T; 314*0Sstevel@tonic-gate pr_wchan = (uintptr_t)T->t_lwpchan.lc_wchan; 315*0Sstevel@tonic-gate pr_stype = T->t_sobj_ops ? T->t_sobj_ops->sobj_type : 0; 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate pr_state = (T->t_proc_flag & @TP_PRVSTOP@) ? SSTOP : 318*0Sstevel@tonic-gate (T->t_state == @TS_SLEEP@) ? SSLEEP : 319*0Sstevel@tonic-gate (T->t_state == @TS_RUN@) ? SRUN : 320*0Sstevel@tonic-gate (T->t_state == @TS_ONPROC@) ? SONPROC : 321*0Sstevel@tonic-gate (T->t_state == @TS_ZOMB@) ? SZOMB : 322*0Sstevel@tonic-gate (T->t_state == @TS_STOPPED@) ? SSTOP : 0; 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate pr_sname = (T->t_proc_flag & @TP_PRVSTOP@) ? 'T' : 325*0Sstevel@tonic-gate (T->t_state == @TS_SLEEP@) ? 'S' : 326*0Sstevel@tonic-gate (T->t_state == @TS_RUN@) ? 'R' : 327*0Sstevel@tonic-gate (T->t_state == @TS_ONPROC@) ? 'O' : 328*0Sstevel@tonic-gate (T->t_state == @TS_ZOMB@) ? 'Z' : 329*0Sstevel@tonic-gate (T->t_state == @TS_STOPPED@) ? 'T' : '?'; 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate pr_syscall = T->t_sysnum; 332*0Sstevel@tonic-gate pr_pri = T->t_pri; 333*0Sstevel@tonic-gate pr_clname = `sclass[T->t_cid].cl_name; 334*0Sstevel@tonic-gate pr_onpro = T->t_cpu->cpu_id; 335*0Sstevel@tonic-gate pr_bindpro = T->t_bind_cpu; 336*0Sstevel@tonic-gate pr_bindpset = T->t_bind_pset; 337*0Sstevel@tonic-gate}; 338*0Sstevel@tonic-gate 339*0Sstevel@tonic-gateinline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread->t_procp); 340*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common curpsinfo 341*0Sstevel@tonic-gate#pragma D binding "1.0" curpsinfo 342*0Sstevel@tonic-gate 343*0Sstevel@tonic-gateinline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread); 344*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common curlwpsinfo 345*0Sstevel@tonic-gate#pragma D binding "1.0" curlwpsinfo 346*0Sstevel@tonic-gate 347*0Sstevel@tonic-gateinline string cwd = curthread->t_procp->p_user.u_cdir->v_path == NULL ? 348*0Sstevel@tonic-gate "<unknown>" : stringof(curthread->t_procp->p_user.u_cdir->v_path); 349*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common cwd 350*0Sstevel@tonic-gate#pragma D binding "1.0" cwd 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gateinline string root = curthread->t_procp->p_user.u_rdir == NULL ? "/" : 353*0Sstevel@tonic-gate curthread->t_procp->p_user.u_rdir->v_path == NULL ? "<unknown>" : 354*0Sstevel@tonic-gate stringof(curthread->t_procp->p_user.u_rdir->v_path); 355*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common root 356*0Sstevel@tonic-gate#pragma D binding "1.0" root 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate/* 359*0Sstevel@tonic-gate * ppid, uid and gid are used frequently enough to merit their own inlines... 360*0Sstevel@tonic-gate */ 361*0Sstevel@tonic-gateinline uid_t ppid = curpsinfo->pr_ppid; 362*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common ppid 363*0Sstevel@tonic-gate#pragma D binding "1.0" ppid 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gateinline uid_t uid = curpsinfo->pr_uid; 366*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common uid 367*0Sstevel@tonic-gate#pragma D binding "1.0" uid 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gateinline gid_t gid = curpsinfo->pr_gid; 370*0Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common gid 371*0Sstevel@tonic-gate#pragma D binding "1.0" gid 372