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