Annotation of src/sys/sys/proc.h, Revision 1.365
1.365 ! kamil 1: /* $NetBSD: proc.h,v 1.364 2020/04/29 01:52:26 thorpej Exp $ */
1.233 ad 2:
3: /*-
1.358 ad 4: * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
1.233 ad 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: */
1.29 cgd 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.
1.168 agc 49: * 3. Neither the name of the University nor the names of its contributors
1.29 cgd 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: *
1.59 fvdl 65: * @(#)proc.h 8.15 (Berkeley) 5/19/95
1.29 cgd 66: */
67:
68: #ifndef _SYS_PROC_H_
69: #define _SYS_PROC_H_
1.57 mrg 70:
1.319 dsl 71: #include <sys/lwp.h>
72:
73: #if defined(_KMEMUSER) || defined(_KERNEL)
74:
1.131 mrg 75: #if defined(_KERNEL_OPT)
1.83 thorpej 76: #include "opt_multiprocessor.h"
1.139 yamt 77: #include "opt_kstack.h"
1.224 yamt 78: #include "opt_lockdebug.h"
1.83 thorpej 79: #endif
80:
1.122 lukem 81: #include <machine/proc.h> /* Machine-dependent proc substruct */
1.318 msaitoh 82: #include <machine/pcb.h>
1.245 rmind 83: #include <sys/aio.h>
1.333 skrll 84: #include <sys/idtype.h>
1.233 ad 85: #include <sys/rwlock.h>
1.254 rmind 86: #include <sys/mqueue.h>
1.233 ad 87: #include <sys/mutex.h>
88: #include <sys/condvar.h>
1.32 mycroft 89: #include <sys/queue.h>
1.358 ad 90: #include <sys/radixtree.h>
1.118 jdolecek 91: #include <sys/signalvar.h>
1.170 christos 92: #include <sys/siginfo.h>
1.147 jdolecek 93: #include <sys/event.h>
1.228 thorpej 94: #include <sys/specificdata.h>
1.29 cgd 95:
1.220 yamt 96: #ifndef _KERNEL
97: #include <sys/time.h>
98: #include <sys/resource.h>
99: #endif
100:
1.29 cgd 101: /*
102: * One structure allocated per session.
103: */
1.122 lukem 104: struct session {
105: int s_count; /* Ref cnt; pgrps in session */
1.159 dsl 106: u_int s_flags;
107: #define S_LOGIN_SET 1 /* s_login set in this session */
1.122 lukem 108: struct proc *s_leader; /* Session leader */
109: struct vnode *s_ttyvp; /* Vnode of controlling terminal */
110: struct tty *s_ttyp; /* Controlling terminal */
111: char s_login[MAXLOGNAME]; /* Setlogin() name */
112: pid_t s_sid; /* Session ID (pid of leader) */
1.29 cgd 113: };
114:
115: /*
116: * One structure allocated per process group.
117: */
1.122 lukem 118: struct pgrp {
119: LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members */
120: struct session *pg_session; /* Pointer to session */
121: pid_t pg_id; /* Pgrp id */
122: int pg_jobc; /*
123: * Number of processes qualifying
124: * pgrp for job control
125: */
1.29 cgd 126: };
127:
128: /*
1.325 pgoyette 129: * Autoloadable syscall definition
130: */
1.326 pgoyette 131: struct sc_autoload {
1.325 pgoyette 132: u_int al_code;
133: const char *al_module;
134: };
135:
136: /*
1.40 christos 137: * One structure allocated per emulation.
138: */
139: struct exec_package;
1.144 gmcgarry 140: struct ras;
1.221 elad 141: struct kauth_cred;
1.40 christos 142:
1.122 lukem 143: struct emul {
144: const char *e_name; /* Symbolic name */
145: const char *e_path; /* Extra emulation path (NULL if none)*/
1.130 manu 146: #ifndef __HAVE_MINIMAL_EMUL
1.129 manu 147: int e_flags; /* Miscellaneous flags, see above */
1.116 mycroft 148: /* Syscall handling function */
1.122 lukem 149: const int *e_errno; /* Errno array */
150: int e_nosys; /* Offset of the nosys() syscall */
151: int e_nsysent; /* Number of system call entries */
1.116 mycroft 152: #endif
1.282 ad 153: struct sysent *e_sysent; /* System call array */
1.349 pgoyette 154: const uint32_t *e_nomodbits; /* sys_nosys/sys_nomodule flags
155: * for syscall_disestablish() */
1.122 lukem 156: const char * const *e_syscallnames; /* System call name array */
1.355 pgoyette 157: struct sc_autoload *e_sc_autoload; /* List of autoloadable syscalls */
1.120 jdolecek 158: /* Signal sending function */
1.196 perry 159: void (*e_sendsig)(const struct ksiginfo *,
160: const sigset_t *);
1.233 ad 161: void (*e_trapsignal)(struct lwp *, struct ksiginfo *);
1.122 lukem 162: char *e_sigcode; /* Start of sigcode */
163: char *e_esigcode; /* End of sigcode */
1.134 jdolecek 164: /* Set registers before execution */
1.169 chs 165: struct uvm_object **e_sigobject;/* shared sigcode object */
1.196 perry 166: void (*e_setregs)(struct lwp *, struct exec_package *,
1.294 matt 167: vaddr_t);
1.106 jdolecek 168:
1.112 jdolecek 169: /* Per-process hooks */
1.196 perry 170: void (*e_proc_exec)(struct proc *, struct exec_package *);
1.298 chs 171: void (*e_proc_fork)(struct proc *, struct lwp *, int);
1.196 perry 172: void (*e_proc_exit)(struct proc *);
173: void (*e_lwp_fork)(struct lwp *, struct lwp *);
174: void (*e_lwp_exit)(struct lwp *);
1.112 jdolecek 175:
1.116 mycroft 176: #ifdef __HAVE_SYSCALL_INTERN
1.196 perry 177: void (*e_syscall_intern)(struct proc *);
1.116 mycroft 178: #else
1.196 perry 179: void (*e_syscall)(void);
1.116 mycroft 180: #endif
1.180 atatat 181: /* Emulation specific sysctl data */
182: struct sysctlnode *e_sysctlovly;
1.198 fvdl 183:
1.324 martin 184: vaddr_t (*e_vm_default_addr)(struct proc *, vaddr_t, vsize_t,
185: int);
1.200 fvdl 186:
187: /* Emulation-specific hook for userspace page faults */
188: int (*e_usertrap)(struct lwp *, vaddr_t, void *);
1.218 cube 189:
1.233 ad 190: size_t e_ucsize; /* size of ucontext_t */
1.239 cube 191: void (*e_startlwp)(void *);
1.321 christos 192:
193: /* Dtrace syscall probe */
194: void (*e_dtrace_syscall)(uint32_t, register_t,
195: const struct sysent *, const void *,
196: const register_t *, int);
1.332 martin 197:
198: /* Emulation specific support for ktracing signal posts */
199: void (*e_ktrpsig)(int, sig_t, const sigset_t *,
200: const struct ksiginfo *);
1.40 christos 201: };
202:
1.197 perry 203: /*
1.341 khorben 204: * Emulation miscellaneous flags
1.127 manu 205: */
1.122 lukem 206: #define EMUL_HAS_SYS___syscall 0x001 /* Has SYS___syscall */
1.114 mycroft 207:
1.40 christos 208: /*
1.29 cgd 209: * Description of a process.
210: *
211: * This structure contains the information needed to manage a thread of
212: * control, known in UN*X as a process; it has references to substructures
213: * containing descriptions of things that the process uses, but may share
214: * with related processes. The process structure and the substructures
215: * are always addressible except for those marked "(PROC ONLY)" below,
216: * which might be addressible only on a processor on which the process
217: * is running.
1.175 dsl 218: *
1.307 rmind 219: * Field markings and the corresponding locks:
1.223 ad 220: *
1.268 ad 221: * a: p_auxlock
1.233 ad 222: * k: ktrace_mutex
1.272 ad 223: * l: proc_lock
1.233 ad 224: * t: p_stmutex
1.273 ad 225: * p: p_lock
1.307 rmind 226: * (: updated atomically
1.270 ad 227: * :: unlocked, stable
1.29 cgd 228: */
1.308 uebayasi 229: struct vmspace;
230:
1.122 lukem 231: struct proc {
1.272 ad 232: LIST_ENTRY(proc) p_list; /* l: List of all processes */
1.273 ad 233: kmutex_t *p_lock; /* :: general mutex */
234: kcondvar_t p_waitcv; /* p: wait, stop CV on children */
235: kcondvar_t p_lwpcv; /* p: wait, stop CV on LWPs */
1.317 rmind 236:
1.122 lukem 237: /* Substructures: */
1.233 ad 238: struct kauth_cred *p_cred; /* p: Master copy of credentials */
1.270 ad 239: struct filedesc *p_fd; /* :: Ptr to open files structure */
240: struct cwdinfo *p_cwdi; /* :: cdir/rdir/cmask info */
241: struct pstats *p_stats; /* :: Accounting/stats (PROC ONLY) */
242: struct plimit *p_limit; /* :: Process limits */
243: struct vmspace *p_vmspace; /* :: Address space */
244: struct sigacts *p_sigacts; /* :: Process sigactions */
1.245 rmind 245: struct aioproc *p_aio; /* p: Asynchronous I/O data */
1.307 rmind 246: u_int p_mqueue_cnt; /* (: Count of open message queues */
1.228 thorpej 247: specificdata_reference
1.270 ad 248: p_specdataref; /* subsystem proc-specific data */
1.228 thorpej 249:
1.233 ad 250: int p_exitsig; /* l: signal to send to parent on exit */
1.289 yamt 251: int p_flag; /* p: PK_* flags */
1.273 ad 252: int p_sflag; /* p: PS_* flags */
1.361 christos 253: int p_slflag; /* p, l: PSL_* flags */
1.233 ad 254: int p_lflag; /* l: PL_* flags */
255: int p_stflag; /* t: PST_* flags */
1.273 ad 256: char p_stat; /* p: S* process status. */
257: char p_trace_enabled;/* p: cached by syscall_intern() */
1.270 ad 258: char p_pad1[2]; /* unused */
1.122 lukem 259:
1.270 ad 260: pid_t p_pid; /* :: Process identifier. */
1.176 dsl 261: LIST_ENTRY(proc) p_pglist; /* l: List of processes in pgrp. */
262: struct proc *p_pptr; /* l: Pointer to parent process. */
263: LIST_ENTRY(proc) p_sibling; /* l: List of sibling processes. */
1.233 ad 264: LIST_HEAD(, proc) p_children; /* l: List of children. */
1.273 ad 265: LIST_HEAD(, lwp) p_lwps; /* p: List of LWPs. */
1.268 ad 266: struct ras *p_raslist; /* a: List of RAS entries */
1.29 cgd 267:
1.153 thorpej 268: /* The following fields are all zeroed upon creation in fork. */
269: #define p_startzero p_nlwps
270:
1.273 ad 271: int p_nlwps; /* p: Number of LWPs */
272: int p_nzlwps; /* p: Number of zombie LWPs */
273: int p_nrlwps; /* p: Number running/sleeping LWPs */
274: int p_nlwpwait; /* p: Number of LWPs in lwp_wait1() */
275: int p_ndlwps; /* p: Number of detached LWPs */
1.272 ad 276: u_int p_nstopchild; /* l: Count of stopped/dead children */
277: u_int p_waited; /* l: parent has waited on child */
1.273 ad 278: struct lwp *p_zomblwp; /* p: detached LWP to be reaped */
1.317 rmind 279: struct lwp *p_vforklwp; /* p: parent LWP waiting at vfork() */
1.29 cgd 280:
1.153 thorpej 281: /* scheduling */
1.273 ad 282: void *p_sched_info; /* p: Scheduler-specific structure */
283: fixpt_t p_estcpu; /* p: Time avg. value of p_cpticks */
284: fixpt_t p_estcpu_inherited; /* p: cpu inherited from children */
1.210 yamt 285: unsigned int p_forktime;
1.273 ad 286: fixpt_t p_pctcpu; /* p: %cpu from dead LWPs */
1.197 perry 287:
1.233 ad 288: struct proc *p_opptr; /* l: save parent during ptrace. */
289: struct ptimers *p_timers; /* Timers: real, virtual, profiling */
1.273 ad 290: struct bintime p_rtime; /* p: real time */
1.233 ad 291: u_quad_t p_uticks; /* t: Statclock hits in user mode */
292: u_quad_t p_sticks; /* t: Statclock hits in system mode */
293: u_quad_t p_iticks; /* t: Statclock hits processing intr */
1.348 kre 294: uint64_t p_xutime; /* p: utime exposed to userspace */
295: uint64_t p_xstime; /* p: stime exposed to userspace */
1.233 ad 296:
297: int p_traceflag; /* k: Kernel trace points */
298: void *p_tracep; /* k: Trace private data */
1.270 ad 299: struct vnode *p_textvp; /* :: Vnode of executable */
1.233 ad 300:
1.283 ad 301: struct emul *p_emul; /* :: emulation information */
1.270 ad 302: void *p_emuldata; /* :: per-proc emul data, or NULL */
303: const struct execsw *p_execsw; /* :: exec package information */
304: struct klist p_klist; /* p: knotes attached to proc */
1.197 perry 305:
1.273 ad 306: LIST_HEAD(, lwp) p_sigwaiters; /* p: LWPs waiting for signals */
307: sigpend_t p_sigpend; /* p: pending signals */
1.270 ad 308: struct lcproc *p_lwpctl; /* p, a: _lwp_ctl() information */
1.277 ad 309: pid_t p_ppid; /* :: cached parent pid */
1.362 kamil 310: pid_t p_oppid; /* :: cached original parent pid */
1.343 christos 311: char *p_path; /* :: full pathname of executable */
1.29 cgd 312:
1.122 lukem 313: /*
314: * End area that is zeroed on creation
315: */
1.29 cgd 316: #define p_endzero p_startcopy
317:
1.122 lukem 318: /*
319: * The following fields are all copied upon creation in fork.
320: */
1.233 ad 321: #define p_startcopy p_sigctx
1.122 lukem 322:
1.273 ad 323: struct sigctx p_sigctx; /* p: Shared signal state */
1.29 cgd 324:
1.273 ad 325: u_char p_nice; /* p: Process "nice" value */
1.233 ad 326: char p_comm[MAXCOMLEN+1];
327: /* p: basename of last exec file */
328: struct pgrp *p_pgrp; /* l: Pointer to process group */
329:
1.301 joerg 330: vaddr_t p_psstrp; /* :: address of process's ps_strings */
1.279 ad 331: u_int p_pax; /* :: PAX flags */
1.328 christos 332: int p_xexit; /* p: exit code */
1.197 perry 333: /*
1.122 lukem 334: * End area that is copied on creation
335: */
1.328 christos 336: #define p_endcopy p_xsig
337: u_short p_xsig; /* p: stop signal */
1.223 ad 338: u_short p_acflag; /* p: Acc. flags; see struct lwp also */
1.270 ad 339: struct mdproc p_md; /* p: Any machine-dependent fields */
340: vaddr_t p_stackbase; /* :: ASLR randomized stack base */
1.295 darran 341: struct kdtrace_proc *p_dtrace; /* :: DTrace-specific data. */
1.358 ad 342: /*
343: * Locks in their own cache line towards the end.
344: */
345: kmutex_t p_auxlock /* :: secondary, longer term lock */
346: __aligned(COHERENCY_UNIT);
347: kmutex_t p_stmutex; /* :: mutex on profiling state */
348: krwlock_t p_reflock; /* :: lock for debugger, procfs */
1.29 cgd 349: };
350:
1.233 ad 351: #define p_rlimit p_limit->pl_rlimit
1.29 cgd 352: #define p_session p_pgrp->pg_session
353: #define p_pgid p_pgrp->pg_id
354:
1.319 dsl 355: #endif /* _KMEMUSER || _KERNEL */
356:
1.91 thorpej 357: /*
358: * Status values.
359: */
1.122 lukem 360: #define SIDL 1 /* Process being created by fork */
1.153 thorpej 361: #define SACTIVE 2 /* Process is not stopped */
1.233 ad 362: #define SDYING 3 /* About to die */
1.122 lukem 363: #define SSTOP 4 /* Process debugging or suspension */
364: #define SZOMB 5 /* Awaiting collection by parent */
1.233 ad 365: #define SDEAD 6 /* Almost a zombie */
1.79 thorpej 366:
1.233 ad 367: #define P_ZOMBIE(p) \
368: ((p)->p_stat == SZOMB || (p)->p_stat == SDYING || (p)->p_stat == SDEAD)
1.29 cgd 369:
1.233 ad 370: /*
1.273 ad 371: * These flags are kept in p_flag and are protected by p_lock. Access from
1.233 ad 372: * process context only.
373: */
1.237 pavel 374: #define PK_ADVLOCK 0x00000001 /* Process may hold a POSIX advisory lock */
375: #define PK_SYSTEM 0x00000002 /* System process (kthread) */
1.274 ad 376: #define PK_SYSVSEM 0x00000004 /* Used SysV semaphores */
1.237 pavel 377: #define PK_SUGID 0x00000100 /* Had set id privileges since last exec */
1.350 christos 378: #define PK_KMEM 0x00000200 /* Has kmem access */
1.237 pavel 379: #define PK_EXEC 0x00004000 /* Process called exec */
380: #define PK_NOCLDWAIT 0x00020000 /* No zombies if child dies */
381: #define PK_32 0x00040000 /* 32-bit process (used on 64-bit kernels) */
382: #define PK_CLDSIGIGN 0x00080000 /* Process is ignoring SIGCHLD */
383: #define PK_MARKER 0x80000000 /* Is a dummy marker process */
1.29 cgd 384:
1.233 ad 385: /*
1.273 ad 386: * These flags are kept in p_sflag and are protected by p_lock. Access from
387: * process context only.
1.233 ad 388: */
389: #define PS_NOCLDSTOP 0x00000008 /* No SIGCHLD when children stop */
1.316 rmind 390: #define PS_RUMP_LWPEXIT 0x00000400 /* LWPs in RUMP kernel should exit for GC */
1.233 ad 391: #define PS_WCORE 0x00001000 /* Process needs to dump core */
392: #define PS_WEXIT 0x00002000 /* Working on exiting */
393: #define PS_STOPFORK 0x00800000 /* Child will be stopped on fork(2) */
394: #define PS_STOPEXEC 0x01000000 /* Will be stopped on exec(2) */
395: #define PS_STOPEXIT 0x02000000 /* Will be stopped at process exit */
1.328 christos 396: #define PS_COREDUMP 0x20000000 /* Process core-dumped */
1.330 christos 397: #define PS_CONTINUED 0x40000000 /* Process is continued */
1.233 ad 398: #define PS_STOPPING 0x80000000 /* Transitioning SACTIVE -> SSTOP */
399:
400: /*
1.328 christos 401: * These flags are kept in p_slflag and are protected by the proc_lock
1.273 ad 402: * and p_lock. Access from process context only.
1.233 ad 403: */
1.310 christos 404: #define PSL_TRACEFORK 0x00000001 /* traced process wants fork events */
1.336 kamil 405: #define PSL_TRACEVFORK 0x00000002 /* traced process wants vfork events */
406: #define PSL_TRACEVFORK_DONE \
407: 0x00000004 /* traced process wants vfork done events */
1.337 kamil 408: #define PSL_TRACELWP_CREATE \
409: 0x00000008 /* traced process wants LWP create events */
410: #define PSL_TRACELWP_EXIT \
411: 0x00000010 /* traced process wants LWP exit events */
1.353 kamil 412: #define PSL_TRACEPOSIX_SPAWN \
413: 0x00000020 /* traced process wants posix_spawn events */
1.337 kamil 414:
1.233 ad 415: #define PSL_TRACED 0x00000800 /* Debugged process being traced */
1.365 ! kamil 416: #define PSL_TRACEDCHILD 0x00001000 /* Report process birth */
1.233 ad 417: #define PSL_CHTRACED 0x00400000 /* Child has been traced & reparented */
418: #define PSL_SYSCALL 0x04000000 /* process has PT_SYSCALL enabled */
1.309 jmcneill 419: #define PSL_SYSCALLEMU 0x08000000 /* cancel in-progress syscall */
1.233 ad 420:
421: /*
422: * Kept in p_stflag and protected by p_stmutex.
423: */
424: #define PST_PROFIL 0x00000020 /* Has started profiling */
425:
426: /*
1.328 christos 427: * Kept in p_lflag and protected by the proc_lock. Access
1.233 ad 428: * from process context only.
429: */
430: #define PL_CONTROLT 0x00000002 /* Has a controlling terminal */
1.280 ad 431: #define PL_PPWAIT 0x00000010 /* Parent is waiting for child exec/exit */
1.283 ad 432: #define PL_SIGCOMPAT 0x00000200 /* Has used compat signal trampoline */
1.272 ad 433: #define PL_ORPHANPG 0x20000000 /* Member of an orphaned pgrp */
1.219 christos 434:
1.319 dsl 435: #if defined(_KMEMUSER) || defined(_KERNEL)
436:
1.29 cgd 437: /*
1.78 thorpej 438: * Macro to compute the exit signal to be delivered.
1.76 thorpej 439: */
1.233 ad 440: #define P_EXITSIG(p) \
1.342 kamil 441: (((p)->p_slflag & PSL_TRACED) ? SIGCHLD : p->p_exitsig)
1.328 christos 442: /*
443: * Compute a wait(2) 16 bit exit status code
444: */
445: #define P_WAITSTATUS(p) W_EXITCODE((p)->p_xexit, ((p)->p_xsig | \
446: (((p)->p_sflag & PS_COREDUMP) ? WCOREFLAG : 0)))
1.76 thorpej 447:
1.122 lukem 448: LIST_HEAD(proclist, proc); /* A list of processes */
1.64 thorpej 449:
450: /*
451: * This structure associates a proclist with its lock.
452: */
453: struct proclist_desc {
1.122 lukem 454: struct proclist *pd_list; /* The list */
1.64 thorpej 455: /*
456: * XXX Add a pointer to the proclist's lock eventually.
457: */
458: };
459:
1.38 jtc 460: #ifdef _KERNEL
1.156 thorpej 461:
1.29 cgd 462: /*
1.162 dsl 463: * We use process IDs <= PID_MAX until there are > 16k processes.
464: * NO_PGID is used to represent "no process group" for a tty.
1.29 cgd 465: */
466: #define PID_MAX 30000
1.163 jdolecek 467: #define NO_PGID ((pid_t)-1)
1.29 cgd 468:
1.122 lukem 469: #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
1.54 thorpej 470:
471: /*
472: * Flags passed to fork1().
473: */
1.255 dsl 474: #define FORK_PPWAIT 0x0001 /* Block parent until child exit */
475: #define FORK_SHAREVM 0x0002 /* Share vmspace with parent */
476: #define FORK_SHARECWD 0x0004 /* Share cdir/rdir/cmask */
477: #define FORK_SHAREFILES 0x0008 /* Share file descriptors */
478: #define FORK_SHARESIGS 0x0010 /* Share signal actions */
479: #define FORK_NOWAIT 0x0020 /* Make init the parent of the child */
480: #define FORK_CLEANFILES 0x0040 /* Start with a clean descriptor set */
481: #define FORK_SYSTEM 0x0080 /* Fork a kernel thread */
1.41 mycroft 482:
1.122 lukem 483: extern struct proc proc0; /* Process slot for swapper */
1.262 ad 484: extern u_int nprocs; /* Current number of procs */
485: extern int maxproc; /* Max number of procs */
1.213 yamt 486: #define vmspace_kernel() (proc0.p_vmspace)
1.29 cgd 487:
1.272 ad 488: extern kmutex_t *proc_lock;
1.122 lukem 489: extern struct proclist allproc; /* List of all processes */
490: extern struct proclist zombproc; /* List of zombie processes */
1.79 thorpej 491:
1.122 lukem 492: extern struct proc *initproc; /* Process slots for init, pager */
1.61 thorpej 493:
1.64 thorpej 494: extern const struct proclist_desc proclists[];
495:
1.153 thorpej 496: extern struct pool ptimer_pool; /* Memory pool for ptimers */
1.29 cgd 497:
1.323 christos 498: int proc_find_locked(struct lwp *, struct proc **, pid_t);
1.297 rmind 499: proc_t * proc_find_raw(pid_t);
500: proc_t * proc_find(pid_t); /* Find process by ID */
1.364 thorpej 501: proc_t * proc_find_lwpid(pid_t); /* Find process by LWP ID */
1.363 thorpej 502: struct lwp * proc_find_lwp(proc_t *, pid_t); /* Find LWP in proc by ID */
1.364 thorpej 503: /* Find LWP, acquire proc */
504: struct lwp * proc_find_lwp_acquire_proc(pid_t, proc_t **);
1.297 rmind 505: struct pgrp * pgrp_find(pid_t); /* Find process group by ID */
1.288 rmind 506:
507: void procinit(void);
1.300 pooka 508: void procinit_sysctl(void);
1.288 rmind 509: int proc_enterpgrp(struct proc *, pid_t, pid_t, bool);
510: void proc_leavepgrp(struct proc *);
511: void proc_sesshold(struct session *);
512: void proc_sessrele(struct session *);
1.167 itojun 513: void fixjobc(struct proc *, struct pgrp *, int);
1.287 rmind 514:
1.314 rmind 515: int tsleep(wchan_t, pri_t, const char *, int);
1.244 ad 516: int mtsleep(wchan_t, pri_t, const char *, int, kmutex_t *);
1.233 ad 517: void wakeup(wchan_t);
1.240 thorpej 518: int kpause(const char *, bool, int, kmutex_t *);
1.329 christos 519: void exit1(struct lwp *, int, int) __dead;
1.322 martin 520: int kill1(struct lwp *l, pid_t pid, ksiginfo_t *ksi, register_t *retval);
1.293 rmind 521: int do_sys_wait(int *, int *, int, struct rusage *);
1.333 skrll 522: int do_sys_waitid(idtype_t, id_t, int *, int *, int, struct wrusage *,
523: siginfo_t *);
524:
1.162 dsl 525: struct proc *proc_alloc(void);
1.204 junyoung 526: void proc0_init(void);
1.298 chs 527: pid_t proc_alloc_pid(struct proc *);
528: void proc_free_pid(pid_t);
1.363 thorpej 529: pid_t proc_alloc_lwpid(struct proc *, struct lwp *);
530: void proc_free_lwpid(struct proc *, pid_t);
1.265 ad 531: void proc_free_mem(struct proc *);
1.153 thorpej 532: void exit_lwps(struct lwp *l);
533: int fork1(struct lwp *, int, int, void *, size_t,
1.345 kamil 534: void (*)(void *), void *, register_t *);
1.161 dsl 535: int pgid_in_session(struct proc *, pid_t);
1.153 thorpej 536: void cpu_lwp_fork(struct lwp *, struct lwp *, void *, size_t,
1.122 lukem 537: void (*)(void *), void *);
1.186 jdolecek 538: void cpu_lwp_free(struct lwp *, int);
1.233 ad 539: void cpu_lwp_free2(struct lwp *);
1.315 martin 540: void cpu_spawn_return(struct lwp*);
1.122 lukem 541:
1.202 christos 542: #ifdef __HAVE_SYSCALL_INTERN
543: void syscall_intern(struct proc *);
544: #endif
545:
1.352 kamil 546: void md_child_return(struct lwp *);
1.122 lukem 547: void child_return(void *);
548:
1.209 christos 549: int proc_isunder(struct proc *, struct lwp *);
1.291 elad 550: int proc_uidmatch(kauth_cred_t, kauth_cred_t);
1.122 lukem 551:
1.213 yamt 552: int proc_vmspace_getref(struct proc *, struct vmspace **);
1.240 thorpej 553: void proc_crmod_leave(kauth_cred_t, kauth_cred_t, bool);
1.233 ad 554: void proc_crmod_enter(void);
1.340 christos 555: int proc_getauxv(struct proc *, void **, size_t *);
1.213 yamt 556:
1.228 thorpej 557: int proc_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
558: void proc_specific_key_delete(specificdata_key_t);
1.287 rmind 559: void proc_initspecific(struct proc *);
560: void proc_finispecific(struct proc *);
1.228 thorpej 561: void * proc_getspecific(struct proc *, specificdata_key_t);
562: void proc_setspecific(struct proc *, specificdata_key_t, void *);
1.311 christos 563: int proc_compare(const struct proc *, const struct lwp *,
564: const struct proc *, const struct lwp *);
1.228 thorpej 565:
1.195 yamt 566: int proclist_foreach_call(struct proclist *,
567: int (*)(struct proc *, void *arg), void *);
568:
1.346 christos 569: static __inline struct proc *
1.195 yamt 570: _proclist_skipmarker(struct proc *p0)
571: {
572: struct proc *p = p0;
573:
1.237 pavel 574: while (p != NULL && p->p_flag & PK_MARKER)
1.195 yamt 575: p = LIST_NEXT(p, p_list);
576:
577: return p;
578: }
1.296 yamt 579:
1.334 christos 580: #define PROC_PTRSZ(p) (((p)->p_flag & PK_32) ? sizeof(int) : sizeof(void *))
1.335 skrll 581: #define PROC_REGSZ(p) (((p)->p_flag & PK_32) ? \
582: sizeof(process_reg32) : sizeof(struct reg))
583: #define PROC_FPREGSZ(p) (((p)->p_flag & PK_32) ? \
584: sizeof(process_fpreg32) : sizeof(struct fpreg))
1.338 kamil 585: #define PROC_DBREGSZ(p) (((p)->p_flag & PK_32) ? \
586: sizeof(process_dbreg32) : sizeof(struct dbreg))
1.334 christos 587:
1.296 yamt 588: /*
589: * PROCLIST_FOREACH: iterate on the given proclist, skipping PK_MARKER ones.
590: */
1.195 yamt 591: #define PROCLIST_FOREACH(var, head) \
592: for ((var) = LIST_FIRST(head); \
593: ((var) = _proclist_skipmarker(var)) != NULL; \
594: (var) = LIST_NEXT(var, p_list))
595:
1.303 mrg 596: #ifdef KSTACK_CHECK_MAGIC
597: void kstack_setup_magic(const struct lwp *);
598: void kstack_check_magic(const struct lwp *);
599: #else
600: #define kstack_setup_magic(x)
601: #define kstack_check_magic(x)
602: #endif
603:
604: extern struct emul emul_netbsd;
605:
606: #endif /* _KERNEL */
607:
1.139 yamt 608: /*
1.299 rmind 609: * Kernel stack parameters.
610: *
611: * KSTACK_LOWEST_ADDR: return the lowest address of the LWP's kernel stack,
612: * excluding red-zone.
613: *
614: * KSTACK_SIZE: the size kernel stack for a LWP, excluding red-zone.
1.290 yamt 615: *
616: * if <machine/proc.h> provides the MD definition, it will be used.
617: */
1.139 yamt 618: #ifndef KSTACK_LOWEST_ADDR
1.299 rmind 619: #define KSTACK_LOWEST_ADDR(l) ((void *)ALIGN((struct pcb *)((l)->l_addr) + 1))
1.139 yamt 620: #endif
621: #ifndef KSTACK_SIZE
1.299 rmind 622: #define KSTACK_SIZE (USPACE - ALIGN(sizeof(struct pcb)))
623: #endif
624:
1.303 mrg 625: #endif /* _KMEMUSER || _KERNEL */
1.98 thorpej 626:
1.29 cgd 627: #endif /* !_SYS_PROC_H_ */
CVSweb <webmaster@jp.NetBSD.org>