Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
316670eb | 2 | * Copyright (c) 2000-2010 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 A |
97 | |
98 | #ifdef MACH_KERNEL_PRIVATE | |
99 | ||
1c79356b A |
100 | #include <mach/boolean.h> |
101 | #include <mach/port.h> | |
102 | #include <mach/time_value.h> | |
103 | #include <mach/message.h> | |
104 | #include <mach/mach_param.h> | |
105 | #include <mach/task_info.h> | |
106 | #include <mach/exception_types.h> | |
6d2010ae | 107 | #include <mach/vm_statistics.h> |
0c530ab8 | 108 | #include <machine/task.h> |
91447636 A |
109 | |
110 | #include <kern/cpu_data.h> | |
1c79356b A |
111 | #include <kern/queue.h> |
112 | #include <kern/exception.h> | |
113 | #include <kern/lock.h> | |
2d21ac55 A |
114 | #include <security/_label.h> |
115 | #include <ipc/ipc_labelh.h> | |
6d2010ae A |
116 | #endif /* MACH_KERNEL_PRIVATE */ |
117 | ||
118 | #ifdef XNU_KERNEL_PRIVATE | |
119 | ||
120 | /* defns for task->rsu_controldata */ | |
121 | #define TASK_POLICY_CPU_RESOURCE_USAGE 0 | |
122 | #define TASK_POLICY_WIREDMEM_RESOURCE_USAGE 1 | |
123 | #define TASK_POLICY_VIRTUALMEM_RESOURCE_USAGE 2 | |
124 | #define TASK_POLICY_DISK_RESOURCE_USAGE 3 | |
125 | #define TASK_POLICY_NETWORK_RESOURCE_USAGE 4 | |
126 | #define TASK_POLICY_POWER_RESOURCE_USAGE 5 | |
127 | ||
128 | #define TASK_POLICY_RESOURCE_USAGE_COUNT 6 | |
129 | ||
39236c6e A |
130 | #define TASK_POLICY_CPUMON_DISABLE 0xFF |
131 | #define TASK_POLICY_CPUMON_DEFAULTS 0xFE | |
6d2010ae A |
132 | |
133 | /* Resource usage/low resource attributes */ | |
134 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_NONE 0x00 | |
135 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_THROTTLE 0x01 | |
136 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_SUSPEND 0x02 | |
137 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_TERMINATE 0x03 | |
316670eb A |
138 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_KQ 0x04 |
139 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_EXC 0x05 | |
140 | #define TASK_POLICY_RESOURCE_ATTRIBUTE_DEFAULT TASK_POLICY_RESOURCE_ATTRIBUTE_NONE | |
6d2010ae A |
141 | |
142 | #endif /* XNU_KERNEL_PRIVATE */ | |
143 | ||
144 | #ifdef MACH_KERNEL_PRIVATE | |
145 | ||
316670eb | 146 | |
6d2010ae A |
147 | #include <kern/thread.h> |
148 | ||
91447636 | 149 | struct task { |
1c79356b | 150 | /* Synchronization/destruction information */ |
b0d623f7 | 151 | decl_lck_mtx_data(,lock) /* Task's lock */ |
2d21ac55 | 152 | uint32_t ref_count; /* Number of references to me */ |
1c79356b | 153 | boolean_t active; /* Task has not been terminated */ |
b0d623f7 | 154 | boolean_t halting; /* Task is being halted */ |
1c79356b A |
155 | |
156 | /* Miscellaneous */ | |
157 | vm_map_t map; /* Address space description */ | |
2d21ac55 | 158 | queue_chain_t tasks; /* global list of tasks */ |
1c79356b | 159 | void *user_data; /* Arbitrary data settable via IPC */ |
1c79356b | 160 | |
55e303ae | 161 | /* Threads in this task */ |
2d21ac55 | 162 | queue_head_t threads; |
b0d623f7 A |
163 | |
164 | processor_set_t pset_hint; | |
165 | struct affinity_space *affinity_space; | |
166 | ||
2d21ac55 A |
167 | int thread_count; |
168 | uint32_t active_thread_count; | |
b0d623f7 | 169 | int suspend_count; /* Internal scheduling only */ |
1c79356b A |
170 | |
171 | /* User-visible scheduling information */ | |
172 | integer_t user_stop_count; /* outstanding stops */ | |
39236c6e | 173 | integer_t legacy_stop_count; /* outstanding legacy stops */ |
1c79356b | 174 | |
0b4e3aa0 A |
175 | integer_t priority; /* base priority for threads */ |
176 | integer_t max_priority; /* maximum priority for threads */ | |
1c79356b | 177 | |
39236c6e A |
178 | integer_t importance; /* priority offset (BSD 'nice' value) */ |
179 | ||
55e303ae | 180 | /* Task security and audit tokens */ |
1c79356b | 181 | security_token_t sec_token; |
55e303ae | 182 | audit_token_t audit_token; |
1c79356b A |
183 | |
184 | /* Statistics */ | |
91447636 A |
185 | uint64_t total_user_time; /* terminated threads only */ |
186 | uint64_t total_system_time; | |
1c79356b | 187 | |
2d21ac55 A |
188 | /* Virtual timers */ |
189 | uint32_t vtimers; | |
1c79356b A |
190 | |
191 | /* IPC structures */ | |
b0d623f7 | 192 | decl_lck_mtx_data(,itk_lock_data) |
1c79356b | 193 | struct ipc_port *itk_self; /* not a right, doesn't hold ref */ |
0c530ab8 | 194 | struct ipc_port *itk_nself; /* not a right, doesn't hold ref */ |
1c79356b A |
195 | struct ipc_port *itk_sself; /* a send right */ |
196 | struct exception_action exc_actions[EXC_TYPES_COUNT]; | |
197 | /* a send right each valid element */ | |
198 | struct ipc_port *itk_host; /* a send right */ | |
199 | struct ipc_port *itk_bootstrap; /* a send right */ | |
2d21ac55 A |
200 | struct ipc_port *itk_seatbelt; /* a send right */ |
201 | struct ipc_port *itk_gssd; /* yet another send right */ | |
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 | |
6d2010ae A |
231 | zinfo_usage_t tkm_zinfo; /* per-task, per-zone usage statistics */ |
232 | ||
1c79356b A |
233 | #ifdef MACH_BSD |
234 | void *bsd_info; | |
235 | #endif | |
2d21ac55 | 236 | struct vm_shared_region *shared_region; |
39236c6e A |
237 | uint32_t t_flags; /* general-purpose task flags protected by task_lock (TL) */ |
238 | #define TF_64B_ADDR 0x1 /* task has 64-bit addressing */ | |
239 | #define TF_64B_DATA 0x2 /* task has 64-bit data registers */ | |
240 | #define TF_CPUMON_WARNING 0x4 /* task has at least one thread in CPU usage warning zone */ | |
241 | #define TF_WAKEMON_WARNING 0x8 /* task is in wakeups monitor warning zone */ | |
242 | #define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */ | |
91447636 | 243 | #define task_has_64BitAddr(task) \ |
39236c6e | 244 | (((task)->t_flags & TF_64B_ADDR) != 0) |
91447636 | 245 | #define task_set_64BitAddr(task) \ |
39236c6e | 246 | ((task)->t_flags |= TF_64B_ADDR) |
91447636 | 247 | #define task_clear_64BitAddr(task) \ |
39236c6e A |
248 | ((task)->t_flags &= ~TF_64B_ADDR) |
249 | #define task_has_64BitData(task) \ | |
250 | (((task)->t_flags & TF_64B_DATA) != 0) | |
91447636 | 251 | |
b0d623f7 A |
252 | mach_vm_address_t all_image_info_addr; /* dyld __all_image_info */ |
253 | mach_vm_size_t all_image_info_size; /* section location and size */ | |
2d21ac55 A |
254 | #if CONFIG_MACF_MACH |
255 | ipc_labelh_t label; | |
256 | #endif | |
257 | ||
b0d623f7 A |
258 | #if CONFIG_COUNTERS |
259 | #define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */ | |
260 | uint32_t t_chud; /* CHUD flags, used for Shark */ | |
261 | #endif | |
262 | ||
316670eb A |
263 | boolean_t pidsuspended; /* pid_suspend called; no threads can execute */ |
264 | boolean_t frozen; /* frozen; private resident pages committed to swap */ | |
39236c6e A |
265 | boolean_t changing_freeze_state; /* in the process of freezing or thawing */ |
266 | uint16_t policy_ru_cpu :4, | |
267 | policy_ru_cpu_ext :4, | |
268 | applied_ru_cpu :4, | |
269 | applied_ru_cpu_ext :4; | |
316670eb A |
270 | uint8_t rusage_cpu_flags; |
271 | uint8_t rusage_cpu_percentage; /* Task-wide CPU limit percentage */ | |
272 | uint64_t rusage_cpu_interval; /* Task-wide CPU limit interval */ | |
273 | uint8_t rusage_cpu_perthr_percentage; /* Per-thread CPU limit percentage */ | |
274 | uint64_t rusage_cpu_perthr_interval; /* Per-thread CPU limit interval */ | |
275 | uint64_t rusage_cpu_deadline; | |
276 | thread_call_t rusage_cpu_callt; | |
39236c6e A |
277 | |
278 | #if IMPORTANCE_INHERITANCE | |
279 | uint32_t imp_receiver :1, /* the task can receive importance boost */ | |
280 | imp_donor :1, /* the task always sends boosts regardless of boost status */ | |
281 | imp_reserved :30; /* reserved for future use */ | |
282 | ||
283 | uint32_t task_imp_assertcnt; /* total number of boost assertions (kernel managed plus userspace managed) */ | |
284 | uint32_t task_imp_externcnt; /* number of boost assertions externalized (userspace managed) */ | |
285 | #endif /* IMPORTANCE_INHERITANCE */ | |
6d2010ae A |
286 | |
287 | vm_extmod_statistics_data_t extmod_statistics; | |
39236c6e A |
288 | |
289 | #if MACH_ASSERT | |
290 | int8_t suspends_outstanding; /* suspends this task performed in excess of resumes */ | |
291 | #endif | |
292 | ||
293 | struct task_requested_policy requested_policy; | |
294 | struct task_effective_policy effective_policy; | |
295 | struct task_pended_policy pended_policy; | |
296 | ||
297 | /* | |
298 | * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away. | |
299 | */ | |
300 | uint32_t low_mem_notified_warn :1, /* warning low memory notification is sent to the task */ | |
301 | low_mem_notified_critical :1, /* critical low memory notification is sent to the task */ | |
302 | purged_memory_warn :1, /* purgeable memory of the task is purged for warning level pressure */ | |
303 | purged_memory_critical :1, /* purgeable memory of the task is purged for critical level pressure */ | |
304 | mem_notify_reserved :28; /* reserved for future use */ | |
4b17d6b6 A |
305 | |
306 | /* Statistics accumulated for terminated threads from this task */ | |
307 | uint32_t task_timer_wakeups_bin_1; | |
308 | uint32_t task_timer_wakeups_bin_2; | |
39236c6e A |
309 | |
310 | int task_volatile_objects; /* # of purgeable VM objects made | |
311 | * "volatile" by this task */ | |
91447636 | 312 | }; |
1c79356b | 313 | |
39236c6e A |
314 | #define task_lock(task) lck_mtx_lock(&(task)->lock) |
315 | #define task_lock_assert_owned(task) lck_mtx_assert(&(task)->lock, LCK_MTX_ASSERT_OWNED) | |
316 | #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock) | |
317 | #define task_unlock(task) lck_mtx_unlock(&(task)->lock) | |
1c79356b | 318 | |
2d21ac55 A |
319 | #if CONFIG_MACF_MACH |
320 | #define maclabel label->lh_label | |
321 | ||
322 | #define tasklabel_lock(task) lh_lock((task)->label) | |
323 | #define tasklabel_unlock(task) lh_unlock((task)->label) | |
324 | ||
325 | extern void tasklabel_lock2(task_t a, task_t b); | |
326 | extern void tasklabel_unlock2(task_t a, task_t b); | |
327 | #endif /* MAC_MACH */ | |
328 | ||
b0d623f7 A |
329 | #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr) |
330 | #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp) | |
331 | #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data) | |
332 | #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data) | |
1c79356b | 333 | |
39236c6e A |
334 | #define TASK_REFERENCE_LEAK_DEBUG 0 |
335 | ||
336 | #if TASK_REFERENCE_LEAK_DEBUG | |
337 | extern void task_reference_internal(task_t task); | |
338 | extern uint32_t task_deallocate_internal(task_t task); | |
339 | #else | |
91447636 | 340 | #define task_reference_internal(task) \ |
2d21ac55 | 341 | (void)hw_atomic_add(&(task)->ref_count, 1) |
9bccf70c | 342 | |
91447636 A |
343 | #define task_deallocate_internal(task) \ |
344 | hw_atomic_sub(&(task)->ref_count, 1) | |
39236c6e | 345 | #endif |
55e303ae | 346 | |
91447636 A |
347 | #define task_reference(task) \ |
348 | MACRO_BEGIN \ | |
349 | if ((task) != TASK_NULL) \ | |
350 | task_reference_internal(task); \ | |
351 | MACRO_END | |
1c79356b | 352 | |
91447636 A |
353 | extern kern_return_t kernel_task_create( |
354 | task_t task, | |
355 | vm_offset_t map_base, | |
356 | vm_size_t map_size, | |
357 | task_t *child); | |
55e303ae | 358 | |
1c79356b | 359 | /* Initialize task module */ |
39236c6e | 360 | extern void task_init(void); |
1c79356b | 361 | |
91447636 A |
362 | #define current_task_fast() (current_thread()->task) |
363 | #define current_task() current_task_fast() | |
1c79356b | 364 | |
b0d623f7 A |
365 | extern lck_attr_t task_lck_attr; |
366 | extern lck_grp_t task_lck_grp; | |
367 | ||
91447636 | 368 | #else /* MACH_KERNEL_PRIVATE */ |
1c79356b | 369 | |
91447636 A |
370 | __BEGIN_DECLS |
371 | ||
372 | extern task_t current_task(void); | |
373 | ||
374 | extern void task_reference(task_t task); | |
375 | ||
376 | __END_DECLS | |
1c79356b | 377 | |
9bccf70c | 378 | #endif /* MACH_KERNEL_PRIVATE */ |
1c79356b | 379 | |
91447636 | 380 | __BEGIN_DECLS |
1c79356b | 381 | |
91447636 A |
382 | #ifdef XNU_KERNEL_PRIVATE |
383 | ||
384 | /* Hold all threads in a task */ | |
1c79356b | 385 | extern kern_return_t task_hold( |
91447636 | 386 | task_t task); |
1c79356b | 387 | |
316670eb A |
388 | /* Wait for task to stop running, either just to get off CPU or to cease being runnable */ |
389 | extern kern_return_t task_wait( | |
390 | task_t task, | |
391 | boolean_t until_not_runnable); | |
392 | ||
91447636 | 393 | /* Release hold on all threads in a task */ |
1c79356b | 394 | extern kern_return_t task_release( |
91447636 | 395 | task_t task); |
1c79356b | 396 | |
316670eb A |
397 | /* Suspends a task by placing a hold on its threads */ |
398 | extern kern_return_t task_pidsuspend( | |
399 | task_t task); | |
400 | extern kern_return_t task_pidsuspend_locked( | |
401 | task_t task); | |
402 | ||
403 | /* Resumes a previously paused task */ | |
404 | extern kern_return_t task_pidresume( | |
405 | task_t task); | |
406 | ||
6d2010ae A |
407 | #if CONFIG_FREEZE |
408 | ||
409 | /* Freeze a task's resident pages */ | |
410 | extern kern_return_t task_freeze( | |
411 | task_t task, | |
412 | uint32_t *purgeable_count, | |
413 | uint32_t *wired_count, | |
414 | uint32_t *clean_count, | |
415 | uint32_t *dirty_count, | |
316670eb | 416 | uint32_t dirty_budget, |
6d2010ae A |
417 | boolean_t *shared, |
418 | boolean_t walk_only); | |
419 | ||
420 | /* Thaw a currently frozen task */ | |
421 | extern kern_return_t task_thaw( | |
422 | task_t task); | |
423 | ||
424 | #endif /* CONFIG_FREEZE */ | |
425 | ||
91447636 | 426 | /* Halt all other threads in the current task */ |
b0d623f7 A |
427 | extern kern_return_t task_start_halt( |
428 | task_t task); | |
429 | ||
430 | /* Wait for other threads to halt and free halting task resources */ | |
431 | extern void task_complete_halt( | |
91447636 A |
432 | task_t task); |
433 | ||
434 | extern kern_return_t task_terminate_internal( | |
435 | task_t task); | |
436 | ||
437 | extern kern_return_t task_create_internal( | |
438 | task_t parent_task, | |
439 | boolean_t inherit_memory, | |
0c530ab8 | 440 | boolean_t is_64bit, |
91447636 | 441 | task_t *child_task); /* OUT */ |
1c79356b | 442 | |
0b4e3aa0 A |
443 | extern kern_return_t task_importance( |
444 | task_t task, | |
445 | integer_t importance); | |
91447636 | 446 | |
39236c6e A |
447 | extern void task_power_info_locked( |
448 | task_t task, | |
449 | task_power_info_t info); | |
450 | ||
2d21ac55 A |
451 | extern void task_vtimer_set( |
452 | task_t task, | |
453 | integer_t which); | |
454 | ||
455 | extern void task_vtimer_clear( | |
456 | task_t task, | |
457 | integer_t which); | |
458 | ||
459 | extern void task_vtimer_update( | |
460 | task_t task, | |
461 | integer_t which, | |
462 | uint32_t *microsecs); | |
463 | ||
464 | #define TASK_VTIMER_USER 0x01 | |
465 | #define TASK_VTIMER_PROF 0x02 | |
466 | #define TASK_VTIMER_RLIM 0x04 | |
467 | ||
91447636 A |
468 | extern void task_set_64bit( |
469 | task_t task, | |
470 | boolean_t is64bit); | |
471 | ||
472 | extern void task_backing_store_privileged( | |
473 | task_t task); | |
474 | ||
b0d623f7 A |
475 | extern void task_set_dyld_info( |
476 | task_t task, | |
477 | mach_vm_address_t addr, | |
478 | mach_vm_size_t size); | |
479 | ||
91447636 A |
480 | /* Get number of activations in a task */ |
481 | extern int get_task_numacts( | |
482 | task_t task); | |
483 | ||
b0d623f7 | 484 | extern int get_task_numactivethreads(task_t task); |
0b4e3aa0 | 485 | |
1c79356b | 486 | /* JMM - should just be temporary (implementation in bsd_kern still) */ |
1c79356b | 487 | extern void set_bsdtask_info(task_t,void *); |
91447636 | 488 | extern vm_map_t get_task_map_reference(task_t); |
6d2010ae | 489 | extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t, boolean_t); |
1c79356b | 490 | extern pmap_t get_task_pmap(task_t); |
b0d623f7 | 491 | extern uint64_t get_task_resident_size(task_t); |
39236c6e A |
492 | extern uint64_t get_task_phys_footprint(task_t); |
493 | extern uint64_t get_task_phys_footprint_max(task_t); | |
494 | ||
495 | extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t); | |
496 | extern kern_return_t task_get_phys_footprint_limit(task_t task, int *limit_mb); | |
9bccf70c | 497 | |
91447636 | 498 | extern boolean_t is_kerneltask(task_t task); |
9bccf70c | 499 | |
2d21ac55 A |
500 | extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast); |
501 | ||
b0d623f7 A |
502 | extern kern_return_t machine_task_get_state( |
503 | task_t task, | |
504 | int flavor, | |
505 | thread_state_t state, | |
506 | mach_msg_type_number_t *state_count); | |
507 | ||
508 | extern kern_return_t machine_task_set_state( | |
509 | task_t task, | |
510 | int flavor, | |
511 | thread_state_t state, | |
512 | mach_msg_type_number_t state_count); | |
513 | ||
316670eb A |
514 | extern void machine_task_terminate(task_t task); |
515 | ||
516 | struct _task_ledger_indices { | |
517 | int cpu_time; | |
518 | int tkm_private; | |
519 | int tkm_shared; | |
520 | int phys_mem; | |
521 | int wired_mem; | |
39236c6e A |
522 | int iokit_mem; |
523 | int phys_footprint; | |
524 | int phys_compressed; | |
4b17d6b6 A |
525 | int platform_idle_wakeups; |
526 | int interrupt_wakeups; | |
316670eb A |
527 | }; |
528 | extern struct _task_ledger_indices task_ledgers; | |
b0d623f7 | 529 | |
39236c6e | 530 | /* Begin task_policy */ |
6d2010ae | 531 | |
39236c6e A |
532 | /* value */ |
533 | #define TASK_POLICY_DISABLE 0x0 | |
534 | #define TASK_POLICY_ENABLE 0x1 | |
316670eb | 535 | |
39236c6e A |
536 | /* category */ |
537 | #define TASK_POLICY_INTERNAL 0x0 | |
538 | #define TASK_POLICY_EXTERNAL 0x1 | |
539 | #define TASK_POLICY_ATTRIBUTE 0x2 | |
6d2010ae | 540 | |
39236c6e A |
541 | /* for tracing */ |
542 | #define TASK_POLICY_TASK 0x4 | |
543 | #define TASK_POLICY_THREAD 0x8 | |
6d2010ae | 544 | |
39236c6e A |
545 | /* flavors (also DBG_IMPORTANCE subclasses 0x20 - 0x3F) */ |
546 | ||
547 | /* internal or external, thread or task */ | |
548 | #define TASK_POLICY_DARWIN_BG 0x21 | |
549 | #define TASK_POLICY_IOPOL 0x22 | |
550 | #define TASK_POLICY_IO 0x23 | |
551 | #define TASK_POLICY_PASSIVE_IO 0x24 | |
552 | ||
553 | /* internal or external, task only */ | |
554 | #define TASK_POLICY_DARWIN_BG_AND_GPU 0x25 | |
555 | #define TASK_POLICY_GPU_DENY 0x26 | |
556 | ||
557 | /* internal, task only */ | |
558 | #define TASK_POLICY_DARWIN_BG_IOPOL 0x27 | |
559 | ||
560 | /* task-only attributes */ | |
561 | #define TASK_POLICY_TAL 0x28 | |
562 | #define TASK_POLICY_BOOST 0x29 | |
563 | #define TASK_POLICY_ROLE 0x2A | |
564 | #define TASK_POLICY_SUPPRESSED_CPU 0x2B | |
565 | #define TASK_POLICY_TERMINATED 0x2C | |
566 | #define TASK_POLICY_NEW_SOCKETS_BG 0x2D | |
567 | #define TASK_POLICY_LOWPRI_CPU 0x2E | |
568 | #define TASK_POLICY_LATENCY_QOS 0x2F | |
569 | #define TASK_POLICY_THROUGH_QOS 0x30 | |
570 | #define TASK_POLICY_WATCHERS_BG 0x31 | |
571 | ||
572 | /* thread-only attributes */ | |
573 | #define TASK_POLICY_PIDBIND_BG 0x32 | |
574 | #define TASK_POLICY_WORKQ_BG 0x33 | |
575 | ||
576 | #define TASK_POLICY_MAX 0x3F | |
577 | ||
578 | /* The main entrance to task policy is this function */ | |
579 | extern void proc_set_task_policy(task_t task, thread_t thread, int category, int flavor, int value); | |
580 | extern int proc_get_task_policy(task_t task, thread_t thread, int category, int flavor); | |
581 | ||
582 | /* For use by kernel threads and others who don't hold a reference on the target thread */ | |
583 | extern void proc_set_task_policy_thread(task_t task, uint64_t tid, int category, int flavor, int value); | |
584 | ||
585 | extern void proc_set_task_apptype(task_t task, int type); | |
586 | ||
587 | /* IO Throttle tiers */ | |
588 | #define THROTTLE_LEVEL_NONE -1 | |
589 | #define THROTTLE_LEVEL_TIER0 0 /* IOPOL_NORMAL, IOPOL_DEFAULT, IOPOL_PASSIVE */ | |
590 | ||
591 | #define THROTTLE_LEVEL_THROTTLED 1 | |
592 | #define THROTTLE_LEVEL_TIER1 1 /* IOPOL_STANDARD */ | |
593 | #define THROTTLE_LEVEL_TIER2 2 /* IOPOL_UTILITY */ | |
594 | #define THROTTLE_LEVEL_TIER3 3 /* IOPOL_THROTTLE */ | |
595 | ||
596 | #define THROTTLE_LEVEL_START 0 | |
597 | #define THROTTLE_LEVEL_END 3 | |
598 | ||
599 | #define THROTTLE_LEVEL_COMPRESSOR_TIER0 THROTTLE_LEVEL_TIER0 | |
600 | #define THROTTLE_LEVEL_COMPRESSOR_TIER1 THROTTLE_LEVEL_TIER1 | |
601 | #define THROTTLE_LEVEL_COMPRESSOR_TIER2 THROTTLE_LEVEL_TIER2 | |
602 | ||
603 | #define THROTTLE_LEVEL_PAGEOUT_THROTTLED THROTTLE_LEVEL_TIER2 | |
604 | #define THROTTLE_LEVEL_PAGEOUT_UNTHROTTLED THROTTLE_LEVEL_TIER1 | |
605 | ||
606 | extern int proc_apply_workq_bgthreadpolicy(thread_t thread); | |
607 | extern int proc_restore_workq_bgthreadpolicy(thread_t thread); | |
608 | ||
609 | extern int proc_get_darwinbgstate(task_t task, uint32_t *flagsp); | |
610 | extern boolean_t proc_task_is_tal(task_t task); | |
611 | extern integer_t task_grab_latency_qos(task_t task); | |
612 | extern void task_policy_create(task_t task, int parent_boosted); | |
613 | ||
614 | /* | |
615 | * Get effective policy | |
616 | * Only for use by relevant subsystem, should never be passed into a setter! | |
617 | */ | |
618 | ||
619 | extern int proc_get_effective_task_policy(task_t task, int flavor); | |
620 | extern int proc_get_effective_thread_policy(thread_t thread, int flavor); | |
621 | ||
622 | /* temporary compatibility */ | |
623 | int proc_setthread_saved_importance(thread_t thread, int importance); | |
624 | ||
625 | int proc_get_task_ruse_cpu(task_t task, uint32_t *policyp, uint8_t *percentagep, uint64_t *intervalp, uint64_t *deadlinep); | |
626 | int proc_set_task_ruse_cpu(task_t task, uint32_t policy, uint8_t percentage, uint64_t interval, uint64_t deadline, int cpumon_entitled); | |
627 | int proc_clear_task_ruse_cpu(task_t task, int cpumon_entitled); | |
628 | thread_t task_findtid(task_t, uint64_t); | |
629 | void set_thread_iotier_override(thread_t, int policy); | |
630 | ||
631 | #define TASK_RUSECPU_FLAGS_PROC_LIMIT 0x01 | |
632 | #define TASK_RUSECPU_FLAGS_PERTHR_LIMIT 0x02 | |
633 | #define TASK_RUSECPU_FLAGS_DEADLINE 0x04 | |
634 | #define TASK_RUSECPU_FLAGS_FATAL_CPUMON 0x08 /* CPU usage monitor violations are fatal */ | |
635 | #define TASK_RUSECPU_FLAGS_FATAL_WAKEUPSMON 0x10 /* wakeups monitor violations are fatal */ | |
636 | #define TASK_RUSECPU_FLAGS_PHYS_FOOTPRINT_EXCEPTION 0x20 /* exceeding physical footprint generates EXC_RESOURCE */ | |
6d2010ae A |
637 | |
638 | /* BSD call back functions */ | |
639 | extern int proc_apply_resource_actions(void * p, int type, int action); | |
640 | extern int proc_restore_resource_actions(void * p, int type, int action); | |
641 | extern int task_restore_resource_actions(task_t task, int type); | |
642 | ||
39236c6e A |
643 | extern int task_clear_cpuusage(task_t task, int cpumon_entitled); |
644 | ||
645 | extern kern_return_t task_wakeups_monitor_ctl(task_t task, uint32_t *rate_hz, int32_t *flags); | |
646 | extern kern_return_t task_cpu_usage_monitor_ctl(task_t task, uint32_t *flags); | |
647 | ||
648 | ||
649 | void task_importance_mark_donor(task_t task, boolean_t donating); | |
650 | ||
651 | #if IMPORTANCE_INHERITANCE | |
652 | extern boolean_t task_is_importance_donor(task_t task); | |
653 | extern boolean_t task_is_importance_receiver(task_t task); | |
654 | ||
655 | extern int task_importance_hold_internal_assertion(task_t target_task, uint32_t count); | |
656 | extern int task_importance_drop_internal_assertion(task_t target_task, uint32_t count); | |
657 | ||
658 | extern int task_importance_hold_external_assertion(task_t target_task, uint32_t count); | |
659 | extern int task_importance_drop_external_assertion(task_t target_task, uint32_t count); | |
660 | ||
661 | extern int task_importance_externalize_assertion(task_t target_task, uint32_t count, int sender_pid); | |
662 | #endif /* IMPORTANCE_INHERITANCE */ | |
663 | ||
664 | extern void task_hold_multiple_assertion(task_t task, uint32_t count); | |
665 | extern void task_add_importance_watchport(task_t task, int pid, mach_port_t port, int *boostp); | |
666 | ||
667 | extern boolean_t task_has_been_notified(task_t task, int pressurelevel); | |
668 | extern boolean_t task_used_for_purging(task_t task, int pressurelevel); | |
669 | extern void task_mark_has_been_notified(task_t task, int pressurelevel); | |
670 | extern void task_mark_used_for_purging(task_t task, int pressurelevel); | |
671 | extern void task_clear_has_been_notified(task_t task, int pressurelevel); | |
672 | extern void task_clear_used_for_purging(task_t task); | |
673 | extern int task_importance_estimate(task_t task); | |
674 | ||
675 | /* | |
676 | * This should only be used for debugging. | |
677 | * pid is stored in audit_token by set_security_token(). | |
678 | */ | |
679 | #define audit_token_pid_from_task(task) ((task)->audit_token.val[5]) | |
680 | ||
681 | /* End task_policy */ | |
316670eb | 682 | |
91447636 | 683 | #endif /* XNU_KERNEL_PRIVATE */ |
9bccf70c | 684 | |
91447636 | 685 | #ifdef KERNEL_PRIVATE |
9bccf70c | 686 | |
91447636 | 687 | extern void *get_bsdtask_info(task_t); |
2d21ac55 | 688 | extern void *get_bsdthreadtask_info(thread_t); |
91447636 | 689 | extern vm_map_t get_task_map(task_t); |
316670eb A |
690 | extern ledger_t get_task_ledger(task_t); |
691 | ||
692 | extern boolean_t get_task_pidsuspended(task_t); | |
693 | extern boolean_t get_task_frozen(task_t); | |
694 | ||
695 | /* Convert from a task to a port */ | |
696 | extern ipc_port_t convert_task_to_port(task_t); | |
316670eb | 697 | extern ipc_port_t convert_task_name_to_port(task_name_t); |
39236c6e A |
698 | extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task); |
699 | ||
700 | /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */ | |
701 | extern task_suspension_token_t convert_port_to_task_suspension_token(ipc_port_t port); | |
702 | ||
703 | extern boolean_t task_suspension_notify(mach_msg_header_t *); | |
9bccf70c | 704 | |
91447636 | 705 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 706 | |
91447636 A |
707 | extern task_t kernel_task; |
708 | ||
709 | extern void task_deallocate( | |
710 | task_t task); | |
9bccf70c | 711 | |
0c530ab8 A |
712 | extern void task_name_deallocate( |
713 | task_name_t task_name); | |
39236c6e A |
714 | |
715 | extern void task_suspension_token_deallocate( | |
716 | task_suspension_token_t token); | |
91447636 | 717 | __END_DECLS |
9bccf70c | 718 | |
1c79356b | 719 | #endif /* _KERN_TASK_H_ */ |