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