]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
3e170ce0 | 2 | * Copyright (c) 2000-2010, 2015 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 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. | |
8f6c56a5 | 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. | |
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 | |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_FREE_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
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. | |
41 | * | |
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. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
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 A |
90 | |
91 | #ifndef _KERN_TASK_H_ | |
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> | |
102 | #endif /* XNU_KERNEL_PRIVATE */ | |
103 | ||
9bccf70c A |
104 | #ifdef MACH_KERNEL_PRIVATE |
105 | ||
1c79356b A |
106 | #include <mach/boolean.h> |
107 | #include <mach/port.h> | |
108 | #include <mach/time_value.h> | |
109 | #include <mach/message.h> | |
110 | #include <mach/mach_param.h> | |
111 | #include <mach/task_info.h> | |
112 | #include <mach/exception_types.h> | |
6d2010ae | 113 | #include <mach/vm_statistics.h> |
0c530ab8 | 114 | #include <machine/task.h> |
91447636 | 115 | |
5ba3f43e A |
116 | #if MONOTONIC |
117 | #include <machine/monotonic.h> | |
118 | #endif /* MONOTONIC */ | |
119 | ||
91447636 | 120 | #include <kern/cpu_data.h> |
1c79356b A |
121 | #include <kern/queue.h> |
122 | #include <kern/exception.h> | |
fe8ab488 | 123 | #include <kern/locks.h> |
2d21ac55 | 124 | #include <security/_label.h> |
fe8ab488 | 125 | #include <ipc/ipc_port.h> |
316670eb | 126 | |
6d2010ae | 127 | #include <kern/thread.h> |
3e170ce0 | 128 | #include <mach/coalition.h> |
5ba3f43e | 129 | #include <stdatomic.h> |
6d2010ae | 130 | |
fe8ab488 A |
131 | #ifdef CONFIG_ATM |
132 | #include <atm/atm_internal.h> | |
133 | #endif | |
134 | ||
135 | struct _cpu_time_qos_stats { | |
136 | uint64_t cpu_time_qos_default; | |
137 | uint64_t cpu_time_qos_maintenance; | |
138 | uint64_t cpu_time_qos_background; | |
139 | uint64_t cpu_time_qos_utility; | |
140 | uint64_t cpu_time_qos_legacy; | |
141 | uint64_t cpu_time_qos_user_initiated; | |
142 | uint64_t cpu_time_qos_user_interactive; | |
143 | }; | |
144 | ||
fe8ab488 | 145 | #include <bank/bank_internal.h> |
fe8ab488 | 146 | |
91447636 | 147 | struct task { |
1c79356b | 148 | /* Synchronization/destruction information */ |
b0d623f7 | 149 | decl_lck_mtx_data(,lock) /* Task's lock */ |
5ba3f43e | 150 | _Atomic uint32_t ref_count; /* Number of references to me */ |
1c79356b | 151 | boolean_t active; /* Task has not been terminated */ |
b0d623f7 | 152 | boolean_t halting; /* Task is being halted */ |
1c79356b A |
153 | |
154 | /* Miscellaneous */ | |
155 | vm_map_t map; /* Address space description */ | |
2d21ac55 | 156 | queue_chain_t tasks; /* global list of tasks */ |
1c79356b | 157 | void *user_data; /* Arbitrary data settable via IPC */ |
1c79356b | 158 | |
fe8ab488 A |
159 | #if defined(CONFIG_SCHED_MULTIQ) |
160 | sched_group_t sched_group; | |
161 | #endif /* defined(CONFIG_SCHED_MULTIQ) */ | |
162 | ||
55e303ae | 163 | /* Threads in this task */ |
2d21ac55 | 164 | queue_head_t threads; |
b0d623f7 A |
165 | |
166 | processor_set_t pset_hint; | |
167 | struct affinity_space *affinity_space; | |
168 | ||
2d21ac55 A |
169 | int thread_count; |
170 | uint32_t active_thread_count; | |
b0d623f7 | 171 | int suspend_count; /* Internal scheduling only */ |
1c79356b A |
172 | |
173 | /* User-visible scheduling information */ | |
174 | integer_t user_stop_count; /* outstanding stops */ | |
39236c6e | 175 | integer_t legacy_stop_count; /* outstanding legacy stops */ |
1c79356b | 176 | |
0b4e3aa0 A |
177 | integer_t priority; /* base priority for threads */ |
178 | integer_t max_priority; /* maximum priority for threads */ | |
1c79356b | 179 | |
39236c6e A |
180 | integer_t importance; /* priority offset (BSD 'nice' value) */ |
181 | ||
55e303ae | 182 | /* Task security and audit tokens */ |
1c79356b | 183 | security_token_t sec_token; |
55e303ae | 184 | audit_token_t audit_token; |
1c79356b A |
185 | |
186 | /* Statistics */ | |
91447636 A |
187 | uint64_t total_user_time; /* terminated threads only */ |
188 | uint64_t total_system_time; | |
5ba3f43e | 189 | uint64_t total_ptime; |
fe8ab488 | 190 | |
2d21ac55 A |
191 | /* Virtual timers */ |
192 | uint32_t vtimers; | |
1c79356b A |
193 | |
194 | /* IPC structures */ | |
b0d623f7 | 195 | decl_lck_mtx_data(,itk_lock_data) |
1c79356b | 196 | struct ipc_port *itk_self; /* not a right, doesn't hold ref */ |
0c530ab8 | 197 | struct ipc_port *itk_nself; /* not a right, doesn't hold ref */ |
1c79356b A |
198 | struct ipc_port *itk_sself; /* a send right */ |
199 | struct exception_action exc_actions[EXC_TYPES_COUNT]; | |
200 | /* a send right each valid element */ | |
201 | struct ipc_port *itk_host; /* a send right */ | |
202 | struct ipc_port *itk_bootstrap; /* a send right */ | |
2d21ac55 A |
203 | struct ipc_port *itk_seatbelt; /* a send right */ |
204 | struct ipc_port *itk_gssd; /* yet another send right */ | |
fe8ab488 | 205 | struct ipc_port *itk_debug_control; /* send right for debugmode communications */ |
2d21ac55 | 206 | struct ipc_port *itk_task_access; /* and another send right */ |
39236c6e | 207 | struct ipc_port *itk_resume; /* a receive right to resume this task */ |
1c79356b A |
208 | struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX]; |
209 | /* all send rights */ | |
210 | ||
211 | struct ipc_space *itk_space; | |
212 | ||
1c79356b A |
213 | /* Synchronizer ownership information */ |
214 | queue_head_t semaphore_list; /* list of owned semaphores */ | |
1c79356b | 215 | int semaphores_owned; /* number of semaphores owned */ |
1c79356b | 216 | |
316670eb A |
217 | ledger_t ledger; |
218 | ||
91447636 A |
219 | unsigned int priv_flags; /* privilege resource flags */ |
220 | #define VM_BACKING_STORE_PRIV 0x1 | |
0c530ab8 A |
221 | |
222 | MACHINE_TASK | |
1c79356b | 223 | |
1c79356b A |
224 | integer_t faults; /* faults counter */ |
225 | integer_t pageins; /* pageins counter */ | |
226 | integer_t cow_faults; /* copy on write fault counter */ | |
227 | integer_t messages_sent; /* messages sent counter */ | |
228 | integer_t messages_received; /* messages received counter */ | |
229 | integer_t syscalls_mach; /* mach system call counter */ | |
230 | integer_t syscalls_unix; /* unix system call counter */ | |
316670eb A |
231 | uint32_t c_switch; /* total context switches */ |
232 | uint32_t p_switch; /* total processor switches */ | |
233 | uint32_t ps_switch; /* total pset switches */ | |
6d2010ae | 234 | |
1c79356b A |
235 | #ifdef MACH_BSD |
236 | void *bsd_info; | |
237 | #endif | |
3e170ce0 | 238 | kcdata_descriptor_t corpse_info; |
5ba3f43e | 239 | uint64_t crashed_thread_id; |
39037602 A |
240 | queue_chain_t corpse_tasks; |
241 | #ifdef CONFIG_MACF | |
242 | struct label * crash_label; | |
243 | #endif | |
2d21ac55 | 244 | struct vm_shared_region *shared_region; |
fe8ab488 | 245 | volatile uint32_t t_flags; /* general-purpose task flags protected by task_lock (TL) */ |
39037602 | 246 | #define TF_NONE 0 |
fe8ab488 A |
247 | #define TF_64B_ADDR 0x00000001 /* task has 64-bit addressing */ |
248 | #define TF_64B_DATA 0x00000002 /* task has 64-bit data registers */ | |
249 | #define TF_CPUMON_WARNING 0x00000004 /* task has at least one thread in CPU usage warning zone */ | |
250 | #define TF_WAKEMON_WARNING 0x00000008 /* task is in wakeups monitor warning zone */ | |
251 | #define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */ | |
252 | #define TF_GPU_DENIED 0x00000010 /* task is not allowed to access the GPU */ | |
3e170ce0 A |
253 | #define TF_CORPSE 0x00000020 /* task is a corpse */ |
254 | #define TF_PENDING_CORPSE 0x00000040 /* task corpse has not been reported yet */ | |
39037602 | 255 | #define TF_CORPSE_FORK 0x00000080 /* task is a forked corpse */ |
743345f9 A |
256 | #define TF_LRETURNWAIT 0x00000100 /* task is waiting for fork/posix_spawn/exec to complete */ |
257 | #define TF_LRETURNWAITER 0x00000200 /* task is waiting for TF_LRETURNWAIT to get cleared */ | |
5ba3f43e | 258 | #define TF_PLATFORM 0x00000400 /* task is a platform binary */ |
fe8ab488 | 259 | |
91447636 | 260 | #define task_has_64BitAddr(task) \ |
39236c6e | 261 | (((task)->t_flags & TF_64B_ADDR) != 0) |
91447636 | 262 | #define task_set_64BitAddr(task) \ |
39236c6e | 263 | ((task)->t_flags |= TF_64B_ADDR) |
91447636 | 264 | #define task_clear_64BitAddr(task) \ |
39236c6e A |
265 | ((task)->t_flags &= ~TF_64B_ADDR) |
266 | #define task_has_64BitData(task) \ | |
267 | (((task)->t_flags & TF_64B_DATA) != 0) | |
91447636 | 268 | |
3e170ce0 A |
269 | #define task_is_a_corpse(task) \ |
270 | (((task)->t_flags & TF_CORPSE) != 0) | |
271 | ||
272 | #define task_set_corpse(task) \ | |
273 | ((task)->t_flags |= TF_CORPSE) | |
274 | ||
275 | #define task_corpse_pending_report(task) \ | |
276 | (((task)->t_flags & TF_PENDING_CORPSE) != 0) | |
277 | ||
278 | #define task_set_corpse_pending_report(task) \ | |
279 | ((task)->t_flags |= TF_PENDING_CORPSE) | |
280 | ||
281 | #define task_clear_corpse_pending_report(task) \ | |
282 | ((task)->t_flags &= ~TF_PENDING_CORPSE) | |
283 | ||
39037602 A |
284 | #define task_is_a_corpse_fork(task) \ |
285 | (((task)->t_flags & TF_CORPSE_FORK) != 0) | |
286 | ||
743345f9 A |
287 | uint32_t t_procflags; /* general-purpose task flags protected by proc_lock (PL) */ |
288 | #define TPF_NONE 0 | |
289 | #define TPF_DID_EXEC 0x00000001 /* task has been execed to a new task */ | |
290 | #define TPF_EXEC_COPY 0x00000002 /* task is the new copy of an exec */ | |
527f9951 A |
291 | #ifdef CONFIG_32BIT_TELEMETRY |
292 | #define TPF_LOG_32BIT_TELEMETRY 0x00000004 /* task should log identifying information */ | |
293 | #endif | |
743345f9 A |
294 | |
295 | #define task_did_exec_internal(task) \ | |
296 | (((task)->t_procflags & TPF_DID_EXEC) != 0) | |
297 | ||
298 | #define task_is_exec_copy_internal(task) \ | |
299 | (((task)->t_procflags & TPF_EXEC_COPY) != 0) | |
300 | ||
b0d623f7 A |
301 | mach_vm_address_t all_image_info_addr; /* dyld __all_image_info */ |
302 | mach_vm_size_t all_image_info_size; /* section location and size */ | |
2d21ac55 | 303 | |
3e170ce0 | 304 | #if KPERF |
fe8ab488 A |
305 | #define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */ |
306 | #define TASK_KPC_FORCED_ALL_CTRS 0x2 /* Bit in "t_chud" signifying KPC forced all counters */ | |
307 | ||
b0d623f7 A |
308 | uint32_t t_chud; /* CHUD flags, used for Shark */ |
309 | #endif | |
310 | ||
316670eb A |
311 | boolean_t pidsuspended; /* pid_suspend called; no threads can execute */ |
312 | boolean_t frozen; /* frozen; private resident pages committed to swap */ | |
39236c6e A |
313 | boolean_t changing_freeze_state; /* in the process of freezing or thawing */ |
314 | uint16_t policy_ru_cpu :4, | |
315 | policy_ru_cpu_ext :4, | |
316 | applied_ru_cpu :4, | |
317 | applied_ru_cpu_ext :4; | |
316670eb A |
318 | uint8_t rusage_cpu_flags; |
319 | uint8_t rusage_cpu_percentage; /* Task-wide CPU limit percentage */ | |
320 | uint64_t rusage_cpu_interval; /* Task-wide CPU limit interval */ | |
321 | uint8_t rusage_cpu_perthr_percentage; /* Per-thread CPU limit percentage */ | |
322 | uint64_t rusage_cpu_perthr_interval; /* Per-thread CPU limit interval */ | |
323 | uint64_t rusage_cpu_deadline; | |
324 | thread_call_t rusage_cpu_callt; | |
5ba3f43e A |
325 | #if CONFIG_EMBEDDED |
326 | queue_head_t task_watchers; /* app state watcher threads */ | |
327 | int num_taskwatchers; | |
328 | int watchapplying; | |
329 | #endif /* CONFIG_EMBEDDED */ | |
39236c6e | 330 | |
fe8ab488 A |
331 | #if CONFIG_ATM |
332 | struct atm_task_descriptor *atm_context; /* pointer to per task atm descriptor */ | |
333 | #endif | |
fe8ab488 | 334 | struct bank_task *bank_context; /* pointer to per task bank structure */ |
39236c6e | 335 | |
fe8ab488 A |
336 | #if IMPORTANCE_INHERITANCE |
337 | struct ipc_importance_task *task_imp_base; /* Base of IPC importance chain */ | |
39236c6e | 338 | #endif /* IMPORTANCE_INHERITANCE */ |
6d2010ae A |
339 | |
340 | vm_extmod_statistics_data_t extmod_statistics; | |
39236c6e A |
341 | |
342 | #if MACH_ASSERT | |
343 | int8_t suspends_outstanding; /* suspends this task performed in excess of resumes */ | |
344 | #endif | |
345 | ||
346 | struct task_requested_policy requested_policy; | |
347 | struct task_effective_policy effective_policy; | |
39236c6e A |
348 | |
349 | /* | |
350 | * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away. | |
351 | */ | |
3e170ce0 A |
352 | uint32_t low_mem_notified_warn :1, /* warning low memory notification is sent to the task */ |
353 | low_mem_notified_critical :1, /* critical low memory notification is sent to the task */ | |
354 | purged_memory_warn :1, /* purgeable memory of the task is purged for warning level pressure */ | |
355 | purged_memory_critical :1, /* purgeable memory of the task is purged for critical level pressure */ | |
356 | low_mem_privileged_listener :1, /* if set, task would like to know about pressure changes before other tasks on the system */ | |
357 | mem_notify_reserved :27; /* reserved for future use */ | |
4b17d6b6 | 358 | |
813fb2f6 A |
359 | uint32_t memlimit_is_active :1, /* if set, use active attributes, otherwise use inactive attributes */ |
360 | memlimit_is_fatal :1, /* if set, exceeding current memlimit will prove fatal to the task */ | |
361 | memlimit_active_exc_resource :1, /* if set, suppress exc_resource exception when task exceeds active memory limit */ | |
362 | memlimit_inactive_exc_resource :1, /* if set, suppress exc_resource exception when task exceeds inactive memory limit */ | |
363 | memlimit_attrs_reserved :28; /* reserved for future use */ | |
364 | ||
4bd07ac2 A |
365 | io_stat_info_t task_io_stats; |
366 | uint64_t task_immediate_writes __attribute__((aligned(8))); | |
367 | uint64_t task_deferred_writes __attribute__((aligned(8))); | |
368 | uint64_t task_invalidated_writes __attribute__((aligned(8))); | |
369 | uint64_t task_metadata_writes __attribute__((aligned(8))); | |
370 | ||
fe8ab488 A |
371 | /* |
372 | * The cpu_time_qos_stats fields are protected by the task lock | |
373 | */ | |
374 | struct _cpu_time_qos_stats cpu_time_qos_stats; | |
375 | ||
4b17d6b6 A |
376 | /* Statistics accumulated for terminated threads from this task */ |
377 | uint32_t task_timer_wakeups_bin_1; | |
378 | uint32_t task_timer_wakeups_bin_2; | |
fe8ab488 | 379 | uint64_t task_gpu_ns; |
39037602 | 380 | uint64_t task_energy; |
fe8ab488 | 381 | |
5ba3f43e A |
382 | #if MONOTONIC |
383 | /* Read and written under task_lock */ | |
384 | struct mt_task task_monotonic; | |
385 | #endif /* MONOTONIC */ | |
386 | ||
fe8ab488 A |
387 | /* # of purgeable volatile VM objects owned by this task: */ |
388 | int task_volatile_objects; | |
389 | /* # of purgeable but not volatile VM objects owned by this task: */ | |
390 | int task_nonvolatile_objects; | |
391 | boolean_t task_purgeable_disowning; | |
392 | boolean_t task_purgeable_disowned; | |
393 | ||
3e170ce0 A |
394 | /* |
395 | * A task's coalition set is "adopted" in task_create_internal | |
396 | * and unset in task_deallocate_internal, so each array member | |
397 | * can be referenced without the task lock. | |
398 | * Note: these fields are protected by coalition->lock, | |
399 | * not the task lock. | |
400 | */ | |
401 | coalition_t coalition[COALITION_NUM_TYPES]; | |
402 | queue_chain_t task_coalition[COALITION_NUM_TYPES]; | |
403 | uint64_t dispatchqueue_offset; | |
fe8ab488 | 404 | |
39037602 A |
405 | #if DEVELOPMENT || DEBUG |
406 | boolean_t task_unnested; | |
407 | int task_disconnected_count; | |
408 | #endif | |
409 | ||
fe8ab488 A |
410 | #if HYPERVISOR |
411 | void *hv_task_target; /* hypervisor virtual machine object associated with this task */ | |
412 | #endif /* HYPERVISOR */ | |
7e41aa88 | 413 | |
39037602 A |
414 | #if CONFIG_SECLUDED_MEMORY |
415 | boolean_t task_can_use_secluded_mem; | |
416 | boolean_t task_could_use_secluded_mem; | |
417 | boolean_t task_could_also_use_secluded_mem; | |
418 | #endif /* CONFIG_SECLUDED_MEMORY */ | |
419 | ||
7e41aa88 | 420 | queue_head_t io_user_clients; |
39037602 | 421 | uint32_t exec_token; |
91447636 | 422 | }; |
1c79356b | 423 | |
39236c6e | 424 | #define task_lock(task) lck_mtx_lock(&(task)->lock) |
5ba3f43e | 425 | #define task_lock_assert_owned(task) LCK_MTX_ASSERT(&(task)->lock, LCK_MTX_ASSERT_OWNED) |
39236c6e A |
426 | #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock) |
427 | #define task_unlock(task) lck_mtx_unlock(&(task)->lock) | |
1c79356b | 428 | |
b0d623f7 A |
429 | #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr) |
430 | #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp) | |
431 | #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data) | |
432 | #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data) | |
1c79356b | 433 | |
39236c6e A |
434 | #define TASK_REFERENCE_LEAK_DEBUG 0 |
435 | ||
436 | #if TASK_REFERENCE_LEAK_DEBUG | |
437 | extern void task_reference_internal(task_t task); | |
438 | extern uint32_t task_deallocate_internal(task_t task); | |
439 | #else | |
91447636 | 440 | #define task_reference_internal(task) \ |
5ba3f43e | 441 | (void)atomic_fetch_add_explicit(&(task)->ref_count, 1, memory_order_relaxed) |
9bccf70c | 442 | |
91447636 | 443 | #define task_deallocate_internal(task) \ |
5ba3f43e | 444 | (atomic_fetch_sub_explicit(&task->ref_count, 1, memory_order_release) - 1) |
39236c6e | 445 | #endif |
55e303ae | 446 | |
91447636 A |
447 | #define task_reference(task) \ |
448 | MACRO_BEGIN \ | |
449 | if ((task) != TASK_NULL) \ | |
450 | task_reference_internal(task); \ | |
451 | MACRO_END | |
1c79356b | 452 | |
91447636 A |
453 | extern kern_return_t kernel_task_create( |
454 | task_t task, | |
455 | vm_offset_t map_base, | |
456 | vm_size_t map_size, | |
457 | task_t *child); | |
55e303ae | 458 | |
1c79356b | 459 | /* Initialize task module */ |
39236c6e | 460 | extern void task_init(void); |
1c79356b | 461 | |
fe8ab488 A |
462 | /* coalition_init() calls this to initialize ledgers before task_init() */ |
463 | extern void init_task_ledgers(void); | |
464 | ||
91447636 A |
465 | #define current_task_fast() (current_thread()->task) |
466 | #define current_task() current_task_fast() | |
1c79356b | 467 | |
b0d623f7 A |
468 | extern lck_attr_t task_lck_attr; |
469 | extern lck_grp_t task_lck_grp; | |
470 | ||
a1c7dba1 | 471 | |
91447636 | 472 | #else /* MACH_KERNEL_PRIVATE */ |
1c79356b | 473 | |
91447636 A |
474 | __BEGIN_DECLS |
475 | ||
476 | extern task_t current_task(void); | |
477 | ||
478 | extern void task_reference(task_t task); | |
479 | ||
39037602 | 480 | #define TF_NONE 0 |
743345f9 A |
481 | #define TF_LRETURNWAIT 0x00000100 /* task is waiting for fork/posix_spawn/exec to complete */ |
482 | #define TF_LRETURNWAITER 0x00000200 /* task is waiting for TF_LRETURNWAIT to get cleared */ | |
483 | ||
484 | #define TPF_NONE 0 | |
485 | #define TPF_EXEC_COPY 0x00000002 /* task is the new copy of an exec */ | |
486 | ||
39037602 | 487 | |
91447636 | 488 | __END_DECLS |
1c79356b | 489 | |
9bccf70c | 490 | #endif /* MACH_KERNEL_PRIVATE */ |
1c79356b | 491 | |
91447636 | 492 | __BEGIN_DECLS |
1c79356b | 493 | |
91447636 A |
494 | #ifdef XNU_KERNEL_PRIVATE |
495 | ||
496 | /* Hold all threads in a task */ | |
1c79356b | 497 | extern kern_return_t task_hold( |
91447636 | 498 | task_t task); |
1c79356b | 499 | |
316670eb A |
500 | /* Wait for task to stop running, either just to get off CPU or to cease being runnable */ |
501 | extern kern_return_t task_wait( | |
502 | task_t task, | |
503 | boolean_t until_not_runnable); | |
504 | ||
91447636 | 505 | /* Release hold on all threads in a task */ |
1c79356b | 506 | extern kern_return_t task_release( |
91447636 | 507 | task_t task); |
1c79356b | 508 | |
3e170ce0 A |
509 | /* Suspend/resume a task where the kernel owns the suspend count */ |
510 | extern kern_return_t task_suspend_internal( task_t task); | |
511 | extern kern_return_t task_resume_internal( task_t task); | |
512 | ||
316670eb A |
513 | /* Suspends a task by placing a hold on its threads */ |
514 | extern kern_return_t task_pidsuspend( | |
515 | task_t task); | |
516 | extern kern_return_t task_pidsuspend_locked( | |
517 | task_t task); | |
518 | ||
519 | /* Resumes a previously paused task */ | |
520 | extern kern_return_t task_pidresume( | |
521 | task_t task); | |
522 | ||
fe8ab488 A |
523 | extern kern_return_t task_send_trace_memory( |
524 | task_t task, | |
525 | uint32_t pid, | |
526 | uint64_t uniqueid); | |
527 | ||
39037602 A |
528 | #if DEVELOPMENT || DEBUG |
529 | ||
530 | extern kern_return_t task_disconnect_page_mappings( | |
531 | task_t task); | |
532 | #endif | |
533 | ||
4bd07ac2 A |
534 | extern void tasks_system_suspend(boolean_t suspend); |
535 | ||
6d2010ae A |
536 | #if CONFIG_FREEZE |
537 | ||
538 | /* Freeze a task's resident pages */ | |
539 | extern kern_return_t task_freeze( | |
540 | task_t task, | |
541 | uint32_t *purgeable_count, | |
542 | uint32_t *wired_count, | |
543 | uint32_t *clean_count, | |
544 | uint32_t *dirty_count, | |
316670eb | 545 | uint32_t dirty_budget, |
6d2010ae A |
546 | boolean_t *shared, |
547 | boolean_t walk_only); | |
548 | ||
549 | /* Thaw a currently frozen task */ | |
550 | extern kern_return_t task_thaw( | |
551 | task_t task); | |
552 | ||
553 | #endif /* CONFIG_FREEZE */ | |
554 | ||
91447636 | 555 | /* Halt all other threads in the current task */ |
b0d623f7 A |
556 | extern kern_return_t task_start_halt( |
557 | task_t task); | |
558 | ||
559 | /* Wait for other threads to halt and free halting task resources */ | |
560 | extern void task_complete_halt( | |
91447636 A |
561 | task_t task); |
562 | ||
563 | extern kern_return_t task_terminate_internal( | |
564 | task_t task); | |
565 | ||
566 | extern kern_return_t task_create_internal( | |
567 | task_t parent_task, | |
3e170ce0 | 568 | coalition_t *parent_coalitions, |
91447636 | 569 | boolean_t inherit_memory, |
0c530ab8 | 570 | boolean_t is_64bit, |
39037602 | 571 | uint32_t flags, |
743345f9 | 572 | uint32_t procflags, |
91447636 | 573 | task_t *child_task); /* OUT */ |
1c79356b | 574 | |
5ba3f43e A |
575 | extern kern_return_t task_info( |
576 | task_t task, | |
577 | task_flavor_t flavor, | |
578 | task_info_t task_info_out, | |
579 | mach_msg_type_number_t *task_info_count); | |
91447636 | 580 | |
39236c6e A |
581 | extern void task_power_info_locked( |
582 | task_t task, | |
fe8ab488 | 583 | task_power_info_t info, |
5ba3f43e A |
584 | gpu_energy_data_t gpu_energy, |
585 | task_power_info_v2_t infov2); | |
fe8ab488 A |
586 | |
587 | extern uint64_t task_gpu_utilisation( | |
588 | task_t task); | |
39236c6e | 589 | |
39037602 A |
590 | extern uint64_t task_energy( |
591 | task_t task); | |
592 | ||
5ba3f43e A |
593 | extern uint64_t task_cpu_ptime( |
594 | task_t task); | |
595 | ||
2d21ac55 A |
596 | extern void task_vtimer_set( |
597 | task_t task, | |
598 | integer_t which); | |
599 | ||
600 | extern void task_vtimer_clear( | |
601 | task_t task, | |
602 | integer_t which); | |
603 | ||
604 | extern void task_vtimer_update( | |
605 | task_t task, | |
606 | integer_t which, | |
607 | uint32_t *microsecs); | |
608 | ||
609 | #define TASK_VTIMER_USER 0x01 | |
610 | #define TASK_VTIMER_PROF 0x02 | |
611 | #define TASK_VTIMER_RLIM 0x04 | |
612 | ||
91447636 A |
613 | extern void task_set_64bit( |
614 | task_t task, | |
615 | boolean_t is64bit); | |
616 | ||
5ba3f43e A |
617 | extern void task_set_platform_binary( |
618 | task_t task, | |
619 | boolean_t is_platform); | |
620 | ||
91447636 A |
621 | extern void task_backing_store_privileged( |
622 | task_t task); | |
623 | ||
b0d623f7 A |
624 | extern void task_set_dyld_info( |
625 | task_t task, | |
626 | mach_vm_address_t addr, | |
627 | mach_vm_size_t size); | |
628 | ||
91447636 A |
629 | /* Get number of activations in a task */ |
630 | extern int get_task_numacts( | |
631 | task_t task); | |
632 | ||
b0d623f7 | 633 | extern int get_task_numactivethreads(task_t task); |
5ba3f43e A |
634 | |
635 | struct label; | |
636 | extern kern_return_t task_collect_crash_info( | |
637 | task_t task, | |
638 | #if CONFIG_MACF | |
639 | struct label *crash_label, | |
640 | #endif | |
641 | int is_corpse_fork); | |
39037602 A |
642 | void task_port_notify(mach_msg_header_t *msg); |
643 | void task_wait_till_threads_terminate_locked(task_t task); | |
0b4e3aa0 | 644 | |
1c79356b | 645 | /* JMM - should just be temporary (implementation in bsd_kern still) */ |
1c79356b | 646 | extern void set_bsdtask_info(task_t,void *); |
91447636 | 647 | extern vm_map_t get_task_map_reference(task_t); |
d190cdc3 | 648 | extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t); |
1c79356b | 649 | extern pmap_t get_task_pmap(task_t); |
b0d623f7 | 650 | extern uint64_t get_task_resident_size(task_t); |
fe8ab488 A |
651 | extern uint64_t get_task_compressed(task_t); |
652 | extern uint64_t get_task_resident_max(task_t); | |
39236c6e | 653 | extern uint64_t get_task_phys_footprint(task_t); |
5ba3f43e A |
654 | extern uint64_t get_task_phys_footprint_recent_max(task_t); |
655 | extern uint64_t get_task_phys_footprint_lifetime_max(task_t); | |
39037602 | 656 | extern uint64_t get_task_phys_footprint_limit(task_t); |
fe8ab488 A |
657 | extern uint64_t get_task_purgeable_size(task_t); |
658 | extern uint64_t get_task_cpu_time(task_t); | |
3e170ce0 | 659 | extern uint64_t get_task_dispatchqueue_offset(task_t); |
39037602 | 660 | extern uint64_t get_task_dispatchqueue_serialno_offset(task_t); |
5ba3f43e A |
661 | extern uint64_t get_task_uniqueid(task_t task); |
662 | extern int get_task_version(task_t task); | |
39037602 A |
663 | |
664 | extern uint64_t get_task_internal(task_t); | |
665 | extern uint64_t get_task_internal_compressed(task_t); | |
666 | extern uint64_t get_task_purgeable_nonvolatile(task_t); | |
667 | extern uint64_t get_task_purgeable_nonvolatile_compressed(task_t); | |
668 | extern uint64_t get_task_iokit_mapped(task_t); | |
669 | extern uint64_t get_task_alternate_accounting(task_t); | |
670 | extern uint64_t get_task_alternate_accounting_compressed(task_t); | |
671 | extern uint64_t get_task_memory_region_count(task_t); | |
672 | extern uint64_t get_task_page_table(task_t); | |
39236c6e | 673 | |
3e170ce0 | 674 | extern kern_return_t task_convert_phys_footprint_limit(int, int *); |
813fb2f6 | 675 | extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t, boolean_t); |
39236c6e | 676 | extern kern_return_t task_get_phys_footprint_limit(task_t task, int *limit_mb); |
9bccf70c | 677 | |
813fb2f6 A |
678 | /* Jetsam memlimit attributes */ |
679 | extern boolean_t task_get_memlimit_is_active(task_t task); | |
680 | extern boolean_t task_get_memlimit_is_fatal(task_t task); | |
681 | extern void task_set_memlimit_is_active(task_t task, boolean_t memlimit_is_active); | |
682 | extern void task_set_memlimit_is_fatal(task_t task, boolean_t memlimit_is_fatal); | |
683 | extern boolean_t task_has_triggered_exc_resource(task_t task, boolean_t memlimit_is_active); | |
684 | extern void task_mark_has_triggered_exc_resource(task_t task, boolean_t memlimit_is_active); | |
685 | ||
91447636 | 686 | extern boolean_t is_kerneltask(task_t task); |
39037602 | 687 | extern boolean_t is_corpsetask(task_t task); |
9bccf70c | 688 | |
2d21ac55 A |
689 | extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast); |
690 | ||
b0d623f7 A |
691 | extern kern_return_t machine_task_get_state( |
692 | task_t task, | |
693 | int flavor, | |
694 | thread_state_t state, | |
695 | mach_msg_type_number_t *state_count); | |
696 | ||
697 | extern kern_return_t machine_task_set_state( | |
698 | task_t task, | |
699 | int flavor, | |
700 | thread_state_t state, | |
701 | mach_msg_type_number_t state_count); | |
702 | ||
316670eb A |
703 | extern void machine_task_terminate(task_t task); |
704 | ||
705 | struct _task_ledger_indices { | |
706 | int cpu_time; | |
707 | int tkm_private; | |
708 | int tkm_shared; | |
709 | int phys_mem; | |
710 | int wired_mem; | |
fe8ab488 A |
711 | int internal; |
712 | int iokit_mapped; | |
713 | int alternate_accounting; | |
3e170ce0 | 714 | int alternate_accounting_compressed; |
39037602 | 715 | int page_table; |
39236c6e | 716 | int phys_footprint; |
fe8ab488 A |
717 | int internal_compressed; |
718 | int purgeable_volatile; | |
719 | int purgeable_nonvolatile; | |
720 | int purgeable_volatile_compressed; | |
721 | int purgeable_nonvolatile_compressed; | |
4b17d6b6 A |
722 | int platform_idle_wakeups; |
723 | int interrupt_wakeups; | |
3e170ce0 A |
724 | #if CONFIG_SCHED_SFI |
725 | int sfi_wait_times[MAX_SFI_CLASS_ID]; | |
726 | #endif /* CONFIG_SCHED_SFI */ | |
fe8ab488 A |
727 | int cpu_time_billed_to_me; |
728 | int cpu_time_billed_to_others; | |
39037602 A |
729 | int physical_writes; |
730 | int logical_writes; | |
5ba3f43e A |
731 | int energy_billed_to_me; |
732 | int energy_billed_to_others; | |
316670eb A |
733 | }; |
734 | extern struct _task_ledger_indices task_ledgers; | |
b0d623f7 | 735 | |
39037602 A |
736 | /* requires task to be unlocked, returns a referenced thread */ |
737 | thread_t task_findtid(task_t task, uint64_t tid); | |
813fb2f6 | 738 | int pid_from_task(task_t task); |
39236c6e A |
739 | |
740 | extern kern_return_t task_wakeups_monitor_ctl(task_t task, uint32_t *rate_hz, int32_t *flags); | |
741 | extern kern_return_t task_cpu_usage_monitor_ctl(task_t task, uint32_t *flags); | |
743345f9 | 742 | extern void task_rollup_accounting_info(task_t new_task, task_t parent_task); |
39037602 | 743 | extern kern_return_t task_io_monitor_ctl(task_t task, uint32_t *flags); |
743345f9 A |
744 | extern void task_set_did_exec_flag(task_t task); |
745 | extern void task_clear_exec_copy_flag(task_t task); | |
746 | extern boolean_t task_is_exec_copy(task_t); | |
747 | extern boolean_t task_did_exec(task_t task); | |
527f9951 A |
748 | #ifdef CONFIG_32BIT_TELEMETRY |
749 | extern boolean_t task_consume_32bit_log_flag(task_t task); | |
750 | extern void task_set_32bit_log_flag(task_t task); | |
751 | #endif /* CONFIG_32BIT_TELEMETRY */ | |
743345f9 | 752 | extern boolean_t task_is_active(task_t task); |
5ba3f43e | 753 | extern boolean_t task_is_halting(task_t task); |
743345f9 A |
754 | extern void task_clear_return_wait(task_t task); |
755 | extern void task_wait_to_return(void); | |
756 | extern event_t task_get_return_wait_event(task_t task); | |
39236c6e | 757 | |
fe8ab488 | 758 | extern void task_atm_reset(task_t task); |
490019cf A |
759 | extern void task_bank_reset(task_t task); |
760 | extern void task_bank_init(task_t task); | |
39236c6e | 761 | |
3e170ce0 | 762 | extern int task_pid(task_t task); |
39037602 | 763 | extern boolean_t task_has_assertions(task_t task); |
39236c6e | 764 | /* End task_policy */ |
316670eb | 765 | |
fe8ab488 A |
766 | extern void task_set_gpu_denied(task_t task, boolean_t denied); |
767 | extern boolean_t task_is_gpu_denied(task_t task); | |
768 | ||
7e41aa88 A |
769 | extern queue_head_t * task_io_user_clients(task_t task); |
770 | ||
5ba3f43e A |
771 | extern void task_copy_fields_for_exec(task_t dst_task, task_t src_task); |
772 | ||
91447636 | 773 | #endif /* XNU_KERNEL_PRIVATE */ |
9bccf70c | 774 | |
91447636 | 775 | #ifdef KERNEL_PRIVATE |
9bccf70c | 776 | |
91447636 | 777 | extern void *get_bsdtask_info(task_t); |
2d21ac55 | 778 | extern void *get_bsdthreadtask_info(thread_t); |
3e170ce0 | 779 | extern void task_bsdtask_kill(task_t); |
91447636 | 780 | extern vm_map_t get_task_map(task_t); |
316670eb A |
781 | extern ledger_t get_task_ledger(task_t); |
782 | ||
783 | extern boolean_t get_task_pidsuspended(task_t); | |
784 | extern boolean_t get_task_frozen(task_t); | |
785 | ||
786 | /* Convert from a task to a port */ | |
787 | extern ipc_port_t convert_task_to_port(task_t); | |
316670eb | 788 | extern ipc_port_t convert_task_name_to_port(task_name_t); |
813fb2f6 | 789 | extern ipc_port_t convert_task_inspect_to_port(task_inspect_t); |
39236c6e A |
790 | extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task); |
791 | ||
792 | /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */ | |
793 | extern task_suspension_token_t convert_port_to_task_suspension_token(ipc_port_t port); | |
794 | ||
795 | extern boolean_t task_suspension_notify(mach_msg_header_t *); | |
9bccf70c | 796 | |
39037602 A |
797 | #define TASK_WRITE_IMMEDIATE 0x1 |
798 | #define TASK_WRITE_DEFERRED 0x2 | |
799 | #define TASK_WRITE_INVALIDATED 0x4 | |
800 | #define TASK_WRITE_METADATA 0x8 | |
801 | extern void task_update_logical_writes(task_t task, uint32_t io_size, int flags, void *vp); | |
802 | ||
803 | #if CONFIG_SECLUDED_MEMORY | |
804 | extern void task_set_can_use_secluded_mem( | |
805 | task_t task, | |
806 | boolean_t can_use_secluded_mem); | |
807 | extern void task_set_could_use_secluded_mem( | |
808 | task_t task, | |
809 | boolean_t could_use_secluded_mem); | |
810 | extern void task_set_could_also_use_secluded_mem( | |
811 | task_t task, | |
812 | boolean_t could_also_use_secluded_mem); | |
813 | extern boolean_t task_can_use_secluded_mem(task_t task); | |
814 | extern boolean_t task_could_use_secluded_mem(task_t task); | |
815 | #endif /* CONFIG_SECLUDED_MEMORY */ | |
816 | ||
817 | #if CONFIG_MACF | |
818 | extern struct label *get_task_crash_label(task_t task); | |
39037602 A |
819 | #endif /* CONFIG_MACF */ |
820 | ||
91447636 | 821 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 822 | |
91447636 A |
823 | extern task_t kernel_task; |
824 | ||
825 | extern void task_deallocate( | |
826 | task_t task); | |
9bccf70c | 827 | |
0c530ab8 A |
828 | extern void task_name_deallocate( |
829 | task_name_t task_name); | |
39236c6e | 830 | |
813fb2f6 A |
831 | extern void task_inspect_deallocate( |
832 | task_inspect_t task_inspect); | |
833 | ||
39236c6e A |
834 | extern void task_suspension_token_deallocate( |
835 | task_suspension_token_t token); | |
91447636 | 836 | __END_DECLS |
9bccf70c | 837 | |
1c79356b | 838 | #endif /* _KERN_TASK_H_ */ |