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