FreeBSD/Linux Kernel Cross Reference
sys/sys/proc.h
1 /*-
2 * Copyright (c) 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)proc.h 8.15 (Berkeley) 5/19/95
39 * $FreeBSD$
40 */
41
42 #ifndef _SYS_PROC_H_
43 #define _SYS_PROC_H_
44
45 #include <machine/proc.h> /* Machine-dependent proc substruct. */
46 #include <sys/callout.h> /* For struct callout_handle. */
47 #include <sys/rtprio.h> /* For struct rtprio. */
48 #include <sys/select.h> /* For struct selinfo. */
49 #include <sys/signal.h>
50 #include <sys/signalvar.h>
51 #ifndef KERNEL
52 #include <sys/time.h> /* For structs itimerval, timeval. */
53 #endif
54 #include <sys/ucred.h>
55 #include <sys/queue.h>
56 #include <sys/filedesc.h>
57
58 /*
59 * One structure allocated per session.
60 */
61 struct session {
62 int s_count; /* Ref cnt; pgrps in session. */
63 struct proc *s_leader; /* Session leader. */
64 struct vnode *s_ttyvp; /* Vnode of controlling terminal. */
65 struct tty *s_ttyp; /* Controlling terminal. */
66 pid_t s_sid; /* Session ID */
67 char s_login[roundup(MAXLOGNAME, sizeof(long))]; /* Setlogin() name. */
68 };
69
70 /*
71 * One structure allocated per process group.
72 */
73 struct pgrp {
74 LIST_ENTRY(pgrp) pg_hash; /* Hash chain. */
75 LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members. */
76 struct session *pg_session; /* Pointer to session. */
77 struct sigiolst pg_sigiolst; /* List of sigio sources. */
78 pid_t pg_id; /* Pgrp id. */
79 int pg_jobc; /* # procs qualifying pgrp for job control */
80 };
81
82 struct procsig {
83 #define ps_begincopy ps_sigignore
84 sigset_t ps_sigignore; /* Signals being ignored. */
85 sigset_t ps_sigcatch; /* Signals being caught by user. */
86 int ps_flag;
87 struct sigacts *ps_sigacts;
88 #define ps_endcopy ps_refcnt
89 int ps_refcnt;
90 };
91
92 /*
93 * pasleep structure, used by asleep() syscall to hold requested priority
94 * and timeout values for await().
95 */
96 struct pasleep {
97 int as_priority; /* Async priority. */
98 int as_timo; /* Async timeout. */
99 };
100
101 /*
102 * Description of a process.
103 *
104 * This structure contains the information needed to manage a thread of
105 * control, known in UN*X as a process; it has references to substructures
106 * containing descriptions of things that the process uses, but may share
107 * with related processes. The process structure and the substructures
108 * are always addressable except for those marked "(PROC ONLY)" below,
109 * which might be addressable only on a processor on which the process
110 * is running.
111 */
112 struct proc {
113 TAILQ_ENTRY(proc) p_procq; /* run/sleep queue. */
114 LIST_ENTRY(proc) p_list; /* List of all processes. */
115
116 /* substructures: */
117 struct pcred *p_cred; /* Process owner's identity. */
118 struct filedesc *p_fd; /* Ptr to open files structure. */
119 struct pstats *p_stats; /* Accounting/statistics (PROC ONLY). */
120 struct plimit *p_limit; /* Process limits. */
121 struct vm_object *p_upages_obj;/* Upages object */
122 struct procsig *p_procsig;
123 #define p_sigacts p_procsig->ps_sigacts
124 #define p_sigignore p_procsig->ps_sigignore
125 #define p_sigcatch p_procsig->ps_sigcatch
126
127 #define p_ucred p_cred->pc_ucred
128 #define p_rlimit p_limit->pl_rlimit
129
130 int p_flag; /* P_* flags. */
131 char p_stat; /* S* process status. */
132 char p_pad1[3];
133
134 pid_t p_pid; /* Process identifier. */
135 LIST_ENTRY(proc) p_hash; /* Hash chain. */
136 LIST_ENTRY(proc) p_pglist; /* List of processes in pgrp. */
137 struct proc *p_pptr; /* Pointer to parent process. */
138 LIST_ENTRY(proc) p_sibling; /* List of sibling processes. */
139 LIST_HEAD(, proc) p_children; /* Pointer to list of children. */
140
141 struct callout_handle p_ithandle; /*
142 * Callout handle for scheduling
143 * p_realtimer.
144 */
145 /* The following fields are all zeroed upon creation in fork. */
146 #define p_startzero p_oppid
147
148 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
149 int p_dupfd; /* Sideways return value from fdopen. XXX */
150
151 struct vmspace *p_vmspace; /* Address space. */
152
153 /* scheduling */
154 u_int p_estcpu; /* Time averaged value of p_cpticks. */
155 int p_cpticks; /* Ticks of cpu time. */
156 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
157 void *p_wchan; /* Sleep address. */
158 const char *p_wmesg; /* Reason for sleep. */
159 u_int p_swtime; /* Time swapped in or out. */
160 u_int p_slptime; /* Time since last blocked. */
161
162 struct itimerval p_realtimer; /* Alarm timer. */
163 u_int64_t p_runtime; /* Real time in microsec. */
164 struct timeval p_switchtime; /* When last scheduled */
165 u_quad_t p_uticks; /* Statclock hits in user mode. */
166 u_quad_t p_sticks; /* Statclock hits in system mode. */
167 u_quad_t p_iticks; /* Statclock hits processing intr. */
168
169 int p_traceflag; /* Kernel trace points. */
170 struct vnode *p_tracep; /* Trace to vnode. */
171
172 int p_siglist; /* Signals arrived but not delivered. */
173
174 struct vnode *p_textvp; /* Vnode of executable. */
175
176 char p_lock; /* Process lock (prevent swap) count. */
177 char p_oncpu; /* Which cpu we are on */
178 char p_lastcpu; /* Last cpu we were on */
179 char p_pad2; /* alignment */
180
181 short p_locks; /* DEBUG: lockmgr count of held locks */
182 short p_simple_locks; /* DEBUG: count of held simple locks */
183 unsigned int p_stops; /* procfs event bitmask */
184 unsigned int p_stype; /* procfs stop event type */
185 char p_step; /* procfs stop *once* flag */
186 unsigned char p_pfsflags; /* procfs flags */
187 char p_pad3[2]; /* padding for alignment */
188 register_t p_retval[2]; /* syscall aux returns */
189 struct sigiolst p_sigiolst; /* list of sigio sources */
190 int p_sigparent; /* signal to parent on exit */
191 sigset_t p_oldsigmask; /* saved mask from before sigpause */
192 int p_sig; /* for core dump/debugger XXX */
193 u_long p_code; /* for core dump/debugger XXX */
194
195 /* End area that is zeroed on creation. */
196 #define p_endzero p_startcopy
197
198 /* The following fields are all copied upon creation in fork. */
199 #define p_startcopy p_sigmask
200
201 sigset_t p_sigmask; /* Current signal mask. */
202 u_char p_priority; /* Process priority. */
203 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
204 char p_nice; /* Process "nice" value. */
205 char p_comm[MAXCOMLEN+1];
206
207 struct pgrp *p_pgrp; /* Pointer to process group. */
208
209 struct sysentvec *p_sysent; /* System call dispatch information. */
210
211 struct rtprio p_rtprio; /* Realtime priority. */
212 /* End area that is copied on creation. */
213 #define p_endcopy p_addr
214 struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
215 struct mdproc p_md; /* Any machine-dependent fields. */
216
217 u_short p_xstat; /* Exit status for wait; also stop signal. */
218 u_short p_acflag; /* Accounting flags. */
219 struct rusage *p_ru; /* Exit information. XXX */
220
221 int p_nthreads; /* number of threads (only in leader) */
222 void *p_aioinfo; /* ASYNC I/O info */
223 int p_wakeup; /* thread id */
224 struct proc *p_peers;
225 struct proc *p_leader;
226 struct pasleep p_asleep; /* Used by asleep()/await(). */
227 };
228
229 #define p_session p_pgrp->pg_session
230 #define p_pgid p_pgrp->pg_id
231
232 /* Status values. */
233 #define SIDL 1 /* Process being created by fork. */
234 #define SRUN 2 /* Currently runnable. */
235 #define SSLEEP 3 /* Sleeping on an address. */
236 #define SSTOP 4 /* Process debugging or suspension. */
237 #define SZOMB 5 /* Awaiting collection by parent. */
238
239 /* These flags are kept in p_flags. */
240 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
241 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
242 #define P_INMEM 0x00004 /* Loaded into memory. */
243 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
244 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
245 #define P_PROFIL 0x00020 /* Has started profiling. */
246 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
247 #define P_SINTR 0x00080 /* Sleep is interruptible. */
248 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
249 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
250 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
251 #define P_TRACED 0x00800 /* Debugged process being traced. */
252 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
253 #define P_WEXIT 0x02000 /* Working on exiting. */
254 #define P_EXEC 0x04000 /* Process called exec. */
255
256 /* Should probably be changed into a hold count. */
257 #define P_NOSWAP 0x08000 /* Another flag to prevent swap out. */
258 #define P_PHYSIO 0x10000 /* Doing physical I/O. */
259
260 /* Should be moved to machine-dependent areas. */
261 #define P_OWEUPC 0x20000 /* Owe process an addupc() call at next ast. */
262
263 #define P_SWAPPING 0x40000 /* Process is being swapped. */
264 #define P_SWAPINREQ 0x80000 /* Swapin request due to wakeup */
265
266 /* Marked a kernel thread */
267 #define P_KTHREADP 0x200000 /* Process is really a kernel thread */
268
269 #define P_NOCLDWAIT 0x400000 /* No zombies if child dies */
270
271
272 /*
273 * MOVE TO ucred.h?
274 *
275 * Shareable process credentials (always resident). This includes a reference
276 * to the current user credentials as well as real and saved ids that may be
277 * used to change ids.
278 */
279 struct pcred {
280 struct ucred *pc_ucred; /* Current credentials. */
281 uid_t p_ruid; /* Real user id. */
282 uid_t p_svuid; /* Saved effective user id. */
283 gid_t p_rgid; /* Real group id. */
284 gid_t p_svgid; /* Saved effective group id. */
285 int p_refcnt; /* Number of references. */
286 };
287
288 #ifdef KERNEL
289
290 #ifdef MALLOC_DECLARE
291 MALLOC_DECLARE(M_SESSION);
292 MALLOC_DECLARE(M_SUBPROC);
293 #endif
294
295 /*
296 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
297 * as it is used to represent "no process group".
298 */
299 #define PID_MAX 99999
300 #define NO_PID 100000
301
302 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
303 #define SESSHOLD(s) ((s)->s_count++)
304 #define SESSRELE(s) { \
305 if (--(s)->s_count == 0) \
306 FREE(s, M_SESSION); \
307 }
308
309 extern void stopevent(struct proc*, unsigned int, unsigned int);
310 #define STOPEVENT(p,e,v) do { \
311 if ((p)->p_stops & (e)) stopevent(p,e,v); } while (0)
312
313 /* hold process U-area in memory, normally for ptrace/procfs work */
314 #define PHOLD(p) { \
315 if ((p)->p_lock++ == 0 && ((p)->p_flag & P_INMEM) == 0) \
316 faultin(p); \
317 }
318 #define PRELE(p) (--(p)->p_lock)
319
320 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
321 extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
322 extern u_long pidhash;
323
324 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
325 extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
326 extern u_long pgrphash;
327
328 extern struct proc *curproc; /* Current running proc. */
329 extern struct proc proc0; /* Process slot for swapper. */
330 extern int hogticks; /* Limit on kernel cpu hogs. */
331 extern int nprocs, maxproc; /* Current and max number of procs. */
332 extern int maxprocperuid; /* Max procs per uid. */
333 extern int switchticks; /* `ticks' at last context switch. */
334 extern struct timeval switchtime; /* Uptime at last context switch */
335
336 LIST_HEAD(proclist, proc);
337 extern struct proclist allproc; /* List of all processes. */
338 extern struct proclist zombproc; /* List of zombie processes. */
339 extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */
340
341 #define NQS 32 /* 32 run queues. */
342 extern struct prochd qs[];
343 extern struct prochd rtqs[];
344 extern struct prochd idqs[];
345 extern int whichqs; /* Bit mask summary of non-empty Q's. */
346 extern int whichrtqs; /* Bit mask summary of non-empty Q's. */
347 extern int whichidqs; /* Bit mask summary of non-empty Q's. */
348 struct prochd {
349 struct proc *ph_link; /* Linked list of running processes. */
350 struct proc *ph_rlink;
351 };
352
353 struct proc *pfind __P((pid_t)); /* Find process by id. */
354 struct pgrp *pgfind __P((pid_t)); /* Find process group by id. */
355
356 struct vm_zone;
357 extern struct vm_zone *proc_zone;
358
359 int chgproccnt __P((uid_t uid, int diff));
360 int enterpgrp __P((struct proc *p, pid_t pgid, int mksess));
361 void fixjobc __P((struct proc *p, struct pgrp *pgrp, int entering));
362 int inferior __P((struct proc *p));
363 int leavepgrp __P((struct proc *p));
364 void mi_switch __P((void));
365 void procinit __P((void));
366 void resetpriority __P((struct proc *));
367 int roundrobin_interval __P((void));
368 void setrunnable __P((struct proc *));
369 void setrunqueue __P((struct proc *));
370 void sleepinit __P((void));
371 void remrq __P((struct proc *));
372 void cpu_switch __P((struct proc *));
373 void unsleep __P((struct proc *));
374 void wakeup_one __P((void *chan));
375
376 void cpu_exit __P((struct proc *)) __dead2;
377 void exit1 __P((struct proc *, int)) __dead2;
378 void cpu_fork __P((struct proc *, struct proc *));
379 int fork1 __P((struct proc *, int));
380 int trace_req __P((struct proc *));
381 void cpu_wait __P((struct proc *));
382 int cpu_coredump __P((struct proc *, struct vnode *, struct ucred *));
383 void setsugid __P((struct proc *p));
384 #endif /* KERNEL */
385
386 #endif /* !_SYS_PROC_H_ */
Cache object: 9fa5cac23b4b7be6d55fdb9ec6bd6a95
|