2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
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.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
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.
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
66 * @(#)proc_internal.h 8.15 (Berkeley) 5/19/95
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,
75 #ifndef _SYS_PROC_INTERNAL_H_
76 #define _SYS_PROC_INTERNAL_H_
78 #include <libkern/OSAtomic.h>
81 #include <kern/locks.h>
83 #include <kern/thread_call.h>
88 #define __PROC_INTERNAL_DEBUG 1
92 * The short form for various locks that protect fields in the data structures.
94 * PGL = Process Group Lock
95 * PFDL = Process File Desc Lock
96 * PUCL = Process User Credentials Lock
97 * PSL = Process Spin Lock
98 * PPL = Parent Process Lock (planed for later usage)
105 * One structure allocated per session.
108 int s_count
; /* Ref cnt; pgrps in session. (LL) */
109 struct proc
* s_leader
; /* Session leader.(static) */
110 struct vnode
* s_ttyvp
; /* Vnode of controlling terminal.(SL) */
111 int s_ttyvid
; /* Vnode id of the controlling terminal (SL) */
112 struct tty
* s_ttyp
; /* Controlling terminal. (SL + ttyvp != NULL) */
113 pid_t s_ttypgrpid
; /* tty's pgrp id */
114 pid_t s_sid
; /* Session ID (static) */
115 char s_login
[MAXLOGNAME
]; /* Setlogin() name.(SL) */
116 int s_flags
; /* Session flags (s_mlock) */
117 LIST_ENTRY(session
) s_hash
; /* Hash chain.(LL) */
118 lck_mtx_t s_mlock
; /* mutex lock to protect session */
122 #define SESSION_NULL (struct session *)0
125 * accessor for s_ttyp which treats it as invalid if s_ttyvp is not valid;
126 * note that s_ttyp is not a reference in the session structre, so it can
127 * become invalid out from under the session if the device is closed, without
128 * this protection. We can't safely make it into a reference without reflexive
129 * close notification of tty devices through cdevsw[].
131 * NB: <sys/tty.h> is not in scope and there is not typedef type enforcement,
132 * or '0' below would be 'TTY_NULL'.
134 #define SESSION_TP(sp) (((sp)->s_ttyvp != 0) ? (sp)->s_ttyp : 0)
137 * Session flags; used to tunnel information to lower layers and line
140 #define S_DEFAULT 0x00000000 /* No flags set */
141 #define S_NOCTTY 0x00000001 /* Do not associate controlling tty */
142 #define S_CTTYREF 0x00000010 /* vnode ref taken by cttyopen */
145 #define S_LIST_TERM 1 /* marked for termination */
146 #define S_LIST_DEAD 2 /* already dead */
148 * One structure allocated per process group.
151 LIST_ENTRY(pgrp
) pg_hash
; /* Hash chain. (LL) */
152 LIST_HEAD(, proc
) pg_members
; /* Pointer to pgrp members. (PGL) */
153 struct session
* pg_session
; /* Pointer to session. (LL ) */
154 pid_t pg_id
; /* Pgrp id. (static) */
155 int pg_jobc
; /* # procs qualifying pgrp for job control (PGL) */
156 int pg_membercnt
; /* Number of processes in the pgrocess group (PGL) */
157 int pg_refcount
; /* number of current iterators (LL) */
158 unsigned int pg_listflags
; /* (LL) */
159 lck_mtx_t pg_mlock
; /* mutex lock to protect pgrp */
162 #define PGRP_FLAG_TERMINATE 1
163 #define PGRP_FLAG_WAITTERMINATE 2
164 #define PGRP_FLAG_DEAD 4
165 #define PGRP_FLAG_ITERABEGIN 8
166 #define PGRP_FLAG_ITERWAIT 0x10
168 #define PGRP_NULL (struct pgrp *)0
171 #define PROC_NULL (struct proc *)0
173 #define PROC_UPDATE_CREDS_ONPROC(p) { \
174 p->p_uid = kauth_cred_getuid(p->p_ucred); \
175 p->p_gid = kauth_cred_getgid(p->p_ucred); \
176 p->p_ruid = kauth_cred_getruid(p->p_ucred); \
177 p->p_rgid = kauth_cred_getrgid(p->p_ucred); \
178 p->p_svuid = kauth_cred_getsvuid(p->p_ucred); \
179 p->p_svgid = kauth_cred_getsvgid(p->p_ucred); \
182 * Description of a process.
184 * This structure contains the information needed to manage a thread of
185 * control, known in UN*X as a process; it has references to substructures
186 * containing descriptions of things that the process uses, but may share
187 * with related processes. The process structure and the substructures
188 * are always addressible except for those marked "(PROC ONLY)" below,
189 * which might be addressible only on a processor on which the process
193 LIST_ENTRY(proc
) p_list
; /* List of all processes. */
195 pid_t p_pid
; /* Process identifier. (static)*/
196 void * task
; /* corresponding task (static)*/
197 struct proc
* p_pptr
; /* Pointer to parent process.(LL) */
198 pid_t p_ppid
; /* process's parent pid number */
199 pid_t p_pgrpid
; /* process group id of the process (LL)*/
206 uint64_t p_uniqueid
; /* process unique ID - incremented on fork/spawn/vfork, remains same across exec. */
207 uint64_t p_puniqueid
; /* parent's unique ID - set on fork/spawn/vfork, doesn't change if reparented. */
209 lck_mtx_t p_mlock
; /* mutex lock for proc */
211 char p_stat
; /* S* process status. (PL)*/
212 char p_shutdownstate
;
213 char p_kdebug
; /* P_KDEBUG eq (CC)*/
214 char p_btrace
; /* P_BTRACE eq (CC)*/
216 LIST_ENTRY(proc
) p_pglist
; /* List of processes in pgrp.(PGL) */
217 LIST_ENTRY(proc
) p_sibling
; /* List of sibling processes. (LL)*/
218 LIST_HEAD(, proc
) p_children
; /* Pointer to list of children. (LL)*/
219 TAILQ_HEAD( , uthread
) p_uthlist
; /* List of uthreads (PL) */
221 LIST_ENTRY(proc
) p_hash
; /* Hash chain. (LL)*/
222 TAILQ_HEAD( ,eventqelt
) p_evlist
; /* (PL) */
224 lck_mtx_t p_fdmlock
; /* proc lock to protect fdesc */
225 lck_mtx_t p_ucred_mlock
; /* mutex lock to protect p_ucred */
228 kauth_cred_t p_ucred
; /* Process owner's identity. (PUCL) */
229 struct filedesc
*p_fd
; /* Ptr to open files structure. (PFDL) */
230 struct pstats
*p_stats
; /* Accounting/statistics (PL). */
231 struct plimit
*p_limit
; /* Process limits.(PL) */
233 struct sigacts
*p_sigacts
; /* Signal actions, state (PL) */
234 int p_siglist
; /* signals captured back from threads */
235 lck_spin_t p_slock
; /* spin lock for itimer/profil protection */
237 #define p_rlimit p_limit->pl_rlimit
239 struct plimit
*p_olimit
; /* old process limits - not inherited by child (PL) */
240 unsigned int p_flag
; /* P_* flags. (atomic bit ops) */
241 unsigned int p_lflag
; /* local flags (PL) */
242 unsigned int p_listflag
; /* list flags (LL) */
243 unsigned int p_ladvflag
; /* local adv flags (atomic) */
244 int p_refcount
; /* number of outstanding users(LL) */
245 int p_childrencnt
; /* children holding ref on parent (LL) */
246 int p_parentref
; /* children lookup ref on parent (LL) */
248 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
249 u_int p_xstat
; /* Exit status for wait; also stop signal. */
251 #ifdef _PROC_HAS_SCHEDINFO_
252 /* may need cleanup, not used */
253 u_int p_estcpu
; /* Time averaged value of p_cpticks.(used by aio and proc_comapre) */
254 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime (used by aio)*/
255 u_int p_slptime
; /* used by proc_compare */
256 #endif /* _PROC_HAS_SCHEDINFO_ */
258 struct itimerval p_realtimer
; /* Alarm timer. (PSL) */
259 struct timeval p_rtime
; /* Real time.(PSL) */
260 struct itimerval p_vtimer_user
; /* Virtual timers.(PSL) */
261 struct itimerval p_vtimer_prof
; /* (PSL) */
263 struct timeval p_rlim_cpu
; /* Remaining rlim cpu value.(PSL) */
264 int p_debugger
; /* NU 1: can exec set-bit programs if suser */
265 boolean_t sigwait
; /* indication to suspend (PL) */
266 void *sigwait_thread
; /* 'thread' holding sigwait(PL) */
267 void *exit_thread
; /* Which thread is exiting(PL) */
268 int p_vforkcnt
; /* number of outstanding vforks(PL) */
269 void * p_vforkact
; /* activation running this vfork proc)(static) */
270 int p_fpdrainwait
; /* (PFDL) */
271 pid_t p_contproc
; /* last PID to send us a SIGCONT (PL) */
273 /* Following fields are info from SIGCHLD (PL) */
274 pid_t si_pid
; /* (PL) */
275 u_int si_status
; /* (PL) */
276 u_int si_code
; /* (PL) */
277 uid_t si_uid
; /* (PL) */
279 void * vm_shm
; /* (SYSV SHM Lock) for sysV shared memory */
282 user_addr_t p_dtrace_argv
; /* (write once, read only after that) */
283 user_addr_t p_dtrace_envp
; /* (write once, read only after that) */
284 lck_mtx_t p_dtrace_sprlock
; /* sun proc lock emulation */
285 int p_dtrace_probes
; /* (PL) are there probes for this proc? */
286 u_int p_dtrace_count
; /* (sprlock) number of DTrace tracepoints */
287 uint8_t p_dtrace_stop
; /* indicates a DTrace-desired stop */
288 struct dtrace_ptss_page
* p_dtrace_ptss_pages
; /* (sprlock) list of user ptss pages */
289 struct dtrace_ptss_page_entry
* p_dtrace_ptss_free_list
; /* (atomic) list of individual ptss entries */
290 struct dtrace_helpers
* p_dtrace_helpers
; /* (dtrace_lock) DTrace per-proc private */
291 struct dof_ioctl_data
* p_dtrace_lazy_dofs
; /* (sprlock) unloaded dof_helper_t's */
292 #endif /* CONFIG_DTRACE */
294 /* XXXXXXXXXXXXX BCOPY'ed on fork XXXXXXXXXXXXXXXX */
295 /* The following fields are all copied upon creation in fork. */
296 #define p_startcopy p_argslen
298 u_int p_argslen
; /* Length of process arguments. */
299 int p_argc
; /* saved argc for sysctl_procargs() */
300 user_addr_t user_stack
; /* where user stack was allocated */
301 struct vnode
*p_textvp
; /* Vnode of executable. */
302 off_t p_textoff
; /* offset in executable vnode */
304 sigset_t p_sigmask
; /* DEPRECATED */
305 sigset_t p_sigignore
; /* Signals being ignored. (PL) */
306 sigset_t p_sigcatch
; /* Signals being caught by user.(PL) */
308 u_char p_priority
; /* (NU) Process priority. */
309 u_char p_resv0
; /* (NU) User-priority based on p_cpu and p_nice. */
310 char p_nice
; /* Process "nice" value.(PL) */
311 u_char p_resv1
; /* (NU) User-priority based on p_cpu and p_nice. */
314 int p_mac_enforce
; /* MAC policy enforcement control */
317 char p_comm
[MAXCOMLEN
+1];
318 char p_name
[(2*MAXCOMLEN
)+1]; /* PL */
320 struct pgrp
*p_pgrp
; /* Pointer to process group. (LL) */
321 uint32_t p_csflags
; /* flags for codesign (PL) */
322 uint32_t p_pcaction
; /* action for process control on starvation */
323 uint8_t p_uuid
[16]; /* from LC_UUID load command */
326 * CPU type and subtype of binary slice executed in
327 * this process. Protected by proc lock.
329 cpu_type_t p_cputype
;
330 cpu_subtype_t p_cpusubtype
;
332 /* End area that is copied on creation. */
333 /* XXXXXXXXXXXXX End of BCOPY'ed on fork (AIOLOCK)XXXXXXXXXXXXXXXX */
334 #define p_endcopy p_aio_total_count
335 int p_aio_total_count
; /* all allocated AIO requests for this proc */
336 int p_aio_active_count
; /* all unfinished AIO requests for this proc */
337 TAILQ_HEAD( , aio_workq_entry
) p_aio_activeq
; /* active async IO requests */
338 TAILQ_HEAD( , aio_workq_entry
) p_aio_doneq
; /* completed async IO requests */
340 struct klist p_klist
; /* knote list (PL ?)*/
342 struct rusage_superset
*p_ru
; /* Exit information. (PL) */
344 thread_t p_signalholder
;
345 thread_t p_transholder
;
347 /* DEPRECATE following field */
348 u_short p_acflag
; /* Accounting flags. */
349 volatile u_short p_vfs_iopolicy
; /* VFS iopolicy flags. (atomic bit ops) */
351 user_addr_t p_threadstart
; /* pthread start fn */
352 user_addr_t p_wqthread
; /* pthread workqueue fn */
353 int p_pthsize
; /* pthread size */
354 uint32_t p_pth_tsd_offset
; /* offset from pthread_t to TSD for new threads */
355 user_addr_t p_targconc
; /* target concurrency ptr */
356 user_addr_t p_stack_addr_hint
; /* stack allocation hint for wq threads */
357 void * p_wqptr
; /* workq ptr */
358 int p_wqsize
; /* allocated size */
359 boolean_t p_wqiniting
; /* semaphore to serialze wq_open */
360 lck_spin_t p_wqlock
; /* lock to protect work queue */
361 struct kqueue
* p_wqkqueue
; /* private workq kqueue */
363 struct timeval p_start
; /* starting time */
366 int p_idversion
; /* version of process identity */
367 void * p_pthhash
; /* pthread waitqueue hash */
368 volatile uint64_t was_throttled
__attribute__((aligned(8))); /* Counter for number of throttled I/Os */
369 volatile uint64_t did_throttle
__attribute__((aligned(8))); /* Counter for number of I/Os this proc throttled */
372 unsigned int p_fdlock_pc
[4];
373 unsigned int p_fdunlock_pc
[4];
375 unsigned int lockpc
[8];
376 unsigned int unlockpc
[8];
377 #endif /* SIGNAL_DEBUG */
378 #endif /* DIAGNOSTIC */
379 uint64_t p_dispatchqueue_offset
;
380 uint64_t p_dispatchqueue_serialno_offset
;
381 #if VM_PRESSURE_EVENTS
382 struct timeval vm_pressure_last_notify_tstamp
;
385 #if CONFIG_MEMORYSTATUS
386 /* Fields protected by proc list lock */
387 TAILQ_ENTRY(proc
) p_memstat_list
; /* priority bucket link */
388 uint32_t p_memstat_state
; /* state */
389 int32_t p_memstat_effectivepriority
; /* priority after transaction state accounted for */
390 int32_t p_memstat_requestedpriority
; /* active priority */
391 uint32_t p_memstat_dirty
; /* dirty state */
392 uint64_t p_memstat_userdata
; /* user state */
393 uint64_t p_memstat_idledeadline
; /* time at which process became clean */
395 int32_t p_memstat_memlimit
; /* cached memory limit, toggles between active and inactive limits */
396 int32_t p_memstat_memlimit_active
; /* memory limit enforced when process is in active jetsam state */
397 int32_t p_memstat_memlimit_inactive
; /* memory limit enforced when process is in inactive jetsam state */
400 uint32_t p_memstat_suspendedfootprint
; /* footprint at time of suspensions */
401 #endif /* CONFIG_FREEZE */
402 #endif /* CONFIG_MEMORYSTATUS */
404 /* cached proc-specific data required for corpse inspection */
405 pid_t p_responsible_pid
; /* pid resonsible for this process */
408 #define PGRPID_DEAD 0xdeaddead
411 #define P_LIST_DRAIN 0x00000001
412 #define P_LIST_DRAINWAIT 0x00000002
413 #define P_LIST_DRAINED 0x00000004
414 #define P_LIST_DEAD 0x00000008
415 #define P_LIST_WAITING 0x00000010
416 #define P_LIST_EXITED 0x00000040
417 #define P_LIST_CHILDDRSTART 0x00000080
418 #define P_LIST_CHILDDRAINED 0x00000100
419 #define P_LIST_CHILDDRWAIT 0x00000200
420 #define P_LIST_CHILDLKWAIT 0x00000400
421 #define P_LIST_DEADPARENT 0x00000800
422 #define P_LIST_PARENTREFWAIT 0x00001000
423 #define P_LIST_INCREATE 0x00002000
424 /* 0x4000 & 0x8000 Not used */
425 #define P_LIST_INHASH 0x00010000 /* process is in hash */
426 #define P_LIST_INPGRP 0x00020000 /* process is in pgrp */
427 #define P_LIST_PGRPTRANS 0x00040000 /* pgrp is getting replaced */
428 #define P_LIST_PGRPTRWAIT 0x00080000 /* wait for pgrp replacement */
429 #define P_LIST_EXITCOUNT 0x00100000 /* counted for process exit */
433 #define P_LDELAYTERM 0x00000001 /* */
434 #define P_LNOZOMB 0x00000002 /* */
435 #define P_LTERM 0x00000004 /* */
436 #define P_LEXIT 0x00000008 /* */
437 #define P_LPEXIT 0x00000010
438 #define P_LTRANSCOMMIT 0x00000020 /* process is committed to trans */
439 #define P_LINTRANSIT 0x00000040 /* process in exec or in creation */
440 #define P_LTRANSWAIT 0x00000080 /* waiting for trans to complete */
441 #define P_LVFORK 0x00000100 /* parent proc of a vfork */
442 #define P_LINVFORK 0x00000200 /* child proc of a vfork */
443 #define P_LTRACED 0x00000400 /* */
444 #define P_LSIGEXC 0x00000800 /* */
445 #define P_LNOATTACH 0x00001000 /* */
446 #define P_LPPWAIT 0x00002000 /* */
447 #define P_LKQWDRAIN 0x00004000
448 #define P_LKQWDRAINWAIT 0x00008000
449 #define P_LKQWDEAD 0x00010000
450 #define P_LLIMCHANGE 0x00020000
451 #define P_LLIMWAIT 0x00040000
452 #define P_LWAITED 0x00080000
453 #define P_LINSIGNAL 0x00100000
454 #define P_LRETURNWAIT 0x00200000 /* process is completing spawn/vfork-exec/fork */
455 #define P_LRAGE_VNODES 0x00400000
456 #define P_LREGISTER 0x00800000 /* thread start fns registered */
457 #define P_LVMRSRCOWNER 0x01000000 /* can handle the resource ownership of */
458 #define P_LRETURNWAITER 0x02000000 /* thread is waiting on P_LRETURNWAIT being cleared */
459 #define P_LTERM_DECRYPTFAIL 0x04000000 /* process terminating due to key failure to decrypt */
460 #define P_LTERM_JETSAM 0x08000000 /* process is being jetsam'd */
461 #define P_JETSAM_VMPAGESHORTAGE 0x00000000 /* jetsam: lowest jetsam priority proc, killed due to vm page shortage */
462 #define P_JETSAM_VMTHRASHING 0x10000000 /* jetsam: lowest jetsam priority proc, killed due to vm thrashing */
463 #define P_JETSAM_HIWAT 0x20000000 /* jetsam: high water mark */
464 #define P_JETSAM_PID 0x30000000 /* jetsam: pid */
465 #define P_JETSAM_IDLEEXIT 0x40000000 /* jetsam: idle exit */
466 #define P_JETSAM_VNODE 0x50000000 /* jetsam: vnode kill */
467 #define P_JETSAM_FCTHRASHING 0x60000000 /* jetsam: lowest jetsam priority proc, killed due to filecache thrashing */
468 #define P_JETSAM_MASK 0x70000000 /* jetsam type mask */
470 /* Process control state for resource starvation */
471 #define P_PCTHROTTLE 1
476 /* Process control action state on resrouce starvation */
477 #define PROC_ACTION_MASK 0xffff0000;
478 #define PROC_CONTROL_STATE(p) (p->p_pcaction & P_PCMAX)
479 #define PROC_ACTION_STATE(p) ((p->p_pcaction >> 16) & P_PCMAX)
480 #define PROC_SETACTION_STATE(p) (p->p_pcaction = (PROC_CONTROL_STATE(p) | (PROC_CONTROL_STATE(p) << 16)))
481 #define PROC_RESETACTION_STATE(p) (p->p_pcaction = PROC_CONTROL_STATE(p))
483 /* additional process flags */
484 #define P_LADVLOCK 0x01
485 #define P_LXBKIDLEINPROG 0x02
487 /* p_vfs_iopolicy flags */
488 #define P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY 0x0001
490 /* defns for proc_iterate */
491 #define PROC_ALLPROCLIST 1 /* walk the allproc list (procs not exited yet) */
492 #define PROC_ZOMBPROCLIST 2 /* walk the zombie list */
493 #define PROC_NOWAITTRANS 4 /* do not wait for transitions (checkdirs only) */
495 /* defns for pgrp_iterate */
496 #define PGRP_DROPREF 1
497 #define PGRP_BLOCKITERATE 2
499 /* return values of the proc iteration callback routine */
500 #define PROC_RETURNED 0
501 #define PROC_RETURNED_DONE 1
502 #define PROC_CLAIMED 2
503 #define PROC_CLAIMED_DONE 3
505 /* process creation arguments */
506 #define PROC_CREATE_FORK 0 /* independent child (running) */
507 #define PROC_CREATE_SPAWN 1 /* independent child (suspended) */
508 #define PROC_CREATE_VFORK 2 /* child borrows context */
511 /* LP64 version of extern_proc. all pointers
512 * grow when we're dealing with a 64-bit process.
513 * WARNING - keep in sync with extern_proc
514 * but use native alignment of 64-bit process.
518 #include <sys/time.h> /* user_timeval, user_itimerval */
520 /* This packing breaks symmetry with userspace side (struct extern_proc
521 * of proc.h) for the ARMV7K ABI where 64-bit types are 64-bit aligned
524 struct user32_extern_proc
{
527 uint32_t __p_forw
; /* Doubly-linked run/sleep queue. */
530 struct user32_timeval __p_starttime
; /* process start time */
532 uint32_t p_vmspace
; /* Address space. */
533 uint32_t p_sigacts
; /* Signal actions, state (PROC ONLY). */
534 int p_flag
; /* P_* flags. */
535 char p_stat
; /* S* process status. */
536 pid_t p_pid
; /* Process identifier. */
537 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
538 int p_dupfd
; /* Sideways return value from fdopen. XXX */
540 uint32_t user_stack
; /* where user stack was allocated */
541 uint32_t exit_thread
; /* XXX Which thread is exiting? */
542 int p_debugger
; /* allow to debug */
543 boolean_t sigwait
; /* indication to suspend */
545 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
546 int p_cpticks
; /* Ticks of cpu time. */
547 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
548 uint32_t p_wchan
; /* Sleep address. */
549 uint32_t p_wmesg
; /* Reason for sleep. */
550 u_int p_swtime
; /* Time swapped in or out. */
551 u_int p_slptime
; /* Time since last blocked. */
552 struct user32_itimerval p_realtimer
; /* Alarm timer. */
553 struct user32_timeval p_rtime
; /* Real time. */
554 u_quad_t p_uticks
; /* Statclock hits in user mode. */
555 u_quad_t p_sticks
; /* Statclock hits in system mode. */
556 u_quad_t p_iticks
; /* Statclock hits processing intr. */
557 int p_traceflag
; /* Kernel trace points. */
558 uint32_t p_tracep
; /* Trace to vnode. */
559 int p_siglist
; /* DEPRECATED */
560 uint32_t p_textvp
; /* Vnode of executable. */
561 int p_holdcnt
; /* If non-zero, don't swap. */
562 sigset_t p_sigmask
; /* DEPRECATED. */
563 sigset_t p_sigignore
; /* Signals being ignored. */
564 sigset_t p_sigcatch
; /* Signals being caught by user. */
565 u_char p_priority
; /* Process priority. */
566 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
567 char p_nice
; /* Process "nice" value. */
568 char p_comm
[MAXCOMLEN
+1];
569 uint32_t p_pgrp
; /* Pointer to process group. */
570 uint32_t p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
571 u_short p_xstat
; /* Exit status for wait; also stop signal. */
572 u_short p_acflag
; /* Accounting flags. */
573 uint32_t p_ru
; /* Exit information. XXX */
576 struct user64_extern_proc
{
579 user_addr_t __p_forw
; /* Doubly-linked run/sleep queue. */
580 user_addr_t __p_back
;
582 struct user64_timeval __p_starttime
; /* process start time */
584 user_addr_t p_vmspace
; /* Address space. */
585 user_addr_t p_sigacts
; /* Signal actions, state (PROC ONLY). */
586 int p_flag
; /* P_* flags. */
587 char p_stat
; /* S* process status. */
588 pid_t p_pid
; /* Process identifier. */
589 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
590 int p_dupfd
; /* Sideways return value from fdopen. XXX */
592 user_addr_t user_stack
__attribute((aligned(8))); /* where user stack was allocated */
593 user_addr_t exit_thread
; /* XXX Which thread is exiting? */
594 int p_debugger
; /* allow to debug */
595 boolean_t sigwait
; /* indication to suspend */
597 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
598 int p_cpticks
; /* Ticks of cpu time. */
599 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
600 user_addr_t p_wchan
__attribute((aligned(8))); /* Sleep address. */
601 user_addr_t p_wmesg
; /* Reason for sleep. */
602 u_int p_swtime
; /* Time swapped in or out. */
603 u_int p_slptime
; /* Time since last blocked. */
604 struct user64_itimerval p_realtimer
; /* Alarm timer. */
605 struct user64_timeval p_rtime
; /* Real time. */
606 u_quad_t p_uticks
; /* Statclock hits in user mode. */
607 u_quad_t p_sticks
; /* Statclock hits in system mode. */
608 u_quad_t p_iticks
; /* Statclock hits processing intr. */
609 int p_traceflag
; /* Kernel trace points. */
610 user_addr_t p_tracep
__attribute((aligned(8))); /* Trace to vnode. */
611 int p_siglist
; /* DEPRECATED */
612 user_addr_t p_textvp
__attribute((aligned(8))); /* Vnode of executable. */
613 int p_holdcnt
; /* If non-zero, don't swap. */
614 sigset_t p_sigmask
; /* DEPRECATED. */
615 sigset_t p_sigignore
; /* Signals being ignored. */
616 sigset_t p_sigcatch
; /* Signals being caught by user. */
617 u_char p_priority
; /* Process priority. */
618 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
619 char p_nice
; /* Process "nice" value. */
620 char p_comm
[MAXCOMLEN
+1];
621 user_addr_t p_pgrp
__attribute((aligned(8))); /* Pointer to process group. */
622 user_addr_t p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
623 u_short p_xstat
; /* Exit status for wait; also stop signal. */
624 u_short p_acflag
; /* Accounting flags. */
625 user_addr_t p_ru
__attribute((aligned(8))); /* Exit information. XXX */
630 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
631 * as it is used to represent "no process group".
633 extern int nprocs
, maxproc
; /* Current and max number of procs. */
634 extern int maxprocperuid
; /* Current number of procs per uid */
635 extern int hard_maxproc
; /* hard limit */
636 extern unsigned int proc_shutdown_exitcount
;
638 #define PID_MAX 99999
639 #define NO_PID 100000
640 extern lck_mtx_t
* proc_list_mlock
;
641 extern lck_mtx_t
* proc_klist_mlock
;
643 #define BSD_SIMUL_EXECS 33 /* 32 , allow for rounding */
644 #define BSD_PAGEABLE_SIZE_PER_EXEC (NCARGS + PAGE_SIZE + PAGE_SIZE) /* page for apple vars, page for executable header */
645 extern int execargs_cache_size
;
646 extern int execargs_free_count
;
647 extern vm_offset_t
* execargs_cache
;
649 #define SESS_LEADER(p, sessp) ((sessp)->s_leader == (p))
651 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
652 extern LIST_HEAD(pidhashhead
, proc
) *pidhashtbl
;
653 extern u_long pidhash
;
655 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
656 extern LIST_HEAD(pgrphashhead
, pgrp
) *pgrphashtbl
;
657 extern u_long pgrphash
;
658 #define SESSHASH(sessid) (&sesshashtbl[(sessid) & sesshash])
659 extern LIST_HEAD(sesshashhead
, session
) *sesshashtbl
;
660 extern u_long sesshash
;
662 extern lck_grp_t
* proc_lck_grp
;
663 #if CONFIG_FINE_LOCK_GROUPS
664 extern lck_grp_t
* proc_mlock_grp
;
665 extern lck_grp_t
* proc_fdmlock_grp
;
666 extern lck_grp_t
* proc_ucred_mlock_grp
;
667 extern lck_grp_t
* proc_slock_grp
;
669 extern lck_grp_attr_t
* proc_lck_grp_attr
;
670 extern lck_attr_t
* proc_lck_attr
;
672 LIST_HEAD(proclist
, proc
);
673 extern struct proclist allproc
; /* List of all processes. */
674 extern struct proclist zombproc
; /* List of zombie processes. */
675 extern struct proc
*initproc
;
676 extern void procinit(void);
677 extern void proc_lock(struct proc
*);
678 extern void proc_unlock(struct proc
*);
679 extern void proc_spinlock(struct proc
*);
680 extern void proc_spinunlock(struct proc
*);
681 extern void proc_list_lock(void);
682 extern void proc_list_unlock(void);
683 extern void proc_klist_lock(void);
684 extern void proc_klist_unlock(void);
685 extern void proc_fdlock(struct proc
*);
686 extern void proc_fdlock_spin(struct proc
*);
687 extern void proc_fdunlock(struct proc
*);
688 extern void proc_fdlock_assert(proc_t p
, int assertflags
);
689 extern void proc_ucred_lock(struct proc
*);
690 extern void proc_ucred_unlock(struct proc
*);
691 __private_extern__
int proc_core_name(const char *name
, uid_t uid
, pid_t pid
,
692 char *cr_name
, size_t cr_name_len
);
693 extern int isinferior(struct proc
*, struct proc
*);
694 __private_extern__
struct proc
*pzfind(pid_t
); /* Find zombie by id. */
695 __private_extern__
struct proc
*proc_find_zombref(pid_t
); /* Find zombie by id. */
696 __private_extern__
void proc_drop_zombref(struct proc
* p
); /* Find zombie by id. */
699 extern int chgproccnt(uid_t uid
, int diff
);
700 extern void pinsertchild(struct proc
*parent
, struct proc
*child
);
701 extern int enterpgrp(struct proc
*p
, pid_t pgid
, int mksess
);
702 extern void fixjobc(struct proc
*p
, struct pgrp
*pgrp
, int entering
);
703 extern int inferior(struct proc
*p
);
704 extern int leavepgrp(struct proc
*p
);
705 extern void resetpriority(struct proc
*);
706 extern void setrunnable(struct proc
*);
707 extern void setrunqueue(struct proc
*);
708 extern int sleep(void *chan
, int pri
);
709 extern int tsleep0(void *chan
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
710 extern int tsleep1(void *chan
, int pri
, const char *wmesg
, u_int64_t abstime
, int (*continuation
)(int));
711 extern int msleep0(void *chan
, lck_mtx_t
*mtx
, int pri
, const char *wmesg
, int timo
, int (*continuation
)(int));
712 extern void vfork_return(struct proc
*child
, int32_t *retval
, int rval
);
713 extern int exit1(struct proc
*, int, int *);
714 extern int exit1_internal(struct proc
*, int, int *, boolean_t
, boolean_t
, int);
715 extern int fork1(proc_t
, thread_t
*, int, coalition_t
*);
716 extern void vfork_exit_internal(struct proc
*p
, int rv
, int forced
);
717 extern void proc_reparentlocked(struct proc
*child
, struct proc
* newparent
, int cansignal
, int locked
);
718 extern int pgrp_iterate(struct pgrp
* pgrp
, int flags
, int (*callout
)(proc_t
, void *), void *arg
, int (*filterfn
)(proc_t
, void *), void *filterarg
);
719 extern int proc_iterate(int flags
, int (*callout
)(proc_t
, void *), void *arg
, int (*filterfn
)(proc_t
, void *), void *filterarg
);
720 extern int proc_rebootscan(int (*callout
)(proc_t
, void *), void *arg
, int (*filterfn
)(proc_t
, void *), void *filterarg
);
721 extern int proc_childrenwalk(proc_t p
, int (*callout
)(proc_t
, void *), void *arg
);
722 extern proc_t
proc_findinternal(int pid
, int locked
);
723 extern proc_t
proc_findthread(thread_t thread
);
724 extern void proc_refdrain(proc_t
);
725 extern void proc_childdrainlocked(proc_t
);
726 extern void proc_childdrainstart(proc_t
);
727 extern void proc_childdrainend(proc_t
);
728 extern void proc_checkdeadrefs(proc_t
);
729 struct proc
*pfind_locked(pid_t
);
730 extern struct pgrp
*pgfind(pid_t
);
731 extern void pg_rele(struct pgrp
* pgrp
);
732 extern struct session
* session_find_internal(pid_t sessid
);
733 extern struct pgrp
* proc_pgrp(proc_t
);
734 extern struct pgrp
* tty_pgrp(struct tty
* tp
);
735 extern struct pgrp
* pgfind_internal(pid_t
);
736 extern struct session
* proc_session(proc_t
);
737 extern void pgrp_lock(struct pgrp
* pgrp
);
738 extern void pgrp_unlock(struct pgrp
* pgrp
);
739 extern void session_lock(struct session
* sess
);
740 extern void session_unlock(struct session
* sess
);
741 extern struct session
* pgrp_session(struct pgrp
* pgrp
);
742 extern void session_rele(struct session
*sess
);
743 extern int isbackground(proc_t p
, struct tty
*tp
);
744 extern proc_t
proc_parent(proc_t
);
745 extern proc_t
proc_parentholdref(proc_t
);
746 extern int proc_parentdropref(proc_t
, int);
747 int itimerfix(struct timeval
*tv
);
748 int itimerdecr(struct proc
* p
, struct itimerval
*itp
, int usec
);
749 int timespec_is_valid(const struct timespec
*);
750 void proc_signalstart(struct proc
*, int locked
);
751 void proc_signalend(struct proc
*, int locked
);
752 int proc_transstart(struct proc
*, int locked
, int non_blocking
);
753 void proc_transcommit(struct proc
*, int locked
);
754 void proc_transend(struct proc
*, int locked
);
755 int proc_transwait(struct proc
*, int locked
);
756 void proc_rele_locked(struct proc
* p
);
757 struct proc
*proc_ref_locked(struct proc
* p
);
758 void proc_knote(struct proc
* p
, long hint
);
759 void proc_knote_drain(struct proc
*p
);
760 void workqueue_init_lock(proc_t p
);
761 void workqueue_destroy_lock(proc_t p
);
762 void proc_setregister(proc_t p
);
763 void proc_resetregister(proc_t p
);
764 /* returns the first thread_t in the process, or NULL XXX for NFS, DO NOT USE */
765 thread_t
proc_thread(proc_t
);
766 extern int proc_pendingsignals(proc_t
, sigset_t
);
767 int proc_getpcontrol(int pid
, int * pcontrolp
);
768 int proc_dopcontrol(proc_t p
);
769 int proc_resetpcontrol(int pid
);
771 void pth_proc_hashinit(proc_t
);
772 void pth_proc_hashdelete(proc_t
);
773 void pth_global_hashinit(void);
774 extern thread_call_t psynch_thcall
;
775 void psynch_wq_cleanup(__unused
void * param
, __unused
void * param1
);
776 extern lck_mtx_t
* pthread_list_mlock
;
778 struct uthread
* current_uthread(void);
780 void proc_set_return_wait(struct proc
*);
781 void proc_clear_return_wait(proc_t p
, thread_t child_thread
);
782 void proc_wait_to_return(void);
784 /* return 1 if process is forcing case-sensitive HFS+ access, 0 for default */
785 extern int proc_is_forcing_hfs_case_sensitivity(proc_t
);
787 pid_t
dtrace_proc_selfpid(void);
788 pid_t
dtrace_proc_selfppid(void);
789 uid_t
dtrace_proc_selfruid(void);
790 #endif /* !_SYS_PROC_INTERNAL_H_ */