proc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /* $OpenBSD: proc.h,v 1.203 2015/07/27 18:22:37 deraadt Exp $ */
  2. /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
  3. /*-
  4. * Copyright (c) 1986, 1989, 1991, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. * (c) UNIX System Laboratories, Inc.
  7. * All or some portions of this file are derived from material licensed
  8. * to the University of California by American Telephone and Telegraph
  9. * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  10. * the permission of UNIX System Laboratories, Inc.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of the University nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * @(#)proc.h 8.8 (Berkeley) 1/21/94
  37. */
  38. #ifndef _SYS_PROC_H_
  39. #define _SYS_PROC_H_
  40. #include <machine/proc.h> /* Machine-dependent proc substruct. */
  41. #include <sys/selinfo.h> /* For struct selinfo */
  42. #include <sys/syslimits.h> /* For LOGIN_NAME_MAX */
  43. #include <sys/queue.h>
  44. #include <sys/timeout.h> /* For struct timeout */
  45. #include <sys/event.h> /* For struct klist */
  46. #include <sys/mutex.h> /* For struct mutex */
  47. #include <sys/resource.h> /* For struct rusage */
  48. #include <machine/atomic.h>
  49. #ifdef _KERNEL
  50. #define __need_process
  51. #endif
  52. /*
  53. * One structure allocated per session.
  54. */
  55. struct process;
  56. struct session {
  57. int s_count; /* Ref cnt; pgrps in session. */
  58. struct process *s_leader; /* Session leader. */
  59. struct vnode *s_ttyvp; /* Vnode of controlling terminal. */
  60. struct tty *s_ttyp; /* Controlling terminal. */
  61. char s_login[LOGIN_NAME_MAX]; /* Setlogin() name. */
  62. };
  63. /*
  64. * One structure allocated per process group.
  65. */
  66. struct pgrp {
  67. LIST_ENTRY(pgrp) pg_hash; /* Hash chain. */
  68. LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */
  69. struct session *pg_session; /* Pointer to session. */
  70. pid_t pg_id; /* Pgrp id. */
  71. int pg_jobc; /* # procs qualifying pgrp for job control */
  72. };
  73. /*
  74. * One structure allocated per emulation.
  75. */
  76. struct exec_package;
  77. struct proc;
  78. struct ps_strings;
  79. struct uvm_object;
  80. union sigval;
  81. struct emul {
  82. char e_name[8]; /* Symbolic name */
  83. int *e_errno; /* Errno array */
  84. /* Signal sending function */
  85. void (*e_sendsig)(void (*)(int), int, int, u_long, int, union sigval);
  86. int e_nosys; /* Offset of the nosys() syscall */
  87. int e_nsysent; /* Number of system call entries */
  88. struct sysent *e_sysent; /* System call array */
  89. char **e_syscallnames; /* System call name array */
  90. int e_arglen; /* Extra argument size in words */
  91. /* Copy arguments on the stack */
  92. void *(*e_copyargs)(struct exec_package *, struct ps_strings *,
  93. void *, void *);
  94. /* Set registers before execution */
  95. void (*e_setregs)(struct proc *, struct exec_package *,
  96. u_long, register_t *);
  97. int (*e_fixup)(struct proc *, struct exec_package *);
  98. int (*e_coredump)(struct proc *, void *cookie);
  99. char *e_sigcode; /* Start of sigcode */
  100. char *e_esigcode; /* End of sigcode */
  101. int e_flags; /* Flags, see below */
  102. struct uvm_object *e_sigobject; /* shared sigcode object */
  103. /* Per-process hooks */
  104. void (*e_proc_exec)(struct proc *, struct exec_package *);
  105. void (*e_proc_fork)(struct proc *p, struct proc *parent);
  106. void (*e_proc_exit)(struct proc *);
  107. };
  108. /* Flags for e_flags */
  109. #define EMUL_ENABLED 0x0001 /* Allow exec to continue */
  110. #define EMUL_NATIVE 0x0002 /* Always enabled */
  111. /*
  112. * time usage: accumulated times in ticks
  113. * One a second, each thread's immediate counts (p_[usi]ticks) are
  114. * accumulated into these.
  115. */
  116. struct tusage {
  117. struct timespec tu_runtime; /* Realtime. */
  118. uint64_t tu_uticks; /* Statclock hits in user mode. */
  119. uint64_t tu_sticks; /* Statclock hits in system mode. */
  120. uint64_t tu_iticks; /* Statclock hits processing intr. */
  121. };
  122. /*
  123. * Description of a process.
  124. *
  125. * These structures contain the information needed to manage a thread of
  126. * control, known in UN*X as a process; it has references to substructures
  127. * containing descriptions of things that the process uses, but may share
  128. * with related processes.
  129. *
  130. * struct process is the higher level process containing information
  131. * shared by all threads in a process, while struct proc contains the
  132. * run-time information needed by threads.
  133. */
  134. #ifdef __need_process
  135. struct process {
  136. /*
  137. * ps_mainproc is the main thread in the process.
  138. * Ultimately, we shouldn't need that, threads should be able to exit
  139. * at will. Unfortunately until the pid is moved into struct process
  140. * we'll have to remember the main threads and abuse its pid as the
  141. * the pid of the process. This is gross, but considering the horrible
  142. * pid semantics we have right now, it's unavoidable.
  143. */
  144. struct proc *ps_mainproc;
  145. struct ucred *ps_ucred; /* Process owner's identity. */
  146. LIST_ENTRY(process) ps_list; /* List of all processes. */
  147. TAILQ_HEAD(,proc) ps_threads; /* Threads in this process. */
  148. LIST_ENTRY(process) ps_pglist; /* List of processes in pgrp. */
  149. struct process *ps_pptr; /* Pointer to parent process. */
  150. LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */
  151. LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
  152. struct sigacts *ps_sigacts; /* Signal actions, state */
  153. struct vnode *ps_textvp; /* Vnode of executable. */
  154. struct filedesc *ps_fd; /* Ptr to open files structure */
  155. struct vmspace *ps_vmspace; /* Address space */
  156. /* The following fields are all zeroed upon creation in process_new. */
  157. #define ps_startzero ps_klist
  158. struct klist ps_klist; /* knotes attached to this process */
  159. int ps_flags; /* PS_* flags. */
  160. struct proc *ps_single; /* Single threading to this thread. */
  161. int ps_singlecount; /* Not yet suspended threads. */
  162. int ps_traceflag; /* Kernel trace points. */
  163. struct vnode *ps_tracevp; /* Trace to vnode. */
  164. struct ucred *ps_tracecred; /* Creds for writing trace */
  165. pid_t ps_oppid; /* Save parent pid during ptrace. */
  166. int ps_ptmask; /* Ptrace event mask */
  167. struct ptrace_state *ps_ptstat;/* Ptrace state */
  168. struct rusage *ps_ru; /* sum of stats for dead threads. */
  169. struct tusage ps_tu; /* accumulated times. */
  170. struct rusage ps_cru; /* sum of stats for reaped children */
  171. struct itimerval ps_timer[3]; /* timers, indexed by ITIMER_* */
  172. /* End area that is zeroed on creation. */
  173. #define ps_endzero ps_startcopy
  174. /* The following fields are all copied upon creation in process_new. */
  175. #define ps_startcopy ps_limit
  176. struct plimit *ps_limit; /* Process limits. */
  177. struct pgrp *ps_pgrp; /* Pointer to process group. */
  178. struct emul *ps_emul; /* Emulation information */
  179. vaddr_t ps_strings; /* User pointers to argv/env */
  180. vaddr_t ps_stackgap; /* User pointer to the "stackgap" */
  181. vaddr_t ps_sigcode; /* User pointer to the signal code */
  182. u_int ps_rtableid; /* Process routing table/domain. */
  183. char ps_nice; /* Process "nice" value. */
  184. struct uprof { /* profile arguments */
  185. caddr_t pr_base; /* buffer base */
  186. size_t pr_size; /* buffer size */
  187. u_long pr_off; /* pc offset */
  188. u_int pr_scale; /* pc scaling */
  189. } ps_prof;
  190. u_short ps_acflag; /* Accounting flags. */
  191. u_int ps_tame;
  192. int64_t ps_kbind_cookie;
  193. u_long ps_kbind_addr;
  194. /* End area that is copied on creation. */
  195. #define ps_endcopy ps_refcnt
  196. int ps_refcnt; /* Number of references. */
  197. struct timespec ps_start; /* starting time. */
  198. struct timeout ps_realit_to; /* real-time itimer trampoline. */
  199. };
  200. #define ps_pid ps_mainproc->p_pid
  201. #define ps_session ps_pgrp->pg_session
  202. #define ps_pgid ps_pgrp->pg_id
  203. #endif /* __need_process */
  204. /*
  205. * These flags are kept in ps_flags.
  206. */
  207. #define PS_CONTROLT 0x00000001 /* Has a controlling terminal. */
  208. #define PS_EXEC 0x00000002 /* Process called exec. */
  209. #define PS_INEXEC 0x00000004 /* Process is doing an exec right now */
  210. #define PS_EXITING 0x00000008 /* Process is exiting. */
  211. #define PS_SUGID 0x00000010 /* Had set id privs since last exec. */
  212. #define PS_SUGIDEXEC 0x00000020 /* last execve() was set[ug]id */
  213. #define PS_PPWAIT 0x00000040 /* Parent waits for exec/exit. */
  214. #define PS_ISPWAIT 0x00000080 /* Is parent of PPWAIT child. */
  215. #define PS_PROFIL 0x00000100 /* Has started profiling. */
  216. #define PS_TRACED 0x00000200 /* Being ptraced. */
  217. #define PS_WAITED 0x00000400 /* Stopped proc has waited for. */
  218. #define PS_COREDUMP 0x00000800 /* Busy coredumping */
  219. #define PS_SINGLEEXIT 0x00001000 /* Other threads must die. */
  220. #define PS_SINGLEUNWIND 0x00002000 /* Other threads must unwind. */
  221. #define PS_NOZOMBIE 0x00004000 /* No signal or zombie at exit. */
  222. #define PS_STOPPED 0x00008000 /* Just stopped, need sig to parent. */
  223. #define PS_SYSTEM 0x00010000 /* No sigs, stats or swapping. */
  224. #define PS_EMBRYO 0x00020000 /* New process, not yet fledged */
  225. #define PS_ZOMBIE 0x00040000 /* Dead and ready to be waited for */
  226. #define PS_NOBROADCASTKILL 0x00080000 /* Process excluded from kill -1. */
  227. #define PS_TAMED 0x00100000 /* Has called tame(2) */
  228. #define PS_BITS \
  229. ("\20" "\01CONTROLT" "\02EXEC" "\03INEXEC" "\04EXITING" "\05SUGID" \
  230. "\06SUGIDEXEC" "\07PPWAIT" "\010ISPWAIT" "\011PROFIL" "\012TRACED" \
  231. "\013WAITED" "\014COREDUMP" "\015SINGLEEXIT" "\016SINGLEUNWIND" \
  232. "\017NOZOMBIE" "\020STOPPED" "\021SYSTEM" "\022EMBRYO" "\023ZOMBIE" \
  233. "\024NOBROADCASTKILL" "\025TAMED")
  234. struct proc {
  235. TAILQ_ENTRY(proc) p_runq;
  236. LIST_ENTRY(proc) p_list; /* List of all threads. */
  237. struct process *p_p; /* The process of this thread. */
  238. TAILQ_ENTRY(proc) p_thr_link;/* Threads in a process linkage. */
  239. /* substructures: */
  240. struct filedesc *p_fd; /* copy of p_p->ps_fd */
  241. struct vmspace *p_vmspace; /* copy of p_p->ps_vmspace */
  242. #define p_rlimit p_p->ps_limit->pl_rlimit
  243. int p_flag; /* P_* flags. */
  244. u_char p_spare; /* unused */
  245. char p_stat; /* S* process status. */
  246. char p_pad1[1];
  247. u_char p_descfd; /* if not 255, fdesc permits this fd */
  248. pid_t p_pid; /* Process identifier. */
  249. LIST_ENTRY(proc) p_hash; /* Hash chain. */
  250. /* The following fields are all zeroed upon creation in fork. */
  251. #define p_startzero p_dupfd
  252. int p_dupfd; /* Sideways return value from filedescopen. XXX */
  253. long p_thrslpid; /* for thrsleep syscall */
  254. /* scheduling */
  255. u_int p_estcpu; /* Time averaged value of p_cpticks. */
  256. int p_cpticks; /* Ticks of cpu time. */
  257. const volatile void *p_wchan;/* Sleep address. */
  258. struct timeout p_sleep_to;/* timeout for tsleep() */
  259. const char *p_wmesg; /* Reason for sleep. */
  260. fixpt_t p_pctcpu; /* %cpu for this thread */
  261. u_int p_slptime; /* Time since last blocked. */
  262. u_int p_uticks; /* Statclock hits in user mode. */
  263. u_int p_sticks; /* Statclock hits in system mode. */
  264. u_int p_iticks; /* Statclock hits processing intr. */
  265. struct cpu_info * volatile p_cpu; /* CPU we're running on. */
  266. struct rusage p_ru; /* Statistics */
  267. struct tusage p_tu; /* accumulated times. */
  268. struct timespec p_rtime; /* Real time. */
  269. void *p_systrace; /* Back pointer to systrace */
  270. void *p_emuldata; /* Per-process emulation data, or */
  271. /* NULL. Malloc type M_EMULDATA */
  272. int p_siglist; /* Signals arrived but not delivered. */
  273. /* End area that is zeroed on creation. */
  274. #define p_endzero p_startcopy
  275. /* The following fields are all copied upon creation in fork. */
  276. #define p_startcopy p_sigmask
  277. sigset_t p_sigmask; /* Current signal mask. */
  278. u_char p_priority; /* Process priority. */
  279. u_char p_usrpri; /* User-priority based on p_cpu and ps_nice. */
  280. char p_comm[MAXCOMLEN+1];
  281. int p_tame_syscall; /* Cache of current syscall */
  282. int p_tamenote; /* Observance during syscall */
  283. #define TMN_CREAT 0x00000001
  284. #define TMN_WRITE 0x00000002
  285. #define TMN_IMODIFY 0x00000004
  286. #define TMN_YPLOCK 0x00000008
  287. #define TMN_DNSRESOLV 0x00000010
  288. #define TMN_COREDUMP 0x00000020
  289. int p_tameafter;
  290. #ifndef __HAVE_MD_TCB
  291. void *p_tcb; /* user-space thread-control-block address */
  292. # define TCB_SET(p, addr) ((p)->p_tcb = (addr))
  293. # define TCB_GET(p) ((p)->p_tcb)
  294. #endif
  295. struct ucred *p_ucred; /* cached credentials */
  296. struct sigaltstack p_sigstk; /* sp & on stack state variable */
  297. u_long p_prof_addr; /* tmp storage for profiling addr until AST */
  298. u_long p_prof_ticks; /* tmp storage for profiling ticks until AST */
  299. /* End area that is copied on creation. */
  300. #define p_endcopy p_addr
  301. struct user *p_addr; /* Kernel virtual addr of u-area */
  302. struct mdproc p_md; /* Any machine-dependent fields. */
  303. sigset_t p_oldmask; /* Saved mask from before sigpause */
  304. int p_sisig; /* For core dump/debugger XXX */
  305. union sigval p_sigval; /* For core dump/debugger XXX */
  306. long p_sitrapno; /* For core dump/debugger XXX */
  307. int p_sicode; /* For core dump/debugger XXX */
  308. u_short p_xstat; /* Exit status for wait; also stop signal. */
  309. };
  310. /* Status values. */
  311. #define SIDL 1 /* Thread being created by fork. */
  312. #define SRUN 2 /* Currently runnable. */
  313. #define SSLEEP 3 /* Sleeping on an address. */
  314. #define SSTOP 4 /* Debugging or suspension. */
  315. #define SZOMB 5 /* unused */
  316. #define SDEAD 6 /* Thread is almost gone */
  317. #define SONPROC 7 /* Thread is currently on a CPU. */
  318. #define P_ZOMBIE(p) ((p)->p_stat == SDEAD)
  319. /*
  320. * These flags are per-thread and kept in p_flag
  321. */
  322. #define P_INKTR 0x00000001 /* In a ktrace op, don't recurse */
  323. #define P_PROFPEND 0x00000002 /* SIGPROF needs to be posted */
  324. #define P_ALRMPEND 0x00000004 /* SIGVTALRM needs to be posted */
  325. #define P_SIGSUSPEND 0x00000008 /* Need to restore before-suspend mask*/
  326. #define P_CANTSLEEP 0x00000010 /* insomniac thread */
  327. #define P_SELECT 0x00000040 /* Selecting; wakeup/waiting danger. */
  328. #define P_SINTR 0x00000080 /* Sleep is interruptible. */
  329. #define P_SYSTEM 0x00000200 /* No sigs, stats or swapping. */
  330. #define P_TIMEOUT 0x00000400 /* Timing out during sleep. */
  331. #define P_WEXIT 0x00002000 /* Working on exiting. */
  332. #define P_OWEUPC 0x00008000 /* Owe proc an addupc() at next ast. */
  333. #define P_SUSPSINGLE 0x00080000 /* Need to stop for single threading. */
  334. #define P_SYSTRACE 0x00400000 /* Process system call tracing active*/
  335. #define P_CONTINUED 0x00800000 /* Proc has continued from a stopped state. */
  336. #define P_THREAD 0x04000000 /* Only a thread, not a real process */
  337. #define P_SUSPSIG 0x08000000 /* Stopped from signal. */
  338. #define P_SOFTDEP 0x10000000 /* Stuck processing softdep worklist */
  339. #define P_CPUPEG 0x40000000 /* Do not move to another cpu. */
  340. #define P_BITS \
  341. ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \
  342. "\05CANTSLEEP" "\07SELECT" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \
  343. "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\027SYSTRACE" \
  344. "\030CONTINUED" "\033THREAD" "\034SUSPSIG" "\035SOFTDEP" "\037CPUPEG")
  345. #define THREAD_PID_OFFSET 1000000
  346. #ifdef _KERNEL
  347. struct uidinfo {
  348. LIST_ENTRY(uidinfo) ui_hash;
  349. uid_t ui_uid;
  350. long ui_proccnt; /* proc structs */
  351. long ui_lockcnt; /* lockf structs */
  352. };
  353. struct uidinfo *uid_find(uid_t);
  354. /*
  355. * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
  356. * as it is used to represent "no process group".
  357. * We set PID_MAX to (SHRT_MAX - 1) so we don't break sys/compat.
  358. */
  359. #define PID_MAX 32766
  360. #define NO_PID (PID_MAX+1)
  361. #define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr))
  362. #define SESSHOLD(s) ((s)->s_count++)
  363. #define SESSRELE(s) do { \
  364. if (--(s)->s_count == 0) \
  365. pool_put(&session_pool, (s)); \
  366. } while (/* CONSTCOND */ 0)
  367. /*
  368. * Flags to fork1().
  369. */
  370. #define FORK_FORK 0x00000001
  371. #define FORK_VFORK 0x00000002
  372. #define FORK_IDLE 0x00000004
  373. #define FORK_PPWAIT 0x00000008
  374. #define FORK_SHAREFILES 0x00000010
  375. #define FORK_SYSTEM 0x00000020
  376. #define FORK_NOZOMBIE 0x00000040
  377. #define FORK_SHAREVM 0x00000080
  378. #define FORK_TFORK 0x00000100
  379. #define FORK_SIGHAND 0x00000200
  380. #define FORK_PTRACE 0x00000400
  381. #define FORK_THREAD 0x00000800
  382. #define EXIT_NORMAL 0x00000001
  383. #define EXIT_THREAD 0x00000002
  384. #define EXIT_THREAD_NOCHECK 0x00000003
  385. #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
  386. extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
  387. extern u_long pidhash;
  388. #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
  389. extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
  390. extern u_long pgrphash;
  391. extern struct proc proc0; /* Process slot for swapper. */
  392. extern struct process process0; /* Process slot for kernel threads. */
  393. extern int nprocesses, maxprocess; /* Cur and max number of processes. */
  394. extern int nthreads, maxthread; /* Cur and max number of threads. */
  395. extern int randompid; /* fork() should create random pid's */
  396. LIST_HEAD(proclist, proc);
  397. LIST_HEAD(processlist, process);
  398. extern struct processlist allprocess; /* List of all processes. */
  399. extern struct processlist zombprocess; /* List of zombie processes. */
  400. extern struct proclist allproc; /* List of all threads. */
  401. extern struct process *initprocess; /* Process slot for init. */
  402. extern struct proc *reaperproc; /* Thread slot for reaper. */
  403. extern struct proc *syncerproc; /* filesystem syncer daemon */
  404. extern struct pool process_pool; /* memory pool for processes */
  405. extern struct pool proc_pool; /* memory pool for procs */
  406. extern struct pool rusage_pool; /* memory pool for zombies */
  407. extern struct pool ucred_pool; /* memory pool for ucreds */
  408. extern struct pool session_pool; /* memory pool for sessions */
  409. extern struct pool pgrp_pool; /* memory pool for pgrps */
  410. int ispidtaken(pid_t);
  411. pid_t allocpid(void);
  412. void freepid(pid_t);
  413. struct process *prfind(pid_t); /* Find process by id. */
  414. struct proc *pfind(pid_t); /* Find thread by id. */
  415. struct pgrp *pgfind(pid_t); /* Find process group by id. */
  416. void proc_printit(struct proc *p, const char *modif,
  417. int (*pr)(const char *, ...));
  418. int chgproccnt(uid_t uid, int diff);
  419. int enterpgrp(struct process *, pid_t, struct pgrp *, struct session *);
  420. void fixjobc(struct process *, struct pgrp *, int);
  421. int inferior(struct process *, struct process *);
  422. void leavepgrp(struct process *);
  423. void preempt(struct proc *);
  424. void pgdelete(struct pgrp *);
  425. void procinit(void);
  426. void resetpriority(struct proc *);
  427. void setrunnable(struct proc *);
  428. void endtsleep(void *);
  429. void unsleep(struct proc *);
  430. void reaper(void);
  431. void exit1(struct proc *, int, int);
  432. void exit2(struct proc *);
  433. int dowait4(struct proc *, pid_t, int *, int, struct rusage *,
  434. register_t *);
  435. void cpu_exit(struct proc *);
  436. void process_initialize(struct process *, struct proc *);
  437. int fork1(struct proc *, int, void *, pid_t *, void (*)(void *),
  438. void *, register_t *, struct proc **);
  439. int groupmember(gid_t, struct ucred *);
  440. void dorefreshcreds(struct process *, struct proc *);
  441. void dosigsuspend(struct proc *, sigset_t);
  442. static inline void
  443. refreshcreds(struct proc *p)
  444. {
  445. struct process *pr = p->p_p;
  446. /* this is an unlocked access to ps_ucred, but the result is benign */
  447. if (pr->ps_ucred != p->p_ucred)
  448. dorefreshcreds(pr, p);
  449. }
  450. enum single_thread_mode {
  451. SINGLE_SUSPEND, /* other threads to stop wherever they are */
  452. SINGLE_PTRACE, /* other threads to stop but don't wait */
  453. SINGLE_UNWIND, /* other threads to unwind and stop */
  454. SINGLE_EXIT /* other threads to unwind and then exit */
  455. };
  456. int single_thread_set(struct proc *, enum single_thread_mode, int);
  457. void single_thread_wait(struct process *);
  458. void single_thread_clear(struct proc *, int);
  459. int single_thread_check(struct proc *, int);
  460. void child_return(void *);
  461. int proc_cansugid(struct proc *);
  462. void proc_finish_wait(struct proc *, struct proc *);
  463. void process_zap(struct process *);
  464. void proc_free(struct proc *);
  465. struct sleep_state {
  466. int sls_s;
  467. int sls_catch;
  468. int sls_do_sleep;
  469. int sls_sig;
  470. };
  471. #if defined(MULTIPROCESSOR)
  472. void proc_trampoline_mp(void); /* XXX */
  473. #endif
  474. /*
  475. * functions to handle sets of cpus.
  476. *
  477. * For now we keep the cpus in ints so that we can use the generic
  478. * atomic ops.
  479. */
  480. #define CPUSET_ASIZE(x) (((x) - 1)/32 + 1)
  481. #define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS)
  482. struct cpuset {
  483. int cs_set[CPUSET_SSIZE];
  484. };
  485. void cpuset_init_cpu(struct cpu_info *);
  486. void cpuset_clear(struct cpuset *);
  487. void cpuset_add(struct cpuset *, struct cpu_info *);
  488. void cpuset_del(struct cpuset *, struct cpu_info *);
  489. int cpuset_isset(struct cpuset *, struct cpu_info *);
  490. void cpuset_add_all(struct cpuset *);
  491. void cpuset_copy(struct cpuset *, struct cpuset *);
  492. void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
  493. void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
  494. void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
  495. struct cpu_info *cpuset_first(struct cpuset *);
  496. #endif /* _KERNEL */
  497. #endif /* !_SYS_PROC_H_ */