user.h revision 224199
1139825Simp/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1991, 1993
3174167Srwatson *	The Regents of the University of California.
4174167Srwatson * Copyright (c) 2007 Robert N. M. Watson
5174167Srwatson * All rights reserved.
61541Srgrimes *
71541Srgrimes * Redistribution and use in source and binary forms, with or without
81541Srgrimes * modification, are permitted provided that the following conditions
91541Srgrimes * are met:
101541Srgrimes * 1. Redistributions of source code must retain the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer.
121541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
131541Srgrimes *    notice, this list of conditions and the following disclaimer in the
141541Srgrimes *    documentation and/or other materials provided with the distribution.
151541Srgrimes * 4. Neither the name of the University nor the names of its contributors
161541Srgrimes *    may be used to endorse or promote products derived from this software
171541Srgrimes *    without specific prior written permission.
181541Srgrimes *
191541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291541Srgrimes * SUCH DAMAGE.
301541Srgrimes *
311541Srgrimes *	@(#)user.h	8.2 (Berkeley) 9/23/93
3250477Speter * $FreeBSD: head/sys/sys/user.h 224199 2011-07-18 20:06:15Z bz $
331541Srgrimes */
341541Srgrimes
352165Spaul#ifndef _SYS_USER_H_
362165Spaul#define _SYS_USER_H_
372165Spaul
381541Srgrimes#include <machine/pcb.h>
3955205Speter#ifndef _KERNEL
401541Srgrimes/* stuff that *used* to be included by user.h, or is now needed */
4118207Sbde#include <sys/errno.h>
421541Srgrimes#include <sys/time.h>
431541Srgrimes#include <sys/resource.h>
441541Srgrimes#include <sys/ucred.h>
451541Srgrimes#include <sys/uio.h>
4692047Sdd#include <sys/queue.h>
4781202Sjhb#include <sys/_lock.h>
4876166Smarkm#include <sys/_mutex.h>
4911913Sphk#include <sys/proc.h>
5012685Speter#include <vm/vm.h>		/* XXX */
5112685Speter#include <vm/vm_param.h>	/* XXX */
5212685Speter#include <vm/pmap.h>		/* XXX */
5312685Speter#include <vm/vm_map.h>		/* XXX */
5455205Speter#endif /* !_KERNEL */
5534924Sbde#ifndef _SYS_RESOURCEVAR_H_
561541Srgrimes#include <sys/resourcevar.h>
5734924Sbde#endif
5834924Sbde#ifndef _SYS_SIGNALVAR_H_
591541Srgrimes#include <sys/signalvar.h>
6034924Sbde#endif
61174167Srwatson#ifndef _SYS_SOCKET_VAR_H_
62174167Srwatson#include <sys/socket.h>
63174167Srwatson#endif
641541Srgrimes
651541Srgrimes/*
6669896Smckusick * KERN_PROC subtype ops return arrays of selected proc structure entries:
6769896Smckusick *
68147188Sgad * This struct includes several arrays of spare space, with different arrays
69147188Sgad * for different standard C-types.  When adding new variables to this struct,
70147188Sgad * the space for byte-aligned data should be taken from the ki_sparestring,
71147188Sgad * pointers from ki_spareptrs, word-aligned data from ki_spareints, and
72147188Sgad * doubleword-aligned data from ki_sparelongs.  Make sure the space for new
73147188Sgad * variables come from the array which matches the size and alignment of
74147188Sgad * those variables on ALL hardware platforms, and then adjust the appropriate
75147188Sgad * KI_NSPARE_* value(s) to match.
76130825Sgad *
77147188Sgad * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all
78147188Sgad * platforms after you have added new variables.  Note that if you change
79147188Sgad * the value of KINFO_PROC_SIZE, then many userland programs will stop
80147188Sgad * working until they are recompiled!
81147188Sgad *
82147188Sgad * Once you have added the new field, you will need to add code to initialize
83147188Sgad * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
84147188Sgad * function kvm_proclist in lib/libkvm/kvm_proc.c .
8511865Sphk */
86193255Srwatson#define	KI_NSPARE_INT	9
87147188Sgad#define	KI_NSPARE_LONG	12
88213536Semaste#define	KI_NSPARE_PTR	6
89130825Sgad
90207152Skib#ifndef _KERNEL
91130825Sgad#ifndef KINFO_PROC_SIZE
92130825Sgad#error "Unknown architecture"
93130825Sgad#endif
94207152Skib#endif /* !_KERNEL */
95130825Sgad
9669896Smckusick#define	WMESGLEN	8		/* size of returned wchan message */
97104387Sjhb#define	LOCKNAMELEN	8		/* size of returned lock name */
98224199Sbz#define	TDNAMLEN	16		/* size of returned thread name */
9981759Speter#define	COMMLEN		19		/* size of returned ki_comm name */
100130726Sgad#define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
101195843Sbrooks#define KI_NGROUPS	16		/* number of groups in ki_groups */
10281759Speter#define	LOGNAMELEN	17		/* size of returned ki_login */
103219307Strasz#define	LOGINCLASSLEN	17		/* size of returned ki_loginclass */
10469896Smckusick
105224199Sbz#ifndef BURN_BRIDGES
106224199Sbz#define	OCOMMLEN	TDNAMLEN
107224199Sbz#define	ki_ocomm	ki_tdname
108224199Sbz#endif
109224199Sbz
110219129Srwatson/* Flags for the process credential. */
111219129Srwatson#define	KI_CRF_CAPABILITY_MODE	0x00000001
112195843Sbrooks/*
113219129Srwatson * Steal a bit from ki_cr_flags to indicate that the cred had more than
114219129Srwatson * KI_NGROUPS groups.
115195843Sbrooks */
116195843Sbrooks#define KI_CRF_GRP_OVERFLOW	0x80000000
117195843Sbrooks
11811865Sphkstruct kinfo_proc {
11969896Smckusick	int	ki_structsize;		/* size of this structure */
12072415Sphk	int	ki_layout;		/* reserved: layout identifier */
12169896Smckusick	struct	pargs *ki_args;		/* address of command arguments */
12269896Smckusick	struct	proc *ki_paddr;		/* address of proc */
12369896Smckusick	struct	user *ki_addr;		/* kernel virtual addr of u-area */
12469896Smckusick	struct	vnode *ki_tracep;	/* pointer to trace file */
12569896Smckusick	struct	vnode *ki_textvp;	/* pointer to executable file */
12669896Smckusick	struct	filedesc *ki_fd;	/* pointer to open file info */
12769896Smckusick	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
12869896Smckusick	void	*ki_wchan;		/* sleep address */
12969896Smckusick	pid_t	ki_pid;			/* Process identifier */
13069896Smckusick	pid_t	ki_ppid;		/* parent process id */
13169896Smckusick	pid_t	ki_pgid;		/* process group id */
13269896Smckusick	pid_t	ki_tpgid;		/* tty process group id */
13369896Smckusick	pid_t	ki_sid;			/* Process session ID */
13469896Smckusick	pid_t	ki_tsid;		/* Terminal session ID */
13569896Smckusick	short	ki_jobc;		/* job control counter */
136130726Sgad	short	ki_spare_short1;	/* unused (just here for alignment) */
137130640Sphk	dev_t	ki_tdev;		/* controlling tty dev */
13869896Smckusick	sigset_t ki_siglist;		/* Signals arrived but not delivered */
13969896Smckusick	sigset_t ki_sigmask;		/* Current signal mask */
14069896Smckusick	sigset_t ki_sigignore;		/* Signals being ignored */
14169896Smckusick	sigset_t ki_sigcatch;		/* Signals being caught by user */
14269896Smckusick	uid_t	ki_uid;			/* effective user id */
14369896Smckusick	uid_t	ki_ruid;		/* Real user id */
14469896Smckusick	uid_t	ki_svuid;		/* Saved effective user id */
14569896Smckusick	gid_t	ki_rgid;		/* Real group id */
14669896Smckusick	gid_t	ki_svgid;		/* Saved effective group id */
14769896Smckusick	short	ki_ngroups;		/* number of groups */
148130726Sgad	short	ki_spare_short2;	/* unused (just here for alignment) */
149195843Sbrooks	gid_t 	ki_groups[KI_NGROUPS];	/* groups */
15069896Smckusick	vm_size_t ki_size;		/* virtual size */
15169896Smckusick	segsz_t ki_rssize;		/* current resident set size in pages */
15269896Smckusick	segsz_t ki_swrss;		/* resident set size before last swap */
15369896Smckusick	segsz_t ki_tsize;		/* text size (pages) XXX */
15469896Smckusick	segsz_t ki_dsize;		/* data size (pages) XXX */
15569896Smckusick	segsz_t ki_ssize;		/* stack size (pages) */
15669896Smckusick	u_short	ki_xstat;		/* Exit status for wait & stop signal */
15769896Smckusick	u_short	ki_acflag;		/* Accounting flags */
15869896Smckusick	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
15969896Smckusick	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
16069896Smckusick	u_int	ki_slptime;	 	/* Time since last blocked */
16169896Smckusick	u_int	ki_swtime;	 	/* Time swapped in or out */
162147188Sgad	int	ki_spareint1;	 	/* unused (just here for alignment) */
16369896Smckusick	u_int64_t ki_runtime;		/* Real time in microsec */
16469896Smckusick	struct	timeval ki_start;	/* starting time */
16569896Smckusick	struct	timeval ki_childtime;	/* time used by process children */
16669896Smckusick	long	ki_flag;		/* P_* flags */
16769896Smckusick	long	ki_kiflag;		/* KI_* flags (below) */
16869896Smckusick	int	ki_traceflag;		/* Kernel trace points */
16969896Smckusick	char	ki_stat;		/* S* process status */
170124829Sgrehan	signed char ki_nice;		/* Process "nice" value */
17169896Smckusick	char	ki_lock;		/* Process lock (prevent swap) count */
17269896Smckusick	char	ki_rqindex;		/* Run queue index */
17369896Smckusick	u_char	ki_oncpu;		/* Which cpu we are on */
17469896Smckusick	u_char	ki_lastcpu;		/* Last cpu we were on */
175224199Sbz	char	ki_tdname[TDNAMLEN+1];	/* thread name */
17669896Smckusick	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
17781759Speter	char	ki_login[LOGNAMELEN+1];	/* setlogin name */
178104387Sjhb	char	ki_lockname[LOCKNAMELEN+1]; /* lock name */
17981759Speter	char	ki_comm[COMMLEN+1];	/* command name */
180130726Sgad	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
181219307Strasz	char	ki_loginclass[LOGINCLASSLEN+1]; /* login class */
182147188Sgad	/*
183147188Sgad	 * When adding new variables, take space for char-strings from the
184147188Sgad	 * front of ki_sparestrings, and ints from the end of ki_spareints.
185147188Sgad	 * That way the spare room from both arrays will remain contiguous.
186147188Sgad	 */
187219307Strasz	char	ki_sparestrings[50];	/* spare string space */
188147188Sgad	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
189193255Srwatson	u_int	ki_cr_flags;		/* Credential flags */
190147188Sgad	int	ki_jid;			/* Process jail ID */
191147188Sgad	int	ki_numthreads;		/* XXXKSE number of threads in total */
192147188Sgad	lwpid_t	ki_tid;			/* XXXKSE thread id */
193147188Sgad	struct	priority ki_pri;	/* process priority */
19469896Smckusick	struct	rusage ki_rusage;	/* process rusage statistics */
195147188Sgad	/* XXX - most fields in ki_rusage_ch are not (yet) filled in */
196147188Sgad	struct	rusage ki_rusage_ch;	/* rusage of children processes */
19783366Sjulian	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
19883366Sjulian	void	*ki_kstack;		/* kernel virtual addr of stack */
199132014Salfred	void	*ki_udata;		/* User convenience pointer */
200213536Semaste	struct	thread *ki_tdaddr;	/* address of thread */
201147188Sgad	/*
202147188Sgad	 * When adding new variables, take space for pointers from the
203147188Sgad	 * front of ki_spareptrs, and longs from the end of ki_sparelongs.
204147188Sgad	 * That way the spare room from both arrays will remain contiguous.
205147188Sgad	 */
206147188Sgad	void	*ki_spareptrs[KI_NSPARE_PTR];	/* spare room for growth */
207147188Sgad	long	ki_sparelongs[KI_NSPARE_LONG];	/* spare room for growth */
208147188Sgad	long	ki_sflag;		/* PS_* flags */
209147188Sgad	long	ki_tdflags;		/* XXXKSE kthread flag */
21011865Sphk};
21192719Salfredvoid fill_kinfo_proc(struct proc *, struct kinfo_proc *);
212147188Sgad/* XXX - the following two defines are temporary */
213147188Sgad#define	ki_childstime	ki_rusage_ch.ru_stime
214147188Sgad#define	ki_childutime	ki_rusage_ch.ru_utime
21511865Sphk
216172207Sjeff/*
217172207Sjeff *  Legacy PS_ flag.  This moved to p_flag but is maintained for
218172207Sjeff *  compatibility.
219172207Sjeff */
220172207Sjeff#define	PS_INMEM	0x00001		/* Loaded into memory. */
221172207Sjeff
22269896Smckusick/* ki_sessflag values */
22369896Smckusick#define	KI_CTTY		0x00000001	/* controlling tty vnode active */
22469896Smckusick#define	KI_SLEADER	0x00000002	/* session leader */
225104387Sjhb#define	KI_LOCKBLOCK	0x00000004	/* proc blocked on lock ki_lockname */
22611865Sphk
22711865Sphk/*
228137920Sdas * This used to be the per-process structure containing data that
229137920Sdas * isn't needed in core when the process is swapped out, but now it
230137920Sdas * remains only for the benefit of a.out core dumps.
2311541Srgrimes */
23283421Sobrienstruct user {
23383366Sjulian	struct	pstats u_stats;		/* *p_stats */
23483366Sjulian	struct	kinfo_proc u_kproc;	/* eproc */
2351541Srgrimes};
2361541Srgrimes
237174167Srwatson/*
238176124Smarcus * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor
239174167Srwatson * array of another process.
240174167Srwatson */
241221807Sstas#define	KF_ATTR_VALID	0x0001
242221807Sstas
243174167Srwatson#define	KF_TYPE_NONE	0
244174167Srwatson#define	KF_TYPE_VNODE	1
245174167Srwatson#define	KF_TYPE_SOCKET	2
246174167Srwatson#define	KF_TYPE_PIPE	3
247174167Srwatson#define	KF_TYPE_FIFO	4
248174167Srwatson#define	KF_TYPE_KQUEUE	5
249174167Srwatson#define	KF_TYPE_CRYPTO	6
250174167Srwatson#define	KF_TYPE_MQUEUE	7
251175514Srwatson#define	KF_TYPE_SHM	8
252180059Sjhb#define	KF_TYPE_SEM	9
253181905Sed#define	KF_TYPE_PTS	10
254174167Srwatson#define	KF_TYPE_UNKNOWN	255
255174167Srwatson
256174167Srwatson#define	KF_VTYPE_VNON	0
257174167Srwatson#define	KF_VTYPE_VREG	1
258174167Srwatson#define	KF_VTYPE_VDIR	2
259174167Srwatson#define	KF_VTYPE_VBLK	3
260174167Srwatson#define	KF_VTYPE_VCHR	4
261174167Srwatson#define	KF_VTYPE_VLNK	5
262174167Srwatson#define	KF_VTYPE_VSOCK	6
263174167Srwatson#define	KF_VTYPE_VFIFO	7
264174167Srwatson#define	KF_VTYPE_VBAD	8
265174167Srwatson#define	KF_VTYPE_UNKNOWN	255
266174167Srwatson
267176124Smarcus#define	KF_FD_TYPE_CWD	-1	/* Current working directory */
268176124Smarcus#define	KF_FD_TYPE_ROOT	-2	/* Root directory */
269176124Smarcus#define	KF_FD_TYPE_JAIL	-3	/* Jail directory */
270221807Sstas#define	KF_FD_TYPE_TRACE	-4	/* ptrace vnode */
271221807Sstas#define	KF_FD_TYPE_TEXT	-5	/* Text vnode */
272221807Sstas#define	KF_FD_TYPE_CTTY	-6	/* Controlling terminal */
273176124Smarcus
274174167Srwatson#define	KF_FLAG_READ		0x00000001
275174167Srwatson#define	KF_FLAG_WRITE		0x00000002
276174167Srwatson#define	KF_FLAG_APPEND		0x00000004
277174167Srwatson#define	KF_FLAG_ASYNC		0x00000008
278174167Srwatson#define	KF_FLAG_FSYNC		0x00000010
279174167Srwatson#define	KF_FLAG_NONBLOCK	0x00000020
280174167Srwatson#define	KF_FLAG_DIRECT		0x00000040
281174167Srwatson#define	KF_FLAG_HASLOCK		0x00000080
282221807Sstas#define	KF_FLAG_SHLOCK		0x00000100
283221807Sstas#define	KF_FLAG_EXLOCK		0x00000200
284221807Sstas#define	KF_FLAG_NOFOLLOW	0x00000400
285221807Sstas#define	KF_FLAG_CREAT		0x00000800
286221807Sstas#define	KF_FLAG_TRUNC		0x00001000
287221807Sstas#define	KF_FLAG_EXCL		0x00002000
288221807Sstas#define	KF_FLAG_EXEC		0x00004000
289174167Srwatson
290185548Speter/*
291185548Speter * Old format.  Has variable hidden padding due to alignment.
292185548Speter * This is a compatability hack for pre-build 7.1 packages.
293185548Speter */
294185548Speter#if defined(__amd64__)
295185548Speter#define	KINFO_OFILE_SIZE	1328
296185548Speter#endif
297185548Speter#if defined(__i386__)
298185548Speter#define	KINFO_OFILE_SIZE	1324
299185548Speter#endif
300185548Speter
301185548Speterstruct kinfo_ofile {
302174167Srwatson	int	kf_structsize;			/* Size of kinfo_file. */
303174167Srwatson	int	kf_type;			/* Descriptor type. */
304174167Srwatson	int	kf_fd;				/* Array index. */
305174167Srwatson	int	kf_ref_count;			/* Reference count. */
306174167Srwatson	int	kf_flags;			/* Flags. */
307185548Speter	/* XXX Hidden alignment padding here on amd64 */
308174167Srwatson	off_t	kf_offset;			/* Seek location. */
309174167Srwatson	int	kf_vnode_type;			/* Vnode type. */
310174167Srwatson	int	kf_sock_domain;			/* Socket domain. */
311174167Srwatson	int	kf_sock_type;			/* Socket type. */
312174167Srwatson	int	kf_sock_protocol;		/* Socket protocol. */
313185548Speter	char	kf_path[PATH_MAX];	/* Path to file, if any. */
314174167Srwatson	struct sockaddr_storage kf_sa_local;	/* Socket address. */
315174167Srwatson	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
316174167Srwatson};
317174167Srwatson
318185548Speter#if defined(__amd64__) || defined(__i386__)
319185548Speter#define	KINFO_FILE_SIZE	1392
320185548Speter#endif
321185548Speter
322185548Speterstruct kinfo_file {
323221807Sstas	int		kf_structsize;		/* Variable size of record. */
324221807Sstas	int		kf_type;		/* Descriptor type. */
325221807Sstas	int		kf_fd;			/* Array index. */
326221807Sstas	int		kf_ref_count;		/* Reference count. */
327221807Sstas	int		kf_flags;		/* Flags. */
328221807Sstas	int		kf_pad0;		/* Round to 64 bit alignment. */
329221807Sstas	int64_t		kf_offset;		/* Seek location. */
330221807Sstas	int		kf_vnode_type;		/* Vnode type. */
331221807Sstas	int		kf_sock_domain;		/* Socket domain. */
332221807Sstas	int		kf_sock_type;		/* Socket type. */
333221807Sstas	int		kf_sock_protocol;	/* Socket protocol. */
334185548Speter	struct sockaddr_storage kf_sa_local;	/* Socket address. */
335185548Speter	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
336221807Sstas	union {
337221807Sstas		struct {
338221807Sstas			/* Address of so_pcb. */
339221807Sstas			uint64_t	kf_sock_pcb;
340221807Sstas			/* Address of inp_ppcb. */
341221807Sstas			uint64_t	kf_sock_inpcb;
342221807Sstas			/* Address of unp_conn. */
343221807Sstas			uint64_t	kf_sock_unpconn;
344221807Sstas			/* Send buffer state. */
345221807Sstas			uint16_t	kf_sock_snd_sb_state;
346221807Sstas			/* Receive buffer state. */
347221807Sstas			uint16_t	kf_sock_rcv_sb_state;
348221807Sstas			/* Round to 64 bit alignment. */
349221807Sstas			uint32_t	kf_sock_pad0;
350221807Sstas		} kf_sock;
351221807Sstas		struct {
352221807Sstas			/* Global file id. */
353221807Sstas			uint64_t	kf_file_fileid;
354221807Sstas			/* File size. */
355221807Sstas			uint64_t	kf_file_size;
356221807Sstas			/* Vnode filesystem id. */
357221807Sstas			uint32_t	kf_file_fsid;
358221807Sstas			/* File device. */
359221807Sstas			uint32_t	kf_file_rdev;
360221807Sstas			/* File mode. */
361221807Sstas			uint16_t	kf_file_mode;
362221807Sstas			/* Round to 64 bit alignment. */
363221807Sstas			uint16_t	kf_file_pad0;
364221807Sstas			uint32_t	kf_file_pad1;
365221807Sstas		} kf_file;
366221807Sstas		struct {
367221807Sstas			uint64_t	kf_pipe_addr;
368221807Sstas			uint64_t	kf_pipe_peer;
369221807Sstas			uint32_t	kf_pipe_buffer_cnt;
370221807Sstas			/* Round to 64 bit alignment. */
371221807Sstas			uint32_t	kf_pipe_pad0[3];
372221807Sstas		} kf_pipe;
373221807Sstas		struct {
374221807Sstas			uint32_t	kf_pts_dev;
375221807Sstas			/* Round to 64 bit alignment. */
376221807Sstas			uint32_t	kf_pts_pad0[7];
377221807Sstas		} kf_pts;
378221807Sstas	} kf_un;
379221807Sstas	uint16_t	kf_status;		/* Status flags. */
380221807Sstas	uint16_t	kf_pad1;		/* Round to 32 bit alignment. */
381221807Sstas	int		_kf_ispare[7];		/* Space for more stuff. */
382185548Speter	/* Truncated before copyout in sysctl */
383221807Sstas	char		kf_path[PATH_MAX];	/* Path to file, if any. */
384185548Speter};
385185548Speter
386174167Srwatson/*
387174167Srwatson * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
388174167Srwatson * another process as a series of entries.
389174167Srwatson */
390174167Srwatson#define	KVME_TYPE_NONE		0
391174167Srwatson#define	KVME_TYPE_DEFAULT	1
392174167Srwatson#define	KVME_TYPE_VNODE		2
393174167Srwatson#define	KVME_TYPE_SWAP		3
394174167Srwatson#define	KVME_TYPE_DEVICE	4
395174167Srwatson#define	KVME_TYPE_PHYS		5
396174167Srwatson#define	KVME_TYPE_DEAD		6
397195840Sjhb#define	KVME_TYPE_SG		7
398174167Srwatson#define	KVME_TYPE_UNKNOWN	255
399174167Srwatson
400174167Srwatson#define	KVME_PROT_READ		0x00000001
401174167Srwatson#define	KVME_PROT_WRITE		0x00000002
402174167Srwatson#define	KVME_PROT_EXEC		0x00000004
403174167Srwatson
404174167Srwatson#define	KVME_FLAG_COW		0x00000001
405174167Srwatson#define	KVME_FLAG_NEEDS_COPY	0x00000002
406208587Sattilio#define	KVME_FLAG_NOCOREDUMP	0x00000004
407174167Srwatson
408185548Speter#if defined(__amd64__)
409185548Speter#define	KINFO_OVMENTRY_SIZE	1168
410185548Speter#endif
411185548Speter#if defined(__i386__)
412185548Speter#define	KINFO_OVMENTRY_SIZE	1128
413185548Speter#endif
414185548Speter
415185548Speterstruct kinfo_ovmentry {
416174167Srwatson	int	 kve_structsize;		/* Size of kinfo_vmmapentry. */
417174167Srwatson	int	 kve_type;			/* Type of map entry. */
418185548Speter	void	*kve_start;			/* Starting address. */
419185548Speter	void	*kve_end;			/* Finishing address. */
420174167Srwatson	int	 kve_flags;			/* Flags on map entry. */
421174167Srwatson	int	 kve_resident;			/* Number of resident pages. */
422174167Srwatson	int	 kve_private_resident;		/* Number of private pages. */
423174167Srwatson	int	 kve_protection;		/* Protection bitmask. */
424174167Srwatson	int	 kve_ref_count;			/* VM obj ref count. */
425174167Srwatson	int	 kve_shadow_count;		/* VM obj shadow count. */
426174167Srwatson	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
427174167Srwatson	void	*_kve_pspare[8];		/* Space for more stuff. */
428184492Speter	off_t	 kve_offset;			/* Mapping offset in object */
429185548Speter	uint64_t kve_fileid;			/* inode number if vnode */
430184492Speter	dev_t	 kve_fsid;			/* dev_t of vnode location */
431184492Speter	int	 _kve_ispare[3];		/* Space for more stuff. */
432174167Srwatson};
433174167Srwatson
434185548Speter#if defined(__amd64__) || defined(__i386__)
435185548Speter#define	KINFO_VMENTRY_SIZE	1160
436185548Speter#endif
437185548Speter
438185548Speterstruct kinfo_vmentry {
439185548Speter	int	 kve_structsize;		/* Variable size of record. */
440185548Speter	int	 kve_type;			/* Type of map entry. */
441185548Speter	uint64_t kve_start;			/* Starting address. */
442185548Speter	uint64_t kve_end;			/* Finishing address. */
443185548Speter	uint64_t kve_offset;			/* Mapping offset in object */
444221807Sstas	uint64_t kve_vn_fileid;			/* inode number if vnode */
445221807Sstas	uint32_t kve_vn_fsid;			/* dev_t of vnode location */
446185548Speter	int	 kve_flags;			/* Flags on map entry. */
447185548Speter	int	 kve_resident;			/* Number of resident pages. */
448185548Speter	int	 kve_private_resident;		/* Number of private pages. */
449185548Speter	int	 kve_protection;		/* Protection bitmask. */
450185548Speter	int	 kve_ref_count;			/* VM obj ref count. */
451185548Speter	int	 kve_shadow_count;		/* VM obj shadow count. */
452221807Sstas	int	 kve_vn_type;			/* Vnode type. */
453221807Sstas	uint64_t kve_vn_size;			/* File size. */
454221807Sstas	uint32_t kve_vn_rdev;			/* Device id if device. */
455221807Sstas	uint16_t kve_vn_mode;			/* File mode. */
456221807Sstas	uint16_t kve_status;			/* Status flags. */
457221807Sstas	int	 _kve_ispare[12];		/* Space for more stuff. */
458185548Speter	/* Truncated before copyout in sysctl */
459185548Speter	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
460185548Speter};
461185548Speter
462174197Srwatson/*
463174197Srwatson * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
464174197Srwatson * another process as a series of entries.  Each stack is represented by a
465174197Srwatson * series of symbol names and offsets as generated by stack_sbuf_print(9).
466174197Srwatson */
467174197Srwatson#define	KKST_MAXLEN	1024
468174197Srwatson
469174197Srwatson#define	KKST_STATE_STACKOK	0		/* Stack is valid. */
470174197Srwatson#define	KKST_STATE_SWAPPED	1		/* Stack swapped out. */
471174197Srwatson#define	KKST_STATE_RUNNING	2		/* Stack ephemeral. */
472174197Srwatson
473185548Speter#if defined(__amd64__) || defined(__i386__)
474185548Speter#define	KINFO_KSTACK_SIZE	1096
475185548Speter#endif
476185548Speter
477174197Srwatsonstruct kinfo_kstack {
478174197Srwatson	lwpid_t	 kkst_tid;			/* ID of thread. */
479174197Srwatson	int	 kkst_state;			/* Validity of stack. */
480174197Srwatson	char	 kkst_trace[KKST_MAXLEN];	/* String representing stack. */
481185548Speter	int	 _kkst_ispare[16];		/* Space for more stuff. */
482174197Srwatson};
483174197Srwatson
484221807Sstas#ifdef _KERNEL
485221807Sstasint	vntype_to_kinfo(int vtype);
486221807Sstas#endif /* !_KERNEL */
487221807Sstas
48837689Sdfr#endif
489