1179189Sjb/*
2179189Sjb * CDDL HEADER START
3179189Sjb *
4179189Sjb * The contents of this file are subject to the terms of the
5179189Sjb * Common Development and Distribution License, Version 1.0 only
6179189Sjb * (the "License").  You may not use this file except in compliance
7179189Sjb * with the License.
8179189Sjb *
9179189Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10179189Sjb * or http://www.opensolaris.org/os/licensing.
11179189Sjb * See the License for the specific language governing permissions
12179189Sjb * and limitations under the License.
13179189Sjb *
14179189Sjb * When distributing Covered Code, include this CDDL HEADER in each
15179189Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16179189Sjb * If applicable, add the following below this CDDL HEADER, with the
17179189Sjb * fields enclosed by brackets "[]" replaced with your own identifying
18179189Sjb * information: Portions Copyright [yyyy] [name of copyright owner]
19179189Sjb *
20179189Sjb * CDDL HEADER END
21179189Sjb *
22179189Sjb * Portions Copyright 2006 John Birrell jb@freebsd.org
23179189Sjb *
24179189Sjb * $FreeBSD$
25179189Sjb */
26179189Sjb/*
27179189Sjb * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28179189Sjb * Use is subject to license terms.
29179189Sjb */
30179189Sjb
31179189Sjbtypedef struct psinfo {
32179189Sjb	int	pr_nlwp;	/* number of threads */
33179189Sjb	pid_t	pr_pid;		/* unique process id */
34179189Sjb	pid_t	pr_ppid;	/* process id of parent */
35179189Sjb	pid_t	pr_pgid;	/* pid of process group leader */
36179189Sjb	pid_t	pr_sid;		/* session id */
37179189Sjb	uid_t	pr_uid;		/* real user id */
38179189Sjb	uid_t	pr_euid;	/* effective user id */
39179189Sjb	gid_t	pr_gid;		/* real group id */
40179189Sjb	gid_t	pr_egid;	/* effective group id */
41179189Sjb	uintptr_t
42179189Sjb		pr_addr;	/* address of process */
43179189Sjb	string	pr_psargs;	/* process arguments */
44179189Sjb	u_int	pr_arglen;	/* process argument length */
45179189Sjb} psinfo_t;
46179189Sjb
47179189Sjb#pragma D binding "1.0" translator
48179189Sjbtranslator psinfo_t < struct proc *T > {
49179189Sjb	pr_nlwp = T->p_numthreads;
50179189Sjb	pr_pid = T->p_pid;
51179189Sjb	pr_ppid = (T->p_pptr == 0) ? 0 : T->p_pptr->p_pid;
52179189Sjb	pr_pgid = (T->p_leader == 0) ? 0 : T->p_leader->p_pid;
53179189Sjb	pr_sid = (T->p_pgrp == 0) ? 0 : ((T->p_pgrp->pg_session == 0) ? 0 : T->p_pgrp->pg_session->s_sid);
54179189Sjb	pr_uid = T->p_ucred->cr_ruid;
55179189Sjb	pr_euid = T->p_ucred->cr_uid;
56179189Sjb	pr_gid = T->p_ucred->cr_rgid;
57179189Sjb	pr_egid = T->p_ucred->cr_groups[0];
58179189Sjb	pr_addr = 0;
59179189Sjb	pr_psargs = stringof(T->p_args->ar_args);
60179189Sjb	pr_arglen = T->p_args->ar_length;
61179189Sjb};
62179189Sjb
63179189Sjbtypedef struct lwpsinfo {
64179189Sjb	id_t	pr_lwpid;	/* thread ID. */
65179189Sjb	int	pr_flag;	/* thread flags. */
66179189Sjb	int	pr_pri;		/* thread priority. */
67179189Sjb	char	pr_state;	/* numeric lwp state */
68179189Sjb	char	pr_sname;	/* printable character for pr_state */
69179189Sjb	short	pr_syscall;	/* system call number (if in syscall) */
70179189Sjb	uintptr_t
71179189Sjb		pr_addr;	/* internal address of lwp */
72179189Sjb	uintptr_t
73179189Sjb		pr_wchan;	/* sleep address */
74179189Sjb} lwpsinfo_t;
75179189Sjb
76179189Sjb#pragma D binding "1.0" translator
77179189Sjbtranslator lwpsinfo_t < struct thread *T > {
78179189Sjb	pr_lwpid = T->td_tid;
79179189Sjb	pr_pri = T->td_priority;
80179189Sjb	pr_flag = T->td_flags;
81179189Sjb	pr_state = 0; /* XXX */
82179189Sjb	pr_sname = '?'; /* XXX */
83179189Sjb	pr_syscall = 0; /* XXX */
84179189Sjb	pr_addr = (uintptr_t)T;
85179189Sjb	pr_wchan = (uintptr_t)T->td_wchan;
86179189Sjb};
87179189Sjb
88179189Sjbinline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread->td_proc);
89179189Sjb#pragma D attributes Stable/Stable/Common curpsinfo
90179189Sjb#pragma D binding "1.0" curpsinfo
91179189Sjb
92179189Sjbinline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
93179189Sjb#pragma D attributes Stable/Stable/Common curlwpsinfo
94179189Sjb#pragma D binding "1.0" curlwpsinfo
95179189Sjb
96