]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/proc_internal.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / proc_internal.h
CommitLineData
91447636 1/*
cb323159 2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 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_
0a7de745 76#define _SYS_PROC_INTERNAL_H_
91447636 77
2d21ac55 78#include <libkern/OSAtomic.h>
91447636 79#include <sys/proc.h>
39037602
A
80#include <mach/resource_monitors.h> // command/proc_name_t
81
91447636
A
82__BEGIN_DECLS
83#include <kern/locks.h>
b0d623f7
A
84#if PSYNCH
85#include <kern/thread_call.h>
86#endif /* PSYNCH */
91447636
A
87__END_DECLS
88
593a1d5f 89#if DEBUG
0a7de745 90#define __PROC_INTERNAL_DEBUG 1
593a1d5f 91#endif
2d21ac55 92
0a7de745 93/*
2d21ac55
A
94 * The short form for various locks that protect fields in the data structures.
95 * PL = Process Lock
96 * PGL = Process Group Lock
97 * PFDL = Process File Desc Lock
4bd07ac2 98 * PUCL = Process User Credentials Lock
2d21ac55 99 * PSL = Process Spin Lock
2d21ac55
A
100 * LL = List Lock
101 * SL = Session Lock
0a7de745 102 */
2d21ac55
A
103struct label;
104
91447636
A
105/*
106 * One structure allocated per session.
107 */
0a7de745
A
108struct session {
109 int s_count; /* Ref cnt; pgrps in session. (LL) */
110 struct proc * s_leader; /* Session leader.(static) */
111 struct vnode * s_ttyvp; /* Vnode of controlling terminal.(SL) */
112 int s_ttyvid; /* Vnode id of the controlling terminal (SL) */
113 struct tty * s_ttyp; /* Controlling terminal. (SL + ttyvp != NULL) */
114 pid_t s_ttypgrpid; /* tty's pgrp id */
115 pid_t s_sid; /* Session ID (static) */
116 char s_login[MAXLOGNAME]; /* Setlogin() name.(SL) */
117 int s_flags; /* Session flags (s_mlock) */
118 LIST_ENTRY(session) s_hash; /* Hash chain.(LL) */
119 lck_mtx_t s_mlock; /* mutex lock to protect session */
120 int s_listflags;
91447636
A
121};
122
cb323159 123#define SESSION_NULL (struct session *)NULL
2d21ac55 124
b0d623f7
A
125/*
126 * accessor for s_ttyp which treats it as invalid if s_ttyvp is not valid;
127 * note that s_ttyp is not a reference in the session structre, so it can
128 * become invalid out from under the session if the device is closed, without
129 * this protection. We can't safely make it into a reference without reflexive
130 * close notification of tty devices through cdevsw[].
131 *
132 * NB: <sys/tty.h> is not in scope and there is not typedef type enforcement,
133 * or '0' below would be 'TTY_NULL'.
134 */
0a7de745 135#define SESSION_TP(sp) (((sp)->s_ttyvp != 0) ? (sp)->s_ttyp : 0)
b0d623f7 136
2d21ac55
A
137/*
138 * Session flags; used to tunnel information to lower layers and line
139 * disciplines, etc.
140 */
0a7de745
A
141#define S_DEFAULT 0x00000000 /* No flags set */
142#define S_NOCTTY 0x00000001 /* Do not associate controlling tty */
143#define S_CTTYREF 0x00000010 /* vnode ref taken by cttyopen */
2d21ac55
A
144
145
0a7de745
A
146#define S_LIST_TERM 1 /* marked for termination */
147#define S_LIST_DEAD 2 /* already dead */
91447636
A
148/*
149 * One structure allocated per process group.
150 */
0a7de745
A
151struct pgrp {
152 LIST_ENTRY(pgrp) pg_hash; /* Hash chain. (LL) */
153 LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members. (PGL) */
154 struct session * pg_session; /* Pointer to session. (LL ) */
155 pid_t pg_id; /* Pgrp id. (static) */
156 int pg_jobc; /* # procs qualifying pgrp for job control (PGL) */
157 int pg_membercnt; /* Number of processes in the pgrocess group (PGL) */
158 int pg_refcount; /* number of current iterators (LL) */
159 unsigned int pg_listflags; /* (LL) */
160 lck_mtx_t pg_mlock; /* mutex lock to protect pgrp */
91447636
A
161};
162
0a7de745 163#define PGRP_FLAG_TERMINATE 1
2d21ac55 164#define PGRP_FLAG_WAITTERMINATE 2
0a7de745
A
165#define PGRP_FLAG_DEAD 4
166#define PGRP_FLAG_ITERABEGIN 8
167#define PGRP_FLAG_ITERWAIT 0x10
2d21ac55 168
cb323159 169#define PGRP_NULL (struct pgrp *)NULL
91447636
A
170struct proc;
171
cb323159 172#define PROC_NULL (struct proc *)NULL
91447636 173
6d2010ae
A
174#define PROC_UPDATE_CREDS_ONPROC(p) { \
175 p->p_uid = kauth_cred_getuid(p->p_ucred); \
176 p->p_gid = kauth_cred_getgid(p->p_ucred); \
177 p->p_ruid = kauth_cred_getruid(p->p_ucred); \
178 p->p_rgid = kauth_cred_getrgid(p->p_ucred); \
179 p->p_svuid = kauth_cred_getsvuid(p->p_ucred); \
180 p->p_svgid = kauth_cred_getsvgid(p->p_ucred); \
181 }
91447636
A
182/*
183 * Description of a process.
184 *
185 * This structure contains the information needed to manage a thread of
186 * control, known in UN*X as a process; it has references to substructures
187 * containing descriptions of things that the process uses, but may share
188 * with related processes. The process structure and the substructures
189 * are always addressible except for those marked "(PROC ONLY)" below,
190 * which might be addressible only on a processor on which the process
191 * is running.
192 */
0a7de745
A
193struct proc {
194 LIST_ENTRY(proc) p_list; /* List of all processes. */
195
f427ee49
A
196 void * XNU_PTRAUTH_SIGNED_PTR("proc.task") task; /* corresponding task (static)*/
197 struct proc * XNU_PTRAUTH_SIGNED_PTR("proc.p_pptr") p_pptr; /* Pointer to parent process.(LL) */
0a7de745 198 pid_t p_ppid; /* process's parent pid number */
cb323159 199 pid_t p_original_ppid; /* process's original parent pid number, doesn't change if reparented */
0a7de745
A
200 pid_t p_pgrpid; /* process group id of the process (LL)*/
201 uid_t p_uid;
202 gid_t p_gid;
203 uid_t p_ruid;
204 gid_t p_rgid;
205 uid_t p_svuid;
206 gid_t p_svgid;
207 uint64_t p_uniqueid; /* process unique ID - incremented on fork/spawn/vfork, remains same across exec. */
208 uint64_t p_puniqueid; /* parent's unique ID - set on fork/spawn/vfork, doesn't change if reparented. */
209
210 lck_mtx_t p_mlock; /* mutex lock for proc */
211 pid_t p_pid; /* Process identifier. (static)*/
212 char p_stat; /* S* process status. (PL)*/
213 char p_shutdownstate;
214 char p_kdebug; /* P_KDEBUG eq (CC)*/
215 char p_btrace; /* P_BTRACE eq (CC)*/
216
217 LIST_ENTRY(proc) p_pglist; /* List of processes in pgrp.(PGL) */
218 LIST_ENTRY(proc) p_sibling; /* List of sibling processes. (LL)*/
219 LIST_HEAD(, proc) p_children; /* Pointer to list of children. (LL)*/
220 TAILQ_HEAD(, uthread) p_uthlist; /* List of uthreads (PL) */
221
222 LIST_ENTRY(proc) p_hash; /* Hash chain. (LL)*/
91447636 223
490019cf
A
224#if CONFIG_PERSONAS
225 struct persona *p_persona;
226 LIST_ENTRY(proc) p_persona_list;
227#endif
228
0a7de745
A
229 lck_mtx_t p_fdmlock; /* proc lock to protect fdesc */
230 lck_mtx_t p_ucred_mlock; /* mutex lock to protect p_ucred */
91447636 231
2d21ac55 232 /* substructures: */
f427ee49 233 kauth_cred_t XNU_PTRAUTH_SIGNED_PTR("proc.p_ucred") p_ucred; /* Process owner's identity. (PUCL) */
0a7de745
A
234 struct filedesc *p_fd; /* Ptr to open files structure. (PFDL) */
235 struct pstats *p_stats; /* Accounting/statistics (PL). */
236 struct plimit *p_limit; /* Process limits.(PL) */
237
238 struct sigacts *p_sigacts; /* Signal actions, state (PL) */
239 lck_spin_t p_slock; /* spin lock for itimer/profil protection */
240
0a7de745
A
241 int p_siglist; /* signals captured back from threads */
242 unsigned int p_flag; /* P_* flags. (atomic bit ops) */
243 unsigned int p_lflag; /* local flags (PL) */
244 unsigned int p_listflag; /* list flags (LL) */
245 unsigned int p_ladvflag; /* local adv flags (atomic) */
246 int p_refcount; /* number of outstanding users(LL) */
247 int p_childrencnt; /* children holding ref on parent (LL) */
248 int p_parentref; /* children lookup ref on parent (LL) */
249 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
250 u_int p_xstat; /* Exit status for wait; also stop signal. */
2d21ac55
A
251
252#ifdef _PROC_HAS_SCHEDINFO_
253 /* may need cleanup, not used */
0a7de745
A
254 u_int p_estcpu; /* Time averaged value of p_cpticks.(used by aio and proc_comapre) */
255 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime (used by aio)*/
256 u_int p_slptime; /* used by proc_compare */
2d21ac55
A
257#endif /* _PROC_HAS_SCHEDINFO_ */
258
0a7de745
A
259 struct itimerval p_realtimer; /* Alarm timer. (PSL) */
260 struct timeval p_rtime; /* Real time.(PSL) */
261 struct itimerval p_vtimer_user; /* Virtual timers.(PSL) */
262 struct itimerval p_vtimer_prof; /* (PSL) */
263
264 struct timeval p_rlim_cpu; /* Remaining rlim cpu value.(PSL) */
265 int p_debugger; /* NU 1: can exec set-bit programs if suser */
266 boolean_t sigwait; /* indication to suspend (PL) */
267 void *sigwait_thread; /* 'thread' holding sigwait(PL) */
268 void *exit_thread; /* Which thread is exiting(PL) */
269 void * p_vforkact; /* activation running this vfork proc)(static) */
270 int p_vforkcnt; /* number of outstanding vforks(PL) */
271 int p_fpdrainwait; /* (PFDL) */
2d21ac55 272 /* Following fields are info from SIGCHLD (PL) */
0a7de745
A
273 pid_t si_pid; /* (PL) */
274 u_int si_status; /* (PL) */
275 u_int si_code; /* (PL) */
276 uid_t si_uid; /* (PL) */
2d21ac55 277
0a7de745 278 void * vm_shm; /* (SYSV SHM Lock) for sysV shared memory */
2d21ac55
A
279
280#if CONFIG_DTRACE
0a7de745
A
281 user_addr_t p_dtrace_argv; /* (write once, read only after that) */
282 user_addr_t p_dtrace_envp; /* (write once, read only after that) */
283 lck_mtx_t p_dtrace_sprlock; /* sun proc lock emulation */
d9a64523 284 uint8_t p_dtrace_stop; /* indicates a DTrace-desired stop */
0a7de745
A
285 int p_dtrace_probes; /* (PL) are there probes for this proc? */
286 u_int p_dtrace_count; /* (sprlock) number of DTrace tracepoints */
287 struct dtrace_ptss_page* p_dtrace_ptss_pages; /* (sprlock) list of user ptss pages */
288 struct dtrace_ptss_page_entry* p_dtrace_ptss_free_list; /* (atomic) list of individual ptss entries */
289 struct dtrace_helpers* p_dtrace_helpers; /* (dtrace_lock) DTrace per-proc private */
290 struct dof_ioctl_data* p_dtrace_lazy_dofs; /* (sprlock) unloaded dof_helper_t's */
2d21ac55
A
291#endif /* CONFIG_DTRACE */
292
293/* XXXXXXXXXXXXX BCOPY'ed on fork XXXXXXXXXXXXXXXX */
294/* The following fields are all copied upon creation in fork. */
0a7de745 295#define p_startcopy p_argslen
91447636 296
0a7de745
A
297 u_int p_argslen; /* Length of process arguments. */
298 int p_argc; /* saved argc for sysctl_procargs() */
299 user_addr_t user_stack; /* where user stack was allocated */
f427ee49 300 struct vnode * XNU_PTRAUTH_SIGNED_PTR("proc.p_textvp") p_textvp; /* Vnode of executable. */
0a7de745 301 off_t p_textoff; /* offset in executable vnode */
91447636 302
0a7de745
A
303 sigset_t p_sigmask; /* DEPRECATED */
304 sigset_t p_sigignore; /* Signals being ignored. (PL) */
305 sigset_t p_sigcatch; /* Signals being caught by user.(PL) */
91447636 306
0a7de745
A
307 u_char p_priority; /* (NU) Process priority. */
308 u_char p_resv0; /* (NU) User-priority based on p_cpu and p_nice. */
309 char p_nice; /* Process "nice" value.(PL) */
310 u_char p_resv1; /* (NU) User-priority based on p_cpu and p_nice. */
91447636 311
39037602
A
312 // types currently in sys/param.h
313 command_t p_comm;
0a7de745
A
314 proc_name_t p_name; /* can be changed by the process */
315 uint8_t p_xhighbits; /* Stores the top byte of exit status to avoid truncation*/
316 pid_t p_contproc; /* last PID to send us a SIGCONT (PL) */
39037602 317
f427ee49 318 struct pgrp * XNU_PTRAUTH_SIGNED_PTR("proc.p_pgrp") p_pgrp; /* Pointer to process group. (LL) */
0a7de745
A
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 */
91447636 322
0a7de745 323 /*
fe8ab488
A
324 * CPU type and subtype of binary slice executed in
325 * this process. Protected by proc lock.
326 */
0a7de745
A
327 cpu_type_t p_cputype;
328 cpu_subtype_t p_cpusubtype;
fe8ab488 329
cb323159
A
330 uint8_t *syscall_filter_mask; /* syscall filter bitmask (length: nsysent bits) */
331 uint32_t p_platform;
f427ee49 332 uint32_t p_min_sdk;
cb323159
A
333 uint32_t p_sdk;
334
91447636 335/* End area that is copied on creation. */
2d21ac55 336/* XXXXXXXXXXXXX End of BCOPY'ed on fork (AIOLOCK)XXXXXXXXXXXXXXXX */
0a7de745
A
337#define p_endcopy p_aio_total_count
338 int p_aio_total_count; /* all allocated AIO requests for this proc */
0a7de745
A
339 TAILQ_HEAD(, aio_workq_entry ) p_aio_activeq; /* active async IO requests */
340 TAILQ_HEAD(, aio_workq_entry ) p_aio_doneq; /* completed async IO requests */
2d21ac55
A
341
342 struct klist p_klist; /* knote list (PL ?)*/
91447636 343
0a7de745
A
344 struct rusage_superset *p_ru; /* Exit information. (PL) */
345 thread_t p_signalholder;
346 thread_t p_transholder;
347 int p_sigwaitcnt;
2d21ac55 348 /* DEPRECATE following field */
0a7de745
A
349 u_short p_acflag; /* Accounting flags. */
350 volatile u_short p_vfs_iopolicy; /* VFS iopolicy flags. (atomic bit ops) */
351
352 user_addr_t p_threadstart; /* pthread start fn */
353 user_addr_t p_wqthread; /* pthread workqueue fn */
354 int p_pthsize; /* pthread size */
355 uint32_t p_pth_tsd_offset; /* offset from pthread_t to TSD for new threads */
356 user_addr_t p_stack_addr_hint; /* stack allocation hint for wq threads */
357 struct workqueue *_Atomic p_wqptr; /* workq ptr */
358
359 struct timeval p_start; /* starting time */
360 void * p_rcall;
361 int p_ractive;
362 int p_idversion; /* version of process identity */
363 void * p_pthhash; /* pthread waitqueue hash */
39236c6e
A
364 volatile uint64_t was_throttled __attribute__((aligned(8))); /* Counter for number of throttled I/Os */
365 volatile uint64_t did_throttle __attribute__((aligned(8))); /* Counter for number of I/Os this proc throttled */
366
2d21ac55 367#if DIAGNOSTIC
91447636
A
368 unsigned int p_fdlock_pc[4];
369 unsigned int p_fdunlock_pc[4];
91447636
A
370#if SIGNAL_DEBUG
371 unsigned int lockpc[8];
372 unsigned int unlockpc[8];
373#endif /* SIGNAL_DEBUG */
374#endif /* DIAGNOSTIC */
0a7de745
A
375 uint64_t p_dispatchqueue_offset;
376 uint64_t p_dispatchqueue_serialno_offset;
cb323159 377 uint64_t p_dispatchqueue_label_offset;
0a7de745
A
378 uint64_t p_return_to_kernel_offset;
379 uint64_t p_mach_thread_self_offset;
316670eb 380#if VM_PRESSURE_EVENTS
0a7de745 381 struct timeval vm_pressure_last_notify_tstamp;
316670eb 382#endif
39236c6e
A
383
384#if CONFIG_MEMORYSTATUS
385 /* Fields protected by proc list lock */
386 TAILQ_ENTRY(proc) p_memstat_list; /* priority bucket link */
cb323159 387 uint32_t p_memstat_state; /* state. Also used as a wakeup channel when the memstat's LOCKED bit changes */
39236c6e
A
388 int32_t p_memstat_effectivepriority; /* priority after transaction state accounted for */
389 int32_t p_memstat_requestedpriority; /* active priority */
cb323159 390 int32_t p_memstat_assertionpriority; /* assertion driven priority */
39236c6e 391 uint32_t p_memstat_dirty; /* dirty state */
2a1bd2d3
A
392#if CONFIG_FREEZE
393 uint8_t p_memstat_freeze_skip_reason; /* memorystaus_freeze_skipped_reason_t. Protected by the freezer mutex. */
394#endif
fe8ab488 395 uint64_t p_memstat_userdata; /* user state */
39236c6e 396 uint64_t p_memstat_idledeadline; /* time at which process became clean */
39037602 397 uint64_t p_memstat_idle_start; /* abstime process transitions into the idle band */
0a7de745 398 uint64_t p_memstat_idle_delta; /* abstime delta spent in idle band */
3e170ce0 399 int32_t p_memstat_memlimit; /* cached memory limit, toggles between active and inactive limits */
0a7de745
A
400 int32_t p_memstat_memlimit_active; /* memory limit enforced when process is in active jetsam state */
401 int32_t p_memstat_memlimit_inactive; /* memory limit enforced when process is in inactive jetsam state */
cb323159 402 int32_t p_memstat_relaunch_flags; /* flags indicating relaunch behavior for the process */
39236c6e 403#if CONFIG_FREEZE
d9a64523 404 uint32_t p_memstat_freeze_sharedanon_pages; /* shared pages left behind after freeze */
0a7de745
A
405 uint32_t p_memstat_frozen_count;
406 uint32_t p_memstat_thaw_count;
c3c9b80d 407 uint32_t p_memstat_last_thaw_interval; /* In which freezer interval was this last thawed? */
39236c6e
A
408#endif /* CONFIG_FREEZE */
409#endif /* CONFIG_MEMORYSTATUS */
3e170ce0
A
410
411 /* cached proc-specific data required for corpse inspection */
0a7de745 412 pid_t p_responsible_pid; /* pid resonsible for this process */
5ba3f43e 413 _Atomic uint32_t p_user_faults; /* count the number of user faults generated */
39037602 414
cb323159
A
415 uint32_t p_memlimit_increase; /* byte increase for memory limit for dyld SPI rdar://problem/49950264, structure packing 32-bit and 64-bit */
416
39037602 417 struct os_reason *p_exit_reason;
a39ff7e2 418
f427ee49 419#if CONFIG_PROC_UDATA_STORAGE
0a7de745 420 uint64_t p_user_data; /* general-purpose storage for userland-provided data */
f427ee49
A
421#endif /* CONFIG_PROC_UDATA_STORAGE */
422
423 char * p_subsystem_root_path;
bca245ac 424 lck_rw_t p_dirs_lock; /* keeps fd_cdir and fd_rdir stable across a lookup */
f427ee49
A
425 pid_t p_sessionid;
426};
427
428/*
429 * Identify a process uniquely.
430 * proc_ident's fields match 1-1 with those in struct proc.
431 */
432struct proc_ident {
433 uint64_t p_uniqueid;
434 pid_t p_pid;
435 int p_idversion;
91447636
A
436};
437
2d21ac55
A
438#define PGRPID_DEAD 0xdeaddead
439
0a7de745
A
440/* p_listflag */
441#define P_LIST_DRAIN 0x00000001
442#define P_LIST_DRAINWAIT 0x00000002
443#define P_LIST_DRAINED 0x00000004
444#define P_LIST_DEAD 0x00000008
445#define P_LIST_WAITING 0x00000010
446#define P_LIST_EXITED 0x00000040
447#define P_LIST_CHILDDRSTART 0x00000080
448#define P_LIST_CHILDDRAINED 0x00000100
449#define P_LIST_CHILDDRWAIT 0x00000200
450#define P_LIST_CHILDLKWAIT 0x00000400
451#define P_LIST_DEADPARENT 0x00000800
452#define P_LIST_PARENTREFWAIT 0x00001000
453#define P_LIST_INCREATE 0x00002000
2d21ac55 454/* 0x4000 & 0x8000 Not used */
0a7de745
A
455#define P_LIST_INHASH 0x00010000 /* process is in hash */
456#define P_LIST_INPGRP 0x00020000 /* process is in pgrp */
457#define P_LIST_PGRPTRANS 0x00040000 /* pgrp is getting replaced */
458#define P_LIST_PGRPTRWAIT 0x00080000 /* wait for pgrp replacement */
459#define P_LIST_EXITCOUNT 0x00100000 /* counted for process exit */
460#define P_LIST_REFWAIT 0x00200000 /* wait to take a ref */
461
91447636 462
b36670ce 463/* local flags */
0a7de745
A
464#define P_LDELAYTERM 0x00000001 /* */
465#define P_LNOZOMB 0x00000002 /* */
466#define P_LTERM 0x00000004 /* */
467#define P_LEXIT 0x00000008 /* */
468#define P_LPEXIT 0x00000010
469#define P_LTRANSCOMMIT 0x00000020 /* process is committed to trans */
470#define P_LINTRANSIT 0x00000040 /* process in exec or in creation */
471#define P_LTRANSWAIT 0x00000080 /* waiting for trans to complete */
39236c6e
A
472#define P_LVFORK 0x00000100 /* parent proc of a vfork */
473#define P_LINVFORK 0x00000200 /* child proc of a vfork */
2d21ac55
A
474#define P_LTRACED 0x00000400 /* */
475#define P_LSIGEXC 0x00000800 /* */
476#define P_LNOATTACH 0x00001000 /* */
477#define P_LPPWAIT 0x00002000 /* */
0a7de745
A
478#define P_LKQWDRAIN 0x00004000
479#define P_LKQWDRAINWAIT 0x00008000
480#define P_LKQWDEAD 0x00010000
f427ee49 481#define P_LLIMCHANGE 0x00020000 /* process is changing its plimit (rlim_cur, rlim_max) */
0a7de745
A
482#define P_LLIMWAIT 0x00040000
483#define P_LWAITED 0x00080000
484#define P_LINSIGNAL 0x00100000
485#define P_LCUSTOM_STACK 0x00200000 /* process is using custom stack size */
486#define P_LRAGE_VNODES 0x00400000
487#define P_LREGISTER 0x00800000 /* thread start fns registered */
488#define P_LVMRSRCOWNER 0x01000000 /* can handle the resource ownership of */
489#define P_LTERM_DECRYPTFAIL 0x04000000 /* process terminating due to key failure to decrypt */
490#define P_LTERM_JETSAM 0x08000000 /* process is being jetsam'd */
cb323159 491
0a7de745
A
492#define P_JETSAM_VMPAGESHORTAGE 0x00000000 /* jetsam: lowest jetsam priority proc, killed due to vm page shortage */
493#define P_JETSAM_VMTHRASHING 0x10000000 /* jetsam: lowest jetsam priority proc, killed due to vm thrashing */
494#define P_JETSAM_HIWAT 0x20000000 /* jetsam: high water mark */
495#define P_JETSAM_PID 0x30000000 /* jetsam: pid */
496#define P_JETSAM_IDLEEXIT 0x40000000 /* jetsam: idle exit */
497#define P_JETSAM_VNODE 0x50000000 /* jetsam: vnode kill */
498#define P_JETSAM_FCTHRASHING 0x60000000 /* jetsam: lowest jetsam priority proc, killed due to filecache thrashing */
499#define P_JETSAM_MASK 0x70000000 /* jetsam type mask */
cb323159 500#define P_LNSPACE_RESOLVER 0x80000000 /* process is the namespace resolver */
b0d623f7
A
501
502/* Process control state for resource starvation */
0a7de745
A
503#define P_PCTHROTTLE 1
504#define P_PCSUSP 2
505#define P_PCKILL 3
506#define P_PCMAX 3
b0d623f7
A
507
508/* Process control action state on resrouce starvation */
509#define PROC_ACTION_MASK 0xffff0000;
510#define PROC_CONTROL_STATE(p) (p->p_pcaction & P_PCMAX)
511#define PROC_ACTION_STATE(p) ((p->p_pcaction >> 16) & P_PCMAX)
512#define PROC_SETACTION_STATE(p) (p->p_pcaction = (PROC_CONTROL_STATE(p) | (PROC_CONTROL_STATE(p) << 16)))
513#define PROC_RESETACTION_STATE(p) (p->p_pcaction = PROC_CONTROL_STATE(p))
b36670ce 514
d190cdc3
A
515/* Process exit reason macros */
516#define PROC_HAS_EXITREASON(p) (p->p_exit_reason != OS_REASON_NULL)
517#define PROC_EXITREASON_FLAGS(p) p->p_exit_reason->osr_flags
518
6d2010ae 519/* additional process flags */
0a7de745
A
520#define P_LADVLOCK 0x01
521#define P_LXBKIDLEINPROG 0x02
91447636 522
39236c6e 523/* p_vfs_iopolicy flags */
0a7de745
A
524#define P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY 0x0001
525#define P_VFS_IOPOLICY_ATIME_UPDATES 0x0002
cb323159
A
526#define P_VFS_IOPOLICY_MATERIALIZE_DATALESS_FILES 0x0004
527#define P_VFS_IOPOLICY_STATFS_NO_DATA_VOLUME 0x0008
f427ee49
A
528#define P_VFS_IOPOLICY_TRIGGER_RESOLVE_DISABLE 0x0010
529#define P_VFS_IOPOLICY_IGNORE_CONTENT_PROTECTION 0x0020
c3c9b80d
A
530#define P_VFS_IOPOLICY_IGNORE_NODE_PERMISSIONS 0x0040
531#define P_VFS_IOPOLICY_SKIP_MTIME_UPDATE 0x0080
532#define P_VFS_IOPOLICY_VALID_MASK (P_VFS_IOPOLICY_ATIME_UPDATES | P_VFS_IOPOLICY_FORCE_HFS_CASE_SENSITIVITY | P_VFS_IOPOLICY_MATERIALIZE_DATALESS_FILES | P_VFS_IOPOLICY_STATFS_NO_DATA_VOLUME | \
533 P_VFS_IOPOLICY_TRIGGER_RESOLVE_DISABLE | P_VFS_IOPOLICY_IGNORE_CONTENT_PROTECTION | P_VFS_IOPOLICY_IGNORE_NODE_PERMISSIONS | P_VFS_IOPOLICY_SKIP_MTIME_UPDATE)
39236c6e 534
b0d623f7 535/* process creation arguments */
0a7de745
A
536#define PROC_CREATE_FORK 0 /* independent child (running) */
537#define PROC_CREATE_SPAWN 1 /* independent child (suspended) */
538#define PROC_CREATE_VFORK 2 /* child borrows context */
b0d623f7 539
0a7de745 540/* LP64 version of extern_proc. all pointers
91447636
A
541 * grow when we're dealing with a 64-bit process.
542 * WARNING - keep in sync with extern_proc
543 * but use native alignment of 64-bit process.
544 */
545
546#ifdef KERNEL
0a7de745 547#include <sys/time.h> /* user_timeval, user_itimerval */
91447636 548
d9a64523
A
549/*
550 * This packing is required to ensure symmetry between userspace and kernelspace
551 * when the kernel is 64-bit and the user application is 32-bit. All currently
552 * supported ARM slices (arm64/armv7k/arm64_32) contain the same struct
553 * alignment ABI so this packing isn't needed for ARM.
3e170ce0 554 */
d9a64523 555#if defined(__x86_64__)
b0d623f7 556#pragma pack(4)
5ba3f43e 557#endif
b0d623f7
A
558struct user32_extern_proc {
559 union {
560 struct {
0a7de745 561 uint32_t __p_forw; /* Doubly-linked run/sleep queue. */
b0d623f7
A
562 uint32_t __p_back;
563 } p_st1;
0a7de745 564 struct user32_timeval __p_starttime; /* process start time */
b0d623f7 565 } p_un;
0a7de745
A
566 uint32_t p_vmspace; /* Address space. */
567 uint32_t p_sigacts; /* Signal actions, state (PROC ONLY). */
568 int p_flag; /* P_* flags. */
569 char p_stat; /* S* process status. */
570 pid_t p_pid; /* Process identifier. */
571 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
572 int p_dupfd; /* Sideways return value from fdopen. XXX */
b0d623f7 573 /* Mach related */
0a7de745 574 uint32_t user_stack; /* where user stack was allocated */
b0d623f7 575 uint32_t exit_thread; /* XXX Which thread is exiting? */
0a7de745
A
576 int p_debugger; /* allow to debug */
577 boolean_t sigwait; /* indication to suspend */
b0d623f7 578 /* scheduling */
0a7de745
A
579 u_int p_estcpu; /* Time averaged value of p_cpticks. */
580 int p_cpticks; /* Ticks of cpu time. */
581 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
582 uint32_t p_wchan; /* Sleep address. */
583 uint32_t p_wmesg; /* Reason for sleep. */
584 u_int p_swtime; /* Time swapped in or out. */
585 u_int p_slptime; /* Time since last blocked. */
586 struct user32_itimerval p_realtimer; /* Alarm timer. */
587 struct user32_timeval p_rtime; /* Real time. */
588 u_quad_t p_uticks; /* Statclock hits in user mode. */
589 u_quad_t p_sticks; /* Statclock hits in system mode. */
590 u_quad_t p_iticks; /* Statclock hits processing intr. */
591 int p_traceflag; /* Kernel trace points. */
592 uint32_t p_tracep; /* Trace to vnode. */
593 int p_siglist; /* DEPRECATED */
594 uint32_t p_textvp; /* Vnode of executable. */
595 int p_holdcnt; /* If non-zero, don't swap. */
596 sigset_t p_sigmask; /* DEPRECATED. */
597 sigset_t p_sigignore; /* Signals being ignored. */
598 sigset_t p_sigcatch; /* Signals being caught by user. */
599 u_char p_priority; /* Process priority. */
600 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
601 char p_nice; /* Process "nice" value. */
602 char p_comm[MAXCOMLEN + 1];
603 uint32_t p_pgrp; /* Pointer to process group. */
604 uint32_t p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
605 u_short p_xstat; /* Exit status for wait; also stop signal. */
606 u_short p_acflag; /* Accounting flags. */
607 uint32_t p_ru; /* Exit information. XXX */
b0d623f7
A
608};
609#pragma pack()
610struct user64_extern_proc {
91447636
A
611 union {
612 struct {
0a7de745 613 user_addr_t __p_forw; /* Doubly-linked run/sleep queue. */
91447636
A
614 user_addr_t __p_back;
615 } p_st1;
0a7de745 616 struct user64_timeval __p_starttime; /* process start time */
91447636 617 } p_un;
0a7de745
A
618 user_addr_t p_vmspace; /* Address space. */
619 user_addr_t p_sigacts; /* Signal actions, state (PROC ONLY). */
620 int p_flag; /* P_* flags. */
621 char p_stat; /* S* process status. */
622 pid_t p_pid; /* Process identifier. */
623 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
624 int p_dupfd; /* Sideways return value from fdopen. XXX */
91447636 625 /* Mach related */
0a7de745 626 user_addr_t user_stack __attribute((aligned(8))); /* where user stack was allocated */
91447636 627 user_addr_t exit_thread; /* XXX Which thread is exiting? */
0a7de745
A
628 int p_debugger; /* allow to debug */
629 boolean_t sigwait; /* indication to suspend */
91447636 630 /* scheduling */
0a7de745
A
631 u_int p_estcpu; /* Time averaged value of p_cpticks. */
632 int p_cpticks; /* Ticks of cpu time. */
633 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
634 user_addr_t p_wchan __attribute((aligned(8))); /* Sleep address. */
635 user_addr_t p_wmesg; /* Reason for sleep. */
636 u_int p_swtime; /* Time swapped in or out. */
637 u_int p_slptime; /* Time since last blocked. */
638 struct user64_itimerval p_realtimer; /* Alarm timer. */
639 struct user64_timeval p_rtime; /* Real time. */
640 u_quad_t p_uticks; /* Statclock hits in user mode. */
641 u_quad_t p_sticks; /* Statclock hits in system mode. */
642 u_quad_t p_iticks; /* Statclock hits processing intr. */
643 int p_traceflag; /* Kernel trace points. */
644 user_addr_t p_tracep __attribute((aligned(8))); /* Trace to vnode. */
645 int p_siglist; /* DEPRECATED */
646 user_addr_t p_textvp __attribute((aligned(8))); /* Vnode of executable. */
647 int p_holdcnt; /* If non-zero, don't swap. */
648 sigset_t p_sigmask; /* DEPRECATED. */
649 sigset_t p_sigignore; /* Signals being ignored. */
650 sigset_t p_sigcatch; /* Signals being caught by user. */
651 u_char p_priority; /* Process priority. */
652 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
653 char p_nice; /* Process "nice" value. */
654 char p_comm[MAXCOMLEN + 1];
655 user_addr_t p_pgrp __attribute((aligned(8))); /* Pointer to process group. */
656 user_addr_t p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
657 u_short p_xstat; /* Exit status for wait; also stop signal. */
658 u_short p_acflag; /* Accounting flags. */
659 user_addr_t p_ru __attribute((aligned(8))); /* Exit information. XXX */
91447636 660};
0a7de745 661#endif /* KERNEL */
91447636 662
f427ee49
A
663#ifdef BSD_KERNEL_PRIVATE
664
665#include <os/refcnt.h> /* for struct os_refcnt pl_refcnt */
666
667/*
668 * Kernel shareable process resource limits:
669 * Because this structure is moderately large but changed infrequently, it is normally
670 * shared copy-on-write after a fork. The pl_refcnt variable records the number of
671 * "processes" (NOT threads) currently sharing the plimit. A plimit is freed when the
672 * last referencing process exits the system. The refcnt of the plimit is a race-free
673 * _Atomic variable. We allocate new plimits in proc_limitupdate and free them
674 * in proc_limitdrop/proc_limitupdate.
675 */
676struct plimit {
677 struct rlimit pl_rlimit[RLIM_NLIMITS];
678 os_refcnt_t pl_refcnt; /* number of processes using this plimit */
679};
680
681extern rlim_t proc_limitgetcur(proc_t p, int which, boolean_t to_lock_proc);
682extern void proc_limitsetcur_internal(proc_t p, int which, rlim_t value);
683extern struct proc proc0;
684#endif /* BSD_KERNEL_PRIVATE */
685
91447636
A
686/*
687 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
688 * as it is used to represent "no process group".
689 */
0a7de745
A
690extern int nprocs, maxproc; /* Current and max number of procs. */
691extern int maxprocperuid; /* Current number of procs per uid */
692extern int hard_maxproc; /* hard limit */
b0d623f7 693extern unsigned int proc_shutdown_exitcount;
91447636 694
0a7de745
A
695#define PID_MAX 99999
696#define NO_PID 100000
c3c9b80d 697extern lck_mtx_t proc_list_mlock;
2d21ac55 698
0a7de745
A
699#define BSD_SIMUL_EXECS 33 /* 32 , allow for rounding */
700#define BSD_PAGEABLE_SIZE_PER_EXEC (NCARGS + PAGE_SIZE + PAGE_SIZE) /* page for apple vars, page for executable header */
6d2010ae
A
701extern int execargs_cache_size;
702extern int execargs_free_count;
703extern vm_offset_t * execargs_cache;
b0d623f7 704
0a7de745 705#define SESS_LEADER(p, sessp) ((sessp)->s_leader == (p))
2d21ac55 706
0a7de745
A
707#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
708extern LIST_HEAD(pidhashhead, proc) * pidhashtbl;
91447636
A
709extern u_long pidhash;
710
0a7de745
A
711#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
712extern LIST_HEAD(pgrphashhead, pgrp) * pgrphashtbl;
91447636 713extern u_long pgrphash;
0a7de745
A
714#define SESSHASH(sessid) (&sesshashtbl[(sessid) & sesshash])
715extern LIST_HEAD(sesshashhead, session) * sesshashtbl;
2d21ac55
A
716extern u_long sesshash;
717
c3c9b80d
A
718extern lck_attr_t proc_lck_attr;
719extern lck_grp_t proc_fdmlock_grp;
720extern lck_grp_t proc_lck_grp;
721extern lck_grp_t proc_kqhashlock_grp;
722extern lck_grp_t proc_knhashlock_grp;
723extern lck_grp_t proc_slock_grp;
724extern lck_grp_t proc_mlock_grp;
725extern lck_grp_t proc_ucred_mlock_grp;
726extern lck_grp_t proc_dirslock_grp;
91447636
A
727
728LIST_HEAD(proclist, proc);
0a7de745
A
729extern struct proclist allproc; /* List of all processes. */
730extern struct proclist zombproc; /* List of zombie processes. */
39037602 731
f427ee49
A
732extern struct proc * XNU_PTRAUTH_SIGNED_PTR("initproc") initproc;
733extern void procinit(void);
91447636
A
734extern void proc_lock(struct proc *);
735extern void proc_unlock(struct proc *);
2d21ac55
A
736extern void proc_spinlock(struct proc *);
737extern void proc_spinunlock(struct proc *);
738extern void proc_list_lock(void);
739extern void proc_list_unlock(void);
740extern void proc_klist_lock(void);
741extern void proc_klist_unlock(void);
91447636 742extern void proc_fdlock(struct proc *);
2d21ac55 743extern void proc_fdlock_spin(struct proc *);
91447636 744extern void proc_fdunlock(struct proc *);
2d21ac55 745extern void proc_fdlock_assert(proc_t p, int assertflags);
bca245ac
A
746extern void proc_dirs_lock_shared(struct proc *);
747extern void proc_dirs_unlock_shared(struct proc *);
748extern void proc_dirs_lock_exclusive(struct proc *);
749extern void proc_dirs_unlock_exclusive(struct proc *);
4bd07ac2
A
750extern void proc_ucred_lock(struct proc *);
751extern void proc_ucred_unlock(struct proc *);
2d21ac55 752__private_extern__ int proc_core_name(const char *name, uid_t uid, pid_t pid,
0a7de745 753 char *cr_name, size_t cr_name_len);
91447636 754extern int isinferior(struct proc *, struct proc *);
0a7de745
A
755__private_extern__ struct proc *pzfind(pid_t); /* Find zombie by id. */
756__private_extern__ struct proc *proc_find_zombref(pid_t); /* Find zombie by id. */
757__private_extern__ void proc_drop_zombref(struct proc * p); /* Find zombie by id. */
758
f427ee49 759extern size_t chgproccnt(uid_t uid, int diff);
0a7de745 760extern void pinsertchild(struct proc *parent, struct proc *child);
cb323159
A
761extern int setsid_internal(struct proc *p);
762#ifndef __cplusplus
763extern void setlogin_internal(proc_t p, const char login[static MAXLOGNAME]);
764#endif // __cplusplus
765extern int setgroups_internal(proc_t p, u_int gidsetsize, gid_t *gidset, uid_t gmuid);
0a7de745
A
766extern int enterpgrp(struct proc *p, pid_t pgid, int mksess);
767extern void fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
768extern int inferior(struct proc *p);
769extern int leavepgrp(struct proc *p);
770extern void resetpriority(struct proc *);
771extern void setrunnable(struct proc *);
772extern void setrunqueue(struct proc *);
773extern int sleep(void *chan, int pri);
774extern int tsleep0(void *chan, int pri, const char *wmesg, int timo, int (*continuation)(int));
775extern int tsleep1(void *chan, int pri, const char *wmesg, u_int64_t abstime, int (*continuation)(int));
776extern int msleep0(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, int timo, int (*continuation)(int));
777extern void vfork_return(struct proc *child, int32_t *retval, int rval);
778extern int exit1(struct proc *, int, int *);
779extern int exit1_internal(struct proc *, int, int *, boolean_t, boolean_t, int);
780extern int exit_with_reason(struct proc *, int, int *, boolean_t, boolean_t, int, struct os_reason *);
781extern int fork1(proc_t, thread_t *, int, coalition_t *);
2d21ac55
A
782extern void vfork_exit_internal(struct proc *p, int rv, int forced);
783extern void proc_reparentlocked(struct proc *child, struct proc * newparent, int cansignal, int locked);
39037602 784
fe8ab488 785extern proc_t proc_findinternal(int pid, int locked);
316670eb 786extern proc_t proc_findthread(thread_t thread);
2d21ac55 787extern void proc_refdrain(proc_t);
743345f9
A
788extern proc_t proc_refdrain_with_refwait(proc_t p, boolean_t get_ref_and_allow_wait);
789extern void proc_refwake(proc_t p);
2d21ac55
A
790extern void proc_childdrainlocked(proc_t);
791extern void proc_childdrainstart(proc_t);
792extern void proc_childdrainend(proc_t);
793extern void proc_checkdeadrefs(proc_t);
794struct proc *pfind_locked(pid_t);
795extern struct pgrp *pgfind(pid_t);
796extern void pg_rele(struct pgrp * pgrp);
797extern struct session * session_find_internal(pid_t sessid);
798extern struct pgrp * proc_pgrp(proc_t);
799extern struct pgrp * tty_pgrp(struct tty * tp);
800extern struct pgrp * pgfind_internal(pid_t);
801extern struct session * proc_session(proc_t);
802extern void pgrp_lock(struct pgrp * pgrp);
803extern void pgrp_unlock(struct pgrp * pgrp);
804extern void session_lock(struct session * sess);
805extern void session_unlock(struct session * sess);
806extern struct session * pgrp_session(struct pgrp * pgrp);
0a7de745 807extern void session_rele(struct session *sess);
2d21ac55 808extern int isbackground(proc_t p, struct tty *tp);
2d21ac55
A
809extern proc_t proc_parentholdref(proc_t);
810extern int proc_parentdropref(proc_t, int);
811int itimerfix(struct timeval *tv);
812int itimerdecr(struct proc * p, struct itimerval *itp, int usec);
39037602 813void proc_free_realitimer(proc_t proc);
4bd07ac2 814int timespec_is_valid(const struct timespec *);
2d21ac55
A
815void proc_signalstart(struct proc *, int locked);
816void proc_signalend(struct proc *, int locked);
fe8ab488 817int proc_transstart(struct proc *, int locked, int non_blocking);
b0d623f7 818void proc_transcommit(struct proc *, int locked);
2d21ac55 819void proc_transend(struct proc *, int locked);
b0d623f7 820int proc_transwait(struct proc *, int locked);
2d21ac55 821void proc_rele_locked(struct proc * p);
6d2010ae 822struct proc *proc_ref_locked(struct proc * p);
2d21ac55 823void proc_knote(struct proc * p, long hint);
b0d623f7 824void proc_knote_drain(struct proc *p);
b0d623f7
A
825void proc_setregister(proc_t p);
826void proc_resetregister(proc_t p);
827/* returns the first thread_t in the process, or NULL XXX for NFS, DO NOT USE */
828thread_t proc_thread(proc_t);
829extern int proc_pendingsignals(proc_t, sigset_t);
830int proc_getpcontrol(int pid, int * pcontrolp);
fe8ab488 831int proc_dopcontrol(proc_t p);
b0d623f7
A
832int proc_resetpcontrol(int pid);
833#if PSYNCH
834void pth_proc_hashinit(proc_t);
835void pth_proc_hashdelete(proc_t);
836void pth_global_hashinit(void);
837extern thread_call_t psynch_thcall;
838void psynch_wq_cleanup(__unused void * param, __unused void * param1);
839extern lck_mtx_t * pthread_list_mlock;
840#endif /* PSYNCH */
841struct uthread * current_uthread(void);
39236c6e 842
f427ee49 843
39037602
A
844/* process iteration */
845
846#define ALLPROC_FOREACH(var) \
847 LIST_FOREACH((var), &allproc, p_list)
848
849#define ZOMBPROC_FOREACH(var) \
850 LIST_FOREACH((var), &zombproc, p_list)
851
852#define PGMEMBERS_FOREACH(group, var) \
853 LIST_FOREACH((var), &((struct pgrp *)(group))->pg_members, p_pglist)
854
855#define PCHILDREN_FOREACH(parent, var) \
856 LIST_FOREACH((var), &(((struct proc *)(parent))->p_children), p_sibling)
857
858typedef int (*proc_iterate_fn_t)(proc_t, void *);
859
860/*
861 * These are the only valid return values of `callout` functions provided to
862 * process iterators.
863 *
864 * CLAIMED returns expect the caller to call proc_rele on the proc. DONE
865 * returns stop iterating processes early.
866 */
867#define PROC_RETURNED (0)
868#define PROC_RETURNED_DONE (1)
869#define PROC_CLAIMED (2)
870#define PROC_CLAIMED_DONE (3)
871
872/*
873 * pgrp_iterate walks the provided process group, calling `filterfn` with
874 * `filterarg` for each process. For processes where `filterfn` returned
875 * non-zero, `callout` is called with `arg`. If `PGRP_DROPREF` is supplied in
876 * `flags`, a reference will be dropped from the process group after obtaining
877 * the list of processes to call `callout` on.
878 *
879 * `PGMEMBERS_FOREACH` might also be used under the pgrp_lock to achieve a
880 * similar effect.
881 */
882#define PGRP_DROPREF (1)
883
cb323159 884extern void pgrp_iterate(struct pgrp *pgrp, unsigned int flags, proc_iterate_fn_t callout, void *arg, proc_iterate_fn_t filterfn, void *filterarg);
39037602
A
885
886/*
887 * proc_iterate walks the `allproc` and/or `zombproc` lists, calling `filterfn`
888 * with `filterarg` for each process. For processes where `filterfn` returned
889 * non-zero, `callout` is called with `arg`. If the `PROC_NOWAITTRANS` flag is
890 * set, this function waits for transitions.
891 *
892 * `ALLPROC_FOREACH` or `ZOMBPROC_FOREACH` might also be used under the
893 * `proc_list_lock` to achieve a similar effect.
894 */
895#define PROC_ALLPROCLIST (1U << 0) /* walk the allproc list (processes not yet exited) */
896#define PROC_ZOMBPROCLIST (1U << 1) /* walk the zombie list */
897#define PROC_NOWAITTRANS (1U << 2) /* do not wait for transitions (checkdirs only) */
898
cb323159 899extern void proc_iterate(unsigned int flags, proc_iterate_fn_t callout, void *arg, proc_iterate_fn_t filterfn, void *filterarg);
39037602
A
900
901/*
902 * proc_childrenwalk walks the children of process `p`, calling `callout` for
903 * each one.
904 *
905 * `PCHILDREN_FOREACH` might also be used under the `proc_list_lock` to achieve
906 * a similar effect.
907 */
cb323159 908extern void proc_childrenwalk(proc_t p, proc_iterate_fn_t callout, void *arg);
39037602
A
909
910/*
911 * proc_rebootscan should only be used by kern_shutdown.c
912 */
913extern void proc_rebootscan(proc_iterate_fn_t callout, void *arg, proc_iterate_fn_t filterfn, void *filterarg);
39236c6e
A
914
915pid_t dtrace_proc_selfpid(void);
916pid_t dtrace_proc_selfppid(void);
917uid_t dtrace_proc_selfruid(void);
39037602 918
f427ee49
A
919extern zone_t proc_zone;
920extern zone_t proc_stats_zone;
921extern zone_t proc_sigacts_zone;
922
923extern struct proc_ident proc_ident(proc_t p);
924
c3c9b80d
A
925/*
926 * True if the process ignores file permissions in case it owns the
927 * file/directory
928 */
929bool proc_ignores_node_permissions(proc_t proc);
930
0a7de745 931#endif /* !_SYS_PROC_INTERNAL_H_ */