xref: /freebsd/sys/sys/user.h (revision c68159a6d8eede11766cf13896d0f7670dbd51aa)
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  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)user.h	8.2 (Berkeley) 9/23/93
34  * $FreeBSD$
35  */
36 
37 #ifndef _SYS_USER_H_
38 #define _SYS_USER_H_
39 
40 #include <machine/pcb.h>
41 #ifndef _KERNEL
42 /* stuff that *used* to be included by user.h, or is now needed */
43 #include <sys/errno.h>
44 #include <sys/time.h>
45 #include <sys/resource.h>
46 #include <sys/ucred.h>
47 #include <sys/uio.h>
48 #include <sys/proc.h>
49 #include <vm/vm.h>		/* XXX */
50 #include <vm/vm_param.h>	/* XXX */
51 #include <vm/pmap.h>		/* XXX */
52 #include <sys/lock.h>		/* XXX */
53 #include <vm/vm_map.h>		/* XXX */
54 #endif /* !_KERNEL */
55 #ifndef _SYS_RESOURCEVAR_H_
56 #include <sys/resourcevar.h>
57 #endif
58 #ifndef _SYS_SIGNALVAR_H_
59 #include <sys/signalvar.h>
60 #endif
61 
62 /*
63  * KERN_PROC subtype ops return arrays of selected proc structure entries:
64  *
65  * When adding new fields to this structure, ALWAYS add them at the end
66  * and decrease the size of the spare field by the amount of space that
67  * you are adding.  Byte aligned data should be added to the ki_sparestring
68  * space; other entries should be added to the ki_spare space. Always
69  * verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE when you are
70  * done. If you change the size of this structure, many programs will stop
71  * working! Once you have added the new field, you will need to add code
72  * to initialize it in two places: kern/kern_proc.c in the function
73  * fill_kinfo_proc and in lib/libkvm/kvm_proc.c in the function kvm_proclist.
74  */
75 #define	KINFO_PROC_SIZE	640		/* the correct size for kinfo_proc */
76 #define	WMESGLEN	8		/* size of returned wchan message */
77 #define	MTXNAMELEN	8		/* size of returned mutex name */
78 
79 struct kinfo_proc {
80 	int	ki_structsize;		/* size of this structure */
81 	struct	pargs *ki_args;		/* address of command arguments */
82 	struct	proc *ki_paddr;		/* address of proc */
83 	struct	user *ki_addr;		/* kernel virtual addr of u-area */
84 	struct	vnode *ki_tracep;	/* pointer to trace file */
85 	struct	vnode *ki_textvp;	/* pointer to executable file */
86 	struct	filedesc *ki_fd;	/* pointer to open file info */
87 	struct	vmspace *ki_vmspace;	/* pointer to kernel vmspace struct */
88 	void	*ki_wchan;		/* sleep address */
89 	pid_t	ki_pid;			/* Process identifier */
90 	pid_t	ki_ppid;		/* parent process id */
91 	pid_t	ki_pgid;		/* process group id */
92 	pid_t	ki_tpgid;		/* tty process group id */
93 	pid_t	ki_sid;			/* Process session ID */
94 	pid_t	ki_tsid;		/* Terminal session ID */
95 	short	ki_jobc;		/* job control counter */
96 	udev_t	ki_tdev;		/* controlling tty dev */
97 	sigset_t ki_siglist;		/* Signals arrived but not delivered */
98 	sigset_t ki_sigmask;		/* Current signal mask */
99 	sigset_t ki_sigignore;		/* Signals being ignored */
100 	sigset_t ki_sigcatch;		/* Signals being caught by user */
101 	uid_t	ki_uid;			/* effective user id */
102 	uid_t	ki_ruid;		/* Real user id */
103 	uid_t	ki_svuid;		/* Saved effective user id */
104 	gid_t	ki_rgid;		/* Real group id */
105 	gid_t	ki_svgid;		/* Saved effective group id */
106 	short	ki_ngroups;		/* number of groups */
107 	gid_t	ki_groups[NGROUPS];	/* groups */
108 	vm_size_t ki_size;		/* virtual size */
109 	segsz_t ki_rssize;		/* current resident set size in pages */
110 	segsz_t ki_swrss;		/* resident set size before last swap */
111 	segsz_t ki_tsize;		/* text size (pages) XXX */
112 	segsz_t ki_dsize;		/* data size (pages) XXX */
113 	segsz_t ki_ssize;		/* stack size (pages) */
114 	u_short	ki_xstat;		/* Exit status for wait & stop signal */
115 	u_short	ki_acflag;		/* Accounting flags */
116 	fixpt_t	ki_pctcpu;	 	/* %cpu for process during ki_swtime */
117 	u_int	ki_estcpu;	 	/* Time averaged value of ki_cpticks */
118 	u_int	ki_slptime;	 	/* Time since last blocked */
119 	u_int	ki_swtime;	 	/* Time swapped in or out */
120 	u_int64_t ki_runtime;		/* Real time in microsec */
121 	struct	timeval ki_start;	/* starting time */
122 	struct	timeval ki_childtime;	/* time used by process children */
123 	long	ki_flag;		/* P_* flags */
124 	long	ki_kiflag;		/* KI_* flags (below) */
125 	int	ki_traceflag;		/* Kernel trace points */
126 	u_char	ki_priority;		/* Process priority */
127 	u_char	ki_usrpri;		/* User-priority based on p_cpu */
128 	u_char	ki_nativepri;		/* Priority before propogation */
129 	char	ki_stat;		/* S* process status */
130 	char	ki_nice;		/* Process "nice" value */
131 	char	ki_lock;		/* Process lock (prevent swap) count */
132 	char	ki_rqindex;		/* Run queue index */
133 	u_char	ki_oncpu;		/* Which cpu we are on */
134 	u_char	ki_lastcpu;		/* Last cpu we were on */
135 	char	ki_comm[MAXCOMLEN+1];	/* command name */
136 	char	ki_wmesg[WMESGLEN+1];	/* wchan message */
137 	char	ki_login[MAXLOGNAME+1];	/* setlogin name */
138 	char	ki_mtxname[MTXNAMELEN+1]; /* mutex name */
139 	char	ki_sparestrings[102];	/* spare string space */
140 	struct	rtprio ki_rtprio;	/* Realtime priority */
141 	struct	rusage ki_rusage;	/* process rusage statistics */
142 	long	ki_spare[25];		/* spare constants */
143 };
144 void fill_kinfo_proc __P((struct proc *, struct kinfo_proc *));
145 
146 /* ki_sessflag values */
147 #define	KI_CTTY		0x00000001	/* controlling tty vnode active */
148 #define	KI_SLEADER	0x00000002	/* session leader */
149 #define	KI_MTXBLOCK	0x00000004	/* proc blocked on mutex ki_mtxname */
150 
151 /*
152  * Per process structure containing data that isn't needed in core
153  * when the process isn't running (esp. when swapped out).
154  * This structure may or may not be at the same kernel address
155  * in all processes.
156  */
157 
158 struct	user {
159 	struct	pcb u_pcb;
160 	struct	sigacts u_sigacts;	/* p_sigacts points here (use it!) */
161 	struct	pstats u_stats;		/* p_stats points here (use it!) */
162 	/*
163 	 * Remaining fields only for core dump and/or ptrace--
164 	 * not valid at other times!
165 	 */
166 	struct	kinfo_proc u_kproc;	/* proc + eproc */
167 	struct	md_coredump u_md;	/* machine dependent glop */
168 };
169 
170 /*
171  * Redefinitions to make the debuggers happy for now...  This subterfuge
172  * brought to you by coredump() and trace_req().  These fields are *only*
173  * valid at those times!
174  */
175 #ifdef __i386__
176 #define	U_ar0	u_kproc.kp_proc.p_md.md_regs /* copy of curproc->p_md.md_regs */
177 #endif
178 #ifdef __alpha__
179 #define	U_ar0	u_kproc.kp_proc.p_md.md_tf /* copy of curproc->p_md.md_tf */
180 #endif
181 #define	U_tsize	u_kproc.kp_eproc.e_vm.vm_tsize
182 #define	U_dsize	u_kproc.kp_eproc.e_vm.vm_dsize
183 #define	U_ssize	u_kproc.kp_eproc.e_vm.vm_ssize
184 #define	U_sig	u_kproc.kp_proc.p_sig
185 #define	U_code	u_kproc.kp_proc.p_code
186 
187 #ifndef _KERNEL
188 #define	u_ar0	U_ar0
189 #define	u_tsize	U_tsize
190 #define	u_dsize	U_dsize
191 #define	u_ssize	U_ssize
192 #define	u_sig	U_sig
193 #define	u_code	U_code
194 #endif
195 
196 #endif
197