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