xref: /freebsd/sys/sys/user.h (revision ceaec73d406831b1251babb61675df0a1aa54a31)
1 /*-
2  * Copyright (c) 1982, 1986, 1989, 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	@(#)user.h	8.2 (Berkeley) 9/23/93
30  * $FreeBSD$
31  */
32 
33 #ifndef _SYS_USER_H_
34 #define _SYS_USER_H_
35 
36 #include <machine/pcb.h>
37 #ifndef _KERNEL
38 /* stuff that *used* to be included by user.h, or is now needed */
39 #include <sys/errno.h>
40 #include <sys/time.h>
41 #include <sys/resource.h>
42 #include <sys/ucred.h>
43 #include <sys/uio.h>
44 #include <sys/queue.h>
45 #include <sys/_lock.h>
46 #include <sys/_mutex.h>
47 #include <sys/proc.h>
48 #include <vm/vm.h>		/* XXX */
49 #include <vm/vm_param.h>	/* XXX */
50 #include <vm/pmap.h>		/* XXX */
51 #include <vm/vm_map.h>		/* XXX */
52 #endif /* !_KERNEL */
53 #ifndef _SYS_RESOURCEVAR_H_
54 #include <sys/resourcevar.h>
55 #endif
56 #ifndef _SYS_SIGNALVAR_H_
57 #include <sys/signalvar.h>
58 #endif
59 
60 /*
61  * KERN_PROC subtype ops return arrays of selected proc structure entries:
62  *
63  * When adding new fields to this structure, ALWAYS add them at the end
64  * and decrease the size of the spare field by the amount of space that
65  * you are adding.  Byte aligned data should be added to the ki_sparestring
66  * space; other entries should be added to the ki_spare space. Always
67  * verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE when you are
68  * done. If you change the size of this structure, many programs will stop
69  * working! Once you have added the new field, you will need to add code
70  * to initialize it in two places: kern/kern_proc.c in the function
71  * fill_kinfo_proc and in lib/libkvm/kvm_proc.c in the function kvm_proclist.
72  *
73  * KI_NSPARE is the number of spare-longs to define in the array at the
74  * end of kinfo_proc.  It may need to be overridden on a platform-specific
75  * basis as new fields are added.
76  */
77 #define	KI_NSPARE	15
78 
79 #ifdef __alpha__
80 #define	KINFO_PROC_SIZE	912
81 #endif
82 #ifdef __amd64__
83 #define	KINFO_PROC_SIZE	912
84 #endif
85 #ifdef __arm__
86 #undef KI_NSPARE			/* Fewer spare longs on this arch */
87 #define	KI_NSPARE	13
88 #define	KINFO_PROC_SIZE	648
89 #endif
90 #ifdef __ia64__
91 #define	KINFO_PROC_SIZE 912
92 #endif
93 #ifdef __i386__
94 #undef KI_NSPARE			/* Fewer spare longs on this arch */
95 #define	KI_NSPARE	13
96 #define	KINFO_PROC_SIZE	648
97 #endif
98 #ifdef __powerpc__
99 #undef KI_NSPARE			/* Fewer spare longs on this arch */
100 #define	KI_NSPARE	14
101 #define	KINFO_PROC_SIZE	656
102 #endif
103 #ifdef __sparc64__
104 #define	KINFO_PROC_SIZE 912
105 #endif
106 #ifndef KINFO_PROC_SIZE
107 #error "Unknown architecture"
108 #endif
109 
110 #define	WMESGLEN	8		/* size of returned wchan message */
111 #define	LOCKNAMELEN	8		/* size of returned lock name */
112 #define	OCOMMLEN	16		/* size of returned ki_ocomm name */
113 #define	COMMLEN		19		/* size of returned ki_comm name */
114 #define	KI_EMULNAMELEN	16		/* size of returned ki_emul */
115 #define	KI_NGROUPS	16		/* number of groups in ki_groups */
116 #define	LOGNAMELEN	17		/* size of returned ki_login */
117 
118 struct kinfo_proc {
119 	int	ki_structsize;		/* size of this structure */
120 	int	ki_layout;		/* reserved: layout identifier */
121 	struct	pargs *ki_args;		/* address of command arguments */
122 	struct	proc *ki_paddr;		/* address of proc */
123 	struct	user *ki_addr;		/* kernel virtual addr of u-area */
124 	struct	vnode *ki_tracep;	/* pointer to trace file */
125 	struct	vnode *ki_textvp;	/* pointer to executable file */
126 	struct	filedesc *ki_fd;	/* pointer to open file info */
127 	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
128 	void	*ki_wchan;		/* sleep address */
129 	pid_t	ki_pid;			/* Process identifier */
130 	pid_t	ki_ppid;		/* parent process id */
131 	pid_t	ki_pgid;		/* process group id */
132 	pid_t	ki_tpgid;		/* tty process group id */
133 	pid_t	ki_sid;			/* Process session ID */
134 	pid_t	ki_tsid;		/* Terminal session ID */
135 	short	ki_jobc;		/* job control counter */
136 	short	ki_spare_short1;	/* unused (just here for alignment) */
137 	dev_t	ki_tdev;		/* controlling tty dev */
138 	sigset_t ki_siglist;		/* Signals arrived but not delivered */
139 	sigset_t ki_sigmask;		/* Current signal mask */
140 	sigset_t ki_sigignore;		/* Signals being ignored */
141 	sigset_t ki_sigcatch;		/* Signals being caught by user */
142 	uid_t	ki_uid;			/* effective user id */
143 	uid_t	ki_ruid;		/* Real user id */
144 	uid_t	ki_svuid;		/* Saved effective user id */
145 	gid_t	ki_rgid;		/* Real group id */
146 	gid_t	ki_svgid;		/* Saved effective group id */
147 	short	ki_ngroups;		/* number of groups */
148 	short	ki_spare_short2;	/* unused (just here for alignment) */
149 	gid_t	ki_groups[KI_NGROUPS];	/* groups */
150 	vm_size_t ki_size;		/* virtual size */
151 	segsz_t ki_rssize;		/* current resident set size in pages */
152 	segsz_t ki_swrss;		/* resident set size before last swap */
153 	segsz_t ki_tsize;		/* text size (pages) XXX */
154 	segsz_t ki_dsize;		/* data size (pages) XXX */
155 	segsz_t ki_ssize;		/* stack size (pages) */
156 	u_short	ki_xstat;		/* Exit status for wait & stop signal */
157 	u_short	ki_acflag;		/* Accounting flags */
158 	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
159 	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
160 	u_int	ki_slptime;	 	/* Time since last blocked */
161 	u_int	ki_swtime;	 	/* Time swapped in or out */
162 	u_int64_t ki_runtime;		/* Real time in microsec */
163 	struct	timeval ki_start;	/* starting time */
164 	struct	timeval ki_childtime;	/* time used by process children */
165 	long	ki_flag;		/* P_* flags */
166 	long	ki_kiflag;		/* KI_* flags (below) */
167 	int	ki_traceflag;		/* Kernel trace points */
168 	char	ki_stat;		/* S* process status */
169 	signed char ki_nice;		/* Process "nice" value */
170 	char	ki_lock;		/* Process lock (prevent swap) count */
171 	char	ki_rqindex;		/* Run queue index */
172 	u_char	ki_oncpu;		/* Which cpu we are on */
173 	u_char	ki_lastcpu;		/* Last cpu we were on */
174 	char	ki_ocomm[OCOMMLEN+1];	/* command name */
175 	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
176 	char	ki_login[LOGNAMELEN+1];	/* setlogin name */
177 	char	ki_lockname[LOCKNAMELEN+1]; /* lock name */
178 	char	ki_comm[COMMLEN+1];	/* command name */
179 	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
180 	char	ki_sparestrings[68];	/* spare string space */
181 	struct	rusage ki_rusage;	/* process rusage statistics */
182 	long	ki_sflag;		/* PS_* flags */
183 	struct	priority ki_pri;	/* process priority */
184 	long	ki_tdflags;		/* XXXKSE kthread flag */
185 	struct	pcb *ki_pcb;		/* kernel virtual addr of pcb */
186 	void	*ki_kstack;		/* kernel virtual addr of stack */
187 	struct	timeval ki_childstime;	/* system time used by children */
188 	struct	timeval ki_childutime;	/* user time used by children */
189 	lwpid_t	ki_tid;			/* XXXKSE thread id */
190 	int	ki_numthreads;		/* XXXKSE number of threads in total */
191 	void	*ki_udata;		/* User convenience pointer */
192 	int	ki_jid;			/* Process jail ID */
193 	int	ki_spare_int1;		/* unused (just here for alignment) */
194 	long	ki_spare[KI_NSPARE];	/* spare room for later growth */
195 };
196 void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
197 
198 /* ki_sessflag values */
199 #define	KI_CTTY		0x00000001	/* controlling tty vnode active */
200 #define	KI_SLEADER	0x00000002	/* session leader */
201 #define	KI_LOCKBLOCK	0x00000004	/* proc blocked on lock ki_lockname */
202 
203 /*
204  * This used to be the per-process structure containing data that
205  * isn't needed in core when the process is swapped out, but now it
206  * remains only for the benefit of a.out core dumps.
207  */
208 struct user {
209 	struct	pstats u_stats;		/* *p_stats */
210 	struct	kinfo_proc u_kproc;	/* eproc */
211 };
212 
213 #endif
214