]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/proc_internal.h
280e812b1e59b72c43aa08067955743ebd98ee2e
[apple/xnu.git] / bsd / sys / proc_internal.h
1 /*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
29 /*-
30 * Copyright (c) 1986, 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)proc_internal.h 8.15 (Berkeley) 5/19/95
67 */
68 /*
69 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
70 * support for mandatory and extensible security protections. This notice
71 * is included in support of clause 2.2 (b) of the Apple Public License,
72 * Version 2.0.
73 */
74
75 #ifndef _SYS_PROC_INTERNAL_H_
76 #define _SYS_PROC_INTERNAL_H_
77
78 #include <libkern/OSAtomic.h>
79 #include <sys/proc.h>
80 __BEGIN_DECLS
81 #include <kern/locks.h>
82 __END_DECLS
83
84 #if DEBUG
85 #define __PROC_INTERNAL_DEBUG 1
86 #endif
87
88 /*
89 * The short form for various locks that protect fields in the data structures.
90 * PL = Process Lock
91 * PGL = Process Group Lock
92 * PFDL = Process File Desc Lock
93 * PSL = Process Spin Lock
94 * PPL = Parent Process Lock (planed for later usage)
95 * LL = List Lock
96 * SL = Session Lock
97 */
98 struct label;
99
100 /*
101 * Added by SPARTA, Inc.
102 */
103 /*
104 * Login context.
105 */
106 struct lctx {
107 LIST_ENTRY(lctx) lc_list; /* List of all login contexts. */
108 LIST_HEAD(, proc) lc_members; /* Pointer to lc members. */
109 int lc_mc; /* Member Count. */
110 pid_t lc_id; /* Login context ID. */
111 lck_mtx_t lc_mtx; /* Mutex to protect members */
112
113 struct label *lc_label; /* Login context MAC label. */
114 };
115
116 /*
117 * One structure allocated per session.
118 */
119 struct session {
120 int s_count; /* Ref cnt; pgrps in session. (LL) */
121 struct proc * s_leader; /* Session leader.(static) */
122 struct vnode * s_ttyvp; /* Vnode of controlling terminal.(SL) */
123 int s_ttyvid; /* Vnode id of the controlling terminal (SL) */
124 struct tty * s_ttyp; /* Controlling terminal. (SL) */
125 pid_t s_ttypgrpid; /* tty's pgrp id */
126 pid_t s_sid; /* Session ID (static) */
127 char s_login[MAXLOGNAME]; /* Setlogin() name.(SL) */
128 int s_flags; /* Session flags (s_mlock) */
129 LIST_ENTRY(session) s_hash; /* Hash chain.(LL) */
130 lck_mtx_t s_mlock; /* mutex lock to protect session */
131 int s_listflags;
132 };
133
134 #define SESSION_NULL (struct session *)0
135
136 /*
137 * Session flags; used to tunnel information to lower layers and line
138 * disciplines, etc.
139 */
140 #define S_DEFAULT 0x00000000 /* No flags set */
141 #define S_NOCTTY 0x00000001 /* Do not associate controlling tty */
142
143
144 #define S_LIST_TERM 1 /* marked for termination */
145 #define S_LIST_DEAD 2 /* already dead */
146 /*
147 * One structure allocated per process group.
148 */
149 struct pgrp {
150 LIST_ENTRY(pgrp) pg_hash; /* Hash chain. (LL) */
151 LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members. (PGL) */
152 struct session * pg_session; /* Pointer to session. (LL ) */
153 pid_t pg_id; /* Pgrp id. (static) */
154 int pg_jobc; /* # procs qualifying pgrp for job control (PGL) */
155 int pg_membercnt; /* Number of processes in the pgrocess group (PGL) */
156 int pg_refcount; /* number of current iterators (LL) */
157 unsigned int pg_listflags; /* (LL) */
158 lck_mtx_t pg_mlock; /* mutex lock to protect pgrp */
159 };
160
161 #define PGRP_FLAG_TERMINATE 1
162 #define PGRP_FLAG_WAITTERMINATE 2
163 #define PGRP_FLAG_DEAD 4
164 #define PGRP_FLAG_ITERABEGIN 8
165 #define PGRP_FLAG_ITERWAIT 0x10
166
167 #define PGRP_NULL (struct pgrp *)0
168 struct proc;
169
170 #define PROC_NULL (struct proc *)0
171
172 /*
173 * Description of a process.
174 *
175 * This structure contains the information needed to manage a thread of
176 * control, known in UN*X as a process; it has references to substructures
177 * containing descriptions of things that the process uses, but may share
178 * with related processes. The process structure and the substructures
179 * are always addressible except for those marked "(PROC ONLY)" below,
180 * which might be addressible only on a processor on which the process
181 * is running.
182 */
183 struct proc {
184 LIST_ENTRY(proc) p_list; /* List of all processes. */
185
186 pid_t p_pid; /* Process identifier. (static)*/
187 void * task; /* corresponding task (static)*/
188 struct proc * p_pptr; /* Pointer to parent process.(LL) */
189 pid_t p_ppid; /* process's parent pid number */
190 pid_t p_pgrpid; /* process group id of the process (LL)*/
191
192 lck_mtx_t p_mlock; /* mutex lock for proc */
193
194 char p_stat; /* S* process status. (PL)*/
195 char p_shutdownstate;
196 char p_kdebug; /* P_KDEBUG eq (CC)*/
197 char p_btrace; /* P_BTRACE eq (CC)*/
198
199 LIST_ENTRY(proc) p_pglist; /* List of processes in pgrp.(PGL) */
200 LIST_ENTRY(proc) p_sibling; /* List of sibling processes. (LL)*/
201 LIST_HEAD(, proc) p_children; /* Pointer to list of children. (LL)*/
202 TAILQ_HEAD( , uthread) p_uthlist; /* List of uthreads (PL) */
203
204 LIST_ENTRY(proc) p_hash; /* Hash chain. (LL)*/
205 TAILQ_HEAD( ,eventqelt) p_evlist; /* (PL) */
206
207 lck_mtx_t p_fdmlock; /* proc lock to protect fdesc */
208
209 /* substructures: */
210 kauth_cred_t p_ucred; /* Process owner's identity. (PL) */
211 struct filedesc *p_fd; /* Ptr to open files structure. (PFDL) */
212 struct pstats *p_stats; /* Accounting/statistics (PL). */
213 struct plimit *p_limit; /* Process limits.(PL) */
214
215 struct sigacts *p_sigacts; /* Signal actions, state (PL) */
216 lck_spin_t p_slock; /* spin lock for itimer/profil protection */
217
218 #define p_rlimit p_limit->pl_rlimit
219
220 struct plimit *p_olimit; /* old process limits - not inherited by child (PL) */
221 unsigned int p_flag; /* P_* flags. (atomic bit ops) */
222 unsigned int p_lflag; /* local flags (PL) */
223 unsigned int p_listflag; /* list flags (LL) */
224 unsigned int p_ladvflag; /* local adv flags (atomic) */
225 int p_refcount; /* number of outstanding users(LL) */
226 int p_childrencnt; /* children holding ref on parent (LL) */
227 int p_parentref; /* children lookup ref on parent (LL) */
228
229 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
230 u_int p_xstat; /* Exit status for wait; also stop signal. */
231
232 #ifdef _PROC_HAS_SCHEDINFO_
233 /* may need cleanup, not used */
234 u_int p_estcpu; /* Time averaged value of p_cpticks.(used by aio and proc_comapre) */
235 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime (used by aio)*/
236 u_int p_slptime; /* used by proc_compare */
237 #endif /* _PROC_HAS_SCHEDINFO_ */
238
239 struct itimerval p_realtimer; /* Alarm timer. (PSL) */
240 struct timeval p_rtime; /* Real time.(PSL) */
241 struct itimerval p_vtimer_user; /* Virtual timers.(PSL) */
242 struct itimerval p_vtimer_prof; /* (PSL) */
243
244 struct timeval p_rlim_cpu; /* Remaining rlim cpu value.(PSL) */
245 int p_debugger; /* NU 1: can exec set-bit programs if suser */
246 boolean_t sigwait; /* indication to suspend (PL) */
247 void *sigwait_thread; /* 'thread' holding sigwait(PL) */
248 void *exit_thread; /* Which thread is exiting(PL) */
249 int p_vforkcnt; /* number of outstanding vforks(PL) */
250 void * p_vforkact; /* activation running this vfork proc)(static) */
251 int p_fpdrainwait; /* (PFDL) */
252 pid_t p_contproc; /* last PID to send us a SIGCONT (PL) */
253
254 /* Following fields are info from SIGCHLD (PL) */
255 pid_t si_pid; /* (PL) */
256 u_int si_status; /* (PL) */
257 u_int si_code; /* (PL) */
258 uid_t si_uid; /* (PL) */
259
260 void * vm_shm; /* (SYSV SHM Lock) for sysV shared memory */
261
262 #if CONFIG_DTRACE
263 user_addr_t p_dtrace_argv; /* (write once, read only after that) */
264 user_addr_t p_dtrace_envp; /* (write once, read only after that) */
265 lck_mtx_t p_dtrace_sprlock; /* sun proc lock emulation */
266 int p_dtrace_probes; /* (PL) are there probes for this proc? */
267 u_int p_dtrace_count; /* (sprlock) number of DTrace tracepoints */
268 struct dtrace_ptss_page* p_dtrace_ptss_pages; /* (sprlock) list of user ptss pages */
269 struct dtrace_ptss_page_entry* p_dtrace_ptss_free_list; /* (atomic) list of individual ptss entries */
270 struct dtrace_helpers* p_dtrace_helpers; /* (dtrace_lock) DTrace per-proc private */
271 struct dof_ioctl_data* p_dtrace_lazy_dofs; /* (sprlock) unloaded dof_helper_t's */
272 #endif /* CONFIG_DTRACE */
273
274 /* XXXXXXXXXXXXX BCOPY'ed on fork XXXXXXXXXXXXXXXX */
275 /* The following fields are all copied upon creation in fork. */
276 #define p_startcopy p_argslen
277
278 u_int p_argslen; /* Length of process arguments. */
279 int p_argc; /* saved argc for sysctl_procargs() */
280 user_addr_t user_stack; /* where user stack was allocated */
281 struct vnode *p_textvp; /* Vnode of executable. */
282 off_t p_textoff; /* offset in executable vnode */
283
284 sigset_t p_sigmask; /* DEPRECATED */
285 sigset_t p_sigignore; /* Signals being ignored. (PL) */
286 sigset_t p_sigcatch; /* Signals being caught by user.(PL) */
287
288 u_char p_priority; /* (NU) Process priority. */
289 u_char p_resv0; /* (NU) User-priority based on p_cpu and p_nice. */
290 char p_nice; /* Process "nice" value.(PL) */
291 u_char p_resv1; /* (NU) User-priority based on p_cpu and p_nice. */
292
293 #if CONFIG_MACF
294 int p_mac_enforce; /* MAC policy enforcement control */
295 #endif
296
297 char p_comm[MAXCOMLEN+1];
298 char p_name[(2*MAXCOMLEN)+1]; /* PL */
299
300 struct pgrp *p_pgrp; /* Pointer to process group. (LL) */
301 int p_iopol_disk; /* disk I/O policy (PL) */
302 uint32_t p_csflags; /* flags for codesign (PL) */
303
304 /* End area that is copied on creation. */
305 /* XXXXXXXXXXXXX End of BCOPY'ed on fork (AIOLOCK)XXXXXXXXXXXXXXXX */
306 #define p_endcopy aio_active_count
307 int aio_active_count; /* entries on aio_activeq */
308 int aio_done_count; /* entries on aio_doneq */
309 TAILQ_HEAD( , aio_workq_entry ) aio_activeq; /* active async IO requests */
310 TAILQ_HEAD( , aio_workq_entry ) aio_doneq; /* completed async IO requests */
311
312 struct klist p_klist; /* knote list (PL ?)*/
313
314 struct rusage *p_ru; /* Exit information. (PL) */
315 thread_t p_signalholder;
316 thread_t p_transholder;
317
318 /* DEPRECATE following field */
319 u_short p_acflag; /* Accounting flags. */
320
321 struct lctx *p_lctx; /* Pointer to login context. */
322 LIST_ENTRY(proc) p_lclist; /* List of processes in lctx. */
323 user_addr_t p_threadstart; /* pthread start fn */
324 user_addr_t p_wqthread; /* pthread workqueue fn */
325 int p_pthsize; /* pthread size */
326 void * p_wqptr; /* workq ptr */
327 int p_wqsize; /* allocated size */
328 lck_mtx_t p_wqlock; /* lock to protect work queue */
329 struct timeval p_start; /* starting time */
330 void * p_rcall;
331 int p_ractive;
332 int p_idversion; /* version of process identity */
333 #if DIAGNOSTIC
334 unsigned int p_fdlock_pc[4];
335 unsigned int p_fdunlock_pc[4];
336 #if SIGNAL_DEBUG
337 unsigned int lockpc[8];
338 unsigned int unlockpc[8];
339 #endif /* SIGNAL_DEBUG */
340 #endif /* DIAGNOSTIC */
341 };
342
343 #define PGRPID_DEAD 0xdeaddead
344
345 /* p_listflag */
346 #define P_LIST_DRAIN 0x00000001
347 #define P_LIST_DRAINWAIT 0x00000002
348 #define P_LIST_DRAINED 0x00000004
349 #define P_LIST_DEAD 0x00000008
350 #define P_LIST_WAITING 0x00000010
351 #define P_LIST_EXITED 0x00000040
352 #define P_LIST_CHILDDRSTART 0x00000080
353 #define P_LIST_CHILDDRAINED 0x00000100
354 #define P_LIST_CHILDDRWAIT 0x00000200
355 #define P_LIST_CHILDLKWAIT 0x00000400
356 #define P_LIST_DEADPARENT 0x00000800
357 #define P_LIST_PARENTREFWAIT 0x00001000
358 #define P_LIST_INCREATE 0x00002000
359 /* 0x4000 & 0x8000 Not used */
360 #define P_LIST_INHASH 0x00010000 /* process is in hash */
361 #define P_LIST_INPGRP 0x00020000 /* process is in pgrp */
362 #define P_LIST_PGRPTRANS 0x00040000 /* pgrp is getting replaced */
363 #define P_LIST_PGRPTRWAIT 0x00080000 /* wait for pgrp replacement */
364
365
366 /* local flags */
367 #define P_LDELAYTERM 0x00000001 /* */
368 #define P_LNOZOMB 0x00000002 /* */
369 #define P_LTERM 0x00000004 /* */
370 #define P_LEXIT 0x00000008 /* */
371 #define P_LPEXIT 0x00000010
372 #define P_LTHSIGSTACK 0x00000020
373 #define P_LINTRANSIT 0x00000040 /* process in exec or in creation */
374 #define P_LTRANSWAIT 0x00000080 /* waiting for trans to complete */
375 #define P_LVFORK 0x00000100 /* */
376 #define P_LINVFORK 0x00000200 /* */
377 #define P_LTRACED 0x00000400 /* */
378 #define P_LSIGEXC 0x00000800 /* */
379 #define P_LNOATTACH 0x00001000 /* */
380 #define P_LPPWAIT 0x00002000 /* */
381 #define P_LKQWDRAIN 0x00004000
382 #define P_LKQWDRAINWAIT 0x00008000
383 #define P_LKQWDEAD 0x00010000
384 #define P_LLIMCHANGE 0x00020000
385 #define P_LLIMWAIT 0x00040000
386 #define P_LWAITED 0x00080000
387 #define P_LINSIGNAL 0x00100000
388 #define P_LSIGNALWAIT 0x00200000
389 #define P_LRAGE_VNODES 0x00400000
390
391 /* advisory flags in the proc */
392 #define P_LADVLOCK 0x01
393
394 /* defns for proc_iterate */
395 #define PROC_ALLPROCLIST 1 /* walk the allproc list (procs not exited yet) */
396 #define PROC_ZOMBPROCLIST 2 /* walk the zombie list */
397 #define PROC_NOWAITTRANS 4 /* do not wait for transitions (checkdirs only) */
398
399 /* defns for pgrp_iterate */
400 #define PGRP_DROPREF 1
401 #define PGRP_BLOCKITERATE 2
402
403 /* return values of the proc iteration callback routine */
404 #define PROC_RETURNED 0
405 #define PROC_RETURNED_DONE 1
406 #define PROC_CLAIMED 2
407 #define PROC_CLAIMED_DONE 3
408
409
410 /* LP64 version of extern_proc. all pointers
411 * grow when we're dealing with a 64-bit process.
412 * WARNING - keep in sync with extern_proc
413 * but use native alignment of 64-bit process.
414 */
415
416 #ifdef KERNEL
417 #include <sys/time.h> /* user_timeval, user_itimerval */
418
419 struct user_extern_proc {
420 union {
421 struct {
422 user_addr_t __p_forw; /* Doubly-linked run/sleep queue. */
423 user_addr_t __p_back;
424 } p_st1;
425 struct user_timeval __p_starttime; /* process start time */
426 } p_un;
427 user_addr_t p_vmspace; /* Address space. */
428 user_addr_t p_sigacts; /* Signal actions, state (PROC ONLY). */
429 int p_flag; /* P_* flags. */
430 char p_stat; /* S* process status. */
431 pid_t p_pid; /* Process identifier. */
432 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
433 int p_dupfd; /* Sideways return value from fdopen. XXX */
434 /* Mach related */
435 user_addr_t user_stack __attribute((aligned(8))); /* where user stack was allocated */
436 user_addr_t exit_thread; /* XXX Which thread is exiting? */
437 int p_debugger; /* allow to debug */
438 boolean_t sigwait; /* indication to suspend */
439 /* scheduling */
440 u_int p_estcpu; /* Time averaged value of p_cpticks. */
441 int p_cpticks; /* Ticks of cpu time. */
442 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
443 user_addr_t p_wchan __attribute((aligned(8))); /* Sleep address. */
444 user_addr_t p_wmesg; /* Reason for sleep. */
445 u_int p_swtime; /* Time swapped in or out. */
446 u_int p_slptime; /* Time since last blocked. */
447 struct user_itimerval p_realtimer; /* Alarm timer. */
448 struct user_timeval p_rtime; /* Real time. */
449 u_quad_t p_uticks; /* Statclock hits in user mode. */
450 u_quad_t p_sticks; /* Statclock hits in system mode. */
451 u_quad_t p_iticks; /* Statclock hits processing intr. */
452 int p_traceflag; /* Kernel trace points. */
453 user_addr_t p_tracep __attribute((aligned(8))); /* Trace to vnode. */
454 int p_siglist; /* DEPRECATED */
455 user_addr_t p_textvp __attribute((aligned(8))); /* Vnode of executable. */
456 int p_holdcnt; /* If non-zero, don't swap. */
457 sigset_t p_sigmask; /* DEPRECATED. */
458 sigset_t p_sigignore; /* Signals being ignored. */
459 sigset_t p_sigcatch; /* Signals being caught by user. */
460 u_char p_priority; /* Process priority. */
461 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
462 char p_nice; /* Process "nice" value. */
463 char p_comm[MAXCOMLEN+1];
464 user_addr_t p_pgrp __attribute((aligned(8))); /* Pointer to process group. */
465 user_addr_t p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
466 u_short p_xstat; /* Exit status for wait; also stop signal. */
467 u_short p_acflag; /* Accounting flags. */
468 user_addr_t p_ru __attribute((aligned(8))); /* Exit information. XXX */
469 };
470 #endif /* KERNEL */
471
472 /*
473 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
474 * as it is used to represent "no process group".
475 */
476 extern int nprocs, maxproc; /* Current and max number of procs. */
477 extern int maxprocperuid; /* Current number of procs per uid */
478 __private_extern__ int hard_maxproc; /* hard limit */
479
480 #define PID_MAX 99999
481 #define NO_PID 100000
482 extern lck_mtx_t * proc_list_mlock;
483 extern lck_mtx_t * proc_klist_mlock;
484
485 #define SESS_LEADER(p, sessp) ((sessp)->s_leader == (p))
486
487 /* Lock and unlock a login context. */
488 #define LCTX_LOCK(lc) lck_mtx_lock(&(lc)->lc_mtx)
489 #define LCTX_UNLOCK(lc) lck_mtx_unlock(&(lc)->lc_mtx)
490 #define LCTX_LOCKED(lc)
491 #define LCTX_LOCK_ASSERT(lc, type)
492 #define ALLLCTX_LOCK lck_mtx_lock(&alllctx_lock)
493 #define ALLLCTX_UNLOCK lck_mtx_unlock(&alllctx_lock)
494 extern lck_mtx_t alllctx_lock;
495 extern lck_grp_t * lctx_lck_grp;
496 extern lck_grp_attr_t * lctx_lck_grp_attr;
497 extern lck_attr_t * lctx_lck_attr;
498
499 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
500 extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
501 extern u_long pidhash;
502
503 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
504 extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
505 extern u_long pgrphash;
506 #define SESSHASH(sessid) (&sesshashtbl[(sessid) & sesshash])
507 extern LIST_HEAD(sesshashhead, session) *sesshashtbl;
508 extern u_long sesshash;
509
510 extern lck_grp_t * proc_lck_grp;
511 extern lck_grp_attr_t * proc_lck_grp_attr;
512 extern lck_attr_t * proc_lck_attr;
513
514 LIST_HEAD(proclist, proc);
515 extern struct proclist allproc; /* List of all processes. */
516 extern struct proclist zombproc; /* List of zombie processes. */
517 extern struct proc *initproc;
518 extern void procinit(void) __attribute__((section("__TEXT, initcode")));
519 extern void proc_lock(struct proc *);
520 extern void proc_unlock(struct proc *);
521 extern void proc_spinlock(struct proc *);
522 extern void proc_spinunlock(struct proc *);
523 extern void proc_list_lock(void);
524 extern void proc_list_unlock(void);
525 extern void proc_klist_lock(void);
526 extern void proc_klist_unlock(void);
527 extern void proc_fdlock(struct proc *);
528 extern void proc_fdlock_spin(struct proc *);
529 extern void proc_fdunlock(struct proc *);
530 extern void proc_fdlock_assert(proc_t p, int assertflags);
531 __private_extern__ int proc_core_name(const char *name, uid_t uid, pid_t pid,
532 char *cr_name, size_t cr_name_len);
533 extern int isinferior(struct proc *, struct proc *);
534 __private_extern__ struct proc *pzfind(pid_t); /* Find zombie by id. */
535
536 extern struct lctx *lcfind(pid_t); /* Find a login context by id */
537 extern struct lctx *lccreate(void); /* Create a new login context */
538
539 extern int chgproccnt(uid_t uid, int diff);
540 extern void enterlctx(struct proc *p, struct lctx *l, int create);
541 extern void pinsertchild(struct proc *parent, struct proc *child);
542 extern int enterpgrp(struct proc *p, pid_t pgid, int mksess);
543 extern void fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
544 extern int inferior(struct proc *p);
545 extern int leavepgrp(struct proc *p);
546 extern void leavelctx(struct proc *p);
547 extern void resetpriority(struct proc *);
548 extern void setrunnable(struct proc *);
549 extern void setrunqueue(struct proc *);
550 extern int sleep(void *chan, int pri);
551 extern int tsleep0(void *chan, int pri, const char *wmesg, int timo, int (*continuation)(int));
552 extern int tsleep1(void *chan, int pri, const char *wmesg, u_int64_t abstime, int (*continuation)(int));
553 extern int msleep0(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, int timo, int (*continuation)(int));
554 extern void vfork_return(struct proc *child, register_t *retval, int rval);
555 extern int exit1(struct proc *, int, int *);
556 extern void vfork_exit_internal(struct proc *p, int rv, int forced);
557 extern void proc_reparentlocked(struct proc *child, struct proc * newparent, int cansignal, int locked);
558 extern int pgrp_iterate(struct pgrp * pgrp, int flags, int (*callout)(proc_t , void *), void *arg, int (*filterfn)(proc_t , void *), void *filterarg);
559 extern int proc_iterate(int flags, int (*callout)(proc_t , void *), void *arg, int (*filterfn)(proc_t , void *), void *filterarg);
560 extern int proc_rebootscan(int (*callout)(proc_t , void *), void *arg, int (*filterfn)(proc_t , void *), void *filterarg);
561 extern int proc_childrenwalk(proc_t p, int (*callout)(proc_t , void *), void *arg);
562 extern proc_t proc_findinternal(int pid, int funneled);
563 extern void proc_refdrain(proc_t);
564 extern void proc_childdrainlocked(proc_t);
565 extern void proc_childdrainstart(proc_t);
566 extern void proc_childdrainend(proc_t);
567 extern void proc_checkdeadrefs(proc_t);
568 struct proc *pfind_locked(pid_t);
569 extern struct pgrp *pgfind(pid_t);
570 extern void pg_rele(struct pgrp * pgrp);
571 extern struct session * session_find_internal(pid_t sessid);
572 extern struct pgrp * proc_pgrp(proc_t);
573 extern struct pgrp * tty_pgrp(struct tty * tp);
574 extern struct pgrp * pgfind_internal(pid_t);
575 extern struct session * proc_session(proc_t);
576 extern void pgrp_lock(struct pgrp * pgrp);
577 extern void pgrp_unlock(struct pgrp * pgrp);
578 extern void session_lock(struct session * sess);
579 extern void session_unlock(struct session * sess);
580 extern struct session * pgrp_session(struct pgrp * pgrp);
581 extern void session_rele(struct session *sess);
582 extern int isbackground(proc_t p, struct tty *tp);
583 extern proc_t proc_parent(proc_t);
584 extern proc_t proc_parentholdref(proc_t);
585 extern int proc_parentdropref(proc_t, int);
586 int itimerfix(struct timeval *tv);
587 int itimerdecr(struct proc * p, struct itimerval *itp, int usec);
588 void proc_signalstart(struct proc *, int locked);
589 void proc_signalend(struct proc *, int locked);
590 void proc_transstart(struct proc *, int locked);
591 void proc_transend(struct proc *, int locked);
592 void proc_transwait(struct proc *, int locked);
593 void proc_rele_locked(struct proc * p);
594 void proc_knote(struct proc * p, long hint);
595 void workqueue_init_lock(proc_t p);
596 void workqueue_destroy_lock(proc_t p);
597 #endif /* !_SYS_PROC_INTERNAL_H_ */