xref: /xnu-12377.61.12/bsd/sys/reason.h (revision 4d495c6e23c53686cf65f45067f79024cf5dcee8)
1*4d495c6eSApple OSS Distributions /*
2*4d495c6eSApple OSS Distributions  * Copyright (c) 2019 Apple Inc. All rights reserved.
3*4d495c6eSApple OSS Distributions  *
4*4d495c6eSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*4d495c6eSApple OSS Distributions  *
6*4d495c6eSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*4d495c6eSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*4d495c6eSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*4d495c6eSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*4d495c6eSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*4d495c6eSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*4d495c6eSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*4d495c6eSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*4d495c6eSApple OSS Distributions  *
15*4d495c6eSApple OSS Distributions  * Please obtain a copy of the License at
16*4d495c6eSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*4d495c6eSApple OSS Distributions  *
18*4d495c6eSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*4d495c6eSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*4d495c6eSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*4d495c6eSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*4d495c6eSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*4d495c6eSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*4d495c6eSApple OSS Distributions  * limitations under the License.
25*4d495c6eSApple OSS Distributions  *
26*4d495c6eSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*4d495c6eSApple OSS Distributions  */
28*4d495c6eSApple OSS Distributions 
29*4d495c6eSApple OSS Distributions #ifndef _REASON_H_
30*4d495c6eSApple OSS Distributions #define _REASON_H_
31*4d495c6eSApple OSS Distributions 
32*4d495c6eSApple OSS Distributions #include <stdint.h>
33*4d495c6eSApple OSS Distributions 
34*4d495c6eSApple OSS Distributions __BEGIN_DECLS
35*4d495c6eSApple OSS Distributions 
36*4d495c6eSApple OSS Distributions #ifdef KERNEL_PRIVATE
37*4d495c6eSApple OSS Distributions 
38*4d495c6eSApple OSS Distributions #include <kern/kern_cdata.h>
39*4d495c6eSApple OSS Distributions 
40*4d495c6eSApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
41*4d495c6eSApple OSS Distributions #include <os/refcnt.h>
42*4d495c6eSApple OSS Distributions #include <kern/locks.h>
43*4d495c6eSApple OSS Distributions 
44*4d495c6eSApple OSS Distributions typedef struct os_reason {
45*4d495c6eSApple OSS Distributions 	decl_lck_mtx_data(, osr_lock);
46*4d495c6eSApple OSS Distributions 	os_refcnt_t                     osr_refcount;
47*4d495c6eSApple OSS Distributions 	uint32_t                        osr_namespace;
48*4d495c6eSApple OSS Distributions 	uint64_t                        osr_code;
49*4d495c6eSApple OSS Distributions 	uint64_t                        osr_flags;
50*4d495c6eSApple OSS Distributions 	uint32_t                        osr_bufsize;
51*4d495c6eSApple OSS Distributions 	struct kcdata_descriptor        osr_kcd_descriptor;
52*4d495c6eSApple OSS Distributions 	char                            *osr_kcd_buf;
53*4d495c6eSApple OSS Distributions } *os_reason_t;
54*4d495c6eSApple OSS Distributions 
55*4d495c6eSApple OSS Distributions #define OS_REASON_NULL ((os_reason_t) NULL)
56*4d495c6eSApple OSS Distributions 
57*4d495c6eSApple OSS Distributions /* We only include 800 bytes of the exit reason description to not blow through the panic buffer */
58*4d495c6eSApple OSS Distributions #define LAUNCHD_PANIC_REASON_STRING_MAXLEN "800"
59*4d495c6eSApple OSS Distributions 
60*4d495c6eSApple OSS Distributions void os_reason_init(void);
61*4d495c6eSApple OSS Distributions 
62*4d495c6eSApple OSS Distributions os_reason_t build_userspace_exit_reason(uint32_t reason_namespace, uint64_t reason_code, user_addr_t payload, uint32_t payload_size,
63*4d495c6eSApple OSS Distributions     user_addr_t reason_string, uint64_t reason_flags);
64*4d495c6eSApple OSS Distributions char *exit_reason_get_string_desc(os_reason_t exit_reason);
65*4d495c6eSApple OSS Distributions 
66*4d495c6eSApple OSS Distributions /* The blocking allocation is currently not exported to KEXTs */
67*4d495c6eSApple OSS Distributions int os_reason_alloc_buffer(os_reason_t cur_reason, uint32_t osr_bufsize);
68*4d495c6eSApple OSS Distributions 
69*4d495c6eSApple OSS Distributions typedef struct _exception_info {
70*4d495c6eSApple OSS Distributions 	int os_reason;
71*4d495c6eSApple OSS Distributions 	int signal;
72*4d495c6eSApple OSS Distributions 	exception_type_t exception_type;
73*4d495c6eSApple OSS Distributions 	mach_exception_data_type_t mx_code;
74*4d495c6eSApple OSS Distributions 	mach_exception_data_type_t mx_subcode;
75*4d495c6eSApple OSS Distributions 	struct kt_info {
76*4d495c6eSApple OSS Distributions 		int kt_subsys;
77*4d495c6eSApple OSS Distributions 		uint32_t kt_error;
78*4d495c6eSApple OSS Distributions 	} kt_info;
79*4d495c6eSApple OSS Distributions } exception_info_t;
80*4d495c6eSApple OSS Distributions 
81*4d495c6eSApple OSS Distributions #define PX_FLAGS_NONE           0
82*4d495c6eSApple OSS Distributions /* think twice about userspace debugging experience before using PX_DEBUG_NO_HONOR */
83*4d495c6eSApple OSS Distributions #define PX_DEBUG_NO_HONOR       (1 << 0) /* force exit even when debugging */
84*4d495c6eSApple OSS Distributions #define PX_KTRIAGE              (1 << 1) /* leave a ktriage record */
85*4d495c6eSApple OSS Distributions #define PX_PSIGNAL              (1 << 2) /* send sig instead of forced exit */
86*4d495c6eSApple OSS Distributions #define PX_NO_EXCEPTION_UTHREAD (1 << 3) /* do not set bsdthread exception */
87*4d495c6eSApple OSS Distributions 
88*4d495c6eSApple OSS Distributions int exit_with_mach_exception(struct proc *p, exception_info_t exception, uint32_t flags);
89*4d495c6eSApple OSS Distributions #if CONFIG_EXCLAVES
90*4d495c6eSApple OSS Distributions int exit_with_exclave_exception(struct proc *p, exception_info_t exception, uint32_t flags);
91*4d495c6eSApple OSS Distributions #endif
92*4d495c6eSApple OSS Distributions void exit_with_mach_exception_using_ast(exception_info_t exception, uint32_t flags, bool fatal);
93*4d495c6eSApple OSS Distributions 
94*4d495c6eSApple OSS Distributions #else /* XNU_KERNEL_PRIVATE */
95*4d495c6eSApple OSS Distributions 
96*4d495c6eSApple OSS Distributions typedef void * os_reason_t;
97*4d495c6eSApple OSS Distributions 
98*4d495c6eSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
99*4d495c6eSApple OSS Distributions 
100*4d495c6eSApple OSS Distributions os_reason_t os_reason_create(uint32_t osr_namespace, uint64_t osr_code);
101*4d495c6eSApple OSS Distributions int os_reason_alloc_buffer_noblock(os_reason_t cur_reason, uint32_t osr_bufsize);
102*4d495c6eSApple OSS Distributions struct kcdata_descriptor * os_reason_get_kcdata_descriptor(os_reason_t cur_reason);
103*4d495c6eSApple OSS Distributions void os_reason_ref(os_reason_t cur_reason);
104*4d495c6eSApple OSS Distributions void os_reason_free(os_reason_t cur_reason);
105*4d495c6eSApple OSS Distributions void os_reason_set_flags(os_reason_t cur_reason, uint64_t flags);
106*4d495c6eSApple OSS Distributions void os_reason_set_description_data(os_reason_t cur_reason, uint32_t type, void *reason_data, uint32_t reason_data_len);
107*4d495c6eSApple OSS Distributions #endif /* KERNEL_PRIVATE */
108*4d495c6eSApple OSS Distributions 
109*4d495c6eSApple OSS Distributions /*
110*4d495c6eSApple OSS Distributions  * Reason namespaces.
111*4d495c6eSApple OSS Distributions  */
112*4d495c6eSApple OSS Distributions #define OS_REASON_INVALID       0
113*4d495c6eSApple OSS Distributions #define OS_REASON_JETSAM        1
114*4d495c6eSApple OSS Distributions #define OS_REASON_SIGNAL        2
115*4d495c6eSApple OSS Distributions #define OS_REASON_CODESIGNING   3
116*4d495c6eSApple OSS Distributions #define OS_REASON_HANGTRACER    4
117*4d495c6eSApple OSS Distributions #define OS_REASON_TEST          5
118*4d495c6eSApple OSS Distributions #define OS_REASON_DYLD          6
119*4d495c6eSApple OSS Distributions #define OS_REASON_LIBXPC        7
120*4d495c6eSApple OSS Distributions #define OS_REASON_OBJC          8
121*4d495c6eSApple OSS Distributions #define OS_REASON_EXEC          9
122*4d495c6eSApple OSS Distributions #define OS_REASON_SPRINGBOARD   10
123*4d495c6eSApple OSS Distributions #define OS_REASON_TCC           11
124*4d495c6eSApple OSS Distributions #define OS_REASON_REPORTCRASH   12
125*4d495c6eSApple OSS Distributions #define OS_REASON_COREANIMATION 13
126*4d495c6eSApple OSS Distributions #define OS_REASON_AGGREGATED    14
127*4d495c6eSApple OSS Distributions #define OS_REASON_RUNNINGBOARD  15
128*4d495c6eSApple OSS Distributions #define OS_REASON_ASSERTIOND    OS_REASON_RUNNINGBOARD  /* old name */
129*4d495c6eSApple OSS Distributions #define OS_REASON_SKYWALK       16
130*4d495c6eSApple OSS Distributions #define OS_REASON_SETTINGS      17
131*4d495c6eSApple OSS Distributions #define OS_REASON_LIBSYSTEM     18
132*4d495c6eSApple OSS Distributions #define OS_REASON_FOUNDATION    19
133*4d495c6eSApple OSS Distributions #define OS_REASON_WATCHDOG      20
134*4d495c6eSApple OSS Distributions #define OS_REASON_METAL         21
135*4d495c6eSApple OSS Distributions #define OS_REASON_WATCHKIT      22
136*4d495c6eSApple OSS Distributions #define OS_REASON_GUARD         23
137*4d495c6eSApple OSS Distributions #define OS_REASON_ANALYTICS     24
138*4d495c6eSApple OSS Distributions #define OS_REASON_SANDBOX       25
139*4d495c6eSApple OSS Distributions #define OS_REASON_SECURITY      26
140*4d495c6eSApple OSS Distributions #define OS_REASON_ENDPOINTSECURITY      27
141*4d495c6eSApple OSS Distributions #define OS_REASON_PAC_EXCEPTION 28
142*4d495c6eSApple OSS Distributions #define OS_REASON_BLUETOOTH_CHIP 29
143*4d495c6eSApple OSS Distributions #define OS_REASON_PORT_SPACE    30
144*4d495c6eSApple OSS Distributions #define OS_REASON_WEBKIT        31
145*4d495c6eSApple OSS Distributions #define OS_REASON_BACKLIGHTSERVICES 32
146*4d495c6eSApple OSS Distributions #define OS_REASON_MEDIA 33
147*4d495c6eSApple OSS Distributions #define OS_REASON_ROSETTA 34
148*4d495c6eSApple OSS Distributions #define OS_REASON_LIBIGNITION 35
149*4d495c6eSApple OSS Distributions #define OS_REASON_BOOTMOUNT 36
150*4d495c6eSApple OSS Distributions #define OS_REASON_MTE_FAIL   37
151*4d495c6eSApple OSS Distributions #define OS_REASON_REALITYKIT 38
152*4d495c6eSApple OSS Distributions #define OS_REASON_AUDIO      39
153*4d495c6eSApple OSS Distributions #define OS_REASON_WAKEBOARD  40
154*4d495c6eSApple OSS Distributions #define OS_REASON_CORERC     41
155*4d495c6eSApple OSS Distributions #define OS_REASON_SELF_RESTRICT 42
156*4d495c6eSApple OSS Distributions #define OS_REASON_ARKIT      43
157*4d495c6eSApple OSS Distributions #define OS_REASON_CAMERA     44
158*4d495c6eSApple OSS Distributions #define OS_REASON_BACKBOARD  45
159*4d495c6eSApple OSS Distributions #define OS_REASON_POWEREXCEPTIONS 46
160*4d495c6eSApple OSS Distributions #define OS_REASON_SECINIT    47
161*4d495c6eSApple OSS Distributions 
162*4d495c6eSApple OSS Distributions /*
163*4d495c6eSApple OSS Distributions  * Update whenever new OS_REASON namespaces are added.
164*4d495c6eSApple OSS Distributions  */
165*4d495c6eSApple OSS Distributions #define OS_REASON_MAX_VALID_NAMESPACE OS_REASON_SECINIT
166*4d495c6eSApple OSS Distributions 
167*4d495c6eSApple OSS Distributions #define OS_REASON_BUFFER_MAX_SIZE 5120
168*4d495c6eSApple OSS Distributions 
169*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_NO_CRASH_REPORT          0x1    /* Don't create a crash report */
170*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_GENERATE_CRASH_REPORT    0x2    /* Create a crash report - the default for userspace requests */
171*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_FROM_USERSPACE           0x4    /* Reason created from a userspace syscall */
172*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_FAILED_DATA_COPYIN       0x8    /* We failed to copyin data from userspace */
173*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_PAYLOAD_TRUNCATED        0x10   /* The payload was truncated because it was longer than allowed */
174*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_BAD_PARAMS               0x20   /* Invalid parameters were passed involved with creating this reason */
175*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_CONSISTENT_FAILURE       0x40   /* Whatever caused this reason to be created will happen again */
176*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_ONE_TIME_FAILURE         0x80   /* Whatever caused this reason to be created was a one time issue */
177*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_NO_CRASHED_TID           0x100  /* Don't include the TID that processed the exit in the crash report */
178*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_ABORT                    0x200  /* Reason created from abort_* rather than terminate_* */
179*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_SHAREDREGION_FAULT       0x400  /* Fault happened within the shared cache region */
180*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_CAPTURE_LOGS             0x800  /* The report generated for this reason should capture logs */
181*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_SECURITY_SENSITIVE       0x1000 /* Mark as security sensitive for priority treatment */
182*4d495c6eSApple OSS Distributions 
183*4d495c6eSApple OSS Distributions /*
184*4d495c6eSApple OSS Distributions  * Set of flags that are allowed to be passed from userspace
185*4d495c6eSApple OSS Distributions  */
186*4d495c6eSApple OSS Distributions #define OS_REASON_FLAG_MASK_ALLOWED_FROM_USER (OS_REASON_FLAG_CONSISTENT_FAILURE | OS_REASON_FLAG_ONE_TIME_FAILURE | OS_REASON_FLAG_NO_CRASH_REPORT | OS_REASON_FLAG_ABORT | OS_REASON_FLAG_CAPTURE_LOGS | OS_REASON_FLAG_SECURITY_SENSITIVE)
187*4d495c6eSApple OSS Distributions 
188*4d495c6eSApple OSS Distributions /*
189*4d495c6eSApple OSS Distributions  * Macros to encode the exit reason namespace and first 32 bits of code in exception code
190*4d495c6eSApple OSS Distributions  * which is used by Report Crash as a hint. It should be only used as a hint since it
191*4d495c6eSApple OSS Distributions  * loses higher 32 bits of exit reason code.
192*4d495c6eSApple OSS Distributions  */
193*4d495c6eSApple OSS Distributions #define ENCODE_OSR_NAMESPACE_TO_MACH_EXCEPTION_CODE(code, osr_namespace) \
194*4d495c6eSApple OSS Distributions 	(code) = (code) | (((osr_namespace) & ((uint64_t)UINT32_MAX)) << 32)
195*4d495c6eSApple OSS Distributions #define ENCODE_OSR_CODE_TO_MACH_EXCEPTION_CODE(code, osr_code) \
196*4d495c6eSApple OSS Distributions 	(code) = (code) | ((osr_code) & ((uint64_t)UINT32_MAX))
197*4d495c6eSApple OSS Distributions 
198*4d495c6eSApple OSS Distributions #ifndef KERNEL
199*4d495c6eSApple OSS Distributions /*
200*4d495c6eSApple OSS Distributions  * abort_with_reason: Used to exit the current process and pass along
201*4d495c6eSApple OSS Distributions  *                    specific information about why it is being terminated.
202*4d495c6eSApple OSS Distributions  *
203*4d495c6eSApple OSS Distributions  * Inputs:              args->reason_namespace - OS_REASON namespace specified for the reason
204*4d495c6eSApple OSS Distributions  *                      args->reason_code - code in the specified namespace for the reason
205*4d495c6eSApple OSS Distributions  *                      args->reason_string - additional string formatted information about the request
206*4d495c6eSApple OSS Distributions  *                      args->reason_flags - options requested for how the process should be terminated (see OS_REASON_FLAG_* above).
207*4d495c6eSApple OSS Distributions  *
208*4d495c6eSApple OSS Distributions  * Outputs:             Does not return.
209*4d495c6eSApple OSS Distributions  */
210*4d495c6eSApple OSS Distributions void abort_with_reason(uint32_t reason_namespace, uint64_t reason_code, const char *reason_string, uint64_t reason_flags)
211*4d495c6eSApple OSS Distributions __attribute__((noreturn, cold));
212*4d495c6eSApple OSS Distributions 
213*4d495c6eSApple OSS Distributions /*
214*4d495c6eSApple OSS Distributions  * abort_with_payload: Used to exit the current process and pass along
215*4d495c6eSApple OSS Distributions  *                     specific information about why it is being terminated. The payload pointer
216*4d495c6eSApple OSS Distributions  *                     should point to structured data that can be interpreted by the consumer of
217*4d495c6eSApple OSS Distributions  *                     exit reason information.
218*4d495c6eSApple OSS Distributions  *
219*4d495c6eSApple OSS Distributions  * Inputs:              args->reason_namespace - OS_REASON namespace specified for the reason
220*4d495c6eSApple OSS Distributions  *                      args->reason_code - code in the specified namespace for the reason
221*4d495c6eSApple OSS Distributions  *                      args->payload - pointer to payload structure in user space
222*4d495c6eSApple OSS Distributions  *                      args->payload_size - length of payload buffer (this will be truncated to EXIT_REASON_PAYLOAD_MAX_LEN)
223*4d495c6eSApple OSS Distributions  *                      args->reason_string - additional string formatted information about the request
224*4d495c6eSApple OSS Distributions  *                      args->reason_flags - options requested for how the process should be terminated (see OS_REASON_FLAG_* above).
225*4d495c6eSApple OSS Distributions  *
226*4d495c6eSApple OSS Distributions  * Outputs:             Does not return.
227*4d495c6eSApple OSS Distributions  */
228*4d495c6eSApple OSS Distributions void abort_with_payload(uint32_t reason_namespace, uint64_t reason_code, void *payload, uint32_t payload_size, const char *reason_string,
229*4d495c6eSApple OSS Distributions     uint64_t reason_flags) __attribute__((noreturn, cold));
230*4d495c6eSApple OSS Distributions 
231*4d495c6eSApple OSS Distributions /*
232*4d495c6eSApple OSS Distributions  * terminate_with_reason: Used to terminate a specific process and pass along
233*4d495c6eSApple OSS Distributions  *                        specific information about why it is being terminated.
234*4d495c6eSApple OSS Distributions  *
235*4d495c6eSApple OSS Distributions  * Inputs:              args->pid - the PID of the process to be terminated
236*4d495c6eSApple OSS Distributions  *                      args->reason_namespace - OS_REASON namespace specified for the reason
237*4d495c6eSApple OSS Distributions  *                      args->reason_code - code in the specified namespace for the reason
238*4d495c6eSApple OSS Distributions  *                      args->reason_string - additional string formatted information about the request
239*4d495c6eSApple OSS Distributions  *                      args->reason_flags - options requested for how the process should be terminated (see OS_REASON_FLAG_* above)
240*4d495c6eSApple OSS Distributions  *
241*4d495c6eSApple OSS Distributions  * Outputs:             returns -1 and sets errno to EINVAL if the PID requested is the same as that of the calling process, invalid or the namespace provided is invalid.
242*4d495c6eSApple OSS Distributions  *                      returns -1 and sets errno to ESRCH if we couldn't find a live process with the requested PID
243*4d495c6eSApple OSS Distributions  *                      returns -1 and sets errno to EPERM if the caller is not privileged enough to kill the process with the requested PID
244*4d495c6eSApple OSS Distributions  *                      returns 0 otherwise
245*4d495c6eSApple OSS Distributions  */
246*4d495c6eSApple OSS Distributions int terminate_with_reason(int pid, uint32_t reason_namespace, uint64_t reason_code, const char *reason_string, uint64_t reason_flags);
247*4d495c6eSApple OSS Distributions 
248*4d495c6eSApple OSS Distributions /*
249*4d495c6eSApple OSS Distributions  * terminate_with_payload: Used to terminate a specific process and pass along
250*4d495c6eSApple OSS Distributions  *                         specific information about why it is being terminated. The payload pointer
251*4d495c6eSApple OSS Distributions  *                         should point to structured data that can be interpreted by the consumer of
252*4d495c6eSApple OSS Distributions  *                         exit reason information.
253*4d495c6eSApple OSS Distributions  *
254*4d495c6eSApple OSS Distributions  * Inputs:              args->pid - the PID of the process to be terminated.
255*4d495c6eSApple OSS Distributions  *                      args->reason_namespace - OS_REASON namespace specified for the reason
256*4d495c6eSApple OSS Distributions  *                      args->reason_code - code in the specified namespace for the reason
257*4d495c6eSApple OSS Distributions  *                      args->payload - pointer to payload structure in user space
258*4d495c6eSApple OSS Distributions  *                      args->payload_size - length of payload buffer (this will be truncated to EXIT_REASON_PAYLOAD_MAX_LEN)
259*4d495c6eSApple OSS Distributions  *                      args->reason_string - additional string formatted information about the request
260*4d495c6eSApple OSS Distributions  *                      args->reason_flags - options requested for how the process should be terminated (see OS_REASON_FLAG_* above)
261*4d495c6eSApple OSS Distributions  *
262*4d495c6eSApple OSS Distributions  * Outputs:             returns -1 and sets errno to EINVAL if the PID requested is the same as that of the calling process, is invalid or the namespace provided is invalid.
263*4d495c6eSApple OSS Distributions  *                      returns -1 and sets errno to ESRCH if we couldn't find a live process with the requested PID
264*4d495c6eSApple OSS Distributions  *                      returns -1 and sets errno to EPERM if the caller is not privileged enough to kill the process with the requested PID
265*4d495c6eSApple OSS Distributions  *                      returns 0 otherwise
266*4d495c6eSApple OSS Distributions  */
267*4d495c6eSApple OSS Distributions int terminate_with_payload(int pid, uint32_t reason_namespace, uint64_t reason_code, void *payload, uint32_t payload_size,
268*4d495c6eSApple OSS Distributions     const char *reason_string, uint64_t reason_flags);
269*4d495c6eSApple OSS Distributions #endif /* KERNEL */
270*4d495c6eSApple OSS Distributions 
271*4d495c6eSApple OSS Distributions /*
272*4d495c6eSApple OSS Distributions  * codesigning exit reasons
273*4d495c6eSApple OSS Distributions  */
274*4d495c6eSApple OSS Distributions #define CODESIGNING_EXIT_REASON_TASKGATED_INVALID_SIG           1
275*4d495c6eSApple OSS Distributions #define CODESIGNING_EXIT_REASON_INVALID_PAGE                    2
276*4d495c6eSApple OSS Distributions #define CODESIGNING_EXIT_REASON_TASK_ACCESS_PORT                3
277*4d495c6eSApple OSS Distributions #define CODESIGNING_EXIT_REASON_LAUNCH_CONSTRAINT_VIOLATION     4
278*4d495c6eSApple OSS Distributions /*
279*4d495c6eSApple OSS Distributions  * exec path specific exit reasons
280*4d495c6eSApple OSS Distributions  */
281*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_BAD_MACHO          1
282*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_SUGID_FAILURE      2
283*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_ACTV_THREADSTATE   3
284*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_STACK_ALLOC        4
285*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_APPLE_STRING_INIT  5
286*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_COPYOUT_STRINGS    6
287*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_COPYOUT_DYNLINKER  7
288*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_SECURITY_POLICY    8
289*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_TASKGATED_OTHER    9
290*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_FAIRPLAY_DECRYPT   10
291*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_DECRYPT            11
292*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_UPX                12
293*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_NO32EXEC           13
294*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_WRONG_PLATFORM     14
295*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_MAIN_FD_ALLOC      15
296*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_COPYOUT_ROSETTA    16
297*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_SET_DYLD_INFO      17
298*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_MACHINE_THREAD     18
299*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_BAD_PSATTR         19
300*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_NOX86EXEC          20
301*4d495c6eSApple OSS Distributions #define EXEC_EXIT_REASON_MAP_EXEC_FAILURE   21
302*4d495c6eSApple OSS Distributions /*
303*4d495c6eSApple OSS Distributions  * guard reasons
304*4d495c6eSApple OSS Distributions  */
305*4d495c6eSApple OSS Distributions #define GUARD_REASON_VNODE       1
306*4d495c6eSApple OSS Distributions #define GUARD_REASON_VIRT_MEMORY 2
307*4d495c6eSApple OSS Distributions #define GUARD_REASON_MACH_PORT   3
308*4d495c6eSApple OSS Distributions #define GUARD_REASON_EXCLAVES    4
309*4d495c6eSApple OSS Distributions #define GUARD_REASON_JIT         5
310*4d495c6eSApple OSS Distributions 
311*4d495c6eSApple OSS Distributions __END_DECLS
312*4d495c6eSApple OSS Distributions 
313*4d495c6eSApple OSS Distributions #endif /* _REASON_H_ */
314