xref: /f-stack/tools/compat/include/sys/user.h (revision 1eaf0ac3)
1*1eaf0ac3Slogwang /*-
2*1eaf0ac3Slogwang  * Copyright (c) 1982, 1986, 1989, 1991, 1993
3*1eaf0ac3Slogwang  *	The Regents of the University of California.
4*1eaf0ac3Slogwang  * Copyright (c) 2007 Robert N. M. Watson
5*1eaf0ac3Slogwang  * All rights reserved.
6*1eaf0ac3Slogwang  *
7*1eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
8*1eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
9*1eaf0ac3Slogwang  * are met:
10*1eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
11*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
12*1eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
13*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
14*1eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
15*1eaf0ac3Slogwang  * 4. Neither the name of the University nor the names of its contributors
16*1eaf0ac3Slogwang  *    may be used to endorse or promote products derived from this software
17*1eaf0ac3Slogwang  *    without specific prior written permission.
18*1eaf0ac3Slogwang  *
19*1eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*1eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*1eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*1eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*1eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*1eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*1eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*1eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*1eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*1eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*1eaf0ac3Slogwang  * SUCH DAMAGE.
30*1eaf0ac3Slogwang  *
31*1eaf0ac3Slogwang  *	@(#)user.h	8.2 (Berkeley) 9/23/93
32*1eaf0ac3Slogwang  * $FreeBSD$
33*1eaf0ac3Slogwang  */
34*1eaf0ac3Slogwang 
35*1eaf0ac3Slogwang #ifndef _SYS_USER_H_
36*1eaf0ac3Slogwang #define _SYS_USER_H_
37*1eaf0ac3Slogwang 
38*1eaf0ac3Slogwang //#include <machine/pcb.h>
39*1eaf0ac3Slogwang #ifndef _KERNEL
40*1eaf0ac3Slogwang /* stuff that *used* to be included by user.h, or is now needed */
41*1eaf0ac3Slogwang #include <sys/errno.h>
42*1eaf0ac3Slogwang #include <sys/time.h>
43*1eaf0ac3Slogwang #include <sys/resource.h>
44*1eaf0ac3Slogwang #include <sys/ucred.h>
45*1eaf0ac3Slogwang #include <sys/uio.h>
46*1eaf0ac3Slogwang #include <sys/queue.h>
47*1eaf0ac3Slogwang #include <sys/_lock.h>
48*1eaf0ac3Slogwang #include <sys/_mutex.h>
49*1eaf0ac3Slogwang //#include <sys/proc.h>
50*1eaf0ac3Slogwang //#include <vm/vm.h>		/* XXX */
51*1eaf0ac3Slogwang //#include <vm/vm_param.h>	/* XXX */
52*1eaf0ac3Slogwang //#include <vm/pmap.h>		/* XXX */
53*1eaf0ac3Slogwang //#include <vm/vm_map.h>		/* XXX */
54*1eaf0ac3Slogwang #endif /* !_KERNEL */
55*1eaf0ac3Slogwang #ifndef _SYS_RESOURCEVAR_H_
56*1eaf0ac3Slogwang #include <sys/resourcevar.h>
57*1eaf0ac3Slogwang #endif
58*1eaf0ac3Slogwang //#ifndef _SYS_SIGNALVAR_H_
59*1eaf0ac3Slogwang //#include <sys/signalvar.h>
60*1eaf0ac3Slogwang //#endif
61*1eaf0ac3Slogwang #ifndef _SYS_SOCKET_VAR_H_
62*1eaf0ac3Slogwang #include <sys/socket.h>
63*1eaf0ac3Slogwang #endif
64*1eaf0ac3Slogwang #include <sys/caprights.h>
65*1eaf0ac3Slogwang #include <sys/priority.h>
66*1eaf0ac3Slogwang 
67*1eaf0ac3Slogwang /*
68*1eaf0ac3Slogwang  * KERN_PROC subtype ops return arrays of selected proc structure entries:
69*1eaf0ac3Slogwang  *
70*1eaf0ac3Slogwang  * This struct includes several arrays of spare space, with different arrays
71*1eaf0ac3Slogwang  * for different standard C-types.  When adding new variables to this struct,
72*1eaf0ac3Slogwang  * the space for byte-aligned data should be taken from the ki_sparestring,
73*1eaf0ac3Slogwang  * pointers from ki_spareptrs, word-aligned data from ki_spareints, and
74*1eaf0ac3Slogwang  * doubleword-aligned data from ki_sparelongs.  Make sure the space for new
75*1eaf0ac3Slogwang  * variables come from the array which matches the size and alignment of
76*1eaf0ac3Slogwang  * those variables on ALL hardware platforms, and then adjust the appropriate
77*1eaf0ac3Slogwang  * KI_NSPARE_* value(s) to match.
78*1eaf0ac3Slogwang  *
79*1eaf0ac3Slogwang  * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all
80*1eaf0ac3Slogwang  * platforms after you have added new variables.  Note that if you change
81*1eaf0ac3Slogwang  * the value of KINFO_PROC_SIZE, then many userland programs will stop
82*1eaf0ac3Slogwang  * working until they are recompiled!
83*1eaf0ac3Slogwang  *
84*1eaf0ac3Slogwang  * Once you have added the new field, you will need to add code to initialize
85*1eaf0ac3Slogwang  * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
86*1eaf0ac3Slogwang  * function kvm_proclist in lib/libkvm/kvm_proc.c .
87*1eaf0ac3Slogwang  */
88*1eaf0ac3Slogwang #define	KI_NSPARE_INT	4
89*1eaf0ac3Slogwang #define	KI_NSPARE_LONG	12
90*1eaf0ac3Slogwang #define	KI_NSPARE_PTR	6
91*1eaf0ac3Slogwang 
92*1eaf0ac3Slogwang //#ifndef _KERNEL
93*1eaf0ac3Slogwang //#ifndef KINFO_PROC_SIZE
94*1eaf0ac3Slogwang //#error "Unknown architecture"
95*1eaf0ac3Slogwang //#endif
96*1eaf0ac3Slogwang //#endif /* !_KERNEL */
97*1eaf0ac3Slogwang 
98*1eaf0ac3Slogwang #define	WMESGLEN	8		/* size of returned wchan message */
99*1eaf0ac3Slogwang #define	LOCKNAMELEN	8		/* size of returned lock name */
100*1eaf0ac3Slogwang #define	TDNAMLEN	16		/* size of returned thread name */
101*1eaf0ac3Slogwang #define	COMMLEN		19		/* size of returned ki_comm name */
102*1eaf0ac3Slogwang #define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
103*1eaf0ac3Slogwang #define	KI_NGROUPS	16		/* number of groups in ki_groups */
104*1eaf0ac3Slogwang #define	LOGNAMELEN	17		/* size of returned ki_login */
105*1eaf0ac3Slogwang #define	LOGINCLASSLEN	17		/* size of returned ki_loginclass */
106*1eaf0ac3Slogwang 
107*1eaf0ac3Slogwang #ifndef BURN_BRIDGES
108*1eaf0ac3Slogwang #define	OCOMMLEN	TDNAMLEN
109*1eaf0ac3Slogwang #define	ki_ocomm	ki_tdname
110*1eaf0ac3Slogwang #endif
111*1eaf0ac3Slogwang 
112*1eaf0ac3Slogwang /* Flags for the process credential. */
113*1eaf0ac3Slogwang #define	KI_CRF_CAPABILITY_MODE	0x00000001
114*1eaf0ac3Slogwang /*
115*1eaf0ac3Slogwang  * Steal a bit from ki_cr_flags to indicate that the cred had more than
116*1eaf0ac3Slogwang  * KI_NGROUPS groups.
117*1eaf0ac3Slogwang  */
118*1eaf0ac3Slogwang #define KI_CRF_GRP_OVERFLOW	0x80000000
119*1eaf0ac3Slogwang 
120*1eaf0ac3Slogwang struct kinfo_proc {
121*1eaf0ac3Slogwang 	int	ki_structsize;		/* size of this structure */
122*1eaf0ac3Slogwang 	int	ki_layout;		/* reserved: layout identifier */
123*1eaf0ac3Slogwang 	struct	pargs *ki_args;		/* address of command arguments */
124*1eaf0ac3Slogwang 	struct	proc *ki_paddr;		/* address of proc */
125*1eaf0ac3Slogwang 	struct	user *ki_addr;		/* kernel virtual addr of u-area */
126*1eaf0ac3Slogwang 	struct	vnode *ki_tracep;	/* pointer to trace file */
127*1eaf0ac3Slogwang 	struct	vnode *ki_textvp;	/* pointer to executable file */
128*1eaf0ac3Slogwang 	struct	filedesc *ki_fd;	/* pointer to open file info */
129*1eaf0ac3Slogwang 	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
130*1eaf0ac3Slogwang 	void	*ki_wchan;		/* sleep address */
131*1eaf0ac3Slogwang 	pid_t	ki_pid;			/* Process identifier */
132*1eaf0ac3Slogwang 	pid_t	ki_ppid;		/* parent process id */
133*1eaf0ac3Slogwang 	pid_t	ki_pgid;		/* process group id */
134*1eaf0ac3Slogwang 	pid_t	ki_tpgid;		/* tty process group id */
135*1eaf0ac3Slogwang 	pid_t	ki_sid;			/* Process session ID */
136*1eaf0ac3Slogwang 	pid_t	ki_tsid;		/* Terminal session ID */
137*1eaf0ac3Slogwang 	short	ki_jobc;		/* job control counter */
138*1eaf0ac3Slogwang 	short	ki_spare_short1;	/* unused (just here for alignment) */
139*1eaf0ac3Slogwang 	dev_t	ki_tdev;		/* controlling tty dev */
140*1eaf0ac3Slogwang 	sigset_t ki_siglist;		/* Signals arrived but not delivered */
141*1eaf0ac3Slogwang 	sigset_t ki_sigmask;		/* Current signal mask */
142*1eaf0ac3Slogwang 	sigset_t ki_sigignore;		/* Signals being ignored */
143*1eaf0ac3Slogwang 	sigset_t ki_sigcatch;		/* Signals being caught by user */
144*1eaf0ac3Slogwang 	uid_t	ki_uid;			/* effective user id */
145*1eaf0ac3Slogwang 	uid_t	ki_ruid;		/* Real user id */
146*1eaf0ac3Slogwang 	uid_t	ki_svuid;		/* Saved effective user id */
147*1eaf0ac3Slogwang 	gid_t	ki_rgid;		/* Real group id */
148*1eaf0ac3Slogwang 	gid_t	ki_svgid;		/* Saved effective group id */
149*1eaf0ac3Slogwang 	short	ki_ngroups;		/* number of groups */
150*1eaf0ac3Slogwang 	short	ki_spare_short2;	/* unused (just here for alignment) */
151*1eaf0ac3Slogwang 	gid_t	ki_groups[KI_NGROUPS];	/* groups */
152*1eaf0ac3Slogwang 	vm_size_t ki_size;		/* virtual size */
153*1eaf0ac3Slogwang 	segsz_t ki_rssize;		/* current resident set size in pages */
154*1eaf0ac3Slogwang 	segsz_t ki_swrss;		/* resident set size before last swap */
155*1eaf0ac3Slogwang 	segsz_t ki_tsize;		/* text size (pages) XXX */
156*1eaf0ac3Slogwang 	segsz_t ki_dsize;		/* data size (pages) XXX */
157*1eaf0ac3Slogwang 	segsz_t ki_ssize;		/* stack size (pages) */
158*1eaf0ac3Slogwang 	u_short	ki_xstat;		/* Exit status for wait & stop signal */
159*1eaf0ac3Slogwang 	u_short	ki_acflag;		/* Accounting flags */
160*1eaf0ac3Slogwang 	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
161*1eaf0ac3Slogwang 	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
162*1eaf0ac3Slogwang 	u_int	ki_slptime;	 	/* Time since last blocked */
163*1eaf0ac3Slogwang 	u_int	ki_swtime;	 	/* Time swapped in or out */
164*1eaf0ac3Slogwang 	u_int	ki_cow;			/* number of copy-on-write faults */
165*1eaf0ac3Slogwang 	u_int64_t ki_runtime;		/* Real time in microsec */
166*1eaf0ac3Slogwang 	struct	timeval ki_start;	/* starting time */
167*1eaf0ac3Slogwang 	struct	timeval ki_childtime;	/* time used by process children */
168*1eaf0ac3Slogwang 	long	ki_flag;		/* P_* flags */
169*1eaf0ac3Slogwang 	long	ki_kiflag;		/* KI_* flags (below) */
170*1eaf0ac3Slogwang 	int	ki_traceflag;		/* Kernel trace points */
171*1eaf0ac3Slogwang 	char	ki_stat;		/* S* process status */
172*1eaf0ac3Slogwang 	signed char ki_nice;		/* Process "nice" value */
173*1eaf0ac3Slogwang 	char	ki_lock;		/* Process lock (prevent swap) count */
174*1eaf0ac3Slogwang 	char	ki_rqindex;		/* Run queue index */
175*1eaf0ac3Slogwang 	u_char	ki_oncpu_old;		/* Which cpu we are on (legacy) */
176*1eaf0ac3Slogwang 	u_char	ki_lastcpu_old;		/* Last cpu we were on (legacy) */
177*1eaf0ac3Slogwang 	char	ki_tdname[TDNAMLEN+1];	/* thread name */
178*1eaf0ac3Slogwang 	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
179*1eaf0ac3Slogwang 	char	ki_login[LOGNAMELEN+1];	/* setlogin name */
180*1eaf0ac3Slogwang 	char	ki_lockname[LOCKNAMELEN+1]; /* lock name */
181*1eaf0ac3Slogwang 	char	ki_comm[COMMLEN+1];	/* command name */
182*1eaf0ac3Slogwang 	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
183*1eaf0ac3Slogwang 	char	ki_loginclass[LOGINCLASSLEN+1]; /* login class */
184*1eaf0ac3Slogwang 	/*
185*1eaf0ac3Slogwang 	 * When adding new variables, take space for char-strings from the
186*1eaf0ac3Slogwang 	 * front of ki_sparestrings, and ints from the end of ki_spareints.
187*1eaf0ac3Slogwang 	 * That way the spare room from both arrays will remain contiguous.
188*1eaf0ac3Slogwang 	 */
189*1eaf0ac3Slogwang 	char	ki_sparestrings[50];	/* spare string space */
190*1eaf0ac3Slogwang 	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
191*1eaf0ac3Slogwang 	int	ki_oncpu;		/* Which cpu we are on */
192*1eaf0ac3Slogwang 	int	ki_lastcpu;		/* Last cpu we were on */
193*1eaf0ac3Slogwang 	int	ki_tracer;		/* Pid of tracing process */
194*1eaf0ac3Slogwang 	int	ki_flag2;		/* P2_* flags */
195*1eaf0ac3Slogwang 	int	ki_fibnum;		/* Default FIB number */
196*1eaf0ac3Slogwang 	u_int	ki_cr_flags;		/* Credential flags */
197*1eaf0ac3Slogwang 	int	ki_jid;			/* Process jail ID */
198*1eaf0ac3Slogwang 	int	ki_numthreads;		/* XXXKSE number of threads in total */
199*1eaf0ac3Slogwang 	lwpid_t	ki_tid;			/* XXXKSE thread id */
200*1eaf0ac3Slogwang 	struct	priority ki_pri;	/* process priority */
201*1eaf0ac3Slogwang 	struct	rusage ki_rusage;	/* process rusage statistics */
202*1eaf0ac3Slogwang 	/* XXX - most fields in ki_rusage_ch are not (yet) filled in */
203*1eaf0ac3Slogwang 	struct	rusage ki_rusage_ch;	/* rusage of children processes */
204*1eaf0ac3Slogwang 	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
205*1eaf0ac3Slogwang 	void	*ki_kstack;		/* kernel virtual addr of stack */
206*1eaf0ac3Slogwang 	void	*ki_udata;		/* User convenience pointer */
207*1eaf0ac3Slogwang 	struct	thread *ki_tdaddr;	/* address of thread */
208*1eaf0ac3Slogwang 	/*
209*1eaf0ac3Slogwang 	 * When adding new variables, take space for pointers from the
210*1eaf0ac3Slogwang 	 * front of ki_spareptrs, and longs from the end of ki_sparelongs.
211*1eaf0ac3Slogwang 	 * That way the spare room from both arrays will remain contiguous.
212*1eaf0ac3Slogwang 	 */
213*1eaf0ac3Slogwang 	void	*ki_spareptrs[KI_NSPARE_PTR];	/* spare room for growth */
214*1eaf0ac3Slogwang 	long	ki_sparelongs[KI_NSPARE_LONG];	/* spare room for growth */
215*1eaf0ac3Slogwang 	long	ki_sflag;		/* PS_* flags */
216*1eaf0ac3Slogwang 	long	ki_tdflags;		/* XXXKSE kthread flag */
217*1eaf0ac3Slogwang };
218*1eaf0ac3Slogwang void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
219*1eaf0ac3Slogwang /* XXX - the following two defines are temporary */
220*1eaf0ac3Slogwang #define	ki_childstime	ki_rusage_ch.ru_stime
221*1eaf0ac3Slogwang #define	ki_childutime	ki_rusage_ch.ru_utime
222*1eaf0ac3Slogwang 
223*1eaf0ac3Slogwang /*
224*1eaf0ac3Slogwang  *  Legacy PS_ flag.  This moved to p_flag but is maintained for
225*1eaf0ac3Slogwang  *  compatibility.
226*1eaf0ac3Slogwang  */
227*1eaf0ac3Slogwang #define	PS_INMEM	0x00001		/* Loaded into memory. */
228*1eaf0ac3Slogwang 
229*1eaf0ac3Slogwang /* ki_sessflag values */
230*1eaf0ac3Slogwang #define	KI_CTTY		0x00000001	/* controlling tty vnode active */
231*1eaf0ac3Slogwang #define	KI_SLEADER	0x00000002	/* session leader */
232*1eaf0ac3Slogwang #define	KI_LOCKBLOCK	0x00000004	/* proc blocked on lock ki_lockname */
233*1eaf0ac3Slogwang 
234*1eaf0ac3Slogwang /*
235*1eaf0ac3Slogwang  * This used to be the per-process structure containing data that
236*1eaf0ac3Slogwang  * isn't needed in core when the process is swapped out, but now it
237*1eaf0ac3Slogwang  * remains only for the benefit of a.out core dumps.
238*1eaf0ac3Slogwang  */
239*1eaf0ac3Slogwang struct user {
240*1eaf0ac3Slogwang 	struct	pstats u_stats;		/* *p_stats */
241*1eaf0ac3Slogwang 	struct	kinfo_proc u_kproc;	/* eproc */
242*1eaf0ac3Slogwang };
243*1eaf0ac3Slogwang 
244*1eaf0ac3Slogwang /*
245*1eaf0ac3Slogwang  * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor
246*1eaf0ac3Slogwang  * array of another process.
247*1eaf0ac3Slogwang  */
248*1eaf0ac3Slogwang #define	KF_ATTR_VALID	0x0001
249*1eaf0ac3Slogwang 
250*1eaf0ac3Slogwang #define	KF_TYPE_NONE	0
251*1eaf0ac3Slogwang #define	KF_TYPE_VNODE	1
252*1eaf0ac3Slogwang #define	KF_TYPE_SOCKET	2
253*1eaf0ac3Slogwang #define	KF_TYPE_PIPE	3
254*1eaf0ac3Slogwang #define	KF_TYPE_FIFO	4
255*1eaf0ac3Slogwang #define	KF_TYPE_KQUEUE	5
256*1eaf0ac3Slogwang #define	KF_TYPE_CRYPTO	6
257*1eaf0ac3Slogwang #define	KF_TYPE_MQUEUE	7
258*1eaf0ac3Slogwang #define	KF_TYPE_SHM	8
259*1eaf0ac3Slogwang #define	KF_TYPE_SEM	9
260*1eaf0ac3Slogwang #define	KF_TYPE_PTS	10
261*1eaf0ac3Slogwang #define	KF_TYPE_PROCDESC	11
262*1eaf0ac3Slogwang #define	KF_TYPE_UNKNOWN	255
263*1eaf0ac3Slogwang 
264*1eaf0ac3Slogwang #define	KF_VTYPE_VNON	0
265*1eaf0ac3Slogwang #define	KF_VTYPE_VREG	1
266*1eaf0ac3Slogwang #define	KF_VTYPE_VDIR	2
267*1eaf0ac3Slogwang #define	KF_VTYPE_VBLK	3
268*1eaf0ac3Slogwang #define	KF_VTYPE_VCHR	4
269*1eaf0ac3Slogwang #define	KF_VTYPE_VLNK	5
270*1eaf0ac3Slogwang #define	KF_VTYPE_VSOCK	6
271*1eaf0ac3Slogwang #define	KF_VTYPE_VFIFO	7
272*1eaf0ac3Slogwang #define	KF_VTYPE_VBAD	8
273*1eaf0ac3Slogwang #define	KF_VTYPE_UNKNOWN	255
274*1eaf0ac3Slogwang 
275*1eaf0ac3Slogwang #define	KF_FD_TYPE_CWD	-1	/* Current working directory */
276*1eaf0ac3Slogwang #define	KF_FD_TYPE_ROOT	-2	/* Root directory */
277*1eaf0ac3Slogwang #define	KF_FD_TYPE_JAIL	-3	/* Jail directory */
278*1eaf0ac3Slogwang #define	KF_FD_TYPE_TRACE	-4	/* Ktrace vnode */
279*1eaf0ac3Slogwang #define	KF_FD_TYPE_TEXT	-5	/* Text vnode */
280*1eaf0ac3Slogwang #define	KF_FD_TYPE_CTTY	-6	/* Controlling terminal */
281*1eaf0ac3Slogwang 
282*1eaf0ac3Slogwang #define	KF_FLAG_READ		0x00000001
283*1eaf0ac3Slogwang #define	KF_FLAG_WRITE		0x00000002
284*1eaf0ac3Slogwang #define	KF_FLAG_APPEND		0x00000004
285*1eaf0ac3Slogwang #define	KF_FLAG_ASYNC		0x00000008
286*1eaf0ac3Slogwang #define	KF_FLAG_FSYNC		0x00000010
287*1eaf0ac3Slogwang #define	KF_FLAG_NONBLOCK	0x00000020
288*1eaf0ac3Slogwang #define	KF_FLAG_DIRECT		0x00000040
289*1eaf0ac3Slogwang #define	KF_FLAG_HASLOCK		0x00000080
290*1eaf0ac3Slogwang #define	KF_FLAG_SHLOCK		0x00000100
291*1eaf0ac3Slogwang #define	KF_FLAG_EXLOCK		0x00000200
292*1eaf0ac3Slogwang #define	KF_FLAG_NOFOLLOW	0x00000400
293*1eaf0ac3Slogwang #define	KF_FLAG_CREAT		0x00000800
294*1eaf0ac3Slogwang #define	KF_FLAG_TRUNC		0x00001000
295*1eaf0ac3Slogwang #define	KF_FLAG_EXCL		0x00002000
296*1eaf0ac3Slogwang #define	KF_FLAG_EXEC		0x00004000
297*1eaf0ac3Slogwang 
298*1eaf0ac3Slogwang /*
299*1eaf0ac3Slogwang  * Old format.  Has variable hidden padding due to alignment.
300*1eaf0ac3Slogwang  * This is a compatibility hack for pre-build 7.1 packages.
301*1eaf0ac3Slogwang  */
302*1eaf0ac3Slogwang #if defined(__amd64__)
303*1eaf0ac3Slogwang #define	KINFO_OFILE_SIZE	1328
304*1eaf0ac3Slogwang #endif
305*1eaf0ac3Slogwang #if defined(__i386__)
306*1eaf0ac3Slogwang #define	KINFO_OFILE_SIZE	1324
307*1eaf0ac3Slogwang #endif
308*1eaf0ac3Slogwang 
309*1eaf0ac3Slogwang struct kinfo_ofile {
310*1eaf0ac3Slogwang 	int	kf_structsize;			/* Size of kinfo_file. */
311*1eaf0ac3Slogwang 	int	kf_type;			/* Descriptor type. */
312*1eaf0ac3Slogwang 	int	kf_fd;				/* Array index. */
313*1eaf0ac3Slogwang 	int	kf_ref_count;			/* Reference count. */
314*1eaf0ac3Slogwang 	int	kf_flags;			/* Flags. */
315*1eaf0ac3Slogwang 	/* XXX Hidden alignment padding here on amd64 */
316*1eaf0ac3Slogwang 	off_t	kf_offset;			/* Seek location. */
317*1eaf0ac3Slogwang 	int	kf_vnode_type;			/* Vnode type. */
318*1eaf0ac3Slogwang 	int	kf_sock_domain;			/* Socket domain. */
319*1eaf0ac3Slogwang 	int	kf_sock_type;			/* Socket type. */
320*1eaf0ac3Slogwang 	int	kf_sock_protocol;		/* Socket protocol. */
321*1eaf0ac3Slogwang 	char	kf_path[PATH_MAX];	/* Path to file, if any. */
322*1eaf0ac3Slogwang 	struct sockaddr_storage kf_sa_local;	/* Socket address. */
323*1eaf0ac3Slogwang 	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
324*1eaf0ac3Slogwang };
325*1eaf0ac3Slogwang 
326*1eaf0ac3Slogwang #if defined(__amd64__) || defined(__i386__)
327*1eaf0ac3Slogwang /*
328*1eaf0ac3Slogwang  * This size should never be changed. If you really need to, you must provide
329*1eaf0ac3Slogwang  * backward ABI compatibility by allocating a new sysctl MIB that will return
330*1eaf0ac3Slogwang  * the new structure. The current structure has to be returned by the current
331*1eaf0ac3Slogwang  * sysctl MIB. See how it is done for the kinfo_ofile structure.
332*1eaf0ac3Slogwang  */
333*1eaf0ac3Slogwang #define	KINFO_FILE_SIZE	1392
334*1eaf0ac3Slogwang #endif
335*1eaf0ac3Slogwang 
336*1eaf0ac3Slogwang struct kinfo_file {
337*1eaf0ac3Slogwang 	int		kf_structsize;		/* Variable size of record. */
338*1eaf0ac3Slogwang 	int		kf_type;		/* Descriptor type. */
339*1eaf0ac3Slogwang 	int		kf_fd;			/* Array index. */
340*1eaf0ac3Slogwang 	int		kf_ref_count;		/* Reference count. */
341*1eaf0ac3Slogwang 	int		kf_flags;		/* Flags. */
342*1eaf0ac3Slogwang 	int		kf_pad0;		/* Round to 64 bit alignment. */
343*1eaf0ac3Slogwang 	int64_t		kf_offset;		/* Seek location. */
344*1eaf0ac3Slogwang 	int		kf_vnode_type;		/* Vnode type. */
345*1eaf0ac3Slogwang 	int		kf_sock_domain;		/* Socket domain. */
346*1eaf0ac3Slogwang 	int		kf_sock_type;		/* Socket type. */
347*1eaf0ac3Slogwang 	int		kf_sock_protocol;	/* Socket protocol. */
348*1eaf0ac3Slogwang 	struct sockaddr_storage kf_sa_local;	/* Socket address. */
349*1eaf0ac3Slogwang 	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
350*1eaf0ac3Slogwang 	union {
351*1eaf0ac3Slogwang 		struct {
352*1eaf0ac3Slogwang 			/* Address of so_pcb. */
353*1eaf0ac3Slogwang 			uint64_t	kf_sock_pcb;
354*1eaf0ac3Slogwang 			/* Address of inp_ppcb. */
355*1eaf0ac3Slogwang 			uint64_t	kf_sock_inpcb;
356*1eaf0ac3Slogwang 			/* Address of unp_conn. */
357*1eaf0ac3Slogwang 			uint64_t	kf_sock_unpconn;
358*1eaf0ac3Slogwang 			/* Send buffer state. */
359*1eaf0ac3Slogwang 			uint16_t	kf_sock_snd_sb_state;
360*1eaf0ac3Slogwang 			/* Receive buffer state. */
361*1eaf0ac3Slogwang 			uint16_t	kf_sock_rcv_sb_state;
362*1eaf0ac3Slogwang 			/* Round to 64 bit alignment. */
363*1eaf0ac3Slogwang 			uint32_t	kf_sock_pad0;
364*1eaf0ac3Slogwang 		} kf_sock;
365*1eaf0ac3Slogwang 		struct {
366*1eaf0ac3Slogwang 			/* Global file id. */
367*1eaf0ac3Slogwang 			uint64_t	kf_file_fileid;
368*1eaf0ac3Slogwang 			/* File size. */
369*1eaf0ac3Slogwang 			uint64_t	kf_file_size;
370*1eaf0ac3Slogwang 			/* Vnode filesystem id. */
371*1eaf0ac3Slogwang 			uint32_t	kf_file_fsid;
372*1eaf0ac3Slogwang 			/* File device. */
373*1eaf0ac3Slogwang 			uint32_t	kf_file_rdev;
374*1eaf0ac3Slogwang 			/* File mode. */
375*1eaf0ac3Slogwang 			uint16_t	kf_file_mode;
376*1eaf0ac3Slogwang 			/* Round to 64 bit alignment. */
377*1eaf0ac3Slogwang 			uint16_t	kf_file_pad0;
378*1eaf0ac3Slogwang 			uint32_t	kf_file_pad1;
379*1eaf0ac3Slogwang 		} kf_file;
380*1eaf0ac3Slogwang 		struct {
381*1eaf0ac3Slogwang 			uint32_t	kf_sem_value;
382*1eaf0ac3Slogwang 			uint16_t	kf_sem_mode;
383*1eaf0ac3Slogwang 		} kf_sem;
384*1eaf0ac3Slogwang 		struct {
385*1eaf0ac3Slogwang 			uint64_t	kf_pipe_addr;
386*1eaf0ac3Slogwang 			uint64_t	kf_pipe_peer;
387*1eaf0ac3Slogwang 			uint32_t	kf_pipe_buffer_cnt;
388*1eaf0ac3Slogwang 			/* Round to 64 bit alignment. */
389*1eaf0ac3Slogwang 			uint32_t	kf_pipe_pad0[3];
390*1eaf0ac3Slogwang 		} kf_pipe;
391*1eaf0ac3Slogwang 		struct {
392*1eaf0ac3Slogwang 			uint32_t	kf_pts_dev;
393*1eaf0ac3Slogwang 			/* Round to 64 bit alignment. */
394*1eaf0ac3Slogwang 			uint32_t	kf_pts_pad0[7];
395*1eaf0ac3Slogwang 		} kf_pts;
396*1eaf0ac3Slogwang 		struct {
397*1eaf0ac3Slogwang 			pid_t		kf_pid;
398*1eaf0ac3Slogwang 		} kf_proc;
399*1eaf0ac3Slogwang 	} kf_un;
400*1eaf0ac3Slogwang 	uint16_t	kf_status;		/* Status flags. */
401*1eaf0ac3Slogwang 	uint16_t	kf_pad1;		/* Round to 32 bit alignment. */
402*1eaf0ac3Slogwang 	int		_kf_ispare0;		/* Space for more stuff. */
403*1eaf0ac3Slogwang 	cap_rights_t	kf_cap_rights;		/* Capability rights. */
404*1eaf0ac3Slogwang 	uint64_t	_kf_cap_spare;		/* Space for future cap_rights_t. */
405*1eaf0ac3Slogwang 	/* Truncated before copyout in sysctl */
406*1eaf0ac3Slogwang 	char		kf_path[PATH_MAX];	/* Path to file, if any. */
407*1eaf0ac3Slogwang };
408*1eaf0ac3Slogwang 
409*1eaf0ac3Slogwang /*
410*1eaf0ac3Slogwang  * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
411*1eaf0ac3Slogwang  * another process as a series of entries.
412*1eaf0ac3Slogwang  */
413*1eaf0ac3Slogwang #define	KVME_TYPE_NONE		0
414*1eaf0ac3Slogwang #define	KVME_TYPE_DEFAULT	1
415*1eaf0ac3Slogwang #define	KVME_TYPE_VNODE		2
416*1eaf0ac3Slogwang #define	KVME_TYPE_SWAP		3
417*1eaf0ac3Slogwang #define	KVME_TYPE_DEVICE	4
418*1eaf0ac3Slogwang #define	KVME_TYPE_PHYS		5
419*1eaf0ac3Slogwang #define	KVME_TYPE_DEAD		6
420*1eaf0ac3Slogwang #define	KVME_TYPE_SG		7
421*1eaf0ac3Slogwang #define	KVME_TYPE_MGTDEVICE	8
422*1eaf0ac3Slogwang #define	KVME_TYPE_UNKNOWN	255
423*1eaf0ac3Slogwang 
424*1eaf0ac3Slogwang #define	KVME_PROT_READ		0x00000001
425*1eaf0ac3Slogwang #define	KVME_PROT_WRITE		0x00000002
426*1eaf0ac3Slogwang #define	KVME_PROT_EXEC		0x00000004
427*1eaf0ac3Slogwang 
428*1eaf0ac3Slogwang #define	KVME_FLAG_COW		0x00000001
429*1eaf0ac3Slogwang #define	KVME_FLAG_NEEDS_COPY	0x00000002
430*1eaf0ac3Slogwang #define	KVME_FLAG_NOCOREDUMP	0x00000004
431*1eaf0ac3Slogwang #define	KVME_FLAG_SUPER		0x00000008
432*1eaf0ac3Slogwang #define	KVME_FLAG_GROWS_UP	0x00000010
433*1eaf0ac3Slogwang #define	KVME_FLAG_GROWS_DOWN	0x00000020
434*1eaf0ac3Slogwang 
435*1eaf0ac3Slogwang #if defined(__amd64__)
436*1eaf0ac3Slogwang #define	KINFO_OVMENTRY_SIZE	1168
437*1eaf0ac3Slogwang #endif
438*1eaf0ac3Slogwang #if defined(__i386__)
439*1eaf0ac3Slogwang #define	KINFO_OVMENTRY_SIZE	1128
440*1eaf0ac3Slogwang #endif
441*1eaf0ac3Slogwang 
442*1eaf0ac3Slogwang struct kinfo_ovmentry {
443*1eaf0ac3Slogwang 	int	 kve_structsize;		/* Size of kinfo_vmmapentry. */
444*1eaf0ac3Slogwang 	int	 kve_type;			/* Type of map entry. */
445*1eaf0ac3Slogwang 	void	*kve_start;			/* Starting address. */
446*1eaf0ac3Slogwang 	void	*kve_end;			/* Finishing address. */
447*1eaf0ac3Slogwang 	int	 kve_flags;			/* Flags on map entry. */
448*1eaf0ac3Slogwang 	int	 kve_resident;			/* Number of resident pages. */
449*1eaf0ac3Slogwang 	int	 kve_private_resident;		/* Number of private pages. */
450*1eaf0ac3Slogwang 	int	 kve_protection;		/* Protection bitmask. */
451*1eaf0ac3Slogwang 	int	 kve_ref_count;			/* VM obj ref count. */
452*1eaf0ac3Slogwang 	int	 kve_shadow_count;		/* VM obj shadow count. */
453*1eaf0ac3Slogwang 	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
454*1eaf0ac3Slogwang 	void	*_kve_pspare[8];		/* Space for more stuff. */
455*1eaf0ac3Slogwang 	off_t	 kve_offset;			/* Mapping offset in object */
456*1eaf0ac3Slogwang 	uint64_t kve_fileid;			/* inode number if vnode */
457*1eaf0ac3Slogwang 	dev_t	 kve_fsid;			/* dev_t of vnode location */
458*1eaf0ac3Slogwang 	int	 _kve_ispare[3];		/* Space for more stuff. */
459*1eaf0ac3Slogwang };
460*1eaf0ac3Slogwang 
461*1eaf0ac3Slogwang #if defined(__amd64__) || defined(__i386__)
462*1eaf0ac3Slogwang #define	KINFO_VMENTRY_SIZE	1160
463*1eaf0ac3Slogwang #endif
464*1eaf0ac3Slogwang 
465*1eaf0ac3Slogwang struct kinfo_vmentry {
466*1eaf0ac3Slogwang 	int	 kve_structsize;		/* Variable size of record. */
467*1eaf0ac3Slogwang 	int	 kve_type;			/* Type of map entry. */
468*1eaf0ac3Slogwang 	uint64_t kve_start;			/* Starting address. */
469*1eaf0ac3Slogwang 	uint64_t kve_end;			/* Finishing address. */
470*1eaf0ac3Slogwang 	uint64_t kve_offset;			/* Mapping offset in object */
471*1eaf0ac3Slogwang 	uint64_t kve_vn_fileid;			/* inode number if vnode */
472*1eaf0ac3Slogwang 	uint32_t kve_vn_fsid;			/* dev_t of vnode location */
473*1eaf0ac3Slogwang 	int	 kve_flags;			/* Flags on map entry. */
474*1eaf0ac3Slogwang 	int	 kve_resident;			/* Number of resident pages. */
475*1eaf0ac3Slogwang 	int	 kve_private_resident;		/* Number of private pages. */
476*1eaf0ac3Slogwang 	int	 kve_protection;		/* Protection bitmask. */
477*1eaf0ac3Slogwang 	int	 kve_ref_count;			/* VM obj ref count. */
478*1eaf0ac3Slogwang 	int	 kve_shadow_count;		/* VM obj shadow count. */
479*1eaf0ac3Slogwang 	int	 kve_vn_type;			/* Vnode type. */
480*1eaf0ac3Slogwang 	uint64_t kve_vn_size;			/* File size. */
481*1eaf0ac3Slogwang 	uint32_t kve_vn_rdev;			/* Device id if device. */
482*1eaf0ac3Slogwang 	uint16_t kve_vn_mode;			/* File mode. */
483*1eaf0ac3Slogwang 	uint16_t kve_status;			/* Status flags. */
484*1eaf0ac3Slogwang 	int	 _kve_ispare[12];		/* Space for more stuff. */
485*1eaf0ac3Slogwang 	/* Truncated before copyout in sysctl */
486*1eaf0ac3Slogwang 	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
487*1eaf0ac3Slogwang };
488*1eaf0ac3Slogwang 
489*1eaf0ac3Slogwang /*
490*1eaf0ac3Slogwang  * The "vm.objects" sysctl provides a list of all VM objects in the system
491*1eaf0ac3Slogwang  * via an array of these entries.
492*1eaf0ac3Slogwang  */
493*1eaf0ac3Slogwang struct kinfo_vmobject {
494*1eaf0ac3Slogwang 	int	kvo_structsize;			/* Variable size of record. */
495*1eaf0ac3Slogwang 	int	kvo_type;			/* Object type: KVME_TYPE_*. */
496*1eaf0ac3Slogwang 	uint64_t kvo_size;			/* Object size in pages. */
497*1eaf0ac3Slogwang 	uint64_t kvo_vn_fileid;			/* inode number if vnode. */
498*1eaf0ac3Slogwang 	uint32_t kvo_vn_fsid;			/* dev_t of vnode location. */
499*1eaf0ac3Slogwang 	int	kvo_ref_count;			/* Reference count. */
500*1eaf0ac3Slogwang 	int	kvo_shadow_count;		/* Shadow count. */
501*1eaf0ac3Slogwang 	int	kvo_memattr;			/* Memory attribute. */
502*1eaf0ac3Slogwang 	uint64_t kvo_resident;			/* Number of resident pages. */
503*1eaf0ac3Slogwang 	uint64_t kvo_active;			/* Number of active pages. */
504*1eaf0ac3Slogwang 	uint64_t kvo_inactive;			/* Number of inactive pages. */
505*1eaf0ac3Slogwang 	uint64_t _kvo_qspare[8];
506*1eaf0ac3Slogwang 	uint32_t _kvo_ispare[8];
507*1eaf0ac3Slogwang 	char	kvo_path[PATH_MAX];		/* Pathname, if any. */
508*1eaf0ac3Slogwang };
509*1eaf0ac3Slogwang 
510*1eaf0ac3Slogwang /*
511*1eaf0ac3Slogwang  * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
512*1eaf0ac3Slogwang  * another process as a series of entries.  Each stack is represented by a
513*1eaf0ac3Slogwang  * series of symbol names and offsets as generated by stack_sbuf_print(9).
514*1eaf0ac3Slogwang  */
515*1eaf0ac3Slogwang #define	KKST_MAXLEN	1024
516*1eaf0ac3Slogwang 
517*1eaf0ac3Slogwang #define	KKST_STATE_STACKOK	0		/* Stack is valid. */
518*1eaf0ac3Slogwang #define	KKST_STATE_SWAPPED	1		/* Stack swapped out. */
519*1eaf0ac3Slogwang #define	KKST_STATE_RUNNING	2		/* Stack ephemeral. */
520*1eaf0ac3Slogwang 
521*1eaf0ac3Slogwang #if defined(__amd64__) || defined(__i386__)
522*1eaf0ac3Slogwang #define	KINFO_KSTACK_SIZE	1096
523*1eaf0ac3Slogwang #endif
524*1eaf0ac3Slogwang 
525*1eaf0ac3Slogwang struct kinfo_kstack {
526*1eaf0ac3Slogwang 	lwpid_t	 kkst_tid;			/* ID of thread. */
527*1eaf0ac3Slogwang 	int	 kkst_state;			/* Validity of stack. */
528*1eaf0ac3Slogwang 	char	 kkst_trace[KKST_MAXLEN];	/* String representing stack. */
529*1eaf0ac3Slogwang 	int	 _kkst_ispare[16];		/* Space for more stuff. */
530*1eaf0ac3Slogwang };
531*1eaf0ac3Slogwang 
532*1eaf0ac3Slogwang struct kinfo_sigtramp {
533*1eaf0ac3Slogwang 	void	*ksigtramp_start;
534*1eaf0ac3Slogwang 	void	*ksigtramp_end;
535*1eaf0ac3Slogwang 	void	*ksigtramp_spare[4];
536*1eaf0ac3Slogwang };
537*1eaf0ac3Slogwang 
538*1eaf0ac3Slogwang #ifdef _KERNEL
539*1eaf0ac3Slogwang /* Flags for kern_proc_out function. */
540*1eaf0ac3Slogwang #define KERN_PROC_NOTHREADS	0x1
541*1eaf0ac3Slogwang #define KERN_PROC_MASK32	0x2
542*1eaf0ac3Slogwang 
543*1eaf0ac3Slogwang /* Flags for kern_proc_filedesc_out. */
544*1eaf0ac3Slogwang #define	KERN_FILEDESC_PACK_KINFO	0x00000001U
545*1eaf0ac3Slogwang 
546*1eaf0ac3Slogwang /* Flags for kern_proc_vmmap_out. */
547*1eaf0ac3Slogwang #define	KERN_VMMAP_PACK_KINFO		0x00000001U
548*1eaf0ac3Slogwang struct sbuf;
549*1eaf0ac3Slogwang 
550*1eaf0ac3Slogwang /*
551*1eaf0ac3Slogwang  * The kern_proc out functions are helper functions to dump process
552*1eaf0ac3Slogwang  * miscellaneous kinfo structures to sbuf.  The main consumers are KERN_PROC
553*1eaf0ac3Slogwang  * sysctls but they may also be used by other kernel subsystems.
554*1eaf0ac3Slogwang  *
555*1eaf0ac3Slogwang  * The functions manipulate the process locking state and expect the process
556*1eaf0ac3Slogwang  * to be locked on enter.  On return the process is unlocked.
557*1eaf0ac3Slogwang  */
558*1eaf0ac3Slogwang 
559*1eaf0ac3Slogwang int	kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
560*1eaf0ac3Slogwang 	int flags);
561*1eaf0ac3Slogwang int	kern_proc_cwd_out(struct proc *p, struct sbuf *sb, ssize_t maxlen);
562*1eaf0ac3Slogwang int	kern_proc_out(struct proc *p, struct sbuf *sb, int flags);
563*1eaf0ac3Slogwang int	kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
564*1eaf0ac3Slogwang 	int flags);
565*1eaf0ac3Slogwang 
566*1eaf0ac3Slogwang int	vntype_to_kinfo(int vtype);
567*1eaf0ac3Slogwang #endif /* !_KERNEL */
568*1eaf0ac3Slogwang 
569*1eaf0ac3Slogwang #endif
570