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: stable/10/sys/sys/user.h 310121 2016-12-15 16:52:17Z vangyzen $
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
64255219Spjd#include <sys/caprights.h>
651541Srgrimes
661541Srgrimes/*
6769896Smckusick * KERN_PROC subtype ops return arrays of selected proc structure entries:
6869896Smckusick *
69147188Sgad * This struct includes several arrays of spare space, with different arrays
70147188Sgad * for different standard C-types.  When adding new variables to this struct,
71147188Sgad * the space for byte-aligned data should be taken from the ki_sparestring,
72147188Sgad * pointers from ki_spareptrs, word-aligned data from ki_spareints, and
73147188Sgad * doubleword-aligned data from ki_sparelongs.  Make sure the space for new
74147188Sgad * variables come from the array which matches the size and alignment of
75147188Sgad * those variables on ALL hardware platforms, and then adjust the appropriate
76147188Sgad * KI_NSPARE_* value(s) to match.
77130825Sgad *
78147188Sgad * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all
79147188Sgad * platforms after you have added new variables.  Note that if you change
80147188Sgad * the value of KINFO_PROC_SIZE, then many userland programs will stop
81147188Sgad * working until they are recompiled!
82147188Sgad *
83147188Sgad * Once you have added the new field, you will need to add code to initialize
84147188Sgad * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
85147188Sgad * function kvm_proclist in lib/libkvm/kvm_proc.c .
8611865Sphk */
87255708Sjhb#define	KI_NSPARE_INT	7
88147188Sgad#define	KI_NSPARE_LONG	12
89213536Semaste#define	KI_NSPARE_PTR	6
90130825Sgad
91207152Skib#ifndef _KERNEL
92130825Sgad#ifndef KINFO_PROC_SIZE
93130825Sgad#error "Unknown architecture"
94130825Sgad#endif
95207152Skib#endif /* !_KERNEL */
96130825Sgad
9769896Smckusick#define	WMESGLEN	8		/* size of returned wchan message */
98104387Sjhb#define	LOCKNAMELEN	8		/* size of returned lock name */
99224199Sbz#define	TDNAMLEN	16		/* size of returned thread name */
10081759Speter#define	COMMLEN		19		/* size of returned ki_comm name */
101130726Sgad#define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
102239505Sobrien#define	KI_NGROUPS	16		/* number of groups in ki_groups */
10381759Speter#define	LOGNAMELEN	17		/* size of returned ki_login */
104219307Strasz#define	LOGINCLASSLEN	17		/* size of returned ki_loginclass */
10569896Smckusick
106224199Sbz#ifndef BURN_BRIDGES
107224199Sbz#define	OCOMMLEN	TDNAMLEN
108224199Sbz#define	ki_ocomm	ki_tdname
109224199Sbz#endif
110224199Sbz
111219129Srwatson/* Flags for the process credential. */
112219129Srwatson#define	KI_CRF_CAPABILITY_MODE	0x00000001
113195843Sbrooks/*
114219129Srwatson * Steal a bit from ki_cr_flags to indicate that the cred had more than
115219129Srwatson * KI_NGROUPS groups.
116195843Sbrooks */
117195843Sbrooks#define KI_CRF_GRP_OVERFLOW	0x80000000
118195843Sbrooks
11911865Sphkstruct kinfo_proc {
12069896Smckusick	int	ki_structsize;		/* size of this structure */
12172415Sphk	int	ki_layout;		/* reserved: layout identifier */
12269896Smckusick	struct	pargs *ki_args;		/* address of command arguments */
12369896Smckusick	struct	proc *ki_paddr;		/* address of proc */
12469896Smckusick	struct	user *ki_addr;		/* kernel virtual addr of u-area */
12569896Smckusick	struct	vnode *ki_tracep;	/* pointer to trace file */
12669896Smckusick	struct	vnode *ki_textvp;	/* pointer to executable file */
12769896Smckusick	struct	filedesc *ki_fd;	/* pointer to open file info */
12869896Smckusick	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
12969896Smckusick	void	*ki_wchan;		/* sleep address */
13069896Smckusick	pid_t	ki_pid;			/* Process identifier */
13169896Smckusick	pid_t	ki_ppid;		/* parent process id */
13269896Smckusick	pid_t	ki_pgid;		/* process group id */
13369896Smckusick	pid_t	ki_tpgid;		/* tty process group id */
13469896Smckusick	pid_t	ki_sid;			/* Process session ID */
13569896Smckusick	pid_t	ki_tsid;		/* Terminal session ID */
13669896Smckusick	short	ki_jobc;		/* job control counter */
137130726Sgad	short	ki_spare_short1;	/* unused (just here for alignment) */
138130640Sphk	dev_t	ki_tdev;		/* controlling tty dev */
13969896Smckusick	sigset_t ki_siglist;		/* Signals arrived but not delivered */
14069896Smckusick	sigset_t ki_sigmask;		/* Current signal mask */
14169896Smckusick	sigset_t ki_sigignore;		/* Signals being ignored */
14269896Smckusick	sigset_t ki_sigcatch;		/* Signals being caught by user */
14369896Smckusick	uid_t	ki_uid;			/* effective user id */
14469896Smckusick	uid_t	ki_ruid;		/* Real user id */
14569896Smckusick	uid_t	ki_svuid;		/* Saved effective user id */
14669896Smckusick	gid_t	ki_rgid;		/* Real group id */
14769896Smckusick	gid_t	ki_svgid;		/* Saved effective group id */
14869896Smckusick	short	ki_ngroups;		/* number of groups */
149130726Sgad	short	ki_spare_short2;	/* unused (just here for alignment) */
150239506Sobrien	gid_t	ki_groups[KI_NGROUPS];	/* groups */
15169896Smckusick	vm_size_t ki_size;		/* virtual size */
15269896Smckusick	segsz_t ki_rssize;		/* current resident set size in pages */
15369896Smckusick	segsz_t ki_swrss;		/* resident set size before last swap */
15469896Smckusick	segsz_t ki_tsize;		/* text size (pages) XXX */
15569896Smckusick	segsz_t ki_dsize;		/* data size (pages) XXX */
15669896Smckusick	segsz_t ki_ssize;		/* stack size (pages) */
15769896Smckusick	u_short	ki_xstat;		/* Exit status for wait & stop signal */
15869896Smckusick	u_short	ki_acflag;		/* Accounting flags */
15969896Smckusick	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
16069896Smckusick	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
16169896Smckusick	u_int	ki_slptime;	 	/* Time since last blocked */
16269896Smckusick	u_int	ki_swtime;	 	/* Time swapped in or out */
163235850Skib	u_int	ki_cow;			/* number of copy-on-write faults */
16469896Smckusick	u_int64_t ki_runtime;		/* Real time in microsec */
16569896Smckusick	struct	timeval ki_start;	/* starting time */
16669896Smckusick	struct	timeval ki_childtime;	/* time used by process children */
16769896Smckusick	long	ki_flag;		/* P_* flags */
16869896Smckusick	long	ki_kiflag;		/* KI_* flags (below) */
16969896Smckusick	int	ki_traceflag;		/* Kernel trace points */
17069896Smckusick	char	ki_stat;		/* S* process status */
171124829Sgrehan	signed char ki_nice;		/* Process "nice" value */
17269896Smckusick	char	ki_lock;		/* Process lock (prevent swap) count */
17369896Smckusick	char	ki_rqindex;		/* Run queue index */
17469896Smckusick	u_char	ki_oncpu;		/* Which cpu we are on */
17569896Smckusick	u_char	ki_lastcpu;		/* Last cpu we were on */
176224199Sbz	char	ki_tdname[TDNAMLEN+1];	/* thread name */
17769896Smckusick	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
17881759Speter	char	ki_login[LOGNAMELEN+1];	/* setlogin name */
179104387Sjhb	char	ki_lockname[LOCKNAMELEN+1]; /* lock name */
18081759Speter	char	ki_comm[COMMLEN+1];	/* command name */
181130726Sgad	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
182219307Strasz	char	ki_loginclass[LOGINCLASSLEN+1]; /* login class */
183310121Svangyzen	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];	/* more thread name */
184147188Sgad	/*
185147188Sgad	 * When adding new variables, take space for char-strings from the
186147188Sgad	 * front of ki_sparestrings, and ints from the end of ki_spareints.
187147188Sgad	 * That way the spare room from both arrays will remain contiguous.
188147188Sgad	 */
189310121Svangyzen	char	ki_sparestrings[46];	/* spare string space */
190147188Sgad	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
191255708Sjhb	int	ki_flag2;		/* P2_* flags */
192254943Swill	int	ki_fibnum;		/* Default FIB number */
193193255Srwatson	u_int	ki_cr_flags;		/* Credential flags */
194147188Sgad	int	ki_jid;			/* Process jail ID */
195147188Sgad	int	ki_numthreads;		/* XXXKSE number of threads in total */
196147188Sgad	lwpid_t	ki_tid;			/* XXXKSE thread id */
197147188Sgad	struct	priority ki_pri;	/* process priority */
19869896Smckusick	struct	rusage ki_rusage;	/* process rusage statistics */
199147188Sgad	/* XXX - most fields in ki_rusage_ch are not (yet) filled in */
200147188Sgad	struct	rusage ki_rusage_ch;	/* rusage of children processes */
20183366Sjulian	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
20283366Sjulian	void	*ki_kstack;		/* kernel virtual addr of stack */
203132014Salfred	void	*ki_udata;		/* User convenience pointer */
204213536Semaste	struct	thread *ki_tdaddr;	/* address of thread */
205147188Sgad	/*
206147188Sgad	 * When adding new variables, take space for pointers from the
207147188Sgad	 * front of ki_spareptrs, and longs from the end of ki_sparelongs.
208147188Sgad	 * That way the spare room from both arrays will remain contiguous.
209147188Sgad	 */
210147188Sgad	void	*ki_spareptrs[KI_NSPARE_PTR];	/* spare room for growth */
211147188Sgad	long	ki_sparelongs[KI_NSPARE_LONG];	/* spare room for growth */
212147188Sgad	long	ki_sflag;		/* PS_* flags */
213147188Sgad	long	ki_tdflags;		/* XXXKSE kthread flag */
21411865Sphk};
21592719Salfredvoid fill_kinfo_proc(struct proc *, struct kinfo_proc *);
216147188Sgad/* XXX - the following two defines are temporary */
217147188Sgad#define	ki_childstime	ki_rusage_ch.ru_stime
218147188Sgad#define	ki_childutime	ki_rusage_ch.ru_utime
21911865Sphk
220172207Sjeff/*
221172207Sjeff *  Legacy PS_ flag.  This moved to p_flag but is maintained for
222172207Sjeff *  compatibility.
223172207Sjeff */
224172207Sjeff#define	PS_INMEM	0x00001		/* Loaded into memory. */
225172207Sjeff
22669896Smckusick/* ki_sessflag values */
22769896Smckusick#define	KI_CTTY		0x00000001	/* controlling tty vnode active */
22869896Smckusick#define	KI_SLEADER	0x00000002	/* session leader */
229104387Sjhb#define	KI_LOCKBLOCK	0x00000004	/* proc blocked on lock ki_lockname */
23011865Sphk
23111865Sphk/*
232137920Sdas * This used to be the per-process structure containing data that
233137920Sdas * isn't needed in core when the process is swapped out, but now it
234137920Sdas * remains only for the benefit of a.out core dumps.
2351541Srgrimes */
23683421Sobrienstruct user {
23783366Sjulian	struct	pstats u_stats;		/* *p_stats */
23883366Sjulian	struct	kinfo_proc u_kproc;	/* eproc */
2391541Srgrimes};
2401541Srgrimes
241174167Srwatson/*
242176124Smarcus * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor
243174167Srwatson * array of another process.
244174167Srwatson */
245221807Sstas#define	KF_ATTR_VALID	0x0001
246221807Sstas
247174167Srwatson#define	KF_TYPE_NONE	0
248174167Srwatson#define	KF_TYPE_VNODE	1
249174167Srwatson#define	KF_TYPE_SOCKET	2
250174167Srwatson#define	KF_TYPE_PIPE	3
251174167Srwatson#define	KF_TYPE_FIFO	4
252174167Srwatson#define	KF_TYPE_KQUEUE	5
253174167Srwatson#define	KF_TYPE_CRYPTO	6
254174167Srwatson#define	KF_TYPE_MQUEUE	7
255175514Srwatson#define	KF_TYPE_SHM	8
256180059Sjhb#define	KF_TYPE_SEM	9
257181905Sed#define	KF_TYPE_PTS	10
258247602Spjd#define	KF_TYPE_PROCDESC	11
259174167Srwatson#define	KF_TYPE_UNKNOWN	255
260174167Srwatson
261174167Srwatson#define	KF_VTYPE_VNON	0
262174167Srwatson#define	KF_VTYPE_VREG	1
263174167Srwatson#define	KF_VTYPE_VDIR	2
264174167Srwatson#define	KF_VTYPE_VBLK	3
265174167Srwatson#define	KF_VTYPE_VCHR	4
266174167Srwatson#define	KF_VTYPE_VLNK	5
267174167Srwatson#define	KF_VTYPE_VSOCK	6
268174167Srwatson#define	KF_VTYPE_VFIFO	7
269174167Srwatson#define	KF_VTYPE_VBAD	8
270174167Srwatson#define	KF_VTYPE_UNKNOWN	255
271174167Srwatson
272176124Smarcus#define	KF_FD_TYPE_CWD	-1	/* Current working directory */
273176124Smarcus#define	KF_FD_TYPE_ROOT	-2	/* Root directory */
274176124Smarcus#define	KF_FD_TYPE_JAIL	-3	/* Jail directory */
275221807Sstas#define	KF_FD_TYPE_TRACE	-4	/* ptrace vnode */
276221807Sstas#define	KF_FD_TYPE_TEXT	-5	/* Text vnode */
277221807Sstas#define	KF_FD_TYPE_CTTY	-6	/* Controlling terminal */
278176124Smarcus
279174167Srwatson#define	KF_FLAG_READ		0x00000001
280174167Srwatson#define	KF_FLAG_WRITE		0x00000002
281174167Srwatson#define	KF_FLAG_APPEND		0x00000004
282174167Srwatson#define	KF_FLAG_ASYNC		0x00000008
283174167Srwatson#define	KF_FLAG_FSYNC		0x00000010
284174167Srwatson#define	KF_FLAG_NONBLOCK	0x00000020
285174167Srwatson#define	KF_FLAG_DIRECT		0x00000040
286174167Srwatson#define	KF_FLAG_HASLOCK		0x00000080
287221807Sstas#define	KF_FLAG_SHLOCK		0x00000100
288221807Sstas#define	KF_FLAG_EXLOCK		0x00000200
289221807Sstas#define	KF_FLAG_NOFOLLOW	0x00000400
290221807Sstas#define	KF_FLAG_CREAT		0x00000800
291221807Sstas#define	KF_FLAG_TRUNC		0x00001000
292221807Sstas#define	KF_FLAG_EXCL		0x00002000
293221807Sstas#define	KF_FLAG_EXEC		0x00004000
294174167Srwatson
295185548Speter/*
296185548Speter * Old format.  Has variable hidden padding due to alignment.
297300060Spfg * This is a compatibility hack for pre-build 7.1 packages.
298185548Speter */
299185548Speter#if defined(__amd64__)
300185548Speter#define	KINFO_OFILE_SIZE	1328
301185548Speter#endif
302185548Speter#if defined(__i386__)
303185548Speter#define	KINFO_OFILE_SIZE	1324
304185548Speter#endif
305185548Speter
306185548Speterstruct kinfo_ofile {
307174167Srwatson	int	kf_structsize;			/* Size of kinfo_file. */
308174167Srwatson	int	kf_type;			/* Descriptor type. */
309174167Srwatson	int	kf_fd;				/* Array index. */
310174167Srwatson	int	kf_ref_count;			/* Reference count. */
311174167Srwatson	int	kf_flags;			/* Flags. */
312185548Speter	/* XXX Hidden alignment padding here on amd64 */
313174167Srwatson	off_t	kf_offset;			/* Seek location. */
314174167Srwatson	int	kf_vnode_type;			/* Vnode type. */
315174167Srwatson	int	kf_sock_domain;			/* Socket domain. */
316174167Srwatson	int	kf_sock_type;			/* Socket type. */
317174167Srwatson	int	kf_sock_protocol;		/* Socket protocol. */
318185548Speter	char	kf_path[PATH_MAX];	/* Path to file, if any. */
319174167Srwatson	struct sockaddr_storage kf_sa_local;	/* Socket address. */
320174167Srwatson	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
321174167Srwatson};
322174167Srwatson
323185548Speter#if defined(__amd64__) || defined(__i386__)
324260402Spjd/*
325260402Spjd * This size should never be changed. If you really need to, you must provide
326260402Spjd * backward ABI compatibility by allocating a new sysctl MIB that will return
327260402Spjd * the new structure. The current structure has to be returned by the current
328260402Spjd * sysctl MIB. See how it is done for the kinfo_ofile structure.
329260402Spjd */
330260402Spjd#define	KINFO_FILE_SIZE	1392
331185548Speter#endif
332185548Speter
333185548Speterstruct kinfo_file {
334221807Sstas	int		kf_structsize;		/* Variable size of record. */
335221807Sstas	int		kf_type;		/* Descriptor type. */
336221807Sstas	int		kf_fd;			/* Array index. */
337221807Sstas	int		kf_ref_count;		/* Reference count. */
338221807Sstas	int		kf_flags;		/* Flags. */
339221807Sstas	int		kf_pad0;		/* Round to 64 bit alignment. */
340221807Sstas	int64_t		kf_offset;		/* Seek location. */
341221807Sstas	int		kf_vnode_type;		/* Vnode type. */
342221807Sstas	int		kf_sock_domain;		/* Socket domain. */
343221807Sstas	int		kf_sock_type;		/* Socket type. */
344221807Sstas	int		kf_sock_protocol;	/* Socket protocol. */
345185548Speter	struct sockaddr_storage kf_sa_local;	/* Socket address. */
346185548Speter	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
347221807Sstas	union {
348221807Sstas		struct {
349221807Sstas			/* Address of so_pcb. */
350221807Sstas			uint64_t	kf_sock_pcb;
351221807Sstas			/* Address of inp_ppcb. */
352221807Sstas			uint64_t	kf_sock_inpcb;
353221807Sstas			/* Address of unp_conn. */
354221807Sstas			uint64_t	kf_sock_unpconn;
355221807Sstas			/* Send buffer state. */
356221807Sstas			uint16_t	kf_sock_snd_sb_state;
357221807Sstas			/* Receive buffer state. */
358221807Sstas			uint16_t	kf_sock_rcv_sb_state;
359221807Sstas			/* Round to 64 bit alignment. */
360221807Sstas			uint32_t	kf_sock_pad0;
361221807Sstas		} kf_sock;
362221807Sstas		struct {
363221807Sstas			/* Global file id. */
364221807Sstas			uint64_t	kf_file_fileid;
365221807Sstas			/* File size. */
366221807Sstas			uint64_t	kf_file_size;
367221807Sstas			/* Vnode filesystem id. */
368221807Sstas			uint32_t	kf_file_fsid;
369221807Sstas			/* File device. */
370221807Sstas			uint32_t	kf_file_rdev;
371221807Sstas			/* File mode. */
372221807Sstas			uint16_t	kf_file_mode;
373221807Sstas			/* Round to 64 bit alignment. */
374221807Sstas			uint16_t	kf_file_pad0;
375221807Sstas			uint32_t	kf_file_pad1;
376221807Sstas		} kf_file;
377221807Sstas		struct {
378250223Sjhb			uint32_t	kf_sem_value;
379250223Sjhb			uint16_t	kf_sem_mode;
380250223Sjhb		} kf_sem;
381250223Sjhb		struct {
382221807Sstas			uint64_t	kf_pipe_addr;
383221807Sstas			uint64_t	kf_pipe_peer;
384221807Sstas			uint32_t	kf_pipe_buffer_cnt;
385221807Sstas			/* Round to 64 bit alignment. */
386221807Sstas			uint32_t	kf_pipe_pad0[3];
387221807Sstas		} kf_pipe;
388221807Sstas		struct {
389221807Sstas			uint32_t	kf_pts_dev;
390221807Sstas			/* Round to 64 bit alignment. */
391221807Sstas			uint32_t	kf_pts_pad0[7];
392221807Sstas		} kf_pts;
393224987Sjonathan		struct {
394224987Sjonathan			pid_t		kf_pid;
395224987Sjonathan		} kf_proc;
396221807Sstas	} kf_un;
397221807Sstas	uint16_t	kf_status;		/* Status flags. */
398221807Sstas	uint16_t	kf_pad1;		/* Round to 32 bit alignment. */
399224225Sjonathan	int		_kf_ispare0;		/* Space for more stuff. */
400224225Sjonathan	cap_rights_t	kf_cap_rights;		/* Capability rights. */
401260402Spjd	uint64_t	_kf_cap_spare;		/* Space for future cap_rights_t. */
402185548Speter	/* Truncated before copyout in sysctl */
403221807Sstas	char		kf_path[PATH_MAX];	/* Path to file, if any. */
404185548Speter};
405185548Speter
406174167Srwatson/*
407174167Srwatson * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
408174167Srwatson * another process as a series of entries.
409174167Srwatson */
410174167Srwatson#define	KVME_TYPE_NONE		0
411174167Srwatson#define	KVME_TYPE_DEFAULT	1
412174167Srwatson#define	KVME_TYPE_VNODE		2
413174167Srwatson#define	KVME_TYPE_SWAP		3
414174167Srwatson#define	KVME_TYPE_DEVICE	4
415174167Srwatson#define	KVME_TYPE_PHYS		5
416174167Srwatson#define	KVME_TYPE_DEAD		6
417195840Sjhb#define	KVME_TYPE_SG		7
418262228Sjhb#define	KVME_TYPE_MGTDEVICE	8
419174167Srwatson#define	KVME_TYPE_UNKNOWN	255
420174167Srwatson
421174167Srwatson#define	KVME_PROT_READ		0x00000001
422174167Srwatson#define	KVME_PROT_WRITE		0x00000002
423174167Srwatson#define	KVME_PROT_EXEC		0x00000004
424174167Srwatson
425174167Srwatson#define	KVME_FLAG_COW		0x00000001
426174167Srwatson#define	KVME_FLAG_NEEDS_COPY	0x00000002
427208587Sattilio#define	KVME_FLAG_NOCOREDUMP	0x00000004
428227316Strociny#define	KVME_FLAG_SUPER		0x00000008
429238527Spgj#define	KVME_FLAG_GROWS_UP	0x00000010
430238527Spgj#define	KVME_FLAG_GROWS_DOWN	0x00000020
431174167Srwatson
432185548Speter#if defined(__amd64__)
433185548Speter#define	KINFO_OVMENTRY_SIZE	1168
434185548Speter#endif
435185548Speter#if defined(__i386__)
436185548Speter#define	KINFO_OVMENTRY_SIZE	1128
437185548Speter#endif
438185548Speter
439185548Speterstruct kinfo_ovmentry {
440174167Srwatson	int	 kve_structsize;		/* Size of kinfo_vmmapentry. */
441174167Srwatson	int	 kve_type;			/* Type of map entry. */
442185548Speter	void	*kve_start;			/* Starting address. */
443185548Speter	void	*kve_end;			/* Finishing address. */
444174167Srwatson	int	 kve_flags;			/* Flags on map entry. */
445174167Srwatson	int	 kve_resident;			/* Number of resident pages. */
446174167Srwatson	int	 kve_private_resident;		/* Number of private pages. */
447174167Srwatson	int	 kve_protection;		/* Protection bitmask. */
448174167Srwatson	int	 kve_ref_count;			/* VM obj ref count. */
449174167Srwatson	int	 kve_shadow_count;		/* VM obj shadow count. */
450174167Srwatson	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
451174167Srwatson	void	*_kve_pspare[8];		/* Space for more stuff. */
452184492Speter	off_t	 kve_offset;			/* Mapping offset in object */
453185548Speter	uint64_t kve_fileid;			/* inode number if vnode */
454184492Speter	dev_t	 kve_fsid;			/* dev_t of vnode location */
455184492Speter	int	 _kve_ispare[3];		/* Space for more stuff. */
456174167Srwatson};
457174167Srwatson
458185548Speter#if defined(__amd64__) || defined(__i386__)
459185548Speter#define	KINFO_VMENTRY_SIZE	1160
460185548Speter#endif
461185548Speter
462185548Speterstruct kinfo_vmentry {
463185548Speter	int	 kve_structsize;		/* Variable size of record. */
464185548Speter	int	 kve_type;			/* Type of map entry. */
465185548Speter	uint64_t kve_start;			/* Starting address. */
466185548Speter	uint64_t kve_end;			/* Finishing address. */
467185548Speter	uint64_t kve_offset;			/* Mapping offset in object */
468221807Sstas	uint64_t kve_vn_fileid;			/* inode number if vnode */
469221807Sstas	uint32_t kve_vn_fsid;			/* dev_t of vnode location */
470185548Speter	int	 kve_flags;			/* Flags on map entry. */
471185548Speter	int	 kve_resident;			/* Number of resident pages. */
472185548Speter	int	 kve_private_resident;		/* Number of private pages. */
473185548Speter	int	 kve_protection;		/* Protection bitmask. */
474185548Speter	int	 kve_ref_count;			/* VM obj ref count. */
475185548Speter	int	 kve_shadow_count;		/* VM obj shadow count. */
476221807Sstas	int	 kve_vn_type;			/* Vnode type. */
477221807Sstas	uint64_t kve_vn_size;			/* File size. */
478221807Sstas	uint32_t kve_vn_rdev;			/* Device id if device. */
479221807Sstas	uint16_t kve_vn_mode;			/* File mode. */
480221807Sstas	uint16_t kve_status;			/* Status flags. */
481221807Sstas	int	 _kve_ispare[12];		/* Space for more stuff. */
482185548Speter	/* Truncated before copyout in sysctl */
483185548Speter	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
484185548Speter};
485185548Speter
486174197Srwatson/*
487288453Sjhb * The "vm.objects" sysctl provides a list of all VM objects in the system
488288453Sjhb * via an array of these entries.
489288453Sjhb */
490288453Sjhbstruct kinfo_vmobject {
491288453Sjhb	int	kvo_structsize;			/* Variable size of record. */
492288453Sjhb	int	kvo_type;			/* Object type: KVME_TYPE_*. */
493288453Sjhb	uint64_t kvo_size;			/* Object size in pages. */
494288453Sjhb	uint64_t kvo_vn_fileid;			/* inode number if vnode. */
495288453Sjhb	uint32_t kvo_vn_fsid;			/* dev_t of vnode location. */
496288453Sjhb	int	kvo_ref_count;			/* Reference count. */
497288453Sjhb	int	kvo_shadow_count;		/* Shadow count. */
498288453Sjhb	int	kvo_memattr;			/* Memory attribute. */
499288453Sjhb	uint64_t kvo_resident;			/* Number of resident pages. */
500288453Sjhb	uint64_t kvo_active;			/* Number of active pages. */
501288453Sjhb	uint64_t kvo_inactive;			/* Number of inactive pages. */
502288453Sjhb	uint64_t _kvo_qspare[8];
503288453Sjhb	uint32_t _kvo_ispare[8];
504288453Sjhb	char	kvo_path[PATH_MAX];		/* Pathname, if any. */
505288453Sjhb};
506288453Sjhb
507288453Sjhb/*
508174197Srwatson * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
509174197Srwatson * another process as a series of entries.  Each stack is represented by a
510174197Srwatson * series of symbol names and offsets as generated by stack_sbuf_print(9).
511174197Srwatson */
512174197Srwatson#define	KKST_MAXLEN	1024
513174197Srwatson
514174197Srwatson#define	KKST_STATE_STACKOK	0		/* Stack is valid. */
515174197Srwatson#define	KKST_STATE_SWAPPED	1		/* Stack swapped out. */
516174197Srwatson#define	KKST_STATE_RUNNING	2		/* Stack ephemeral. */
517174197Srwatson
518185548Speter#if defined(__amd64__) || defined(__i386__)
519185548Speter#define	KINFO_KSTACK_SIZE	1096
520185548Speter#endif
521185548Speter
522174197Srwatsonstruct kinfo_kstack {
523174197Srwatson	lwpid_t	 kkst_tid;			/* ID of thread. */
524174197Srwatson	int	 kkst_state;			/* Validity of stack. */
525174197Srwatson	char	 kkst_trace[KKST_MAXLEN];	/* String representing stack. */
526185548Speter	int	 _kkst_ispare[16];		/* Space for more stuff. */
527174197Srwatson};
528174197Srwatson
529258885Skibstruct kinfo_sigtramp {
530258885Skib	void	*ksigtramp_start;
531258885Skib	void	*ksigtramp_end;
532258885Skib	void	*ksigtramp_spare[4];
533258885Skib};
534258885Skib
535221807Sstas#ifdef _KERNEL
536249487Strociny/* Flags for kern_proc_out function. */
537249487Strociny#define KERN_PROC_NOTHREADS	0x1
538249487Strociny#define KERN_PROC_MASK32	0x2
539249487Strociny
540295454Sjhb/* Flags for kern_proc_filedesc_out. */
541295454Sjhb#define	KERN_FILEDESC_PACK_KINFO	0x00000001U
542295454Sjhb
543295454Sjhb/* Flags for kern_proc_vmmap_out. */
544295454Sjhb#define	KERN_VMMAP_PACK_KINFO		0x00000001U
545249487Strocinystruct sbuf;
546249487Strociny
547249487Strociny/*
548249487Strociny * The kern_proc out functions are helper functions to dump process
549249487Strociny * miscellaneous kinfo structures to sbuf.  The main consumers are KERN_PROC
550249487Strociny * sysctls but they may also be used by other kernel subsystems.
551249487Strociny *
552249487Strociny * The functions manipulate the process locking state and expect the process
553249487Strociny * to be locked on enter.  On return the process is unlocked.
554249487Strociny */
555249487Strociny
556295454Sjhbint	kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
557295454Sjhb	int flags);
558249487Strocinyint	kern_proc_out(struct proc *p, struct sbuf *sb, int flags);
559295454Sjhbint	kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
560295454Sjhb	int flags);
561249487Strociny
562221807Sstasint	vntype_to_kinfo(int vtype);
563221807Sstas#endif /* !_KERNEL */
564221807Sstas
56537689Sdfr#endif
566