]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
cb323159 | 2 | * Copyright (c) 2000-2019 Apple Inc. All rights reserved. |
1c79356b | 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@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_FREE_COPYRIGHT@ | |
30 | */ | |
0a7de745 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
0a7de745 | 35 | * |
1c79356b A |
36 | * Permission to use, copy, modify and distribute this software and its |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
0a7de745 | 41 | * |
1c79356b A |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
0a7de745 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 47 | * |
1c79356b A |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 52 | * |
1c79356b A |
53 | * any improvements or extensions that they make and grant Carnegie Mellon |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | /* | |
59 | * File: task.h | |
60 | * Author: Avadis Tevanian, Jr. | |
61 | * | |
62 | * This file contains the structure definitions for tasks. | |
63 | * | |
64 | */ | |
65 | /* | |
66 | * Copyright (c) 1993 The University of Utah and | |
67 | * the Computer Systems Laboratory (CSL). All rights reserved. | |
68 | * | |
69 | * Permission to use, copy, modify and distribute this software and its | |
70 | * documentation is hereby granted, provided that both the copyright | |
71 | * notice and this permission notice appear in all copies of the | |
72 | * software, derivative works or modified versions, and any portions | |
73 | * thereof, and that both notices appear in supporting documentation. | |
74 | * | |
75 | * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS | |
76 | * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF | |
77 | * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
78 | * | |
79 | * CSL requests users of this software to return to csl-dist@cs.utah.edu any | |
80 | * improvements that they make and grant CSL redistribution rights. | |
81 | * | |
82 | */ | |
2d21ac55 A |
83 | /* |
84 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce | |
85 | * support for mandatory and extensible security protections. This notice | |
86 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
87 | * Version 2.0. | |
88 | * Copyright (c) 2005 SPARTA, Inc. | |
89 | */ | |
1c79356b | 90 | |
0a7de745 | 91 | #ifndef _KERN_TASK_H_ |
1c79356b A |
92 | #define _KERN_TASK_H_ |
93 | ||
94 | #include <kern/kern_types.h> | |
95 | #include <mach/mach_types.h> | |
91447636 | 96 | #include <sys/cdefs.h> |
9bccf70c | 97 | |
39037602 A |
98 | #ifdef XNU_KERNEL_PRIVATE |
99 | #include <kern/kern_cdata.h> | |
100 | #include <mach/sfi_class.h> | |
101 | #include <kern/queue.h> | |
cb323159 | 102 | #include <sys/kern_sysctl.h> |
39037602 A |
103 | #endif /* XNU_KERNEL_PRIVATE */ |
104 | ||
0a7de745 | 105 | #ifdef MACH_KERNEL_PRIVATE |
9bccf70c | 106 | |
1c79356b A |
107 | #include <mach/boolean.h> |
108 | #include <mach/port.h> | |
109 | #include <mach/time_value.h> | |
110 | #include <mach/message.h> | |
111 | #include <mach/mach_param.h> | |
112 | #include <mach/task_info.h> | |
113 | #include <mach/exception_types.h> | |
6d2010ae | 114 | #include <mach/vm_statistics.h> |
0c530ab8 | 115 | #include <machine/task.h> |
91447636 | 116 | |
5ba3f43e A |
117 | #if MONOTONIC |
118 | #include <machine/monotonic.h> | |
119 | #endif /* MONOTONIC */ | |
120 | ||
91447636 | 121 | #include <kern/cpu_data.h> |
1c79356b A |
122 | #include <kern/queue.h> |
123 | #include <kern/exception.h> | |
fe8ab488 | 124 | #include <kern/locks.h> |
2d21ac55 | 125 | #include <security/_label.h> |
fe8ab488 | 126 | #include <ipc/ipc_port.h> |
316670eb | 127 | |
6d2010ae | 128 | #include <kern/thread.h> |
3e170ce0 | 129 | #include <mach/coalition.h> |
5ba3f43e | 130 | #include <stdatomic.h> |
e8c3f781 | 131 | #include <os/refcnt.h> |
6d2010ae | 132 | |
fe8ab488 | 133 | struct _cpu_time_qos_stats { |
0a7de745 A |
134 | uint64_t cpu_time_qos_default; |
135 | uint64_t cpu_time_qos_maintenance; | |
136 | uint64_t cpu_time_qos_background; | |
137 | uint64_t cpu_time_qos_utility; | |
138 | uint64_t cpu_time_qos_legacy; | |
139 | uint64_t cpu_time_qos_user_initiated; | |
140 | uint64_t cpu_time_qos_user_interactive; | |
fe8ab488 A |
141 | }; |
142 | ||
cb323159 A |
143 | struct task_writes_counters { |
144 | uint64_t task_immediate_writes; | |
145 | uint64_t task_deferred_writes; | |
146 | uint64_t task_invalidated_writes; | |
147 | uint64_t task_metadata_writes; | |
148 | }; | |
149 | ||
150 | struct task_watchports; | |
fe8ab488 | 151 | #include <bank/bank_internal.h> |
fe8ab488 | 152 | |
91447636 | 153 | struct task { |
1c79356b | 154 | /* Synchronization/destruction information */ |
cb323159 | 155 | decl_lck_mtx_data(, lock); /* Task's lock */ |
0a7de745 A |
156 | os_refcnt_t ref_count; /* Number of references to me */ |
157 | boolean_t active; /* Task has not been terminated */ | |
158 | boolean_t halting; /* Task is being halted */ | |
cb323159 A |
159 | boolean_t message_app_suspended; /* Let iokit know when pidsuspended */ |
160 | ||
d9a64523 | 161 | /* Virtual timers */ |
0a7de745 | 162 | uint32_t vtimers; |
1c79356b A |
163 | |
164 | /* Miscellaneous */ | |
f427ee49 | 165 | vm_map_t XNU_PTRAUTH_SIGNED_PTR("task.map") map; /* Address space description */ |
0a7de745 | 166 | queue_chain_t tasks; /* global list of tasks */ |
cb323159 A |
167 | struct task_watchports *watchports; /* watchports passed in spawn */ |
168 | turnstile_inheritor_t returnwait_inheritor; /* inheritor for task_wait */ | |
1c79356b | 169 | |
fe8ab488 A |
170 | #if defined(CONFIG_SCHED_MULTIQ) |
171 | sched_group_t sched_group; | |
172 | #endif /* defined(CONFIG_SCHED_MULTIQ) */ | |
173 | ||
55e303ae | 174 | /* Threads in this task */ |
0a7de745 | 175 | queue_head_t threads; |
cb323159 | 176 | struct restartable_ranges *restartable_ranges; |
b0d623f7 | 177 | |
0a7de745 A |
178 | processor_set_t pset_hint; |
179 | struct affinity_space *affinity_space; | |
b0d623f7 | 180 | |
0a7de745 A |
181 | int thread_count; |
182 | uint32_t active_thread_count; | |
183 | int suspend_count; /* Internal scheduling only */ | |
1c79356b A |
184 | |
185 | /* User-visible scheduling information */ | |
0a7de745 A |
186 | integer_t user_stop_count; /* outstanding stops */ |
187 | integer_t legacy_stop_count; /* outstanding legacy stops */ | |
1c79356b | 188 | |
f427ee49 A |
189 | int16_t priority; /* base priority for threads */ |
190 | int16_t max_priority; /* maximum priority for threads */ | |
1c79356b | 191 | |
0a7de745 | 192 | integer_t importance; /* priority offset (BSD 'nice' value) */ |
39236c6e | 193 | |
55e303ae | 194 | /* Task security and audit tokens */ |
1c79356b | 195 | security_token_t sec_token; |
0a7de745 | 196 | audit_token_t audit_token; |
d9a64523 | 197 | |
1c79356b | 198 | /* Statistics */ |
0a7de745 A |
199 | uint64_t total_user_time; /* terminated threads only */ |
200 | uint64_t total_system_time; | |
201 | uint64_t total_ptime; | |
202 | uint64_t total_runnable_time; | |
1c79356b A |
203 | |
204 | /* IPC structures */ | |
cb323159 | 205 | decl_lck_mtx_data(, itk_lock_data); |
f427ee49 A |
206 | /* |
207 | * Different flavors of task port. | |
208 | * These flavors TASK_FLAVOR_* are defined in mach_types.h | |
209 | */ | |
210 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_self") itk_self[TASK_SELF_PORT_COUNT]; /* does not hold right */ | |
211 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_settable_self") itk_settable_self; /* a send right */ | |
1c79356b | 212 | struct exception_action exc_actions[EXC_TYPES_COUNT]; |
0a7de745 | 213 | /* a send right each valid element */ |
f427ee49 A |
214 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_host") itk_host; /* a send right */ |
215 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_bootstrap") itk_bootstrap; /* a send right */ | |
216 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_seatbelt") itk_seatbelt; /* a send right */ | |
217 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_gssd") itk_gssd; /* yet another send right */ | |
218 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_debug_control") itk_debug_control; /* send right for debugmode communications */ | |
219 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_task_access") itk_task_access; /* and another send right */ | |
220 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_resume") itk_resume; /* a receive right to resume this task */ | |
221 | struct ipc_port * XNU_PTRAUTH_SIGNED_PTR("task.itk_registered") itk_registered[TASK_PORT_REGISTER_MAX]; | |
0a7de745 | 222 | /* all send rights */ |
1c79356b | 223 | |
f427ee49 | 224 | struct ipc_space * XNU_PTRAUTH_SIGNED_PTR("task.itk_space") itk_space; |
1c79356b | 225 | |
0a7de745 | 226 | ledger_t ledger; |
1c79356b | 227 | /* Synchronizer ownership information */ |
0a7de745 A |
228 | queue_head_t semaphore_list; /* list of owned semaphores */ |
229 | int semaphores_owned; /* number of semaphores owned */ | |
1c79356b | 230 | |
0a7de745 A |
231 | unsigned int priv_flags; /* privilege resource flags */ |
232 | #define VM_BACKING_STORE_PRIV 0x1 | |
0c530ab8 A |
233 | |
234 | MACHINE_TASK | |
0a7de745 | 235 | |
1c79356b | 236 | integer_t faults; /* faults counter */ |
cb323159 | 237 | integer_t decompressions; /* decompression counter */ |
0a7de745 A |
238 | integer_t pageins; /* pageins counter */ |
239 | integer_t cow_faults; /* copy on write fault counter */ | |
240 | integer_t messages_sent; /* messages sent counter */ | |
241 | integer_t messages_received; /* messages received counter */ | |
242 | integer_t syscalls_mach; /* mach system call counter */ | |
243 | integer_t syscalls_unix; /* unix system call counter */ | |
244 | uint32_t c_switch; /* total context switches */ | |
245 | uint32_t p_switch; /* total processor switches */ | |
246 | uint32_t ps_switch; /* total pset switches */ | |
247 | ||
248 | #ifdef MACH_BSD | |
f427ee49 | 249 | void * XNU_PTRAUTH_SIGNED_PTR("task.bsd_info") bsd_info; |
0a7de745 A |
250 | #endif |
251 | kcdata_descriptor_t corpse_info; | |
252 | uint64_t crashed_thread_id; | |
253 | queue_chain_t corpse_tasks; | |
39037602 | 254 | #ifdef CONFIG_MACF |
0a7de745 | 255 | struct label * crash_label; |
f427ee49 A |
256 | uint8_t * mach_trap_filter_mask; /* Mach trap filter bitmask (len: mach_trap_count bits) */ |
257 | uint8_t * mach_kobj_filter_mask; /* Mach kobject filter bitmask (len: mach_kobj_count bits) */ | |
39037602 | 258 | #endif |
0a7de745 | 259 | struct vm_shared_region *shared_region; |
f427ee49 A |
260 | #if __has_feature(ptrauth_calls) |
261 | char *shared_region_id; /* determines which ptr auth key to use */ | |
262 | bool shared_region_auth_remapped; /* authenticated sections ready for use */ | |
263 | #endif /* __has_feature(ptrauth_calls) */ | |
fe8ab488 | 264 | volatile uint32_t t_flags; /* general-purpose task flags protected by task_lock (TL) */ |
39037602 | 265 | #define TF_NONE 0 |
fe8ab488 A |
266 | #define TF_64B_ADDR 0x00000001 /* task has 64-bit addressing */ |
267 | #define TF_64B_DATA 0x00000002 /* task has 64-bit data registers */ | |
268 | #define TF_CPUMON_WARNING 0x00000004 /* task has at least one thread in CPU usage warning zone */ | |
269 | #define TF_WAKEMON_WARNING 0x00000008 /* task is in wakeups monitor warning zone */ | |
270 | #define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */ | |
271 | #define TF_GPU_DENIED 0x00000010 /* task is not allowed to access the GPU */ | |
3e170ce0 A |
272 | #define TF_CORPSE 0x00000020 /* task is a corpse */ |
273 | #define TF_PENDING_CORPSE 0x00000040 /* task corpse has not been reported yet */ | |
39037602 | 274 | #define TF_CORPSE_FORK 0x00000080 /* task is a forked corpse */ |
5ba3f43e | 275 | #define TF_PLATFORM 0x00000400 /* task is a platform binary */ |
a39ff7e2 | 276 | #define TF_CA_CLIENT_WI 0x00000800 /* task has CA_CLIENT work interval */ |
d9a64523 | 277 | #define TF_DARKWAKE_MODE 0x00001000 /* task is in darkwake mode */ |
0a7de745 | 278 | #define TF_NO_SMT 0x00002000 /* task threads must not be paired with SMT threads */ |
f427ee49 A |
279 | #define TF_FILTER_MSG 0x00004000 /* task calls into message filter callback before sending a message */ |
280 | #define TF_SYS_VERSION_COMPAT 0x00008000 /* shim task accesses to OS version data (macOS - app compatibility) */ | |
281 | #define TF_PAC_EXC_FATAL 0x00010000 /* task is marked a corpse if a PAC exception occurs */ | |
282 | #define TF_TECS 0x00020000 /* task threads must enable CPU security */ | |
d9a64523 A |
283 | |
284 | /* | |
285 | * Task is running within a 64-bit address space. | |
286 | */ | |
0a7de745 | 287 | #define task_has_64Bit_addr(task) \ |
d9a64523 | 288 | (((task)->t_flags & TF_64B_ADDR) != 0) |
0a7de745 | 289 | #define task_set_64Bit_addr(task) \ |
d9a64523 | 290 | ((task)->t_flags |= TF_64B_ADDR) |
0a7de745 | 291 | #define task_clear_64Bit_addr(task) \ |
d9a64523 | 292 | ((task)->t_flags &= ~TF_64B_ADDR) |
fe8ab488 | 293 | |
d9a64523 A |
294 | /* |
295 | * Task is using 64-bit machine state. | |
296 | */ | |
0a7de745 | 297 | #define task_has_64Bit_data(task) \ |
d9a64523 | 298 | (((task)->t_flags & TF_64B_DATA) != 0) |
0a7de745 | 299 | #define task_set_64Bit_data(task) \ |
d9a64523 | 300 | ((task)->t_flags |= TF_64B_DATA) |
0a7de745 | 301 | #define task_clear_64Bit_data(task) \ |
d9a64523 | 302 | ((task)->t_flags &= ~TF_64B_DATA) |
91447636 | 303 | |
3e170ce0 A |
304 | #define task_is_a_corpse(task) \ |
305 | (((task)->t_flags & TF_CORPSE) != 0) | |
306 | ||
307 | #define task_set_corpse(task) \ | |
308 | ((task)->t_flags |= TF_CORPSE) | |
309 | ||
0a7de745 | 310 | #define task_corpse_pending_report(task) \ |
3e170ce0 A |
311 | (((task)->t_flags & TF_PENDING_CORPSE) != 0) |
312 | ||
313 | #define task_set_corpse_pending_report(task) \ | |
314 | ((task)->t_flags |= TF_PENDING_CORPSE) | |
315 | ||
316 | #define task_clear_corpse_pending_report(task) \ | |
317 | ((task)->t_flags &= ~TF_PENDING_CORPSE) | |
318 | ||
0a7de745 | 319 | #define task_is_a_corpse_fork(task) \ |
39037602 A |
320 | (((task)->t_flags & TF_CORPSE_FORK) != 0) |
321 | ||
743345f9 A |
322 | uint32_t t_procflags; /* general-purpose task flags protected by proc_lock (PL) */ |
323 | #define TPF_NONE 0 | |
324 | #define TPF_DID_EXEC 0x00000001 /* task has been execed to a new task */ | |
325 | #define TPF_EXEC_COPY 0x00000002 /* task is the new copy of an exec */ | |
527f9951 A |
326 | #ifdef CONFIG_32BIT_TELEMETRY |
327 | #define TPF_LOG_32BIT_TELEMETRY 0x00000004 /* task should log identifying information */ | |
328 | #endif | |
743345f9 | 329 | |
0a7de745 | 330 | #define task_did_exec_internal(task) \ |
743345f9 A |
331 | (((task)->t_procflags & TPF_DID_EXEC) != 0) |
332 | ||
0a7de745 | 333 | #define task_is_exec_copy_internal(task) \ |
743345f9 A |
334 | (((task)->t_procflags & TPF_EXEC_COPY) != 0) |
335 | ||
cb323159 A |
336 | uint8_t t_returnwaitflags; |
337 | #define TWF_NONE 0 | |
338 | #define TRW_LRETURNWAIT 0x01 /* task is waiting for fork/posix_spawn/exec to complete */ | |
339 | #define TRW_LRETURNWAITER 0x02 /* task is waiting for TRW_LRETURNWAIT to get cleared */ | |
340 | ||
0a7de745 A |
341 | mach_vm_address_t all_image_info_addr; /* dyld __all_image_info */ |
342 | mach_vm_size_t all_image_info_size; /* section location and size */ | |
2d21ac55 | 343 | |
a39ff7e2 | 344 | #if KPC |
0a7de745 | 345 | #define TASK_KPC_FORCED_ALL_CTRS 0x2 /* Bit in "t_kpc" signifying this task forced all counters */ |
a39ff7e2 A |
346 | uint32_t t_kpc; /* kpc flags */ |
347 | #endif /* KPC */ | |
b0d623f7 | 348 | |
316670eb A |
349 | boolean_t pidsuspended; /* pid_suspend called; no threads can execute */ |
350 | boolean_t frozen; /* frozen; private resident pages committed to swap */ | |
0a7de745 | 351 | boolean_t changing_freeze_state; /* in the process of freezing or thawing */ |
39236c6e | 352 | uint16_t policy_ru_cpu :4, |
0a7de745 A |
353 | policy_ru_cpu_ext :4, |
354 | applied_ru_cpu :4, | |
355 | applied_ru_cpu_ext :4; | |
316670eb | 356 | uint8_t rusage_cpu_flags; |
0a7de745 | 357 | uint8_t rusage_cpu_percentage; /* Task-wide CPU limit percentage */ |
316670eb | 358 | uint8_t rusage_cpu_perthr_percentage; /* Per-thread CPU limit percentage */ |
d9a64523 | 359 | #if MACH_ASSERT |
0a7de745 | 360 | int8_t suspends_outstanding; /* suspends this task performed in excess of resumes */ |
d9a64523 | 361 | #endif |
0a7de745 | 362 | uint64_t rusage_cpu_interval; /* Task-wide CPU limit interval */ |
316670eb A |
363 | uint64_t rusage_cpu_perthr_interval; /* Per-thread CPU limit interval */ |
364 | uint64_t rusage_cpu_deadline; | |
365 | thread_call_t rusage_cpu_callt; | |
f427ee49 | 366 | #if CONFIG_TASKWATCH |
0a7de745 A |
367 | queue_head_t task_watchers; /* app state watcher threads */ |
368 | int num_taskwatchers; | |
369 | int watchapplying; | |
f427ee49 | 370 | #endif /* CONFIG_TASKWATCH */ |
39236c6e | 371 | |
fe8ab488 | 372 | struct bank_task *bank_context; /* pointer to per task bank structure */ |
39236c6e | 373 | |
fe8ab488 | 374 | #if IMPORTANCE_INHERITANCE |
0a7de745 | 375 | struct ipc_importance_task *task_imp_base; /* Base of IPC importance chain */ |
39236c6e | 376 | #endif /* IMPORTANCE_INHERITANCE */ |
6d2010ae | 377 | |
0a7de745 | 378 | vm_extmod_statistics_data_t extmod_statistics; |
39236c6e | 379 | |
39236c6e A |
380 | struct task_requested_policy requested_policy; |
381 | struct task_effective_policy effective_policy; | |
39236c6e A |
382 | |
383 | /* | |
384 | * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away. | |
385 | */ | |
0a7de745 A |
386 | uint32_t low_mem_notified_warn :1, /* warning low memory notification is sent to the task */ |
387 | low_mem_notified_critical :1, /* critical low memory notification is sent to the task */ | |
388 | purged_memory_warn :1, /* purgeable memory of the task is purged for warning level pressure */ | |
389 | purged_memory_critical :1, /* purgeable memory of the task is purged for critical level pressure */ | |
390 | low_mem_privileged_listener :1, /* if set, task would like to know about pressure changes before other tasks on the system */ | |
391 | mem_notify_reserved :27; /* reserved for future use */ | |
4b17d6b6 | 392 | |
813fb2f6 | 393 | uint32_t memlimit_is_active :1, /* if set, use active attributes, otherwise use inactive attributes */ |
0a7de745 A |
394 | memlimit_is_fatal :1, /* if set, exceeding current memlimit will prove fatal to the task */ |
395 | memlimit_active_exc_resource :1, /* if set, suppress exc_resource exception when task exceeds active memory limit */ | |
396 | memlimit_inactive_exc_resource :1, /* if set, suppress exc_resource exception when task exceeds inactive memory limit */ | |
397 | memlimit_attrs_reserved :28; /* reserved for future use */ | |
398 | ||
399 | io_stat_info_t task_io_stats; | |
cb323159 A |
400 | |
401 | struct task_writes_counters task_writes_counters_internal; | |
402 | struct task_writes_counters task_writes_counters_external; | |
0a7de745 A |
403 | |
404 | /* | |
fe8ab488 A |
405 | * The cpu_time_qos_stats fields are protected by the task lock |
406 | */ | |
0a7de745 A |
407 | struct _cpu_time_qos_stats cpu_time_eqos_stats; |
408 | struct _cpu_time_qos_stats cpu_time_rqos_stats; | |
fe8ab488 | 409 | |
4b17d6b6 | 410 | /* Statistics accumulated for terminated threads from this task */ |
0a7de745 A |
411 | uint32_t task_timer_wakeups_bin_1; |
412 | uint32_t task_timer_wakeups_bin_2; | |
413 | uint64_t task_gpu_ns; | |
414 | uint64_t task_energy; | |
fe8ab488 | 415 | |
5ba3f43e A |
416 | #if MONOTONIC |
417 | /* Read and written under task_lock */ | |
418 | struct mt_task task_monotonic; | |
419 | #endif /* MONOTONIC */ | |
420 | ||
cb323159 A |
421 | uint8_t task_can_transfer_memory_ownership; |
422 | uint8_t task_objects_disowning; | |
423 | uint8_t task_objects_disowned; | |
fe8ab488 | 424 | /* # of purgeable volatile VM objects owned by this task: */ |
0a7de745 | 425 | int task_volatile_objects; |
fe8ab488 | 426 | /* # of purgeable but not volatile VM objects owned by this task: */ |
0a7de745 | 427 | int task_nonvolatile_objects; |
cb323159 | 428 | int task_owned_objects; |
0a7de745 | 429 | queue_head_t task_objq; |
cb323159 | 430 | decl_lck_mtx_data(, task_objq_lock); /* protects "task_objq" */ |
a39ff7e2 | 431 | |
0a7de745 | 432 | unsigned int task_thread_limit:16; |
d9a64523 | 433 | #if __arm64__ |
0a7de745 | 434 | unsigned int task_legacy_footprint:1; |
cb323159 | 435 | unsigned int task_extra_footprint_limit:1; |
94ff46dc | 436 | unsigned int task_ios13extended_footprint_limit:1; |
d9a64523 | 437 | #endif /* __arm64__ */ |
0a7de745 A |
438 | unsigned int task_region_footprint:1; |
439 | unsigned int task_has_crossed_thread_limit:1; | |
440 | uint32_t exec_token; | |
3e170ce0 A |
441 | /* |
442 | * A task's coalition set is "adopted" in task_create_internal | |
443 | * and unset in task_deallocate_internal, so each array member | |
444 | * can be referenced without the task lock. | |
445 | * Note: these fields are protected by coalition->lock, | |
446 | * not the task lock. | |
447 | */ | |
0a7de745 | 448 | coalition_t coalition[COALITION_NUM_TYPES]; |
3e170ce0 A |
449 | queue_chain_t task_coalition[COALITION_NUM_TYPES]; |
450 | uint64_t dispatchqueue_offset; | |
fe8ab488 | 451 | |
39037602 | 452 | #if DEVELOPMENT || DEBUG |
0a7de745 A |
453 | boolean_t task_unnested; |
454 | int task_disconnected_count; | |
39037602 A |
455 | #endif |
456 | ||
fe8ab488 | 457 | #if HYPERVISOR |
f427ee49 | 458 | void * XNU_PTRAUTH_SIGNED_PTR("task.hv_task_target") hv_task_target; /* hypervisor virtual machine object associated with this task */ |
fe8ab488 | 459 | #endif /* HYPERVISOR */ |
7e41aa88 | 460 | |
39037602 | 461 | #if CONFIG_SECLUDED_MEMORY |
0a7de745 A |
462 | uint8_t task_can_use_secluded_mem; |
463 | uint8_t task_could_use_secluded_mem; | |
464 | uint8_t task_could_also_use_secluded_mem; | |
465 | uint8_t task_suppressed_secluded; | |
39037602 A |
466 | #endif /* CONFIG_SECLUDED_MEMORY */ |
467 | ||
cb323159 | 468 | task_exc_guard_behavior_t task_exc_guard; |
d9a64523 | 469 | |
7e41aa88 | 470 | queue_head_t io_user_clients; |
1c79356b | 471 | |
cb323159 | 472 | mach_vm_address_t mach_header_vm_address; |
d9a64523 | 473 | |
cb323159 | 474 | uint32_t loadTag; /* dext ID used for logging identity */ |
f427ee49 A |
475 | #if CONFIG_FREEZE |
476 | queue_head_t task_frozen_cseg_q; /* queue of csegs frozen to NAND */ | |
477 | #endif /* CONFIG_FREEZE */ | |
478 | #if CONFIG_PHYS_WRITE_ACCT | |
479 | uint64_t task_fs_metadata_writes; | |
480 | #endif /* CONFIG_PHYS_WRITE_ACCT */ | |
cb323159 | 481 | }; |
d9a64523 | 482 | |
cb323159 A |
483 | /* |
484 | * EXC_GUARD default delivery behavior for optional Mach port and VM guards. | |
485 | * Applied to new tasks at creation time. | |
486 | */ | |
487 | extern task_exc_guard_behavior_t task_exc_guard_default; | |
d9a64523 A |
488 | |
489 | extern kern_return_t | |
0a7de745 | 490 | task_violated_guard(mach_exception_code_t, mach_exception_subcode_t, void *); |
d9a64523 | 491 | |
f427ee49 A |
492 | static inline void |
493 | task_require(struct task *task) | |
494 | { | |
495 | zone_id_require(ZONE_ID_TASK, sizeof(struct task), task); | |
496 | } | |
497 | ||
0a7de745 A |
498 | #define task_lock(task) lck_mtx_lock(&(task)->lock) |
499 | #define task_lock_assert_owned(task) LCK_MTX_ASSERT(&(task)->lock, LCK_MTX_ASSERT_OWNED) | |
500 | #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock) | |
501 | #define task_unlock(task) lck_mtx_unlock(&(task)->lock) | |
1c79356b | 502 | |
0a7de745 | 503 | #define task_objq_lock_init(task) lck_mtx_init(&(task)->task_objq_lock, &vm_object_lck_grp, &vm_object_lck_attr) |
f427ee49 | 504 | #define task_objq_lock_destroy(task) lck_mtx_destroy(&(task)->task_objq_lock, &vm_object_lck_grp) |
0a7de745 A |
505 | #define task_objq_lock(task) lck_mtx_lock(&(task)->task_objq_lock) |
506 | #define task_objq_lock_assert_owned(task) LCK_MTX_ASSERT(&(task)->task_objq_lock, LCK_MTX_ASSERT_OWNED) | |
507 | #define task_objq_lock_try(task) lck_mtx_try_lock(&(task)->task_objq_lock) | |
508 | #define task_objq_unlock(task) lck_mtx_unlock(&(task)->task_objq_lock) | |
a39ff7e2 | 509 | |
0a7de745 A |
510 | #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr) |
511 | #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp) | |
512 | #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data) | |
513 | #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data) | |
1c79356b | 514 | |
cb323159 A |
515 | /* task clear return wait flags */ |
516 | #define TCRW_CLEAR_INITIAL_WAIT 0x1 | |
517 | #define TCRW_CLEAR_FINAL_WAIT 0x2 | |
518 | #define TCRW_CLEAR_ALL_WAIT (TCRW_CLEAR_INITIAL_WAIT | TCRW_CLEAR_FINAL_WAIT) | |
519 | ||
39236c6e A |
520 | #define TASK_REFERENCE_LEAK_DEBUG 0 |
521 | ||
522 | #if TASK_REFERENCE_LEAK_DEBUG | |
523 | extern void task_reference_internal(task_t task); | |
e8c3f781 | 524 | extern os_ref_count_t task_deallocate_internal(task_t task); |
39236c6e | 525 | #else |
f427ee49 A |
526 | #define task_reference_internal(task) \ |
527 | MACRO_BEGIN \ | |
528 | task_require(task); \ | |
eb6b6ca3 A |
529 | os_ref_retain(&(task)->ref_count); \ |
530 | MACRO_END | |
e8c3f781 | 531 | #define task_deallocate_internal(task) os_ref_release(&(task)->ref_count) |
39236c6e | 532 | #endif |
55e303ae | 533 | |
0a7de745 A |
534 | #define task_reference(task) \ |
535 | MACRO_BEGIN \ | |
536 | if ((task) != TASK_NULL) \ | |
537 | task_reference_internal(task); \ | |
91447636 | 538 | MACRO_END |
1c79356b | 539 | |
0a7de745 A |
540 | extern kern_return_t kernel_task_create( |
541 | task_t task, | |
542 | vm_offset_t map_base, | |
543 | vm_size_t map_size, | |
544 | task_t *child); | |
55e303ae | 545 | |
1c79356b | 546 | /* Initialize task module */ |
0a7de745 | 547 | extern void task_init(void); |
1c79356b | 548 | |
fe8ab488 | 549 | /* coalition_init() calls this to initialize ledgers before task_init() */ |
0a7de745 | 550 | extern void init_task_ledgers(void); |
fe8ab488 | 551 | |
0a7de745 A |
552 | #define current_task_fast() (current_thread()->task) |
553 | #define current_task() current_task_fast() | |
1c79356b | 554 | |
cb323159 A |
555 | extern bool task_is_driver(task_t task); |
556 | ||
b0d623f7 A |
557 | extern lck_attr_t task_lck_attr; |
558 | extern lck_grp_t task_lck_grp; | |
559 | ||
cb323159 A |
560 | struct task_watchport_elem { |
561 | task_t twe_task; | |
562 | ipc_port_t twe_port; /* (Space lock) */ | |
563 | }; | |
564 | ||
565 | struct task_watchports { | |
566 | os_refcnt_t tw_refcount; /* (Space lock) */ | |
567 | task_t tw_task; /* (Space lock) & tw_refcount == 0 */ | |
568 | thread_t tw_thread; /* (Space lock) & tw_refcount == 0 */ | |
569 | uint32_t tw_elem_array_count; /* (Space lock) */ | |
570 | struct task_watchport_elem tw_elem[]; /* (Space lock) & (Portlock) & (mq lock) */ | |
571 | }; | |
572 | ||
573 | #define task_watchports_retain(x) (os_ref_retain(&(x)->tw_refcount)) | |
574 | #define task_watchports_release(x) (os_ref_release(&(x)->tw_refcount)) | |
575 | ||
576 | #define task_watchport_elem_init(elem, task, port) \ | |
577 | do { \ | |
578 | (elem)->twe_task = (task); \ | |
579 | (elem)->twe_port = (port); \ | |
580 | } while(0) | |
581 | ||
582 | #define task_watchport_elem_clear(elem) task_watchport_elem_init((elem), NULL, NULL) | |
583 | ||
584 | extern void | |
585 | task_add_turnstile_watchports( | |
586 | task_t task, | |
587 | thread_t thread, | |
588 | ipc_port_t *portwatch_ports, | |
589 | uint32_t portwatch_count); | |
590 | ||
591 | extern void | |
592 | task_watchport_elem_deallocate( | |
593 | struct task_watchport_elem *watchport_elem); | |
594 | ||
595 | extern boolean_t | |
596 | task_has_watchports(task_t task); | |
597 | ||
0a7de745 | 598 | #else /* MACH_KERNEL_PRIVATE */ |
1c79356b | 599 | |
91447636 A |
600 | __BEGIN_DECLS |
601 | ||
0a7de745 | 602 | extern task_t current_task(void); |
91447636 | 603 | |
0a7de745 | 604 | extern void task_reference(task_t task); |
cb323159 | 605 | extern bool task_is_driver(task_t task); |
91447636 | 606 | |
39037602 | 607 | #define TF_NONE 0 |
cb323159 A |
608 | |
609 | #define TWF_NONE 0 | |
610 | #define TRW_LRETURNWAIT 0x01 /* task is waiting for fork/posix_spawn/exec to complete */ | |
611 | #define TRW_LRETURNWAITER 0x02 /* task is waiting for TRW_LRETURNWAIT to get cleared */ | |
612 | ||
613 | /* task clear return wait flags */ | |
614 | #define TCRW_CLEAR_INITIAL_WAIT 0x1 | |
615 | #define TCRW_CLEAR_FINAL_WAIT 0x2 | |
616 | #define TCRW_CLEAR_ALL_WAIT (TCRW_CLEAR_INITIAL_WAIT | TCRW_CLEAR_FINAL_WAIT) | |
617 | ||
743345f9 A |
618 | |
619 | #define TPF_NONE 0 | |
620 | #define TPF_EXEC_COPY 0x00000002 /* task is the new copy of an exec */ | |
621 | ||
39037602 | 622 | |
91447636 | 623 | __END_DECLS |
1c79356b | 624 | |
0a7de745 | 625 | #endif /* MACH_KERNEL_PRIVATE */ |
1c79356b | 626 | |
91447636 | 627 | __BEGIN_DECLS |
1c79356b | 628 | |
cb323159 A |
629 | #ifdef KERNEL_PRIVATE |
630 | extern boolean_t task_is_app_suspended(task_t task); | |
f427ee49 A |
631 | extern bool task_is_exotic(task_t task); |
632 | extern bool task_is_alien(task_t task); | |
cb323159 A |
633 | #endif |
634 | ||
0a7de745 | 635 | #ifdef XNU_KERNEL_PRIVATE |
91447636 A |
636 | |
637 | /* Hold all threads in a task */ | |
0a7de745 A |
638 | extern kern_return_t task_hold( |
639 | task_t task); | |
1c79356b | 640 | |
316670eb | 641 | /* Wait for task to stop running, either just to get off CPU or to cease being runnable */ |
0a7de745 A |
642 | extern kern_return_t task_wait( |
643 | task_t task, | |
644 | boolean_t until_not_runnable); | |
316670eb | 645 | |
91447636 | 646 | /* Release hold on all threads in a task */ |
0a7de745 A |
647 | extern kern_return_t task_release( |
648 | task_t task); | |
1c79356b | 649 | |
3e170ce0 A |
650 | /* Suspend/resume a task where the kernel owns the suspend count */ |
651 | extern kern_return_t task_suspend_internal( task_t task); | |
652 | extern kern_return_t task_resume_internal( task_t task); | |
653 | ||
316670eb A |
654 | /* Suspends a task by placing a hold on its threads */ |
655 | extern kern_return_t task_pidsuspend( | |
0a7de745 | 656 | task_t task); |
316670eb A |
657 | |
658 | /* Resumes a previously paused task */ | |
659 | extern kern_return_t task_pidresume( | |
0a7de745 | 660 | task_t task); |
316670eb | 661 | |
0a7de745 A |
662 | extern kern_return_t task_send_trace_memory( |
663 | task_t task, | |
664 | uint32_t pid, | |
665 | uint64_t uniqueid); | |
fe8ab488 | 666 | |
cb323159 A |
667 | extern void task_remove_turnstile_watchports( |
668 | task_t task); | |
669 | ||
670 | extern void task_transfer_turnstile_watchports( | |
671 | task_t old_task, | |
672 | task_t new_task, | |
673 | thread_t new_thread); | |
674 | ||
39037602 A |
675 | #if DEVELOPMENT || DEBUG |
676 | ||
0a7de745 A |
677 | extern kern_return_t task_disconnect_page_mappings( |
678 | task_t task); | |
39037602 A |
679 | #endif |
680 | ||
0a7de745 | 681 | extern void tasks_system_suspend(boolean_t suspend); |
4bd07ac2 | 682 | |
6d2010ae A |
683 | #if CONFIG_FREEZE |
684 | ||
685 | /* Freeze a task's resident pages */ | |
0a7de745 A |
686 | extern kern_return_t task_freeze( |
687 | task_t task, | |
688 | uint32_t *purgeable_count, | |
689 | uint32_t *wired_count, | |
690 | uint32_t *clean_count, | |
691 | uint32_t *dirty_count, | |
692 | uint32_t dirty_budget, | |
693 | uint32_t *shared_count, | |
694 | int *freezer_error_code, | |
695 | boolean_t eval_only); | |
6d2010ae A |
696 | |
697 | /* Thaw a currently frozen task */ | |
0a7de745 A |
698 | extern kern_return_t task_thaw( |
699 | task_t task); | |
6d2010ae | 700 | |
f427ee49 A |
701 | typedef enum { |
702 | CREDIT_TO_SWAP = 1, | |
703 | DEBIT_FROM_SWAP = 2 | |
704 | } freezer_acct_op_t; | |
705 | ||
706 | extern void task_update_frozen_to_swap_acct( | |
707 | task_t task, | |
708 | int64_t amount, | |
709 | freezer_acct_op_t op); | |
710 | ||
6d2010ae A |
711 | #endif /* CONFIG_FREEZE */ |
712 | ||
91447636 | 713 | /* Halt all other threads in the current task */ |
0a7de745 A |
714 | extern kern_return_t task_start_halt( |
715 | task_t task); | |
b0d623f7 A |
716 | |
717 | /* Wait for other threads to halt and free halting task resources */ | |
0a7de745 A |
718 | extern void task_complete_halt( |
719 | task_t task); | |
720 | ||
721 | extern kern_return_t task_terminate_internal( | |
722 | task_t task); | |
723 | ||
724 | extern kern_return_t task_create_internal( | |
725 | task_t parent_task, | |
726 | coalition_t *parent_coalitions, | |
727 | boolean_t inherit_memory, | |
728 | boolean_t is_64bit, | |
729 | boolean_t is_64bit_data, | |
730 | uint32_t flags, | |
731 | uint32_t procflags, | |
cb323159 | 732 | uint8_t t_returnwaitflags, |
0a7de745 A |
733 | task_t *child_task); /* OUT */ |
734 | ||
4ba76501 A |
735 | extern kern_return_t task_set_special_port_internal( |
736 | task_t task, | |
737 | int which, | |
738 | ipc_port_t port); | |
739 | ||
0a7de745 A |
740 | extern kern_return_t task_info( |
741 | task_t task, | |
742 | task_flavor_t flavor, | |
743 | task_info_t task_info_out, | |
744 | mach_msg_type_number_t *task_info_count); | |
745 | ||
746 | extern void task_power_info_locked( | |
747 | task_t task, | |
748 | task_power_info_t info, | |
749 | gpu_energy_data_t gpu_energy, | |
cb323159 A |
750 | task_power_info_v2_t infov2, |
751 | uint64_t *runnable_time); | |
0a7de745 A |
752 | |
753 | extern uint64_t task_gpu_utilisation( | |
754 | task_t task); | |
755 | ||
756 | extern uint64_t task_energy( | |
757 | task_t task); | |
758 | ||
759 | extern uint64_t task_cpu_ptime( | |
760 | task_t task); | |
761 | extern void task_update_cpu_time_qos_stats( | |
762 | task_t task, | |
763 | uint64_t *eqos_stats, | |
764 | uint64_t *rqos_stats); | |
765 | ||
766 | extern void task_vtimer_set( | |
767 | task_t task, | |
768 | integer_t which); | |
769 | ||
770 | extern void task_vtimer_clear( | |
771 | task_t task, | |
772 | integer_t which); | |
773 | ||
774 | extern void task_vtimer_update( | |
775 | task_t task, | |
776 | integer_t which, | |
777 | uint32_t *microsecs); | |
778 | ||
779 | #define TASK_VTIMER_USER 0x01 | |
780 | #define TASK_VTIMER_PROF 0x02 | |
781 | #define TASK_VTIMER_RLIM 0x04 | |
782 | ||
783 | extern void task_set_64bit( | |
784 | task_t task, | |
785 | boolean_t is_64bit, | |
786 | boolean_t is_64bit_data); | |
787 | ||
788 | extern boolean_t task_get_64bit_data( | |
789 | task_t task); | |
790 | ||
791 | extern void task_set_platform_binary( | |
792 | task_t task, | |
793 | boolean_t is_platform); | |
794 | extern bool task_set_ca_client_wi( | |
795 | task_t task, | |
796 | boolean_t ca_client_wi); | |
797 | ||
798 | extern void task_set_dyld_info( | |
799 | task_t task, | |
800 | mach_vm_address_t addr, | |
801 | mach_vm_size_t size); | |
b0d623f7 | 802 | |
cb323159 A |
803 | extern void task_set_mach_header_address( |
804 | task_t task, | |
805 | mach_vm_address_t addr); | |
806 | ||
91447636 | 807 | /* Get number of activations in a task */ |
0a7de745 A |
808 | extern int get_task_numacts( |
809 | task_t task); | |
91447636 | 810 | |
5ba3f43e A |
811 | struct label; |
812 | extern kern_return_t task_collect_crash_info( | |
0a7de745 | 813 | task_t task, |
5ba3f43e | 814 | #if CONFIG_MACF |
0a7de745 | 815 | struct label *crash_label, |
5ba3f43e | 816 | #endif |
0a7de745 | 817 | int is_corpse_fork); |
39037602 | 818 | void task_port_notify(mach_msg_header_t *msg); |
f427ee49 | 819 | void task_port_with_flavor_notify(mach_msg_header_t *msg); |
39037602 | 820 | void task_wait_till_threads_terminate_locked(task_t task); |
0b4e3aa0 | 821 | |
1c79356b | 822 | /* JMM - should just be temporary (implementation in bsd_kern still) */ |
0a7de745 | 823 | extern void set_bsdtask_info(task_t, void *); |
cb323159 | 824 | extern uint32_t set_task_loadTag(task_t task, uint32_t loadTag); |
91447636 | 825 | extern vm_map_t get_task_map_reference(task_t); |
0a7de745 A |
826 | extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t); |
827 | extern pmap_t get_task_pmap(task_t); | |
828 | extern uint64_t get_task_resident_size(task_t); | |
829 | extern uint64_t get_task_compressed(task_t); | |
830 | extern uint64_t get_task_resident_max(task_t); | |
831 | extern uint64_t get_task_phys_footprint(task_t); | |
d9a64523 | 832 | #if CONFIG_LEDGER_INTERVAL_MAX |
0a7de745 | 833 | extern uint64_t get_task_phys_footprint_interval_max(task_t, int reset); |
d9a64523 | 834 | #endif /* CONFIG_FOOTPRINT_INTERVAL_MAX */ |
0a7de745 A |
835 | extern uint64_t get_task_phys_footprint_lifetime_max(task_t); |
836 | extern uint64_t get_task_phys_footprint_limit(task_t); | |
837 | extern uint64_t get_task_purgeable_size(task_t); | |
838 | extern uint64_t get_task_cpu_time(task_t); | |
3e170ce0 | 839 | extern uint64_t get_task_dispatchqueue_offset(task_t); |
39037602 | 840 | extern uint64_t get_task_dispatchqueue_serialno_offset(task_t); |
cb323159 | 841 | extern uint64_t get_task_dispatchqueue_label_offset(task_t); |
5ba3f43e A |
842 | extern uint64_t get_task_uniqueid(task_t task); |
843 | extern int get_task_version(task_t task); | |
39037602 A |
844 | |
845 | extern uint64_t get_task_internal(task_t); | |
846 | extern uint64_t get_task_internal_compressed(task_t); | |
847 | extern uint64_t get_task_purgeable_nonvolatile(task_t); | |
848 | extern uint64_t get_task_purgeable_nonvolatile_compressed(task_t); | |
849 | extern uint64_t get_task_iokit_mapped(task_t); | |
850 | extern uint64_t get_task_alternate_accounting(task_t); | |
851 | extern uint64_t get_task_alternate_accounting_compressed(task_t); | |
852 | extern uint64_t get_task_memory_region_count(task_t); | |
853 | extern uint64_t get_task_page_table(task_t); | |
f427ee49 A |
854 | #if CONFIG_FREEZE |
855 | extern uint64_t get_task_frozen_to_swap(task_t); | |
856 | #endif | |
d9a64523 A |
857 | extern uint64_t get_task_network_nonvolatile(task_t); |
858 | extern uint64_t get_task_network_nonvolatile_compressed(task_t); | |
859 | extern uint64_t get_task_wired_mem(task_t); | |
cb323159 | 860 | extern uint32_t get_task_loadTag(task_t task); |
39236c6e | 861 | |
f427ee49 A |
862 | extern uint64_t get_task_tagged_footprint(task_t task); |
863 | extern uint64_t get_task_tagged_footprint_compressed(task_t task); | |
864 | extern uint64_t get_task_media_footprint(task_t task); | |
865 | extern uint64_t get_task_media_footprint_compressed(task_t task); | |
866 | extern uint64_t get_task_graphics_footprint(task_t task); | |
867 | extern uint64_t get_task_graphics_footprint_compressed(task_t task); | |
868 | extern uint64_t get_task_neural_footprint(task_t task); | |
869 | extern uint64_t get_task_neural_footprint_compressed(task_t task); | |
870 | ||
3e170ce0 | 871 | extern kern_return_t task_convert_phys_footprint_limit(int, int *); |
813fb2f6 | 872 | extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t, boolean_t); |
39236c6e | 873 | extern kern_return_t task_get_phys_footprint_limit(task_t task, int *limit_mb); |
9bccf70c | 874 | |
813fb2f6 A |
875 | /* Jetsam memlimit attributes */ |
876 | extern boolean_t task_get_memlimit_is_active(task_t task); | |
877 | extern boolean_t task_get_memlimit_is_fatal(task_t task); | |
878 | extern void task_set_memlimit_is_active(task_t task, boolean_t memlimit_is_active); | |
879 | extern void task_set_memlimit_is_fatal(task_t task, boolean_t memlimit_is_fatal); | |
880 | extern boolean_t task_has_triggered_exc_resource(task_t task, boolean_t memlimit_is_active); | |
881 | extern void task_mark_has_triggered_exc_resource(task_t task, boolean_t memlimit_is_active); | |
882 | ||
d9a64523 A |
883 | extern void task_set_thread_limit(task_t task, uint16_t thread_limit); |
884 | ||
f427ee49 A |
885 | #if XNU_TARGET_OS_OSX |
886 | extern boolean_t task_has_system_version_compat_enabled(task_t task); | |
887 | extern void task_set_system_version_compat_enabled(task_t task, boolean_t enable_system_version_compat); | |
888 | #endif | |
d9a64523 | 889 | |
0a7de745 A |
890 | extern boolean_t is_kerneltask(task_t task); |
891 | extern boolean_t is_corpsetask(task_t task); | |
9bccf70c | 892 | |
2d21ac55 A |
893 | extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast); |
894 | ||
b0d623f7 | 895 | extern kern_return_t machine_task_get_state( |
0a7de745 A |
896 | task_t task, |
897 | int flavor, | |
898 | thread_state_t state, | |
899 | mach_msg_type_number_t *state_count); | |
b0d623f7 A |
900 | |
901 | extern kern_return_t machine_task_set_state( | |
0a7de745 A |
902 | task_t task, |
903 | int flavor, | |
904 | thread_state_t state, | |
905 | mach_msg_type_number_t state_count); | |
b0d623f7 | 906 | |
316670eb A |
907 | extern void machine_task_terminate(task_t task); |
908 | ||
909 | struct _task_ledger_indices { | |
910 | int cpu_time; | |
911 | int tkm_private; | |
912 | int tkm_shared; | |
913 | int phys_mem; | |
914 | int wired_mem; | |
fe8ab488 A |
915 | int internal; |
916 | int iokit_mapped; | |
917 | int alternate_accounting; | |
3e170ce0 | 918 | int alternate_accounting_compressed; |
39037602 | 919 | int page_table; |
39236c6e | 920 | int phys_footprint; |
fe8ab488 A |
921 | int internal_compressed; |
922 | int purgeable_volatile; | |
923 | int purgeable_nonvolatile; | |
924 | int purgeable_volatile_compressed; | |
925 | int purgeable_nonvolatile_compressed; | |
cb323159 A |
926 | int tagged_nofootprint; |
927 | int tagged_footprint; | |
928 | int tagged_nofootprint_compressed; | |
929 | int tagged_footprint_compressed; | |
d9a64523 A |
930 | int network_volatile; |
931 | int network_nonvolatile; | |
932 | int network_volatile_compressed; | |
933 | int network_nonvolatile_compressed; | |
cb323159 A |
934 | int media_nofootprint; |
935 | int media_footprint; | |
936 | int media_nofootprint_compressed; | |
937 | int media_footprint_compressed; | |
938 | int graphics_nofootprint; | |
939 | int graphics_footprint; | |
940 | int graphics_nofootprint_compressed; | |
941 | int graphics_footprint_compressed; | |
942 | int neural_nofootprint; | |
943 | int neural_footprint; | |
944 | int neural_nofootprint_compressed; | |
945 | int neural_footprint_compressed; | |
4b17d6b6 A |
946 | int platform_idle_wakeups; |
947 | int interrupt_wakeups; | |
3e170ce0 A |
948 | #if CONFIG_SCHED_SFI |
949 | int sfi_wait_times[MAX_SFI_CLASS_ID]; | |
950 | #endif /* CONFIG_SCHED_SFI */ | |
fe8ab488 A |
951 | int cpu_time_billed_to_me; |
952 | int cpu_time_billed_to_others; | |
39037602 A |
953 | int physical_writes; |
954 | int logical_writes; | |
cb323159 | 955 | int logical_writes_to_external; |
5ba3f43e A |
956 | int energy_billed_to_me; |
957 | int energy_billed_to_others; | |
cb323159 | 958 | #if DEBUG || DEVELOPMENT |
0a7de745 A |
959 | int pages_grabbed; |
960 | int pages_grabbed_kern; | |
961 | int pages_grabbed_iopl; | |
962 | int pages_grabbed_upl; | |
cb323159 | 963 | #endif |
f427ee49 A |
964 | #if CONFIG_FREEZE |
965 | int frozen_to_swap; | |
966 | #endif /* CONFIG_FREEZE */ | |
967 | #if CONFIG_PHYS_WRITE_ACCT | |
968 | int fs_metadata_writes; | |
969 | #endif /* CONFIG_PHYS_WRITE_ACCT */ | |
316670eb A |
970 | }; |
971 | extern struct _task_ledger_indices task_ledgers; | |
b0d623f7 | 972 | |
39037602 A |
973 | /* requires task to be unlocked, returns a referenced thread */ |
974 | thread_t task_findtid(task_t task, uint64_t tid); | |
813fb2f6 | 975 | int pid_from_task(task_t task); |
39236c6e A |
976 | |
977 | extern kern_return_t task_wakeups_monitor_ctl(task_t task, uint32_t *rate_hz, int32_t *flags); | |
978 | extern kern_return_t task_cpu_usage_monitor_ctl(task_t task, uint32_t *flags); | |
743345f9 | 979 | extern void task_rollup_accounting_info(task_t new_task, task_t parent_task); |
39037602 | 980 | extern kern_return_t task_io_monitor_ctl(task_t task, uint32_t *flags); |
743345f9 A |
981 | extern void task_set_did_exec_flag(task_t task); |
982 | extern void task_clear_exec_copy_flag(task_t task); | |
983 | extern boolean_t task_is_exec_copy(task_t); | |
984 | extern boolean_t task_did_exec(task_t task); | |
527f9951 A |
985 | #ifdef CONFIG_32BIT_TELEMETRY |
986 | extern boolean_t task_consume_32bit_log_flag(task_t task); | |
987 | extern void task_set_32bit_log_flag(task_t task); | |
988 | #endif /* CONFIG_32BIT_TELEMETRY */ | |
743345f9 | 989 | extern boolean_t task_is_active(task_t task); |
5ba3f43e | 990 | extern boolean_t task_is_halting(task_t task); |
cb323159 | 991 | extern void task_clear_return_wait(task_t task, uint32_t flags); |
a39ff7e2 | 992 | extern void task_wait_to_return(void) __attribute__((noreturn)); |
743345f9 | 993 | extern event_t task_get_return_wait_event(task_t task); |
39236c6e | 994 | |
490019cf A |
995 | extern void task_bank_reset(task_t task); |
996 | extern void task_bank_init(task_t task); | |
39236c6e | 997 | |
cb323159 A |
998 | #if CONFIG_ARCADE |
999 | extern void task_prep_arcade(task_t task, thread_t thread); | |
1000 | #endif /* CONFIG_ARCADE */ | |
1001 | ||
3e170ce0 | 1002 | extern int task_pid(task_t task); |
f427ee49 A |
1003 | |
1004 | #if __has_feature(ptrauth_calls) | |
1005 | char *task_get_vm_shared_region_id_and_jop_pid(task_t task, uint64_t *); | |
1006 | void task_set_shared_region_id(task_t task, char *id); | |
1007 | #endif /* __has_feature(ptrauth_calls) */ | |
1008 | ||
39037602 | 1009 | extern boolean_t task_has_assertions(task_t task); |
39236c6e | 1010 | /* End task_policy */ |
316670eb | 1011 | |
fe8ab488 A |
1012 | extern void task_set_gpu_denied(task_t task, boolean_t denied); |
1013 | extern boolean_t task_is_gpu_denied(task_t task); | |
1014 | ||
7e41aa88 | 1015 | extern queue_head_t * task_io_user_clients(task_t task); |
cb323159 | 1016 | extern void task_set_message_app_suspended(task_t task, boolean_t enable); |
7e41aa88 | 1017 | |
5ba3f43e A |
1018 | extern void task_copy_fields_for_exec(task_t dst_task, task_t src_task); |
1019 | ||
f427ee49 A |
1020 | extern void task_copy_vmobjects(task_t task, vm_object_query_t query, size_t len, size_t *num); |
1021 | ||
1022 | extern void task_set_filter_msg_flag(task_t task, boolean_t flag); | |
1023 | extern boolean_t task_get_filter_msg_flag(task_t task); | |
1024 | ||
1025 | extern void task_transfer_mach_filter_bits(task_t new_task, task_t old_mask); | |
cb323159 | 1026 | |
eb6b6ca3 A |
1027 | #if __has_feature(ptrauth_calls) |
1028 | extern bool task_is_pac_exception_fatal(task_t task); | |
1029 | extern void task_set_pac_exception_fatal_flag(task_t task); | |
1030 | #endif /*__has_feature(ptrauth_calls)*/ | |
1031 | ||
f427ee49 A |
1032 | extern void task_set_tecs(task_t task); |
1033 | ||
0a7de745 | 1034 | #endif /* XNU_KERNEL_PRIVATE */ |
9bccf70c | 1035 | |
0a7de745 | 1036 | #ifdef KERNEL_PRIVATE |
9bccf70c | 1037 | |
0a7de745 A |
1038 | extern void *get_bsdtask_info(task_t); |
1039 | extern void *get_bsdthreadtask_info(thread_t); | |
3e170ce0 | 1040 | extern void task_bsdtask_kill(task_t); |
91447636 | 1041 | extern vm_map_t get_task_map(task_t); |
0a7de745 | 1042 | extern ledger_t get_task_ledger(task_t); |
316670eb A |
1043 | |
1044 | extern boolean_t get_task_pidsuspended(task_t); | |
cb323159 | 1045 | extern boolean_t get_task_suspended(task_t); |
316670eb A |
1046 | extern boolean_t get_task_frozen(task_t); |
1047 | ||
1048 | /* Convert from a task to a port */ | |
1049 | extern ipc_port_t convert_task_to_port(task_t); | |
316670eb | 1050 | extern ipc_port_t convert_task_name_to_port(task_name_t); |
813fb2f6 | 1051 | extern ipc_port_t convert_task_inspect_to_port(task_inspect_t); |
f427ee49 | 1052 | extern ipc_port_t convert_task_read_to_port(task_read_t); |
39236c6e A |
1053 | extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task); |
1054 | ||
1055 | /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */ | |
1056 | extern task_suspension_token_t convert_port_to_task_suspension_token(ipc_port_t port); | |
1057 | ||
1058 | extern boolean_t task_suspension_notify(mach_msg_header_t *); | |
9bccf70c | 1059 | |
cb323159 A |
1060 | #define TASK_WRITE_IMMEDIATE 0x1 |
1061 | #define TASK_WRITE_DEFERRED 0x2 | |
1062 | #define TASK_WRITE_INVALIDATED 0x4 | |
1063 | #define TASK_WRITE_METADATA 0x8 | |
0a7de745 | 1064 | extern void task_update_logical_writes(task_t task, uint32_t io_size, int flags, void *vp); |
39037602 | 1065 | |
f427ee49 A |
1066 | __enum_decl(task_balance_flags_t, uint8_t, { |
1067 | TASK_BALANCE_CREDIT = 0x1, | |
1068 | TASK_BALANCE_DEBIT = 0x2, | |
1069 | }); | |
1070 | ||
1071 | __enum_decl(task_physical_write_flavor_t, uint8_t, { | |
1072 | TASK_PHYSICAL_WRITE_METADATA = 0x1, | |
1073 | }); | |
1074 | extern void task_update_physical_writes(task_t task, task_physical_write_flavor_t flavor, | |
1075 | uint64_t io_size, task_balance_flags_t flags); | |
1076 | ||
39037602 A |
1077 | #if CONFIG_SECLUDED_MEMORY |
1078 | extern void task_set_can_use_secluded_mem( | |
1079 | task_t task, | |
1080 | boolean_t can_use_secluded_mem); | |
1081 | extern void task_set_could_use_secluded_mem( | |
1082 | task_t task, | |
1083 | boolean_t could_use_secluded_mem); | |
1084 | extern void task_set_could_also_use_secluded_mem( | |
1085 | task_t task, | |
1086 | boolean_t could_also_use_secluded_mem); | |
d9a64523 A |
1087 | extern boolean_t task_can_use_secluded_mem( |
1088 | task_t task, | |
1089 | boolean_t is_allocate); | |
39037602 | 1090 | extern boolean_t task_could_use_secluded_mem(task_t task); |
cb323159 | 1091 | extern boolean_t task_could_also_use_secluded_mem(task_t task); |
39037602 A |
1092 | #endif /* CONFIG_SECLUDED_MEMORY */ |
1093 | ||
d9a64523 A |
1094 | extern void task_set_darkwake_mode(task_t, boolean_t); |
1095 | extern boolean_t task_get_darkwake_mode(task_t); | |
1096 | ||
1097 | #if __arm64__ | |
cb323159 A |
1098 | extern void task_set_legacy_footprint(task_t task); |
1099 | extern void task_set_extra_footprint_limit(task_t task); | |
94ff46dc | 1100 | extern void task_set_ios13extended_footprint_limit(task_t task); |
d9a64523 A |
1101 | #endif /* __arm64__ */ |
1102 | ||
39037602 A |
1103 | #if CONFIG_MACF |
1104 | extern struct label *get_task_crash_label(task_t task); | |
39037602 A |
1105 | #endif /* CONFIG_MACF */ |
1106 | ||
cb323159 A |
1107 | extern int get_task_cdhash(task_t task, char cdhash[]); |
1108 | ||
0a7de745 | 1109 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 1110 | |
0a7de745 | 1111 | extern task_t kernel_task; |
91447636 | 1112 | |
0a7de745 A |
1113 | extern void task_deallocate( |
1114 | task_t task); | |
9bccf70c | 1115 | |
0a7de745 A |
1116 | extern void task_name_deallocate( |
1117 | task_name_t task_name); | |
39236c6e | 1118 | |
f427ee49 A |
1119 | extern void task_policy_set_deallocate( |
1120 | task_policy_set_t task_policy_set); | |
1121 | ||
1122 | extern void task_policy_get_deallocate( | |
1123 | task_policy_get_t task_policy_get); | |
1124 | ||
0a7de745 A |
1125 | extern void task_inspect_deallocate( |
1126 | task_inspect_t task_inspect); | |
813fb2f6 | 1127 | |
f427ee49 A |
1128 | extern void task_read_deallocate( |
1129 | task_read_t task_read); | |
1130 | ||
0a7de745 A |
1131 | extern void task_suspension_token_deallocate( |
1132 | task_suspension_token_t token); | |
a39ff7e2 A |
1133 | |
1134 | extern boolean_t task_self_region_footprint(void); | |
1135 | extern void task_self_region_footprint_set(boolean_t newval); | |
cb323159 A |
1136 | extern void task_ledgers_footprint(ledger_t ledger, |
1137 | ledger_amount_t *ledger_resident, | |
1138 | ledger_amount_t *ledger_compressed); | |
1139 | extern void task_set_memory_ownership_transfer( | |
1140 | task_t task, | |
1141 | boolean_t value); | |
a39ff7e2 | 1142 | |
f427ee49 | 1143 | |
91447636 | 1144 | __END_DECLS |
9bccf70c | 1145 | |
0a7de745 | 1146 | #endif /* _KERN_TASK_H_ */ |