user.h revision 300060
1185743Ssam/*-
2185743Ssam * Copyright (c) 1982, 1986, 1989, 1991, 1993
3185743Ssam *	The Regents of the University of California.
4185743Ssam * Copyright (c) 2007 Robert N. M. Watson
5185743Ssam * All rights reserved.
6185743Ssam *
7185743Ssam * Redistribution and use in source and binary forms, with or without
8185743Ssam * modification, are permitted provided that the following conditions
9185743Ssam * are met:
10185743Ssam * 1. Redistributions of source code must retain the above copyright
11185743Ssam *    notice, this list of conditions and the following disclaimer.
12185743Ssam * 2. Redistributions in binary form must reproduce the above copyright
13185743Ssam *    notice, this list of conditions and the following disclaimer in the
14185743Ssam *    documentation and/or other materials provided with the distribution.
15185743Ssam * 4. Neither the name of the University nor the names of its contributors
16185743Ssam *    may be used to endorse or promote products derived from this software
17185743Ssam *    without specific prior written permission.
18185743Ssam *
19185743Ssam * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20185743Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21185743Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22185743Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23185743Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24185743Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25185743Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26185743Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27185743Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28185743Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29185743Ssam * SUCH DAMAGE.
30185743Ssam *
31185743Ssam *	@(#)user.h	8.2 (Berkeley) 9/23/93
32185743Ssam * $FreeBSD: stable/10/sys/sys/user.h 300060 2016-05-17 15:18:01Z pfg $
33185743Ssam */
34185743Ssam
35185743Ssam#ifndef _SYS_USER_H_
36185743Ssam#define _SYS_USER_H_
37185743Ssam
38185743Ssam#include <machine/pcb.h>
39185743Ssam#ifndef _KERNEL
40185743Ssam/* stuff that *used* to be included by user.h, or is now needed */
41185743Ssam#include <sys/errno.h>
42185743Ssam#include <sys/time.h>
43185743Ssam#include <sys/resource.h>
44185743Ssam#include <sys/ucred.h>
45185743Ssam#include <sys/uio.h>
46185743Ssam#include <sys/queue.h>
47185743Ssam#include <sys/_lock.h>
48185743Ssam#include <sys/_mutex.h>
49185743Ssam#include <sys/proc.h>
50185743Ssam#include <vm/vm.h>		/* XXX */
51185743Ssam#include <vm/vm_param.h>	/* XXX */
52185743Ssam#include <vm/pmap.h>		/* XXX */
53185743Ssam#include <vm/vm_map.h>		/* XXX */
54185743Ssam#endif /* !_KERNEL */
55185743Ssam#ifndef _SYS_RESOURCEVAR_H_
56185743Ssam#include <sys/resourcevar.h>
57185743Ssam#endif
58185743Ssam#ifndef _SYS_SIGNALVAR_H_
59185743Ssam#include <sys/signalvar.h>
60185743Ssam#endif
61185743Ssam#ifndef _SYS_SOCKET_VAR_H_
62185743Ssam#include <sys/socket.h>
63185743Ssam#endif
64185743Ssam#include <sys/caprights.h>
65185743Ssam
66185743Ssam/*
67185743Ssam * KERN_PROC subtype ops return arrays of selected proc structure entries:
68185743Ssam *
69185743Ssam * This struct includes several arrays of spare space, with different arrays
70185743Ssam * for different standard C-types.  When adding new variables to this struct,
71185743Ssam * the space for byte-aligned data should be taken from the ki_sparestring,
72185743Ssam * pointers from ki_spareptrs, word-aligned data from ki_spareints, and
73185743Ssam * doubleword-aligned data from ki_sparelongs.  Make sure the space for new
74185743Ssam * variables come from the array which matches the size and alignment of
75185743Ssam * those variables on ALL hardware platforms, and then adjust the appropriate
76185743Ssam * KI_NSPARE_* value(s) to match.
77185743Ssam *
78185743Ssam * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all
79185743Ssam * platforms after you have added new variables.  Note that if you change
80185743Ssam * the value of KINFO_PROC_SIZE, then many userland programs will stop
81185743Ssam * working until they are recompiled!
82185743Ssam *
83185743Ssam * Once you have added the new field, you will need to add code to initialize
84185743Ssam * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
85185743Ssam * function kvm_proclist in lib/libkvm/kvm_proc.c .
86185743Ssam */
87185743Ssam#define	KI_NSPARE_INT	7
88185743Ssam#define	KI_NSPARE_LONG	12
89185743Ssam#define	KI_NSPARE_PTR	6
90185743Ssam
91185743Ssam#ifndef _KERNEL
92185743Ssam#ifndef KINFO_PROC_SIZE
93185743Ssam#error "Unknown architecture"
94185743Ssam#endif
95185743Ssam#endif /* !_KERNEL */
96185743Ssam
97185743Ssam#define	WMESGLEN	8		/* size of returned wchan message */
98185743Ssam#define	LOCKNAMELEN	8		/* size of returned lock name */
99185743Ssam#define	TDNAMLEN	16		/* size of returned thread name */
100185743Ssam#define	COMMLEN		19		/* size of returned ki_comm name */
101185743Ssam#define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
102185743Ssam#define	KI_NGROUPS	16		/* number of groups in ki_groups */
103185743Ssam#define	LOGNAMELEN	17		/* size of returned ki_login */
104185743Ssam#define	LOGINCLASSLEN	17		/* size of returned ki_loginclass */
105185743Ssam
106185743Ssam#ifndef BURN_BRIDGES
107185743Ssam#define	OCOMMLEN	TDNAMLEN
108185743Ssam#define	ki_ocomm	ki_tdname
109185743Ssam#endif
110185743Ssam
111185743Ssam/* Flags for the process credential. */
112185743Ssam#define	KI_CRF_CAPABILITY_MODE	0x00000001
113185743Ssam/*
114185743Ssam * Steal a bit from ki_cr_flags to indicate that the cred had more than
115185743Ssam * KI_NGROUPS groups.
116185743Ssam */
117185743Ssam#define KI_CRF_GRP_OVERFLOW	0x80000000
118185743Ssam
119185743Ssamstruct kinfo_proc {
120185743Ssam	int	ki_structsize;		/* size of this structure */
121185743Ssam	int	ki_layout;		/* reserved: layout identifier */
122185743Ssam	struct	pargs *ki_args;		/* address of command arguments */
123185743Ssam	struct	proc *ki_paddr;		/* address of proc */
124185743Ssam	struct	user *ki_addr;		/* kernel virtual addr of u-area */
125185743Ssam	struct	vnode *ki_tracep;	/* pointer to trace file */
126185743Ssam	struct	vnode *ki_textvp;	/* pointer to executable file */
127185743Ssam	struct	filedesc *ki_fd;	/* pointer to open file info */
128185743Ssam	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
129185743Ssam	void	*ki_wchan;		/* sleep address */
130185743Ssam	pid_t	ki_pid;			/* Process identifier */
131185743Ssam	pid_t	ki_ppid;		/* parent process id */
132185743Ssam	pid_t	ki_pgid;		/* process group id */
133185743Ssam	pid_t	ki_tpgid;		/* tty process group id */
134185743Ssam	pid_t	ki_sid;			/* Process session ID */
135185743Ssam	pid_t	ki_tsid;		/* Terminal session ID */
136185743Ssam	short	ki_jobc;		/* job control counter */
137185743Ssam	short	ki_spare_short1;	/* unused (just here for alignment) */
138185743Ssam	dev_t	ki_tdev;		/* controlling tty dev */
139185743Ssam	sigset_t ki_siglist;		/* Signals arrived but not delivered */
140185743Ssam	sigset_t ki_sigmask;		/* Current signal mask */
141185743Ssam	sigset_t ki_sigignore;		/* Signals being ignored */
142185743Ssam	sigset_t ki_sigcatch;		/* Signals being caught by user */
143185743Ssam	uid_t	ki_uid;			/* effective user id */
144185743Ssam	uid_t	ki_ruid;		/* Real user id */
145185743Ssam	uid_t	ki_svuid;		/* Saved effective user id */
146185743Ssam	gid_t	ki_rgid;		/* Real group id */
147185743Ssam	gid_t	ki_svgid;		/* Saved effective group id */
148185743Ssam	short	ki_ngroups;		/* number of groups */
149185743Ssam	short	ki_spare_short2;	/* unused (just here for alignment) */
150185743Ssam	gid_t	ki_groups[KI_NGROUPS];	/* groups */
151185743Ssam	vm_size_t ki_size;		/* virtual size */
152185743Ssam	segsz_t ki_rssize;		/* current resident set size in pages */
153185743Ssam	segsz_t ki_swrss;		/* resident set size before last swap */
154185743Ssam	segsz_t ki_tsize;		/* text size (pages) XXX */
155185743Ssam	segsz_t ki_dsize;		/* data size (pages) XXX */
156185743Ssam	segsz_t ki_ssize;		/* stack size (pages) */
157185743Ssam	u_short	ki_xstat;		/* Exit status for wait & stop signal */
158185743Ssam	u_short	ki_acflag;		/* Accounting flags */
159185743Ssam	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
160185743Ssam	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
161185743Ssam	u_int	ki_slptime;	 	/* Time since last blocked */
162185743Ssam	u_int	ki_swtime;	 	/* Time swapped in or out */
163185743Ssam	u_int	ki_cow;			/* number of copy-on-write faults */
164185743Ssam	u_int64_t ki_runtime;		/* Real time in microsec */
165185743Ssam	struct	timeval ki_start;	/* starting time */
166185743Ssam	struct	timeval ki_childtime;	/* time used by process children */
167185743Ssam	long	ki_flag;		/* P_* flags */
168185743Ssam	long	ki_kiflag;		/* KI_* flags (below) */
169185743Ssam	int	ki_traceflag;		/* Kernel trace points */
170185743Ssam	char	ki_stat;		/* S* process status */
171185743Ssam	signed char ki_nice;		/* Process "nice" value */
172185743Ssam	char	ki_lock;		/* Process lock (prevent swap) count */
173185743Ssam	char	ki_rqindex;		/* Run queue index */
174185743Ssam	u_char	ki_oncpu;		/* Which cpu we are on */
175185743Ssam	u_char	ki_lastcpu;		/* Last cpu we were on */
176185743Ssam	char	ki_tdname[TDNAMLEN+1];	/* thread name */
177185743Ssam	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
178185743Ssam	char	ki_login[LOGNAMELEN+1];	/* setlogin name */
179185743Ssam	char	ki_lockname[LOCKNAMELEN+1]; /* lock name */
180185743Ssam	char	ki_comm[COMMLEN+1];	/* command name */
181185743Ssam	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
182185743Ssam	char	ki_loginclass[LOGINCLASSLEN+1]; /* login class */
183185743Ssam	/*
184185743Ssam	 * When adding new variables, take space for char-strings from the
185185743Ssam	 * front of ki_sparestrings, and ints from the end of ki_spareints.
186185743Ssam	 * That way the spare room from both arrays will remain contiguous.
187185743Ssam	 */
188185743Ssam	char	ki_sparestrings[50];	/* spare string space */
189185743Ssam	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
190185743Ssam	int	ki_flag2;		/* P2_* flags */
191185743Ssam	int	ki_fibnum;		/* Default FIB number */
192185743Ssam	u_int	ki_cr_flags;		/* Credential flags */
193185743Ssam	int	ki_jid;			/* Process jail ID */
194185743Ssam	int	ki_numthreads;		/* XXXKSE number of threads in total */
195185743Ssam	lwpid_t	ki_tid;			/* XXXKSE thread id */
196185743Ssam	struct	priority ki_pri;	/* process priority */
197185743Ssam	struct	rusage ki_rusage;	/* process rusage statistics */
198185743Ssam	/* XXX - most fields in ki_rusage_ch are not (yet) filled in */
199185743Ssam	struct	rusage ki_rusage_ch;	/* rusage of children processes */
200185743Ssam	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
201185743Ssam	void	*ki_kstack;		/* kernel virtual addr of stack */
202185743Ssam	void	*ki_udata;		/* User convenience pointer */
203185743Ssam	struct	thread *ki_tdaddr;	/* address of thread */
204185743Ssam	/*
205185743Ssam	 * When adding new variables, take space for pointers from the
206185743Ssam	 * front of ki_spareptrs, and longs from the end of ki_sparelongs.
207	 * That way the spare room from both arrays will remain contiguous.
208	 */
209	void	*ki_spareptrs[KI_NSPARE_PTR];	/* spare room for growth */
210	long	ki_sparelongs[KI_NSPARE_LONG];	/* spare room for growth */
211	long	ki_sflag;		/* PS_* flags */
212	long	ki_tdflags;		/* XXXKSE kthread flag */
213};
214void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
215/* XXX - the following two defines are temporary */
216#define	ki_childstime	ki_rusage_ch.ru_stime
217#define	ki_childutime	ki_rusage_ch.ru_utime
218
219/*
220 *  Legacy PS_ flag.  This moved to p_flag but is maintained for
221 *  compatibility.
222 */
223#define	PS_INMEM	0x00001		/* Loaded into memory. */
224
225/* ki_sessflag values */
226#define	KI_CTTY		0x00000001	/* controlling tty vnode active */
227#define	KI_SLEADER	0x00000002	/* session leader */
228#define	KI_LOCKBLOCK	0x00000004	/* proc blocked on lock ki_lockname */
229
230/*
231 * This used to be the per-process structure containing data that
232 * isn't needed in core when the process is swapped out, but now it
233 * remains only for the benefit of a.out core dumps.
234 */
235struct user {
236	struct	pstats u_stats;		/* *p_stats */
237	struct	kinfo_proc u_kproc;	/* eproc */
238};
239
240/*
241 * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor
242 * array of another process.
243 */
244#define	KF_ATTR_VALID	0x0001
245
246#define	KF_TYPE_NONE	0
247#define	KF_TYPE_VNODE	1
248#define	KF_TYPE_SOCKET	2
249#define	KF_TYPE_PIPE	3
250#define	KF_TYPE_FIFO	4
251#define	KF_TYPE_KQUEUE	5
252#define	KF_TYPE_CRYPTO	6
253#define	KF_TYPE_MQUEUE	7
254#define	KF_TYPE_SHM	8
255#define	KF_TYPE_SEM	9
256#define	KF_TYPE_PTS	10
257#define	KF_TYPE_PROCDESC	11
258#define	KF_TYPE_UNKNOWN	255
259
260#define	KF_VTYPE_VNON	0
261#define	KF_VTYPE_VREG	1
262#define	KF_VTYPE_VDIR	2
263#define	KF_VTYPE_VBLK	3
264#define	KF_VTYPE_VCHR	4
265#define	KF_VTYPE_VLNK	5
266#define	KF_VTYPE_VSOCK	6
267#define	KF_VTYPE_VFIFO	7
268#define	KF_VTYPE_VBAD	8
269#define	KF_VTYPE_UNKNOWN	255
270
271#define	KF_FD_TYPE_CWD	-1	/* Current working directory */
272#define	KF_FD_TYPE_ROOT	-2	/* Root directory */
273#define	KF_FD_TYPE_JAIL	-3	/* Jail directory */
274#define	KF_FD_TYPE_TRACE	-4	/* ptrace vnode */
275#define	KF_FD_TYPE_TEXT	-5	/* Text vnode */
276#define	KF_FD_TYPE_CTTY	-6	/* Controlling terminal */
277
278#define	KF_FLAG_READ		0x00000001
279#define	KF_FLAG_WRITE		0x00000002
280#define	KF_FLAG_APPEND		0x00000004
281#define	KF_FLAG_ASYNC		0x00000008
282#define	KF_FLAG_FSYNC		0x00000010
283#define	KF_FLAG_NONBLOCK	0x00000020
284#define	KF_FLAG_DIRECT		0x00000040
285#define	KF_FLAG_HASLOCK		0x00000080
286#define	KF_FLAG_SHLOCK		0x00000100
287#define	KF_FLAG_EXLOCK		0x00000200
288#define	KF_FLAG_NOFOLLOW	0x00000400
289#define	KF_FLAG_CREAT		0x00000800
290#define	KF_FLAG_TRUNC		0x00001000
291#define	KF_FLAG_EXCL		0x00002000
292#define	KF_FLAG_EXEC		0x00004000
293
294/*
295 * Old format.  Has variable hidden padding due to alignment.
296 * This is a compatibility hack for pre-build 7.1 packages.
297 */
298#if defined(__amd64__)
299#define	KINFO_OFILE_SIZE	1328
300#endif
301#if defined(__i386__)
302#define	KINFO_OFILE_SIZE	1324
303#endif
304
305struct kinfo_ofile {
306	int	kf_structsize;			/* Size of kinfo_file. */
307	int	kf_type;			/* Descriptor type. */
308	int	kf_fd;				/* Array index. */
309	int	kf_ref_count;			/* Reference count. */
310	int	kf_flags;			/* Flags. */
311	/* XXX Hidden alignment padding here on amd64 */
312	off_t	kf_offset;			/* Seek location. */
313	int	kf_vnode_type;			/* Vnode type. */
314	int	kf_sock_domain;			/* Socket domain. */
315	int	kf_sock_type;			/* Socket type. */
316	int	kf_sock_protocol;		/* Socket protocol. */
317	char	kf_path[PATH_MAX];	/* Path to file, if any. */
318	struct sockaddr_storage kf_sa_local;	/* Socket address. */
319	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
320};
321
322#if defined(__amd64__) || defined(__i386__)
323/*
324 * This size should never be changed. If you really need to, you must provide
325 * backward ABI compatibility by allocating a new sysctl MIB that will return
326 * the new structure. The current structure has to be returned by the current
327 * sysctl MIB. See how it is done for the kinfo_ofile structure.
328 */
329#define	KINFO_FILE_SIZE	1392
330#endif
331
332struct kinfo_file {
333	int		kf_structsize;		/* Variable size of record. */
334	int		kf_type;		/* Descriptor type. */
335	int		kf_fd;			/* Array index. */
336	int		kf_ref_count;		/* Reference count. */
337	int		kf_flags;		/* Flags. */
338	int		kf_pad0;		/* Round to 64 bit alignment. */
339	int64_t		kf_offset;		/* Seek location. */
340	int		kf_vnode_type;		/* Vnode type. */
341	int		kf_sock_domain;		/* Socket domain. */
342	int		kf_sock_type;		/* Socket type. */
343	int		kf_sock_protocol;	/* Socket protocol. */
344	struct sockaddr_storage kf_sa_local;	/* Socket address. */
345	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
346	union {
347		struct {
348			/* Address of so_pcb. */
349			uint64_t	kf_sock_pcb;
350			/* Address of inp_ppcb. */
351			uint64_t	kf_sock_inpcb;
352			/* Address of unp_conn. */
353			uint64_t	kf_sock_unpconn;
354			/* Send buffer state. */
355			uint16_t	kf_sock_snd_sb_state;
356			/* Receive buffer state. */
357			uint16_t	kf_sock_rcv_sb_state;
358			/* Round to 64 bit alignment. */
359			uint32_t	kf_sock_pad0;
360		} kf_sock;
361		struct {
362			/* Global file id. */
363			uint64_t	kf_file_fileid;
364			/* File size. */
365			uint64_t	kf_file_size;
366			/* Vnode filesystem id. */
367			uint32_t	kf_file_fsid;
368			/* File device. */
369			uint32_t	kf_file_rdev;
370			/* File mode. */
371			uint16_t	kf_file_mode;
372			/* Round to 64 bit alignment. */
373			uint16_t	kf_file_pad0;
374			uint32_t	kf_file_pad1;
375		} kf_file;
376		struct {
377			uint32_t	kf_sem_value;
378			uint16_t	kf_sem_mode;
379		} kf_sem;
380		struct {
381			uint64_t	kf_pipe_addr;
382			uint64_t	kf_pipe_peer;
383			uint32_t	kf_pipe_buffer_cnt;
384			/* Round to 64 bit alignment. */
385			uint32_t	kf_pipe_pad0[3];
386		} kf_pipe;
387		struct {
388			uint32_t	kf_pts_dev;
389			/* Round to 64 bit alignment. */
390			uint32_t	kf_pts_pad0[7];
391		} kf_pts;
392		struct {
393			pid_t		kf_pid;
394		} kf_proc;
395	} kf_un;
396	uint16_t	kf_status;		/* Status flags. */
397	uint16_t	kf_pad1;		/* Round to 32 bit alignment. */
398	int		_kf_ispare0;		/* Space for more stuff. */
399	cap_rights_t	kf_cap_rights;		/* Capability rights. */
400	uint64_t	_kf_cap_spare;		/* Space for future cap_rights_t. */
401	/* Truncated before copyout in sysctl */
402	char		kf_path[PATH_MAX];	/* Path to file, if any. */
403};
404
405/*
406 * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
407 * another process as a series of entries.
408 */
409#define	KVME_TYPE_NONE		0
410#define	KVME_TYPE_DEFAULT	1
411#define	KVME_TYPE_VNODE		2
412#define	KVME_TYPE_SWAP		3
413#define	KVME_TYPE_DEVICE	4
414#define	KVME_TYPE_PHYS		5
415#define	KVME_TYPE_DEAD		6
416#define	KVME_TYPE_SG		7
417#define	KVME_TYPE_MGTDEVICE	8
418#define	KVME_TYPE_UNKNOWN	255
419
420#define	KVME_PROT_READ		0x00000001
421#define	KVME_PROT_WRITE		0x00000002
422#define	KVME_PROT_EXEC		0x00000004
423
424#define	KVME_FLAG_COW		0x00000001
425#define	KVME_FLAG_NEEDS_COPY	0x00000002
426#define	KVME_FLAG_NOCOREDUMP	0x00000004
427#define	KVME_FLAG_SUPER		0x00000008
428#define	KVME_FLAG_GROWS_UP	0x00000010
429#define	KVME_FLAG_GROWS_DOWN	0x00000020
430
431#if defined(__amd64__)
432#define	KINFO_OVMENTRY_SIZE	1168
433#endif
434#if defined(__i386__)
435#define	KINFO_OVMENTRY_SIZE	1128
436#endif
437
438struct kinfo_ovmentry {
439	int	 kve_structsize;		/* Size of kinfo_vmmapentry. */
440	int	 kve_type;			/* Type of map entry. */
441	void	*kve_start;			/* Starting address. */
442	void	*kve_end;			/* Finishing address. */
443	int	 kve_flags;			/* Flags on map entry. */
444	int	 kve_resident;			/* Number of resident pages. */
445	int	 kve_private_resident;		/* Number of private pages. */
446	int	 kve_protection;		/* Protection bitmask. */
447	int	 kve_ref_count;			/* VM obj ref count. */
448	int	 kve_shadow_count;		/* VM obj shadow count. */
449	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
450	void	*_kve_pspare[8];		/* Space for more stuff. */
451	off_t	 kve_offset;			/* Mapping offset in object */
452	uint64_t kve_fileid;			/* inode number if vnode */
453	dev_t	 kve_fsid;			/* dev_t of vnode location */
454	int	 _kve_ispare[3];		/* Space for more stuff. */
455};
456
457#if defined(__amd64__) || defined(__i386__)
458#define	KINFO_VMENTRY_SIZE	1160
459#endif
460
461struct kinfo_vmentry {
462	int	 kve_structsize;		/* Variable size of record. */
463	int	 kve_type;			/* Type of map entry. */
464	uint64_t kve_start;			/* Starting address. */
465	uint64_t kve_end;			/* Finishing address. */
466	uint64_t kve_offset;			/* Mapping offset in object */
467	uint64_t kve_vn_fileid;			/* inode number if vnode */
468	uint32_t kve_vn_fsid;			/* dev_t of vnode location */
469	int	 kve_flags;			/* Flags on map entry. */
470	int	 kve_resident;			/* Number of resident pages. */
471	int	 kve_private_resident;		/* Number of private pages. */
472	int	 kve_protection;		/* Protection bitmask. */
473	int	 kve_ref_count;			/* VM obj ref count. */
474	int	 kve_shadow_count;		/* VM obj shadow count. */
475	int	 kve_vn_type;			/* Vnode type. */
476	uint64_t kve_vn_size;			/* File size. */
477	uint32_t kve_vn_rdev;			/* Device id if device. */
478	uint16_t kve_vn_mode;			/* File mode. */
479	uint16_t kve_status;			/* Status flags. */
480	int	 _kve_ispare[12];		/* Space for more stuff. */
481	/* Truncated before copyout in sysctl */
482	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
483};
484
485/*
486 * The "vm.objects" sysctl provides a list of all VM objects in the system
487 * via an array of these entries.
488 */
489struct kinfo_vmobject {
490	int	kvo_structsize;			/* Variable size of record. */
491	int	kvo_type;			/* Object type: KVME_TYPE_*. */
492	uint64_t kvo_size;			/* Object size in pages. */
493	uint64_t kvo_vn_fileid;			/* inode number if vnode. */
494	uint32_t kvo_vn_fsid;			/* dev_t of vnode location. */
495	int	kvo_ref_count;			/* Reference count. */
496	int	kvo_shadow_count;		/* Shadow count. */
497	int	kvo_memattr;			/* Memory attribute. */
498	uint64_t kvo_resident;			/* Number of resident pages. */
499	uint64_t kvo_active;			/* Number of active pages. */
500	uint64_t kvo_inactive;			/* Number of inactive pages. */
501	uint64_t _kvo_qspare[8];
502	uint32_t _kvo_ispare[8];
503	char	kvo_path[PATH_MAX];		/* Pathname, if any. */
504};
505
506/*
507 * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
508 * another process as a series of entries.  Each stack is represented by a
509 * series of symbol names and offsets as generated by stack_sbuf_print(9).
510 */
511#define	KKST_MAXLEN	1024
512
513#define	KKST_STATE_STACKOK	0		/* Stack is valid. */
514#define	KKST_STATE_SWAPPED	1		/* Stack swapped out. */
515#define	KKST_STATE_RUNNING	2		/* Stack ephemeral. */
516
517#if defined(__amd64__) || defined(__i386__)
518#define	KINFO_KSTACK_SIZE	1096
519#endif
520
521struct kinfo_kstack {
522	lwpid_t	 kkst_tid;			/* ID of thread. */
523	int	 kkst_state;			/* Validity of stack. */
524	char	 kkst_trace[KKST_MAXLEN];	/* String representing stack. */
525	int	 _kkst_ispare[16];		/* Space for more stuff. */
526};
527
528struct kinfo_sigtramp {
529	void	*ksigtramp_start;
530	void	*ksigtramp_end;
531	void	*ksigtramp_spare[4];
532};
533
534#ifdef _KERNEL
535/* Flags for kern_proc_out function. */
536#define KERN_PROC_NOTHREADS	0x1
537#define KERN_PROC_MASK32	0x2
538
539/* Flags for kern_proc_filedesc_out. */
540#define	KERN_FILEDESC_PACK_KINFO	0x00000001U
541
542/* Flags for kern_proc_vmmap_out. */
543#define	KERN_VMMAP_PACK_KINFO		0x00000001U
544struct sbuf;
545
546/*
547 * The kern_proc out functions are helper functions to dump process
548 * miscellaneous kinfo structures to sbuf.  The main consumers are KERN_PROC
549 * sysctls but they may also be used by other kernel subsystems.
550 *
551 * The functions manipulate the process locking state and expect the process
552 * to be locked on enter.  On return the process is unlocked.
553 */
554
555int	kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
556	int flags);
557int	kern_proc_out(struct proc *p, struct sbuf *sb, int flags);
558int	kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
559	int flags);
560
561int	vntype_to_kinfo(int vtype);
562#endif /* !_KERNEL */
563
564#endif
565