user.h revision 184492
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 184492 2008-10-31 05:43:19Z peter $
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 */
86147188Sgad#define	KI_NSPARE_INT	10
87147188Sgad#define	KI_NSPARE_LONG	12
88147188Sgad#define	KI_NSPARE_PTR	7
89130825Sgad
90130825Sgad#ifdef __amd64__
91147188Sgad#define	KINFO_PROC_SIZE	1088
9271040Smjacob#endif
93130825Sgad#ifdef __arm__
94158581Scognet#define	KINFO_PROC_SIZE	792
9577956Sbenno#endif
96130825Sgad#ifdef __ia64__
97147188Sgad#define	KINFO_PROC_SIZE 1088
9874022Sdfr#endif
99130825Sgad#ifdef __i386__
100147188Sgad#define	KINFO_PROC_SIZE	768
101130825Sgad#endif
102178660Sgonzo#ifdef __mips__
103178660Sgonzo#define	KINFO_PROC_SIZE	816
104178660Sgonzo#endif
105130825Sgad#ifdef __powerpc__
106147188Sgad#define	KINFO_PROC_SIZE	768
107130825Sgad#endif
108130825Sgad#ifdef __sparc64__
109147188Sgad#define	KINFO_PROC_SIZE 1088
110130825Sgad#endif
111130825Sgad#ifndef KINFO_PROC_SIZE
112130825Sgad#error "Unknown architecture"
113130825Sgad#endif
114130825Sgad
11569896Smckusick#define	WMESGLEN	8		/* size of returned wchan message */
116104387Sjhb#define	LOCKNAMELEN	8		/* size of returned lock name */
117154535Sjulian#define	OCOMMLEN	16		/* size of returned thread name */
11881759Speter#define	COMMLEN		19		/* size of returned ki_comm name */
119130726Sgad#define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
12081759Speter#define	KI_NGROUPS	16		/* number of groups in ki_groups */
12181759Speter#define	LOGNAMELEN	17		/* size of returned ki_login */
12269896Smckusick
12311865Sphkstruct kinfo_proc {
12469896Smckusick	int	ki_structsize;		/* size of this structure */
12572415Sphk	int	ki_layout;		/* reserved: layout identifier */
12669896Smckusick	struct	pargs *ki_args;		/* address of command arguments */
12769896Smckusick	struct	proc *ki_paddr;		/* address of proc */
12869896Smckusick	struct	user *ki_addr;		/* kernel virtual addr of u-area */
12969896Smckusick	struct	vnode *ki_tracep;	/* pointer to trace file */
13069896Smckusick	struct	vnode *ki_textvp;	/* pointer to executable file */
13169896Smckusick	struct	filedesc *ki_fd;	/* pointer to open file info */
13269896Smckusick	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
13369896Smckusick	void	*ki_wchan;		/* sleep address */
13469896Smckusick	pid_t	ki_pid;			/* Process identifier */
13569896Smckusick	pid_t	ki_ppid;		/* parent process id */
13669896Smckusick	pid_t	ki_pgid;		/* process group id */
13769896Smckusick	pid_t	ki_tpgid;		/* tty process group id */
13869896Smckusick	pid_t	ki_sid;			/* Process session ID */
13969896Smckusick	pid_t	ki_tsid;		/* Terminal session ID */
14069896Smckusick	short	ki_jobc;		/* job control counter */
141130726Sgad	short	ki_spare_short1;	/* unused (just here for alignment) */
142130640Sphk	dev_t	ki_tdev;		/* controlling tty dev */
14369896Smckusick	sigset_t ki_siglist;		/* Signals arrived but not delivered */
14469896Smckusick	sigset_t ki_sigmask;		/* Current signal mask */
14569896Smckusick	sigset_t ki_sigignore;		/* Signals being ignored */
14669896Smckusick	sigset_t ki_sigcatch;		/* Signals being caught by user */
14769896Smckusick	uid_t	ki_uid;			/* effective user id */
14869896Smckusick	uid_t	ki_ruid;		/* Real user id */
14969896Smckusick	uid_t	ki_svuid;		/* Saved effective user id */
15069896Smckusick	gid_t	ki_rgid;		/* Real group id */
15169896Smckusick	gid_t	ki_svgid;		/* Saved effective group id */
15269896Smckusick	short	ki_ngroups;		/* number of groups */
153130726Sgad	short	ki_spare_short2;	/* unused (just here for alignment) */
15481759Speter	gid_t	ki_groups[KI_NGROUPS];	/* groups */
15569896Smckusick	vm_size_t ki_size;		/* virtual size */
15669896Smckusick	segsz_t ki_rssize;		/* current resident set size in pages */
15769896Smckusick	segsz_t ki_swrss;		/* resident set size before last swap */
15869896Smckusick	segsz_t ki_tsize;		/* text size (pages) XXX */
15969896Smckusick	segsz_t ki_dsize;		/* data size (pages) XXX */
16069896Smckusick	segsz_t ki_ssize;		/* stack size (pages) */
16169896Smckusick	u_short	ki_xstat;		/* Exit status for wait & stop signal */
16269896Smckusick	u_short	ki_acflag;		/* Accounting flags */
16369896Smckusick	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
16469896Smckusick	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
16569896Smckusick	u_int	ki_slptime;	 	/* Time since last blocked */
16669896Smckusick	u_int	ki_swtime;	 	/* Time swapped in or out */
167147188Sgad	int	ki_spareint1;	 	/* unused (just here for alignment) */
16869896Smckusick	u_int64_t ki_runtime;		/* Real time in microsec */
16969896Smckusick	struct	timeval ki_start;	/* starting time */
17069896Smckusick	struct	timeval ki_childtime;	/* time used by process children */
17169896Smckusick	long	ki_flag;		/* P_* flags */
17269896Smckusick	long	ki_kiflag;		/* KI_* flags (below) */
17369896Smckusick	int	ki_traceflag;		/* Kernel trace points */
17469896Smckusick	char	ki_stat;		/* S* process status */
175124829Sgrehan	signed char ki_nice;		/* Process "nice" value */
17669896Smckusick	char	ki_lock;		/* Process lock (prevent swap) count */
17769896Smckusick	char	ki_rqindex;		/* Run queue index */
17869896Smckusick	u_char	ki_oncpu;		/* Which cpu we are on */
17969896Smckusick	u_char	ki_lastcpu;		/* Last cpu we were on */
180154535Sjulian	char	ki_ocomm[OCOMMLEN+1];	/* thread name */
18169896Smckusick	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
18281759Speter	char	ki_login[LOGNAMELEN+1];	/* setlogin name */
183104387Sjhb	char	ki_lockname[LOCKNAMELEN+1]; /* lock name */
18481759Speter	char	ki_comm[COMMLEN+1];	/* command name */
185130726Sgad	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
186147188Sgad	/*
187147188Sgad	 * When adding new variables, take space for char-strings from the
188147188Sgad	 * front of ki_sparestrings, and ints from the end of ki_spareints.
189147188Sgad	 * That way the spare room from both arrays will remain contiguous.
190147188Sgad	 */
191130726Sgad	char	ki_sparestrings[68];	/* spare string space */
192147188Sgad	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
193147188Sgad	int	ki_jid;			/* Process jail ID */
194147188Sgad	int	ki_numthreads;		/* XXXKSE number of threads in total */
195147188Sgad	lwpid_t	ki_tid;			/* XXXKSE thread id */
196147188Sgad	struct	priority ki_pri;	/* process priority */
19769896Smckusick	struct	rusage ki_rusage;	/* process rusage statistics */
198147188Sgad	/* XXX - most fields in ki_rusage_ch are not (yet) filled in */
199147188Sgad	struct	rusage ki_rusage_ch;	/* rusage of children processes */
20083366Sjulian	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
20183366Sjulian	void	*ki_kstack;		/* kernel virtual addr of stack */
202132014Salfred	void	*ki_udata;		/* User convenience pointer */
203147188Sgad	/*
204147188Sgad	 * When adding new variables, take space for pointers from the
205147188Sgad	 * front of ki_spareptrs, and longs from the end of ki_sparelongs.
206147188Sgad	 * That way the spare room from both arrays will remain contiguous.
207147188Sgad	 */
208147188Sgad	void	*ki_spareptrs[KI_NSPARE_PTR];	/* spare room for growth */
209147188Sgad	long	ki_sparelongs[KI_NSPARE_LONG];	/* spare room for growth */
210147188Sgad	long	ki_sflag;		/* PS_* flags */
211147188Sgad	long	ki_tdflags;		/* XXXKSE kthread flag */
21211865Sphk};
21392719Salfredvoid fill_kinfo_proc(struct proc *, struct kinfo_proc *);
214147188Sgad/* XXX - the following two defines are temporary */
215147188Sgad#define	ki_childstime	ki_rusage_ch.ru_stime
216147188Sgad#define	ki_childutime	ki_rusage_ch.ru_utime
21711865Sphk
218172207Sjeff/*
219172207Sjeff *  Legacy PS_ flag.  This moved to p_flag but is maintained for
220172207Sjeff *  compatibility.
221172207Sjeff */
222172207Sjeff#define	PS_INMEM	0x00001		/* Loaded into memory. */
223172207Sjeff
22469896Smckusick/* ki_sessflag values */
22569896Smckusick#define	KI_CTTY		0x00000001	/* controlling tty vnode active */
22669896Smckusick#define	KI_SLEADER	0x00000002	/* session leader */
227104387Sjhb#define	KI_LOCKBLOCK	0x00000004	/* proc blocked on lock ki_lockname */
22811865Sphk
22911865Sphk/*
230137920Sdas * This used to be the per-process structure containing data that
231137920Sdas * isn't needed in core when the process is swapped out, but now it
232137920Sdas * remains only for the benefit of a.out core dumps.
2331541Srgrimes */
23483421Sobrienstruct user {
23583366Sjulian	struct	pstats u_stats;		/* *p_stats */
23683366Sjulian	struct	kinfo_proc u_kproc;	/* eproc */
2371541Srgrimes};
2381541Srgrimes
239174167Srwatson/*
240176124Smarcus * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor
241174167Srwatson * array of another process.
242174167Srwatson */
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 */
270176124Smarcus
271174167Srwatson#define	KF_FLAG_READ		0x00000001
272174167Srwatson#define	KF_FLAG_WRITE		0x00000002
273174167Srwatson#define	KF_FLAG_APPEND		0x00000004
274174167Srwatson#define	KF_FLAG_ASYNC		0x00000008
275174167Srwatson#define	KF_FLAG_FSYNC		0x00000010
276174167Srwatson#define	KF_FLAG_NONBLOCK	0x00000020
277174167Srwatson#define	KF_FLAG_DIRECT		0x00000040
278174167Srwatson#define	KF_FLAG_HASLOCK		0x00000080
279174167Srwatson
280174167Srwatsonstruct kinfo_file {
281174167Srwatson	int	kf_structsize;			/* Size of kinfo_file. */
282174167Srwatson	int	kf_type;			/* Descriptor type. */
283174167Srwatson	int	kf_fd;				/* Array index. */
284174167Srwatson	int	kf_ref_count;			/* Reference count. */
285174167Srwatson	int	kf_flags;			/* Flags. */
286174167Srwatson	off_t	kf_offset;			/* Seek location. */
287174167Srwatson	int	kf_vnode_type;			/* Vnode type. */
288174167Srwatson	int	kf_sock_domain;			/* Socket domain. */
289174167Srwatson	int	kf_sock_type;			/* Socket type. */
290174167Srwatson	int	kf_sock_protocol;		/* Socket protocol. */
291174167Srwatson	char	kf_path[PATH_MAX];		/* Path to file, if any. */
292174167Srwatson	struct sockaddr_storage kf_sa_local;	/* Socket address. */
293174167Srwatson	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
294174167Srwatson};
295174167Srwatson
296174167Srwatson/*
297174167Srwatson * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
298174167Srwatson * another process as a series of entries.
299174167Srwatson */
300174167Srwatson#define	KVME_TYPE_NONE		0
301174167Srwatson#define	KVME_TYPE_DEFAULT	1
302174167Srwatson#define	KVME_TYPE_VNODE		2
303174167Srwatson#define	KVME_TYPE_SWAP		3
304174167Srwatson#define	KVME_TYPE_DEVICE	4
305174167Srwatson#define	KVME_TYPE_PHYS		5
306174167Srwatson#define	KVME_TYPE_DEAD		6
307174167Srwatson#define	KVME_TYPE_UNKNOWN	255
308174167Srwatson
309174167Srwatson#define	KVME_PROT_READ		0x00000001
310174167Srwatson#define	KVME_PROT_WRITE		0x00000002
311174167Srwatson#define	KVME_PROT_EXEC		0x00000004
312174167Srwatson
313174167Srwatson#define	KVME_FLAG_COW		0x00000001
314174167Srwatson#define	KVME_FLAG_NEEDS_COPY	0x00000002
315174167Srwatson
316174167Srwatsonstruct kinfo_vmentry {
317174167Srwatson	int	 kve_structsize;		/* Size of kinfo_vmmapentry. */
318174167Srwatson	int	 kve_type;			/* Type of map entry. */
319174167Srwatson	void	*kve_start;			/* Starting pointer. */
320174167Srwatson	void	*kve_end;			/* Finishing pointer. */
321174167Srwatson	int	 kve_flags;			/* Flags on map entry. */
322174167Srwatson	int	 kve_resident;			/* Number of resident pages. */
323174167Srwatson	int	 kve_private_resident;		/* Number of private pages. */
324174167Srwatson	int	 kve_protection;		/* Protection bitmask. */
325174167Srwatson	int	 kve_ref_count;			/* VM obj ref count. */
326174167Srwatson	int	 kve_shadow_count;		/* VM obj shadow count. */
327174167Srwatson	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
328174167Srwatson	void	*_kve_pspare[8];		/* Space for more stuff. */
329184492Speter	off_t	 kve_offset;			/* Mapping offset in object */
330184492Speter	uint64_t kve_fileid;			/* inode number of vnode */
331184492Speter	dev_t	 kve_fsid;			/* dev_t of vnode location */
332184492Speter	int	 _kve_ispare[3];		/* Space for more stuff. */
333174167Srwatson};
334174167Srwatson
335174197Srwatson/*
336174197Srwatson * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
337174197Srwatson * another process as a series of entries.  Each stack is represented by a
338174197Srwatson * series of symbol names and offsets as generated by stack_sbuf_print(9).
339174197Srwatson */
340174197Srwatson#define	KKST_MAXLEN	1024
341174197Srwatson
342174197Srwatson#define	KKST_STATE_STACKOK	0		/* Stack is valid. */
343174197Srwatson#define	KKST_STATE_SWAPPED	1		/* Stack swapped out. */
344174197Srwatson#define	KKST_STATE_RUNNING	2		/* Stack ephemeral. */
345174197Srwatson
346174197Srwatsonstruct kinfo_kstack {
347174197Srwatson	lwpid_t	 kkst_tid;			/* ID of thread. */
348174197Srwatson	int	 kkst_state;			/* Validity of stack. */
349174197Srwatson	char	 kkst_trace[KKST_MAXLEN];	/* String representing stack. */
350174197Srwatson	void	*_kkst_pspare[8];		/* Space for more stuff. */
351174197Srwatson	int	 _kkst_ispare[8];		/* Space for more stuff. */
352174197Srwatson};
353174197Srwatson
35437689Sdfr#endif
355