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