xref: /illumos-gate/usr/src/lib/libdtrace/common/procfs.d.in (revision 68ac2337c38c8af06edcf32a72e42de36ec72a9d)
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 2006 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
36/*
37 * The following miscellaneous constants are used by the proc(4) translators
38 * defined below.  These are assigned the latest values from the system .h's.
39 */
40inline char SSLEEP = @SSLEEP@;
41#pragma D binding "1.0" SSLEEP
42inline char SRUN = @SRUN@;
43#pragma D binding "1.0" SRUN
44inline char SZOMB = @SZOMB@;
45#pragma D binding "1.0" SZOMB
46inline char SSTOP = @SSTOP@;
47#pragma D binding "1.0" SSTOP
48inline char SIDL = @SIDL@;
49#pragma D binding "1.0" SIDL
50inline char SONPROC = @SONPROC@;
51#pragma D binding "1.0" SONPROC
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};
251
252/*
253 * Translate from the kernel's kthread_t structure to a proc(4) psinfo_t
254 * struct.  Lacking a facility to define one translator only in terms of
255 * another, we explicitly define each member by using the proc_t-to-psinfo_t
256 * translator, above; any members added to that translator should also be
257 * added here.  (The only exception to this is pr_start, which -- due to it
258 * being a structure -- cannot be defined in terms of a translator at all.)
259 */
260#pragma D binding "1.0" translator
261translator psinfo_t < kthread_t *T > {
262	pr_nlwp = xlate <psinfo_t> (T->t_procp).pr_nlwp;
263	pr_pid = xlate <psinfo_t> (T->t_procp).pr_pid;
264	pr_ppid = xlate <psinfo_t> (T->t_procp).pr_ppid;
265	pr_pgid = xlate <psinfo_t> (T->t_procp).pr_pgid;
266	pr_sid = xlate <psinfo_t> (T->t_procp).pr_sid;
267	pr_uid = xlate <psinfo_t> (T->t_procp).pr_uid;
268	pr_euid = xlate <psinfo_t> (T->t_procp).pr_euid;
269	pr_gid = xlate <psinfo_t> (T->t_procp).pr_gid;
270	pr_egid = xlate <psinfo_t> (T->t_procp).pr_egid;
271	pr_addr = xlate <psinfo_t> (T->t_procp).pr_addr;
272	pr_ttydev = xlate <psinfo_t> (T->t_procp).pr_ttydev;
273	pr_start = (timestruc_t)xlate <psinfo_t> (T->t_procp).pr_start;
274	pr_fname = xlate <psinfo_t> (T->t_procp).pr_fname;
275	pr_psargs = xlate <psinfo_t> (T->t_procp).pr_psargs;
276	pr_argc = xlate <psinfo_t> (T->t_procp).pr_argc;
277	pr_argv = xlate <psinfo_t> (T->t_procp).pr_argv;
278	pr_envp = xlate <psinfo_t> (T->t_procp).pr_envp;
279	pr_dmodel = xlate <psinfo_t> (T->t_procp).pr_dmodel;
280	pr_taskid = xlate <psinfo_t> (T->t_procp).pr_taskid;
281	pr_projid = xlate <psinfo_t> (T->t_procp).pr_projid;
282	pr_poolid = xlate <psinfo_t> (T->t_procp).pr_poolid;
283	pr_zoneid = xlate <psinfo_t> (T->t_procp).pr_zoneid;
284};
285
286/*
287 * Translate from the kernel's kthread_t structure to a proc(4) lwpsinfo_t.
288 * We do not provide support for pr_nice, pr_oldpri, pr_cpu, or pr_pctcpu.
289 * Also, for the moment, pr_start and pr_time are not supported, but these
290 * could be supported by DTrace in the future using subroutines.
291 */
292#pragma D binding "1.0" translator
293translator lwpsinfo_t < kthread_t *T > {
294	pr_flag = ((T->t_state == @TS_STOPPED@) ? (PR_STOPPED |
295	    ((!(T->t_schedflag & @TS_PSTART@)) ? PR_ISTOP : 0)) :
296	    ((T->t_proc_flag & @TP_PRVSTOP@) ? PR_STOPPED | PR_ISTOP : 0)) |
297	    ((T == T->t_procp->p_agenttp) ? PR_AGENT : 0) |
298	    ((!(T->t_proc_flag & @TP_TWAIT@)) ? PR_DETACH : 0) |
299	    ((T->t_proc_flag & @TP_DAEMON@) ? PR_DAEMON : 0) |
300	    ((T->t_procp->p_pidflag & @CLDNOSIGCHLD@) ? PR_NOSIGCHLD : 0) |
301	    ((T->t_procp->p_pidflag & @CLDWAITPID@) ? PR_WAITPID : 0) |
302	    ((T->t_procp->p_proc_flag & @P_PR_FORK@) ? PR_FORK : 0) |
303	    ((T->t_procp->p_proc_flag & @P_PR_RUNLCL@) ? PR_RLC : 0) |
304	    ((T->t_procp->p_proc_flag & @P_PR_KILLCL@) ? PR_KLC : 0) |
305	    ((T->t_procp->p_proc_flag & @P_PR_ASYNC@) ? PR_ASYNC : 0) |
306	    ((T->t_procp->p_proc_flag & @P_PR_BPTADJ@) ? PR_BPTADJ : 0) |
307	    ((T->t_procp->p_proc_flag & @P_PR_PTRACE@) ? PR_PTRACE : 0) |
308	    ((T->t_procp->p_flag & @SMSACCT@) ? PR_MSACCT : 0) |
309	    ((T->t_procp->p_flag & @SMSFORK@) ? PR_MSFORK : 0) |
310	    ((T->t_procp->p_flag & @SVFWAIT@) ? PR_VFORKP : 0) |
311	    (((T->t_procp->p_flag & @SSYS@) ||
312	    (T->t_procp->p_as == &`kas)) ? PR_ISSYS : 0) |
313	    ((T == T->t_cpu->cpu_idle_thread) ? PR_IDLE : 0);
314
315	pr_lwpid = T->t_tid;
316	pr_addr = (uintptr_t)T;
317	pr_wchan = (uintptr_t)T->t_lwpchan.lc_wchan;
318	pr_stype = T->t_sobj_ops ? T->t_sobj_ops->sobj_type : 0;
319
320	pr_state = (T->t_proc_flag & @TP_PRVSTOP@) ? SSTOP :
321	    (T->t_state == @TS_SLEEP@) ? SSLEEP :
322	    (T->t_state == @TS_RUN@) ? SRUN :
323	    (T->t_state == @TS_ONPROC@) ? SONPROC :
324	    (T->t_state == @TS_ZOMB@) ? SZOMB :
325	    (T->t_state == @TS_STOPPED@) ? SSTOP : 0;
326
327	pr_sname = (T->t_proc_flag & @TP_PRVSTOP@) ? 'T' :
328	    (T->t_state == @TS_SLEEP@) ? 'S' :
329	    (T->t_state == @TS_RUN@) ? 'R' :
330	    (T->t_state == @TS_ONPROC@) ? 'O' :
331	    (T->t_state == @TS_ZOMB@) ? 'Z' :
332	    (T->t_state == @TS_STOPPED@) ? 'T' : '?';
333
334	pr_syscall = T->t_sysnum;
335	pr_pri = T->t_pri;
336	pr_clname = `sclass[T->t_cid].cl_name;
337	pr_onpro = T->t_cpu->cpu_id;
338	pr_bindpro = T->t_bind_cpu;
339	pr_bindpset = T->t_bind_pset;
340	pr_lgrp = T->t_lpl->lpl_lgrpid;
341};
342
343inline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread->t_procp);
344#pragma D attributes Stable/Stable/Common curpsinfo
345#pragma D binding "1.0" curpsinfo
346
347inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
348#pragma D attributes Stable/Stable/Common curlwpsinfo
349#pragma D binding "1.0" curlwpsinfo
350
351inline string cwd = curthread->t_procp->p_user.u_cdir->v_path == NULL ?
352    "<unknown>" : stringof(curthread->t_procp->p_user.u_cdir->v_path);
353#pragma D attributes Stable/Stable/Common cwd
354#pragma D binding "1.0" cwd
355
356inline string root = curthread->t_procp->p_user.u_rdir == NULL ? "/" :
357    curthread->t_procp->p_user.u_rdir->v_path == NULL ? "<unknown>" :
358    stringof(curthread->t_procp->p_user.u_rdir->v_path);
359#pragma D attributes Stable/Stable/Common root
360#pragma D binding "1.0" root
361