1 | /* $NetBSD: proc.h,v 1.355 2019/07/15 19:34:45 pgoyette Exp $ */ |
2 | |
3 | /*- |
4 | * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. |
6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Doran. |
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 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
31 | |
32 | /*- |
33 | * Copyright (c) 1986, 1989, 1991, 1993 |
34 | * The Regents of the University of California. All rights reserved. |
35 | * (c) UNIX System Laboratories, Inc. |
36 | * All or some portions of this file are derived from material licensed |
37 | * to the University of California by American Telephone and Telegraph |
38 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with |
39 | * the permission of UNIX System Laboratories, Inc. |
40 | * |
41 | * Redistribution and use in source and binary forms, with or without |
42 | * modification, are permitted provided that the following conditions |
43 | * are met: |
44 | * 1. Redistributions of source code must retain the above copyright |
45 | * notice, this list of conditions and the following disclaimer. |
46 | * 2. Redistributions in binary form must reproduce the above copyright |
47 | * notice, this list of conditions and the following disclaimer in the |
48 | * documentation and/or other materials provided with the distribution. |
49 | * 3. Neither the name of the University nor the names of its contributors |
50 | * may be used to endorse or promote products derived from this software |
51 | * without specific prior written permission. |
52 | * |
53 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
63 | * SUCH DAMAGE. |
64 | * |
65 | * @(#)proc.h 8.15 (Berkeley) 5/19/95 |
66 | */ |
67 | |
68 | #ifndef _SYS_PROC_H_ |
69 | #define _SYS_PROC_H_ |
70 | |
71 | #include <sys/lwp.h> |
72 | |
73 | #if defined(_KMEMUSER) || defined(_KERNEL) |
74 | |
75 | #if defined(_KERNEL_OPT) |
76 | #include "opt_multiprocessor.h" |
77 | #include "opt_kstack.h" |
78 | #include "opt_lockdebug.h" |
79 | #endif |
80 | |
81 | #include <machine/proc.h> /* Machine-dependent proc substruct */ |
82 | #include <machine/pcb.h> |
83 | #include <sys/aio.h> |
84 | #include <sys/idtype.h> |
85 | #include <sys/rwlock.h> |
86 | #include <sys/mqueue.h> |
87 | #include <sys/mutex.h> |
88 | #include <sys/condvar.h> |
89 | #include <sys/queue.h> |
90 | #include <sys/signalvar.h> |
91 | #include <sys/siginfo.h> |
92 | #include <sys/event.h> |
93 | #include <sys/specificdata.h> |
94 | |
95 | #ifndef _KERNEL |
96 | #include <sys/time.h> |
97 | #include <sys/resource.h> |
98 | #endif |
99 | |
100 | /* |
101 | * One structure allocated per session. |
102 | */ |
103 | struct session { |
104 | int s_count; /* Ref cnt; pgrps in session */ |
105 | u_int s_flags; |
106 | #define S_LOGIN_SET 1 /* s_login set in this session */ |
107 | struct proc *s_leader; /* Session leader */ |
108 | struct vnode *s_ttyvp; /* Vnode of controlling terminal */ |
109 | struct tty *s_ttyp; /* Controlling terminal */ |
110 | char s_login[MAXLOGNAME]; /* Setlogin() name */ |
111 | pid_t s_sid; /* Session ID (pid of leader) */ |
112 | }; |
113 | |
114 | /* |
115 | * One structure allocated per process group. |
116 | */ |
117 | struct pgrp { |
118 | LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members */ |
119 | struct session *pg_session; /* Pointer to session */ |
120 | pid_t pg_id; /* Pgrp id */ |
121 | int pg_jobc; /* |
122 | * Number of processes qualifying |
123 | * pgrp for job control |
124 | */ |
125 | }; |
126 | |
127 | /* |
128 | * Autoloadable syscall definition |
129 | */ |
130 | struct sc_autoload { |
131 | u_int al_code; |
132 | const char *al_module; |
133 | }; |
134 | |
135 | /* |
136 | * One structure allocated per emulation. |
137 | */ |
138 | struct exec_package; |
139 | struct ras; |
140 | struct kauth_cred; |
141 | |
142 | struct emul { |
143 | const char *e_name; /* Symbolic name */ |
144 | const char *e_path; /* Extra emulation path (NULL if none)*/ |
145 | #ifndef __HAVE_MINIMAL_EMUL |
146 | int e_flags; /* Miscellaneous flags, see above */ |
147 | /* Syscall handling function */ |
148 | const int *e_errno; /* Errno array */ |
149 | int e_nosys; /* Offset of the nosys() syscall */ |
150 | int e_nsysent; /* Number of system call entries */ |
151 | #endif |
152 | struct sysent *e_sysent; /* System call array */ |
153 | const uint32_t *e_nomodbits; /* sys_nosys/sys_nomodule flags |
154 | * for syscall_disestablish() */ |
155 | const char * const *e_syscallnames; /* System call name array */ |
156 | struct sc_autoload *e_sc_autoload; /* List of autoloadable syscalls */ |
157 | /* Signal sending function */ |
158 | void (*e_sendsig)(const struct ksiginfo *, |
159 | const sigset_t *); |
160 | void (*e_trapsignal)(struct lwp *, struct ksiginfo *); |
161 | char *e_sigcode; /* Start of sigcode */ |
162 | char *e_esigcode; /* End of sigcode */ |
163 | /* Set registers before execution */ |
164 | struct uvm_object **e_sigobject;/* shared sigcode object */ |
165 | void (*e_setregs)(struct lwp *, struct exec_package *, |
166 | vaddr_t); |
167 | |
168 | /* Per-process hooks */ |
169 | void (*e_proc_exec)(struct proc *, struct exec_package *); |
170 | void (*e_proc_fork)(struct proc *, struct lwp *, int); |
171 | void (*e_proc_exit)(struct proc *); |
172 | void (*e_lwp_fork)(struct lwp *, struct lwp *); |
173 | void (*e_lwp_exit)(struct lwp *); |
174 | |
175 | #ifdef __HAVE_SYSCALL_INTERN |
176 | void (*e_syscall_intern)(struct proc *); |
177 | #else |
178 | void (*e_syscall)(void); |
179 | #endif |
180 | /* Emulation specific sysctl data */ |
181 | struct sysctlnode *e_sysctlovly; |
182 | |
183 | vaddr_t (*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t, |
184 | int); |
185 | |
186 | /* Emulation-specific hook for userspace page faults */ |
187 | int (*e_usertrap)(struct lwp *, vaddr_t, void *); |
188 | |
189 | size_t e_ucsize; /* size of ucontext_t */ |
190 | void (*e_startlwp)(void *); |
191 | |
192 | /* Dtrace syscall probe */ |
193 | void (*e_dtrace_syscall)(uint32_t, register_t, |
194 | const struct sysent *, const void *, |
195 | const register_t *, int); |
196 | |
197 | /* Emulation specific support for ktracing signal posts */ |
198 | void (*e_ktrpsig)(int, sig_t, const sigset_t *, |
199 | const struct ksiginfo *); |
200 | }; |
201 | |
202 | /* |
203 | * Emulation miscellaneous flags |
204 | */ |
205 | #define EMUL_HAS_SYS___syscall 0x001 /* Has SYS___syscall */ |
206 | |
207 | /* |
208 | * Description of a process. |
209 | * |
210 | * This structure contains the information needed to manage a thread of |
211 | * control, known in UN*X as a process; it has references to substructures |
212 | * containing descriptions of things that the process uses, but may share |
213 | * with related processes. The process structure and the substructures |
214 | * are always addressible except for those marked "(PROC ONLY)" below, |
215 | * which might be addressible only on a processor on which the process |
216 | * is running. |
217 | * |
218 | * Field markings and the corresponding locks: |
219 | * |
220 | * a: p_auxlock |
221 | * k: ktrace_mutex |
222 | * l: proc_lock |
223 | * t: p_stmutex |
224 | * p: p_lock |
225 | * (: updated atomically |
226 | * :: unlocked, stable |
227 | */ |
228 | struct vmspace; |
229 | |
230 | struct proc { |
231 | LIST_ENTRY(proc) p_list; /* l: List of all processes */ |
232 | |
233 | kmutex_t p_auxlock; /* :: secondary, longer term lock */ |
234 | kmutex_t *p_lock; /* :: general mutex */ |
235 | kmutex_t p_stmutex; /* :: mutex on profiling state */ |
236 | krwlock_t p_reflock; /* p: lock for debugger, procfs */ |
237 | kcondvar_t p_waitcv; /* p: wait, stop CV on children */ |
238 | kcondvar_t p_lwpcv; /* p: wait, stop CV on LWPs */ |
239 | |
240 | /* Substructures: */ |
241 | struct kauth_cred *p_cred; /* p: Master copy of credentials */ |
242 | struct filedesc *p_fd; /* :: Ptr to open files structure */ |
243 | struct cwdinfo *p_cwdi; /* :: cdir/rdir/cmask info */ |
244 | struct pstats *p_stats; /* :: Accounting/stats (PROC ONLY) */ |
245 | struct plimit *p_limit; /* :: Process limits */ |
246 | struct vmspace *p_vmspace; /* :: Address space */ |
247 | struct sigacts *p_sigacts; /* :: Process sigactions */ |
248 | struct aioproc *p_aio; /* p: Asynchronous I/O data */ |
249 | u_int p_mqueue_cnt; /* (: Count of open message queues */ |
250 | specificdata_reference |
251 | p_specdataref; /* subsystem proc-specific data */ |
252 | |
253 | int p_exitsig; /* l: signal to send to parent on exit */ |
254 | int p_flag; /* p: PK_* flags */ |
255 | int p_sflag; /* p: PS_* flags */ |
256 | int p_slflag; /* s, l: PSL_* flags */ |
257 | int p_lflag; /* l: PL_* flags */ |
258 | int p_stflag; /* t: PST_* flags */ |
259 | char p_stat; /* p: S* process status. */ |
260 | char p_trace_enabled;/* p: cached by syscall_intern() */ |
261 | char p_pad1[2]; /* unused */ |
262 | |
263 | pid_t p_pid; /* :: Process identifier. */ |
264 | LIST_ENTRY(proc) p_pglist; /* l: List of processes in pgrp. */ |
265 | struct proc *p_pptr; /* l: Pointer to parent process. */ |
266 | LIST_ENTRY(proc) p_sibling; /* l: List of sibling processes. */ |
267 | LIST_HEAD(, proc) p_children; /* l: List of children. */ |
268 | LIST_HEAD(, lwp) p_lwps; /* p: List of LWPs. */ |
269 | struct ras *p_raslist; /* a: List of RAS entries */ |
270 | |
271 | /* The following fields are all zeroed upon creation in fork. */ |
272 | #define p_startzero p_nlwps |
273 | |
274 | int p_nlwps; /* p: Number of LWPs */ |
275 | int p_nzlwps; /* p: Number of zombie LWPs */ |
276 | int p_nrlwps; /* p: Number running/sleeping LWPs */ |
277 | int p_nlwpwait; /* p: Number of LWPs in lwp_wait1() */ |
278 | int p_ndlwps; /* p: Number of detached LWPs */ |
279 | int p_nlwpid; /* p: Next LWP ID */ |
280 | u_int p_nstopchild; /* l: Count of stopped/dead children */ |
281 | u_int p_waited; /* l: parent has waited on child */ |
282 | struct lwp *p_zomblwp; /* p: detached LWP to be reaped */ |
283 | struct lwp *p_vforklwp; /* p: parent LWP waiting at vfork() */ |
284 | |
285 | /* scheduling */ |
286 | void *p_sched_info; /* p: Scheduler-specific structure */ |
287 | fixpt_t p_estcpu; /* p: Time avg. value of p_cpticks */ |
288 | fixpt_t p_estcpu_inherited; /* p: cpu inherited from children */ |
289 | unsigned int p_forktime; |
290 | fixpt_t p_pctcpu; /* p: %cpu from dead LWPs */ |
291 | |
292 | struct proc *p_opptr; /* l: save parent during ptrace. */ |
293 | struct ptimers *p_timers; /* Timers: real, virtual, profiling */ |
294 | struct bintime p_rtime; /* p: real time */ |
295 | u_quad_t p_uticks; /* t: Statclock hits in user mode */ |
296 | u_quad_t p_sticks; /* t: Statclock hits in system mode */ |
297 | u_quad_t p_iticks; /* t: Statclock hits processing intr */ |
298 | uint64_t p_xutime; /* p: utime exposed to userspace */ |
299 | uint64_t p_xstime; /* p: stime exposed to userspace */ |
300 | |
301 | int p_traceflag; /* k: Kernel trace points */ |
302 | void *p_tracep; /* k: Trace private data */ |
303 | struct vnode *p_textvp; /* :: Vnode of executable */ |
304 | |
305 | struct emul *p_emul; /* :: emulation information */ |
306 | void *p_emuldata; /* :: per-proc emul data, or NULL */ |
307 | const struct execsw *p_execsw; /* :: exec package information */ |
308 | struct klist p_klist; /* p: knotes attached to proc */ |
309 | |
310 | LIST_HEAD(, lwp) p_sigwaiters; /* p: LWPs waiting for signals */ |
311 | sigpend_t p_sigpend; /* p: pending signals */ |
312 | struct lcproc *p_lwpctl; /* p, a: _lwp_ctl() information */ |
313 | pid_t p_ppid; /* :: cached parent pid */ |
314 | pid_t p_fpid; /* :: forked pid */ |
315 | pid_t p_vfpid; /* :: vforked pid */ |
316 | pid_t p_vfpid_done; /* :: vforked done pid */ |
317 | lwpid_t p_lwp_created; /* :: lwp created */ |
318 | lwpid_t p_lwp_exited; /* :: lwp exited */ |
319 | pid_t p_pspid; /* :: posix_spawn pid */ |
320 | char *p_path; /* :: full pathname of executable */ |
321 | |
322 | /* |
323 | * End area that is zeroed on creation |
324 | */ |
325 | #define p_endzero p_startcopy |
326 | |
327 | /* |
328 | * The following fields are all copied upon creation in fork. |
329 | */ |
330 | #define p_startcopy p_sigctx |
331 | |
332 | struct sigctx p_sigctx; /* p: Shared signal state */ |
333 | |
334 | u_char p_nice; /* p: Process "nice" value */ |
335 | char p_comm[MAXCOMLEN+1]; |
336 | /* p: basename of last exec file */ |
337 | struct pgrp *p_pgrp; /* l: Pointer to process group */ |
338 | |
339 | vaddr_t p_psstrp; /* :: address of process's ps_strings */ |
340 | u_int p_pax; /* :: PAX flags */ |
341 | int p_xexit; /* p: exit code */ |
342 | /* |
343 | * End area that is copied on creation |
344 | */ |
345 | #define p_endcopy p_xsig |
346 | u_short p_xsig; /* p: stop signal */ |
347 | u_short p_acflag; /* p: Acc. flags; see struct lwp also */ |
348 | struct mdproc p_md; /* p: Any machine-dependent fields */ |
349 | vaddr_t p_stackbase; /* :: ASLR randomized stack base */ |
350 | struct kdtrace_proc *p_dtrace; /* :: DTrace-specific data. */ |
351 | }; |
352 | |
353 | #define p_rlimit p_limit->pl_rlimit |
354 | #define p_session p_pgrp->pg_session |
355 | #define p_pgid p_pgrp->pg_id |
356 | |
357 | #endif /* _KMEMUSER || _KERNEL */ |
358 | |
359 | /* |
360 | * Status values. |
361 | */ |
362 | #define SIDL 1 /* Process being created by fork */ |
363 | #define SACTIVE 2 /* Process is not stopped */ |
364 | #define SDYING 3 /* About to die */ |
365 | #define SSTOP 4 /* Process debugging or suspension */ |
366 | #define SZOMB 5 /* Awaiting collection by parent */ |
367 | #define SDEAD 6 /* Almost a zombie */ |
368 | |
369 | #define P_ZOMBIE(p) \ |
370 | ((p)->p_stat == SZOMB || (p)->p_stat == SDYING || (p)->p_stat == SDEAD) |
371 | |
372 | /* |
373 | * These flags are kept in p_flag and are protected by p_lock. Access from |
374 | * process context only. |
375 | */ |
376 | #define PK_ADVLOCK 0x00000001 /* Process may hold a POSIX advisory lock */ |
377 | #define PK_SYSTEM 0x00000002 /* System process (kthread) */ |
378 | #define PK_SYSVSEM 0x00000004 /* Used SysV semaphores */ |
379 | #define PK_SUGID 0x00000100 /* Had set id privileges since last exec */ |
380 | #define PK_KMEM 0x00000200 /* Has kmem access */ |
381 | #define PK_EXEC 0x00004000 /* Process called exec */ |
382 | #define PK_NOCLDWAIT 0x00020000 /* No zombies if child dies */ |
383 | #define PK_32 0x00040000 /* 32-bit process (used on 64-bit kernels) */ |
384 | #define PK_CLDSIGIGN 0x00080000 /* Process is ignoring SIGCHLD */ |
385 | #define PK_MARKER 0x80000000 /* Is a dummy marker process */ |
386 | |
387 | /* |
388 | * These flags are kept in p_sflag and are protected by p_lock. Access from |
389 | * process context only. |
390 | */ |
391 | #define PS_NOCLDSTOP 0x00000008 /* No SIGCHLD when children stop */ |
392 | #define PS_RUMP_LWPEXIT 0x00000400 /* LWPs in RUMP kernel should exit for GC */ |
393 | #define PS_WCORE 0x00001000 /* Process needs to dump core */ |
394 | #define PS_WEXIT 0x00002000 /* Working on exiting */ |
395 | #define PS_STOPFORK 0x00800000 /* Child will be stopped on fork(2) */ |
396 | #define PS_STOPEXEC 0x01000000 /* Will be stopped on exec(2) */ |
397 | #define PS_STOPEXIT 0x02000000 /* Will be stopped at process exit */ |
398 | #define PS_COREDUMP 0x20000000 /* Process core-dumped */ |
399 | #define PS_CONTINUED 0x40000000 /* Process is continued */ |
400 | #define PS_STOPPING 0x80000000 /* Transitioning SACTIVE -> SSTOP */ |
401 | |
402 | /* |
403 | * These flags are kept in p_slflag and are protected by the proc_lock |
404 | * and p_lock. Access from process context only. |
405 | */ |
406 | #define PSL_TRACEFORK 0x00000001 /* traced process wants fork events */ |
407 | #define PSL_TRACEVFORK 0x00000002 /* traced process wants vfork events */ |
408 | #define PSL_TRACEVFORK_DONE \ |
409 | 0x00000004 /* traced process wants vfork done events */ |
410 | #define PSL_TRACELWP_CREATE \ |
411 | 0x00000008 /* traced process wants LWP create events */ |
412 | #define PSL_TRACELWP_EXIT \ |
413 | 0x00000010 /* traced process wants LWP exit events */ |
414 | #define PSL_TRACEPOSIX_SPAWN \ |
415 | 0x00000020 /* traced process wants posix_spawn events */ |
416 | |
417 | #define PSL_TRACED 0x00000800 /* Debugged process being traced */ |
418 | #define PSL_CHTRACED 0x00400000 /* Child has been traced & reparented */ |
419 | #define PSL_SYSCALL 0x04000000 /* process has PT_SYSCALL enabled */ |
420 | #define PSL_SYSCALLEMU 0x08000000 /* cancel in-progress syscall */ |
421 | |
422 | /* |
423 | * Kept in p_stflag and protected by p_stmutex. |
424 | */ |
425 | #define PST_PROFIL 0x00000020 /* Has started profiling */ |
426 | |
427 | /* |
428 | * Kept in p_lflag and protected by the proc_lock. Access |
429 | * from process context only. |
430 | */ |
431 | #define PL_CONTROLT 0x00000002 /* Has a controlling terminal */ |
432 | #define PL_PPWAIT 0x00000010 /* Parent is waiting for child exec/exit */ |
433 | #define PL_SIGCOMPAT 0x00000200 /* Has used compat signal trampoline */ |
434 | #define PL_ORPHANPG 0x20000000 /* Member of an orphaned pgrp */ |
435 | |
436 | #if defined(_KMEMUSER) || defined(_KERNEL) |
437 | |
438 | /* |
439 | * Macro to compute the exit signal to be delivered. |
440 | */ |
441 | #define P_EXITSIG(p) \ |
442 | (((p)->p_slflag & PSL_TRACED) ? SIGCHLD : p->p_exitsig) |
443 | /* |
444 | * Compute a wait(2) 16 bit exit status code |
445 | */ |
446 | #define P_WAITSTATUS(p) W_EXITCODE((p)->p_xexit, ((p)->p_xsig | \ |
447 | (((p)->p_sflag & PS_COREDUMP) ? WCOREFLAG : 0))) |
448 | |
449 | LIST_HEAD(proclist, proc); /* A list of processes */ |
450 | |
451 | /* |
452 | * This structure associates a proclist with its lock. |
453 | */ |
454 | struct proclist_desc { |
455 | struct proclist *pd_list; /* The list */ |
456 | /* |
457 | * XXX Add a pointer to the proclist's lock eventually. |
458 | */ |
459 | }; |
460 | |
461 | #ifdef _KERNEL |
462 | |
463 | /* |
464 | * We use process IDs <= PID_MAX until there are > 16k processes. |
465 | * NO_PGID is used to represent "no process group" for a tty. |
466 | */ |
467 | #define PID_MAX 30000 |
468 | #define NO_PGID ((pid_t)-1) |
469 | |
470 | #define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) |
471 | |
472 | /* |
473 | * Flags passed to fork1(). |
474 | */ |
475 | #define FORK_PPWAIT 0x0001 /* Block parent until child exit */ |
476 | #define FORK_SHAREVM 0x0002 /* Share vmspace with parent */ |
477 | #define FORK_SHARECWD 0x0004 /* Share cdir/rdir/cmask */ |
478 | #define FORK_SHAREFILES 0x0008 /* Share file descriptors */ |
479 | #define FORK_SHARESIGS 0x0010 /* Share signal actions */ |
480 | #define FORK_NOWAIT 0x0020 /* Make init the parent of the child */ |
481 | #define FORK_CLEANFILES 0x0040 /* Start with a clean descriptor set */ |
482 | #define FORK_SYSTEM 0x0080 /* Fork a kernel thread */ |
483 | |
484 | extern struct proc proc0; /* Process slot for swapper */ |
485 | extern u_int nprocs; /* Current number of procs */ |
486 | extern int maxproc; /* Max number of procs */ |
487 | #define vmspace_kernel() (proc0.p_vmspace) |
488 | |
489 | extern kmutex_t *proc_lock; |
490 | extern struct proclist allproc; /* List of all processes */ |
491 | extern struct proclist zombproc; /* List of zombie processes */ |
492 | |
493 | extern struct proc *initproc; /* Process slots for init, pager */ |
494 | |
495 | extern const struct proclist_desc proclists[]; |
496 | |
497 | extern struct pool ptimer_pool; /* Memory pool for ptimers */ |
498 | |
499 | int proc_find_locked(struct lwp *, struct proc **, pid_t); |
500 | proc_t * proc_find_raw(pid_t); |
501 | proc_t * proc_find(pid_t); /* Find process by ID */ |
502 | struct pgrp * pgrp_find(pid_t); /* Find process group by ID */ |
503 | |
504 | void procinit(void); |
505 | void procinit_sysctl(void); |
506 | int proc_enterpgrp(struct proc *, pid_t, pid_t, bool); |
507 | void proc_leavepgrp(struct proc *); |
508 | void proc_sesshold(struct session *); |
509 | void proc_sessrele(struct session *); |
510 | void fixjobc(struct proc *, struct pgrp *, int); |
511 | |
512 | int tsleep(wchan_t, pri_t, const char *, int); |
513 | int mtsleep(wchan_t, pri_t, const char *, int, kmutex_t *); |
514 | void wakeup(wchan_t); |
515 | int kpause(const char *, bool, int, kmutex_t *); |
516 | void exit1(struct lwp *, int, int) __dead; |
517 | int kill1(struct lwp *l, pid_t pid, ksiginfo_t *ksi, register_t *retval); |
518 | int do_sys_wait(int *, int *, int, struct rusage *); |
519 | int do_sys_waitid(idtype_t, id_t, int *, int *, int, struct wrusage *, |
520 | siginfo_t *); |
521 | |
522 | struct proc *proc_alloc(void); |
523 | void proc0_init(void); |
524 | pid_t proc_alloc_pid(struct proc *); |
525 | void proc_free_pid(pid_t); |
526 | void proc_free_mem(struct proc *); |
527 | void exit_lwps(struct lwp *l); |
528 | int fork1(struct lwp *, int, int, void *, size_t, |
529 | void (*)(void *), void *, register_t *); |
530 | int pgid_in_session(struct proc *, pid_t); |
531 | void cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t, |
532 | void (*)(void *), void *); |
533 | void cpu_lwp_free(struct lwp *, int); |
534 | void cpu_lwp_free2(struct lwp *); |
535 | void cpu_spawn_return(struct lwp*); |
536 | |
537 | #ifdef __HAVE_SYSCALL_INTERN |
538 | void syscall_intern(struct proc *); |
539 | #endif |
540 | |
541 | void md_child_return(struct lwp *); |
542 | void child_return(void *); |
543 | |
544 | int proc_isunder(struct proc *, struct lwp *); |
545 | int proc_uidmatch(kauth_cred_t, kauth_cred_t); |
546 | |
547 | int proc_vmspace_getref(struct proc *, struct vmspace **); |
548 | void proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool); |
549 | void proc_crmod_enter(void); |
550 | int proc_getauxv(struct proc *, void **, size_t *); |
551 | |
552 | int proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t); |
553 | void proc_specific_key_delete(specificdata_key_t); |
554 | void proc_initspecific(struct proc *); |
555 | void proc_finispecific(struct proc *); |
556 | void * proc_getspecific(struct proc *, specificdata_key_t); |
557 | void proc_setspecific(struct proc *, specificdata_key_t, void *); |
558 | int proc_compare(const struct proc *, const struct lwp *, |
559 | const struct proc *, const struct lwp *); |
560 | |
561 | int proclist_foreach_call(struct proclist *, |
562 | int (*)(struct proc *, void *arg), void *); |
563 | |
564 | static __inline struct proc * |
565 | _proclist_skipmarker(struct proc *p0) |
566 | { |
567 | struct proc *p = p0; |
568 | |
569 | while (p != NULL && p->p_flag & PK_MARKER) |
570 | p = LIST_NEXT(p, p_list); |
571 | |
572 | return p; |
573 | } |
574 | |
575 | #define PROC_PTRSZ(p) (((p)->p_flag & PK_32) ? sizeof(int) : sizeof(void *)) |
576 | #define PROC_REGSZ(p) (((p)->p_flag & PK_32) ? \ |
577 | sizeof(process_reg32) : sizeof(struct reg)) |
578 | #define PROC_FPREGSZ(p) (((p)->p_flag & PK_32) ? \ |
579 | sizeof(process_fpreg32) : sizeof(struct fpreg)) |
580 | #define PROC_DBREGSZ(p) (((p)->p_flag & PK_32) ? \ |
581 | sizeof(process_dbreg32) : sizeof(struct dbreg)) |
582 | |
583 | /* |
584 | * PROCLIST_FOREACH: iterate on the given proclist, skipping PK_MARKER ones. |
585 | */ |
586 | #define PROCLIST_FOREACH(var, head) \ |
587 | for ((var) = LIST_FIRST(head); \ |
588 | ((var) = _proclist_skipmarker(var)) != NULL; \ |
589 | (var) = LIST_NEXT(var, p_list)) |
590 | |
591 | #ifdef KSTACK_CHECK_MAGIC |
592 | void kstack_setup_magic(const struct lwp *); |
593 | void kstack_check_magic(const struct lwp *); |
594 | #else |
595 | #define kstack_setup_magic(x) |
596 | #define kstack_check_magic(x) |
597 | #endif |
598 | |
599 | extern struct emul emul_netbsd; |
600 | |
601 | #endif /* _KERNEL */ |
602 | |
603 | /* |
604 | * Kernel stack parameters. |
605 | * |
606 | * KSTACK_LOWEST_ADDR: return the lowest address of the LWP's kernel stack, |
607 | * excluding red-zone. |
608 | * |
609 | * KSTACK_SIZE: the size kernel stack for a LWP, excluding red-zone. |
610 | * |
611 | * if <machine/proc.h> provides the MD definition, it will be used. |
612 | */ |
613 | #ifndef KSTACK_LOWEST_ADDR |
614 | #define KSTACK_LOWEST_ADDR(l) ((void *)ALIGN((struct pcb *)((l)->l_addr) + 1)) |
615 | #endif |
616 | #ifndef KSTACK_SIZE |
617 | #define KSTACK_SIZE (USPACE - ALIGN(sizeof(struct pcb))) |
618 | #endif |
619 | |
620 | #endif /* _KMEMUSER || _KERNEL */ |
621 | |
622 | #endif /* !_SYS_PROC_H_ */ |
623 | |