xref: /freebsd/cddl/lib/libdtrace/psinfo.d (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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  * Portions Copyright 2006 John Birrell jb@freebsd.org
23  *
24  * $FreeBSD$
25  */
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma D depends_on module kernel
32 
33 typedef struct psinfo {
34 	int	pr_nlwp;	/* number of threads */
35 	pid_t	pr_pid;		/* unique process id */
36 	pid_t	pr_ppid;	/* process id of parent */
37 	pid_t	pr_pgid;	/* pid of process group leader */
38 	pid_t	pr_sid;		/* session id */
39 	uid_t	pr_uid;		/* real user id */
40 	uid_t	pr_euid;	/* effective user id */
41 	gid_t	pr_gid;		/* real group id */
42 	gid_t	pr_egid;	/* effective group id */
43 	uintptr_t
44 		pr_addr;	/* address of process */
45 	string	pr_psargs;	/* process arguments */
46 	u_int	pr_arglen;	/* process argument length */
47 	u_int	pr_jailid;	/* jail id */
48 } psinfo_t;
49 
50 #pragma D binding "1.0" translator
51 translator psinfo_t < struct proc *T > {
52 	pr_nlwp = T->p_numthreads;
53 	pr_pid = T->p_pid;
54 	pr_ppid = (T->p_pptr == 0) ? 0 : T->p_pptr->p_pid;
55 	pr_pgid = (T->p_leader == 0) ? 0 : T->p_leader->p_pid;
56 	pr_sid = (T->p_pgrp == 0) ? 0 : ((T->p_pgrp->pg_session == 0) ? 0 : T->p_pgrp->pg_session->s_sid);
57 	pr_uid = T->p_ucred->cr_ruid;
58 	pr_euid = T->p_ucred->cr_uid;
59 	pr_gid = T->p_ucred->cr_rgid;
60 	pr_egid = T->p_ucred->cr_groups[0];
61 	pr_addr = 0;
62 	pr_psargs = (T->p_args == 0) ? "" :
63 	    memstr(T->p_args->ar_args, ' ', T->p_args->ar_length);
64 	pr_arglen = T->p_args->ar_length;
65 	pr_jailid = T->p_ucred->cr_prison->pr_id;
66 };
67 
68 typedef struct lwpsinfo {
69 	id_t	pr_lwpid;	/* thread ID. */
70 	int	pr_flag;	/* thread flags. */
71 	int	pr_pri;		/* thread priority. */
72 	char	pr_state;	/* numeric lwp state */
73 	char	pr_sname;	/* printable character for pr_state */
74 	short	pr_syscall;	/* system call number (if in syscall) */
75 	uintptr_t
76 		pr_addr;	/* internal address of lwp */
77 	uintptr_t
78 		pr_wchan;	/* sleep address */
79 } lwpsinfo_t;
80 
81 #pragma D binding "1.0" translator
82 translator lwpsinfo_t < struct thread *T > {
83 	pr_lwpid = T->td_tid;
84 	pr_pri = T->td_priority;
85 	pr_flag = T->td_flags;
86 	pr_state = 0; /* XXX */
87 	pr_sname = '?'; /* XXX */
88 	pr_syscall = 0; /* XXX */
89 	pr_addr = (uintptr_t)T;
90 	pr_wchan = (uintptr_t)T->td_wchan;
91 };
92 
93 inline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread->td_proc);
94 #pragma D attributes Stable/Stable/Common curpsinfo
95 #pragma D binding "1.0" curpsinfo
96 
97 inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
98 #pragma D attributes Stable/Stable/Common curlwpsinfo
99 #pragma D binding "1.0" curlwpsinfo
100