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