xref: /xnu-12377.81.4/bsd/sys/proc.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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.h	8.15 (Berkeley) 5/19/95
67  */
68 
69 #ifndef _SYS_PROC_H_
70 #define _SYS_PROC_H_
71 
72 #include <sys/appleapiopts.h>
73 #include <sys/cdefs.h>
74 #include <sys/select.h>                 /* For struct selinfo. */
75 #include <sys/queue.h>
76 #include <sys/lock.h>
77 #include <sys/param.h>
78 #include <sys/event.h>
79 #include <sys/time.h>
80 #ifdef KERNEL
81 #include <sys/kernel_types.h>
82 #include <uuid/uuid.h>
83 #endif
84 #include <mach/boolean.h>
85 
86 #ifdef XNU_KERNEL_PRIVATE
87 #include <mach/coalition.h>             /* COALITION_NUM_TYPES */
88 #include <sys/codesign.h>
89 #endif
90 
91 #ifndef KERNEL
92 #include <Availability.h>
93 #endif
94 
95 #if defined(XNU_KERNEL_PRIVATE) || !defined(KERNEL)
96 
97 struct session;
98 struct pgrp;
99 struct proc;
100 struct proc_ident;
101 
102 /* Exported fields for kern sysctls */
103 struct extern_proc {
104 	union {
105 		struct {
106 			struct  proc *__p_forw; /* Doubly-linked run/sleep queue. */
107 			struct  proc *__p_back;
108 		} p_st1;
109 		struct timeval __p_starttime;   /* process start time */
110 	} p_un;
111 #define p_forw p_un.p_st1.__p_forw
112 #define p_back p_un.p_st1.__p_back
113 #define p_starttime p_un.__p_starttime
114 	struct  vmspace *p_vmspace;     /* Address space. */
115 	struct  sigacts *p_sigacts;     /* Signal actions, state (PROC ONLY). */
116 	int     p_flag;                 /* P_* flags. */
117 	char    p_stat;                 /* S* process status. */
118 	pid_t   p_pid;                  /* Process identifier. */
119 	pid_t   p_oppid;         /* Save parent pid during ptrace. XXX */
120 	int     p_dupfd;         /* Sideways return value from fdopen. XXX */
121 	/* Mach related  */
122 	caddr_t user_stack;     /* where user stack was allocated */
123 	void    *exit_thread;   /* XXX Which thread is exiting? */
124 	int             p_debugger;             /* allow to debug */
125 	boolean_t       sigwait;        /* indication to suspend */
126 	/* scheduling */
127 	u_int   p_estcpu;        /* Time averaged value of p_cpticks. */
128 	int     p_cpticks;       /* Ticks of cpu time. */
129 	fixpt_t p_pctcpu;        /* %cpu for this process during p_swtime */
130 	void    *p_wchan;        /* Sleep address. */
131 	char    *p_wmesg;        /* Reason for sleep. */
132 	u_int   p_swtime;        /* Time swapped in or out. */
133 	u_int   p_slptime;       /* Time since last blocked. */
134 	struct  itimerval p_realtimer;  /* Alarm timer. */
135 	struct  timeval p_rtime;        /* Real time. */
136 	u_quad_t p_uticks;              /* Statclock hits in user mode. */
137 	u_quad_t p_sticks;              /* Statclock hits in system mode. */
138 	u_quad_t p_iticks;              /* Statclock hits processing intr. */
139 	int     p_traceflag;            /* Kernel trace points. */
140 	struct  vnode *p_tracep;        /* Trace to vnode. */
141 	int     p_siglist;              /* DEPRECATED. */
142 	struct  vnode *p_textvp;        /* Vnode of executable. */
143 	int     p_holdcnt;              /* If non-zero, don't swap. */
144 	sigset_t p_sigmask;     /* DEPRECATED. */
145 	sigset_t p_sigignore;   /* Signals being ignored. */
146 	sigset_t p_sigcatch;    /* Signals being caught by user. */
147 	u_char  p_priority;     /* Process priority. */
148 	u_char  p_usrpri;       /* User-priority based on p_cpu and p_nice. */
149 	char    p_nice;         /* Process "nice" value. */
150 	char    p_comm[MAXCOMLEN + 1];
151 	struct  pgrp *p_pgrp;   /* Pointer to process group. */
152 	struct  user *p_addr;   /* Kernel virtual addr of u-area (PROC ONLY). */
153 	u_short p_xstat;        /* Exit status for wait; also stop signal. */
154 	u_short p_acflag;       /* Accounting flags. */
155 	struct  rusage *p_ru;   /* Exit information. XXX */
156 };
157 
158 
159 /* Status values. */
160 #define SIDL    1               /* Process being created by fork. */
161 #define SRUN    2               /* Currently runnable. */
162 #define SSLEEP  3               /* Sleeping on an address. */
163 #define SSTOP   4               /* Process debugging or suspension. */
164 #define SZOMB   5               /* Awaiting collection by parent. */
165 
166 /* These flags are kept in extern_proc.p_flag. */
167 #define P_ADVLOCK       0x00000001      /* Process may hold POSIX adv. lock */
168 #define P_CONTROLT      0x00000002      /* Has a controlling terminal */
169 #define P_LP64          0x00000004      /* Process is LP64 */
170 #define P_NOCLDSTOP     0x00000008      /* No SIGCHLD when children stop */
171 
172 #define P_PPWAIT        0x00000010      /* Parent waiting for chld exec/exit */
173 #define P_PROFIL        0x00000020      /* Has started profiling */
174 #define P_SELECT        0x00000040      /* Selecting; wakeup/waiting danger */
175 #define P_CONTINUED     0x00000080      /* Process was stopped and continued */
176 
177 #define P_SUGID         0x00000100      /* Has set privileges since last exec */
178 #define P_SYSTEM        0x00000200      /* Sys proc: no sigs, stats or swap */
179 #define P_TIMEOUT       0x00000400      /* Timing out during sleep */
180 #define P_TRACED        0x00000800      /* Debugged process being traced */
181 
182 #define P_DISABLE_ASLR  0x00001000      /* Disable address space layout randomization */
183 #define P_WEXIT         0x00002000      /* Working on exiting */
184 #define P_EXEC          0x00004000      /* Process called exec. */
185 
186 /* Should be moved to machine-dependent areas. */
187 #define P_OWEUPC        0x00008000      /* Owe process an addupc() call at next ast. */
188 
189 #define P_AFFINITY      0x00010000      /* xxx */
190 #define P_TRANSLATED    0x00020000      /* xxx */
191 #define P_CLASSIC       P_TRANSLATED    /* xxx */
192 
193 #define P_DELAYIDLESLEEP 0x00040000     /* Process is marked to delay idle sleep on disk IO */
194 #define P_CHECKOPENEVT  0x00080000      /* check if a vnode has the OPENEVT flag set on open */
195 
196 #define P_DEPENDENCY_CAPABLE    0x00100000      /* process is ok to call vfs_markdependency() */
197 #define P_REBOOT        0x00200000      /* Process called reboot() */
198 #define P_RESV6         0x00400000      /* used to be P_TBE */
199 #define P_RESV7         0x00800000      /* (P_SIGEXC)signal exceptions */
200 
201 #define P_THCWD         0x01000000      /* process has thread cwd  */
202 #define P_RESV9         0x02000000      /* (P_VFORK)process has vfork children */
203 #define P_ADOPTPERSONA  0x04000000      /* process adopted a persona (used to be P_NOATTACH) */
204 #define P_RESV11        0x08000000      /* (P_INVFORK) proc in vfork */
205 
206 #define P_NOSHLIB       0x10000000      /* no shared libs are in use for proc */
207                                         /* flag set on exec */
208 #define P_FORCEQUOTA    0x20000000      /* Force quota for root */
209 #define P_NOCLDWAIT     0x40000000      /* No zombies when chil procs exit */
210 #define P_NOREMOTEHANG  0x80000000      /* Don't hang on remote FS ops */
211 
212 #define P_INMEM         0               /* Obsolete: retained for compilation */
213 #define P_NOSWAP        0               /* Obsolete: retained for compilation */
214 #define P_PHYSIO        0               /* Obsolete: retained for compilation */
215 #define P_FSTRACE       0               /* Obsolete: retained for compilation */
216 #define P_SSTEP         0               /* Obsolete: retained for compilation */
217 
218 #define P_DIRTY_TRACK                           0x00000001      /* track dirty state */
219 #define P_DIRTY_ALLOW_IDLE_EXIT                 0x00000002      /* process can be idle-exited when clean */
220 #define P_DIRTY_DEFER                           0x00000004      /* defer initial opt-in to idle-exit */
221 #define P_DIRTY                                 0x00000008      /* process is dirty */
222 #define P_DIRTY_SHUTDOWN                        0x00000010      /* process is dirty during shutdown */
223 #define P_DIRTY_TERMINATED                      0x00000020      /* process has been marked for termination */
224 #define P_DIRTY_BUSY                            0x00000040      /* serialization flag */
225 #define P_DIRTY_MARKED                          0x00000080      /* marked dirty previously */
226 #define P_DIRTY_AGING_IN_PROGRESS               0x00000100      /* aging in one of the 'aging bands' */
227 #define P_DIRTY_LAUNCH_IN_PROGRESS              0x00000200      /* launch is in progress */
228 #define P_DIRTY_DEFER_ALWAYS                    0x00000400      /* defer going to idle-exit after every dirty->clean transition.
229 	                                                         * For legacy jetsam policy only. This is the default with the other policies.*/
230 #define P_DIRTY_SHUTDOWN_ON_CLEAN               0x00000800      /* process should shutdown on going clean */
231 
232 #define P_DIRTY_IS_DIRTY                        (P_DIRTY | P_DIRTY_SHUTDOWN)
233 #define P_DIRTY_IDLE_EXIT_ENABLED               (P_DIRTY_TRACK|P_DIRTY_ALLOW_IDLE_EXIT)
234 
235 #endif /* XNU_KERNEL_PRIVATE || !KERNEL */
236 
237 #ifdef KERNEL
238 __BEGIN_DECLS
239 
240 extern proc_t kernproc;
241 
242 extern int proc_is_classic(proc_t p);
243 extern bool proc_is_exotic(proc_t p);
244 extern bool proc_is_alien(proc_t p);
245 proc_t current_proc_EXTERNAL(void);
246 
247 #if XNU_KERNEL_PRIVATE
248 
249 extern bool proc_is_driver(proc_t p);
250 extern bool proc_is_third_party_debuggable_driver(proc_t p);
251 
252 #endif /* XNU_KERNEL_PRIVATE */
253 
254 /*
255  * __unsafe_indexable is a workaround for
256  * rdar://88409003 (PredefinedExpr trips C string detection)
257  */
258 extern int      msleep(void *chan, lck_mtx_t *mtx, int pri, const char *__unsafe_indexable wmesg, struct timespec * ts );
259 extern int      msleep0(void *chan, lck_mtx_t *mtx, int pri, const char *__unsafe_indexable wmesg, int timo, int (*continuation)(int));
260 extern void     wakeup(void *chan);
261 extern void wakeup_one(caddr_t chan);
262 
263 /* proc kpis */
264 /* this routine returns the pid of the current process */
265 extern int proc_selfpid(void);
266 /* this routine returns the pid of the parent of the current process */
267 extern int proc_selfppid(void);
268 /* this routine returns the csflags of the current process */
269 extern uint64_t proc_selfcsflags(void);
270 /* this routine populates the given flags param with the csflags of the given process. Returns 0 on success, -1 on error. */
271 extern int proc_csflags(proc_t p, uint64_t* flags);
272 /* this routine returns sends a signal signum to the process identified by the pid */
273 extern void proc_signal(int pid, int signum);
274 /* this routine checks whether any signal identified by the mask are pending in the  process identified by the pid. The check is  on all threads of the process. */
275 extern int proc_issignal(int pid, sigset_t mask);
276 /* this routine returns 1 if the pid1 is inferior of pid2 */
277 extern int proc_isinferior(int pid1, int pid2);
278 /* this routine copies the process's name of the executable to the passed in buffer. It
279  * is always null terminated. The size of the buffer is to be passed in as well. This
280  * routine is to be used typically for debugging
281  */
282 void proc_name(int pid, char * buf, int size);
283 /* returns the 32-byte name if it exists, otherwise returns the 16-byte name */
284 #ifdef XNU_KERNEL_PRIVATE
285 extern const char *proc_best_name(proc_t p);
286 #else
287 extern char *proc_best_name(proc_t p);
288 #endif
289 /* this routine is similar to proc_name except it returns for current process */
290 void proc_selfname(char * buf, int size);
291 
292 /* find a process with a given pid. This comes with a reference which needs to be dropped by proc_rele */
293 extern proc_t proc_find(int pid);
294 /*
295  * Function: proc_find_ident
296  *
297  * Description: Obtain a proc ref from the provided proc_ident.
298  *
299  * Returns:
300  *    - Non-null proc_t on success
301  *    - PROC_NULL on error
302  */
303 extern proc_t proc_find_ident(const proc_ident_t i);
304 #ifdef KERNEL_PRIVATE
305 /*
306  * Function: proc_find_ident_validated
307  *
308  * Description: Obtain a proc ref from the provided proc_ident.
309  *
310  * Returns:
311  *   - 0 on Success
312  *   - EINVAL: When the provided arguments are invalid (NULL)
313  *   - ESTALE: The process exists but is currently a zombie and has not been reaped
314  *     via wait(). Callers may choose to handle this edge case as a non-error.
315  *   - ESRCH: When the lookup or validation fails otherwise. The process
316  *     described by the identifier no longer exists.
317  */
318 extern errno_t proc_find_ident_validated(const proc_ident_t i, proc_t *out);
319 /* compare a proc_ident to a proc ref */
320 extern bool proc_ident_equal_ref(proc_ident_t ident, proc_t proc);
321 /* compare a proc_ident to another proc_ident */
322 extern bool proc_ident_equal(proc_ident_t ident, proc_ident_t other);
323 /* compare a proc_ident to an audit_token_t */
324 extern bool proc_ident_equal_token(proc_ident_t ident, audit_token_t token);
325 #endif /* KERNEL_PRIVATE */
326 /* find a process with a given audit token */
327 extern proc_t proc_find_audit_token(const audit_token_t token);
328 /* returns a handle to current process which is referenced. The reference needs to be dropped with proc_rele */
329 extern proc_t proc_self(void);
330 /* releases the held reference on the process */
331 extern int proc_rele(proc_t p);
332 /* returns the pid of the given process */
333 extern int proc_pid(proc_t);
334 /* returns the pid of the parent of a given process */
335 extern int proc_ppid(proc_t);
336 /* returns the original pid of the parent of a given process */
337 extern int proc_original_ppid(proc_t);
338 /* returns the pid version of the original parent of a given process */
339 extern int proc_orig_ppidversion(proc_t);
340 /* returns the start time of the given process */
341 extern int proc_starttime(proc_t, struct timeval *);
342 /* returns whether the given process is on simulated platform */
343 extern boolean_t proc_is_simulated(const proc_t);
344 /* returns the platform (macos, ios, watchos, tvos, ...) of the given process */
345 extern uint32_t proc_platform(const proc_t);
346 /* returns the minimum sdk version used by the current process */
347 extern uint32_t proc_min_sdk(proc_t);
348 /* returns the sdk version used by the current process */
349 extern uint32_t proc_sdk(proc_t);
350 /* returns 1 if the process is marked for no remote hangs */
351 extern int proc_noremotehang(proc_t);
352 /* returns 1 if the process is marked for force quota */
353 extern int proc_forcequota(proc_t);
354 /* returns 1 if the process is chrooted */
355 extern int proc_chrooted(proc_t);
356 /* returns TRUE if a sync EXC_RESOURCE should be sent for the process */
357 extern boolean_t proc_send_synchronous_EXC_RESOURCE(proc_t p);
358 
359 /* this routine returns 1 if the process is running with a 64bit address space, else 0 */
360 extern int proc_is64bit(proc_t);
361 /* this routine returns 1 if the process is running with a 64bit register state, else 0 */
362 extern int proc_is64bit_data(proc_t);
363 /* this routine returns 1 if the process is initproc */
364 extern int proc_isinitproc(proc_t);
365 /* is this process exiting? */
366 extern int proc_exiting(proc_t);
367 /* returns whether the process has started down proc_exit() */
368 extern int proc_in_teardown(proc_t);
369 /* this routine returns error if the process is not one with super user privileges */
370 extern int proc_suser(proc_t p);
371 
372 /* returns the cred assicaited with the process; temporary api */
373 #if !BSD_KERNEL_PRIVATE
374 __deprecated_msg("proc_ucred is unsafe, use kauth_cred_proc_ref() or current_cached_proc_cred()")
375 kauth_cred_t proc_ucred(proc_t p);
376 #endif
377 
378 /* returns 1 if the process is tainted by uid or gid changes,e else 0 */
379 extern int proc_issetugid(proc_t p);
380 
381 extern int proc_tbe(proc_t);
382 
383 /*!
384  *  @function proc_gettty
385  *  @abstract Copies the associated tty vnode for a given process if it exists. The caller needs to decrement the iocount of the vnode.
386  *  @return 0 on success. ENOENT if the process has no associated TTY. EINVAL if arguments are NULL or vnode_getwithvid fails.
387  */
388 extern int proc_gettty(proc_t p, vnode_t *vp);
389 
390 /* this routine populates the associated tty device for a given process if it exists, returns 0 on success or else returns EINVAL */
391 extern int proc_gettty_dev(proc_t p, dev_t *dev);
392 
393 /*!
394  *  @function proc_selfpgrpid
395  *  @abstract Get the process group id for the current process, as with proc_pgrpid().
396  *  @return pgrpid of current process.
397  */
398 pid_t proc_selfpgrpid(void);
399 
400 /*!
401  *  @function proc_pgrpid
402  *  @abstract Get the process group id for the passed-in process.
403  *  @param p Process whose pgrpid to grab.
404  *  @return pgrpid for "p".
405  */
406 pid_t proc_pgrpid(proc_t p);
407 
408 /*!
409  *  @function proc_sessionid
410  *  @abstract Get the process session id for the passed-in process.
411  *  @param p Process whose session id to grab.
412  *  @return session id of current process.
413  */
414 pid_t proc_sessionid(proc_t p);
415 
416 #ifdef KERNEL_PRIVATE
417 // mark a process as being allowed to call vfs_markdependency()
418 void bsd_set_dependency_capable(task_t task);
419 #ifdef  __arm__
420 static inline int
IS_64BIT_PROCESS(__unused proc_t p)421 IS_64BIT_PROCESS(__unused proc_t p)
422 {
423 	return 0;
424 }
425 #else
426 extern int IS_64BIT_PROCESS(proc_t);
427 #endif /* __arm__ */
428 
429 extern int      tsleep(void *chan, int pri, const char *wmesg, int timo);
430 extern int      msleep1(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg, u_int64_t timo);
431 
432 task_t proc_task(proc_t);
433 extern int proc_pidversion(proc_t);
434 extern proc_t proc_parent(proc_t);
435 extern void proc_parent_audit_token(proc_t, audit_token_t *);
436 extern uint32_t proc_persona_id(proc_t);
437 extern uint32_t proc_getuid(proc_t);
438 extern uint32_t proc_getgid(proc_t);
439 extern int proc_getcdhash(proc_t, unsigned char *);
440 
441 /*!
442  *  @function    proc_pidbackgrounded
443  *  @abstract    KPI to determine if a process is currently backgrounded.
444  *  @discussion  The process may move into or out of background state at any time,
445  *             so be prepared for this value to be outdated immediately.
446  *  @param pid   PID of the process to be queried.
447  *  @param state Pointer to a value which will be set to 1 if the process
448  *             is currently backgrounded, 0 otherwise.
449  *  @return      ESRCH if pid cannot be found or has started exiting.
450  *
451  *             EINVAL if state is NULL.
452  */
453 extern int proc_pidbackgrounded(pid_t pid, uint32_t* state);
454 
455 /*
456  * This returns an unique 64bit id of a given process.
457  * Caller needs to hold proper reference on the
458  * passed in process strucutre.
459  */
460 extern uint64_t proc_uniqueid(proc_t);
461 
462 /* unique 64bit id for process's original parent */
463 extern uint64_t proc_puniqueid(proc_t);
464 
465 extern void proc_set_responsible_pid(proc_t target_proc, pid_t responsible_pid);
466 
467 /* return 1 if process is forcing case-sensitive HFS+ access, 0 for default */
468 extern int proc_is_forcing_hfs_case_sensitivity(proc_t);
469 
470 /* returns 1 if the process is parent of a vfork */
471 extern int proc_lvfork(proc_t);
472 
473 /* increments process block output operations counter. returns original value if valid long pointer was passed */
474 extern int proc_increment_ru_oublock(proc_t, long *);
475 
476 /* Check if process is aborted, but not killed by a signal or is not the exiting thread or is not attempting to dump core */
477 extern int proc_isabortedsignal(proc_t);
478 
479 /* return true if the process is translated, false for default */
480 extern boolean_t proc_is_translated(proc_t);
481 
482 /* return true if this is an x86_64 process running under translation */
483 extern bool proc_is_x86_64_compat(proc_t);
484 
485 /* true if the process ignores errors from content protection APIs */
486 extern bool proc_ignores_content_protection(proc_t proc);
487 
488 /* true if the file system shouldn't update mtime for operations by the process */
489 extern bool proc_skip_mtime_update(proc_t proc);
490 
491 /* true if syscalls support long paths */
492 extern bool proc_support_long_paths(proc_t proc);
493 
494 /* return true if the process is flagged as allow-low-space */
495 extern bool proc_allow_low_space_writes(proc_t p);
496 
497 /* return true if process needs to use alternative extended attribute for symlinks */
498 bool proc_use_alternative_symlink_ea(proc_t p);
499 
500 /* return true if rsr is set for process */
501 bool proc_is_rsr(proc_t p);
502 
503 /*
504  * Return true if the process disallows read or write access for files that
505  * it opens with O_EVTONLY.
506  */
507 extern bool proc_disallow_rw_for_o_evtonly(proc_t p);
508 
509 /*!
510  *  @function    proc_exitstatus
511  *  @abstract    KPI to determine a process's exit status.
512  *  @discussion  This function is not safe to call if the process could be
513  *               concurrently stopped or started, but it can be called from a
514  *               mpo_proc_notify_exit callback.
515  *  @param p     The process to be queried.
516  *  @return      Value in the same format as wait()'s output parameter.
517  */
518 extern int proc_exitstatus(proc_t p);
519 
520 /*!
521  *  @function    proc_is_zombie
522  *  @abstract    KPI to determine if the provided process is a zombie
523  *  @discussion  This lookup is atomic and safe to call with either a proc ref or
524  *               or a zombie ref.
525  *  @param p     The process to be queried.
526  *  @return      Boolean indicating whether the process has been removed from the primary proclist
527  *               and moved to the zombproc list.
528  */
529 extern bool   proc_is_zombie(proc_t p);
530 
531 #endif /* KERNEL_PRIVATE */
532 
533 #ifdef XNU_KERNEL_PRIVATE
534 
535 extern void proc_getexecutableuuid(proc_t, unsigned char *, unsigned long);
536 extern int proc_get_originatorbgstate(uint32_t *is_backgrounded);
537 
538 /* Kernel interface to get the uuid of the originator of the work.*/
539 extern int proc_pidoriginatoruuid(uuid_t uuid_buf, uint32_t buffersize);
540 
541 extern uint64_t proc_was_throttled(proc_t);
542 extern uint64_t proc_did_throttle(proc_t);
543 extern bool proc_is_traced(proc_t p);
544 
545 extern void proc_coalitionids(proc_t, uint64_t[COALITION_NUM_TYPES]);
546 
547 extern uint64_t get_current_unique_pid(void);
548 #endif /* XNU_KERNEL_PRIVATE*/
549 
550 #ifdef KERNEL_PRIVATE
551 /* If buf argument is NULL, the necessary length to allocate will be set in buflen */
552 extern int proc_selfexecutableargs(uint8_t *buf, size_t *buflen);
553 extern off_t proc_getexecutableoffset(proc_t p);
554 extern vnode_t proc_getexecutablevnode(proc_t); /* Returned with iocount, use vnode_put() to drop */
555 extern vnode_t proc_getexecutablevnode_noblock(proc_t); /* Returned with iocount, use vnode_put() to drop */
556 
557 /* System call filtering for BSD syscalls, mach traps and kobject routines. */
558 #define SYSCALL_MASK_UNIX 0
559 #define SYSCALL_MASK_MACH 1
560 #define SYSCALL_MASK_KOBJ 2
561 
562 #define SYSCALL_FILTER_CALLBACK_VERSION 1
563 typedef int (*syscall_filter_cbfunc_t)(proc_t p, int num);
564 typedef int (*kobject_filter_cbfunc_t)(proc_t p, int msgid, int idx);
565 struct syscall_filter_callbacks {
566 	int version;
567 	const syscall_filter_cbfunc_t unix_filter_cbfunc;
568 	const syscall_filter_cbfunc_t mach_filter_cbfunc;
569 	const kobject_filter_cbfunc_t kobj_filter_cbfunc;
570 };
571 typedef struct syscall_filter_callbacks * syscall_filter_cbs_t;
572 
573 extern int proc_set_syscall_filter_callbacks(syscall_filter_cbs_t callback);
574 extern int proc_set_syscall_filter_index(int which, int num, int index);
575 extern size_t proc_get_syscall_filter_mask_size(int which);
576 extern unsigned char *proc_get_syscall_filter_mask(proc_t p, int which);
577 extern int proc_set_syscall_filter_mask(proc_t p, int which, unsigned char *maskptr, size_t masklen);
578 
579 extern int proc_set_filter_message_flag(proc_t p, boolean_t flag);
580 extern int proc_get_filter_message_flag(proc_t p, boolean_t *flag);
581 
582 #endif /* KERNEL_PRIVATE */
583 
584 __END_DECLS
585 
586 #endif  /* KERNEL */
587 
588 #ifdef PRIVATE
589 
590 /* Values for pid_shutdown_sockets */
591 #define SHUTDOWN_SOCKET_LEVEL_DISCONNECT_SVC            0x00000001
592 #define SHUTDOWN_SOCKET_LEVEL_DISCONNECT_ALL            0x00000002
593 
594 #ifdef KERNEL
595 #define SHUTDOWN_SOCKET_LEVEL_DISCONNECT_INTERNAL       0x10000000
596 #define SHUTDOWN_SOCKET_LEVEL_NECP                      0x20000000
597 #define SHUTDOWN_SOCKET_LEVEL_CONTENT_FILTER            0x40000000
598 #endif
599 
600 #ifndef KERNEL
601 
602 __BEGIN_DECLS
603 
604 int pid_suspend(int pid);
605 int pid_resume(int pid);
606 __API_AVAILABLE(macos(11.3), ios(14.5), tvos(14.5), watchos(7.3))
607 int task_inspect_for_pid(unsigned int target_tport, int pid, unsigned int *t);  /* Returns task inspect port */
608 __API_AVAILABLE(macos(11.3), ios(14.5), tvos(14.5), watchos(7.3))
609 int task_read_for_pid(unsigned int target_tport, int pid, unsigned int *t);     /* Returns task read port */
610 
611 #if defined(__arm__) || defined(__arm64__)
612 int pid_hibernate(int pid);
613 #endif /* defined(__arm__) || defined(__arm64__)  */
614 int pid_shutdown_sockets(int pid, int level);
615 int pid_shutdown_networking(int pid, int level);
616 __END_DECLS
617 
618 #endif /* !KERNEL */
619 
620 /* Entitlement to allow non-root processes to suspend/resume any task */
621 #define PROCESS_RESUME_SUSPEND_ENTITLEMENT "com.apple.private.process.suspend-resume.any"
622 
623 #endif /* PRIVATE */
624 
625 #endif  /* !_SYS_PROC_H_ */
626