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