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