]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/task.h
xnu-3248.40.184.tar.gz
[apple/xnu.git] / osfmk / kern / task.h
CommitLineData
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
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>
fe8ab488 113#include <kern/locks.h>
2d21ac55 114#include <security/_label.h>
fe8ab488 115#include <ipc/ipc_port.h>
6d2010ae
A
116#endif /* MACH_KERNEL_PRIVATE */
117
118#ifdef XNU_KERNEL_PRIVATE
119
3e170ce0 120#include <kern/kern_cdata.h>
fe8ab488
A
121#include <mach/sfi_class.h>
122
6d2010ae
A
123/* defns for task->rsu_controldata */
124#define TASK_POLICY_CPU_RESOURCE_USAGE 0
125#define TASK_POLICY_WIREDMEM_RESOURCE_USAGE 1
126#define TASK_POLICY_VIRTUALMEM_RESOURCE_USAGE 2
127#define TASK_POLICY_DISK_RESOURCE_USAGE 3
128#define TASK_POLICY_NETWORK_RESOURCE_USAGE 4
129#define TASK_POLICY_POWER_RESOURCE_USAGE 5
130
131#define TASK_POLICY_RESOURCE_USAGE_COUNT 6
132
39236c6e
A
133#define TASK_POLICY_CPUMON_DISABLE 0xFF
134#define TASK_POLICY_CPUMON_DEFAULTS 0xFE
6d2010ae
A
135
136/* Resource usage/low resource attributes */
137#define TASK_POLICY_RESOURCE_ATTRIBUTE_NONE 0x00
138#define TASK_POLICY_RESOURCE_ATTRIBUTE_THROTTLE 0x01
139#define TASK_POLICY_RESOURCE_ATTRIBUTE_SUSPEND 0x02
140#define TASK_POLICY_RESOURCE_ATTRIBUTE_TERMINATE 0x03
316670eb
A
141#define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_KQ 0x04
142#define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_EXC 0x05
143#define TASK_POLICY_RESOURCE_ATTRIBUTE_DEFAULT TASK_POLICY_RESOURCE_ATTRIBUTE_NONE
6d2010ae
A
144
145#endif /* XNU_KERNEL_PRIVATE */
146
147#ifdef MACH_KERNEL_PRIVATE
148
316670eb 149
6d2010ae 150#include <kern/thread.h>
3e170ce0 151#include <mach/coalition.h>
6d2010ae 152
fe8ab488
A
153#ifdef CONFIG_ATM
154#include <atm/atm_internal.h>
155#endif
156
157struct _cpu_time_qos_stats {
158 uint64_t cpu_time_qos_default;
159 uint64_t cpu_time_qos_maintenance;
160 uint64_t cpu_time_qos_background;
161 uint64_t cpu_time_qos_utility;
162 uint64_t cpu_time_qos_legacy;
163 uint64_t cpu_time_qos_user_initiated;
164 uint64_t cpu_time_qos_user_interactive;
165};
166
167#ifdef CONFIG_BANK
168#include <bank/bank_internal.h>
169#endif
170
91447636 171struct task {
1c79356b 172 /* Synchronization/destruction information */
b0d623f7 173 decl_lck_mtx_data(,lock) /* Task's lock */
2d21ac55 174 uint32_t ref_count; /* Number of references to me */
1c79356b 175 boolean_t active; /* Task has not been terminated */
b0d623f7 176 boolean_t halting; /* Task is being halted */
1c79356b
A
177
178 /* Miscellaneous */
179 vm_map_t map; /* Address space description */
2d21ac55 180 queue_chain_t tasks; /* global list of tasks */
1c79356b 181 void *user_data; /* Arbitrary data settable via IPC */
1c79356b 182
fe8ab488
A
183#if defined(CONFIG_SCHED_MULTIQ)
184 sched_group_t sched_group;
185#endif /* defined(CONFIG_SCHED_MULTIQ) */
186
55e303ae 187 /* Threads in this task */
2d21ac55 188 queue_head_t threads;
b0d623f7
A
189
190 processor_set_t pset_hint;
191 struct affinity_space *affinity_space;
192
2d21ac55
A
193 int thread_count;
194 uint32_t active_thread_count;
b0d623f7 195 int suspend_count; /* Internal scheduling only */
1c79356b
A
196
197 /* User-visible scheduling information */
198 integer_t user_stop_count; /* outstanding stops */
39236c6e 199 integer_t legacy_stop_count; /* outstanding legacy stops */
1c79356b 200
0b4e3aa0
A
201 integer_t priority; /* base priority for threads */
202 integer_t max_priority; /* maximum priority for threads */
1c79356b 203
39236c6e
A
204 integer_t importance; /* priority offset (BSD 'nice' value) */
205
55e303ae 206 /* Task security and audit tokens */
1c79356b 207 security_token_t sec_token;
55e303ae 208 audit_token_t audit_token;
1c79356b
A
209
210 /* Statistics */
91447636
A
211 uint64_t total_user_time; /* terminated threads only */
212 uint64_t total_system_time;
fe8ab488 213
2d21ac55
A
214 /* Virtual timers */
215 uint32_t vtimers;
1c79356b
A
216
217 /* IPC structures */
b0d623f7 218 decl_lck_mtx_data(,itk_lock_data)
1c79356b 219 struct ipc_port *itk_self; /* not a right, doesn't hold ref */
0c530ab8 220 struct ipc_port *itk_nself; /* not a right, doesn't hold ref */
1c79356b
A
221 struct ipc_port *itk_sself; /* a send right */
222 struct exception_action exc_actions[EXC_TYPES_COUNT];
223 /* a send right each valid element */
224 struct ipc_port *itk_host; /* a send right */
225 struct ipc_port *itk_bootstrap; /* a send right */
2d21ac55
A
226 struct ipc_port *itk_seatbelt; /* a send right */
227 struct ipc_port *itk_gssd; /* yet another send right */
fe8ab488 228 struct ipc_port *itk_debug_control; /* send right for debugmode communications */
2d21ac55 229 struct ipc_port *itk_task_access; /* and another send right */
39236c6e 230 struct ipc_port *itk_resume; /* a receive right to resume this task */
1c79356b
A
231 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
232 /* all send rights */
233
234 struct ipc_space *itk_space;
235
1c79356b
A
236 /* Synchronizer ownership information */
237 queue_head_t semaphore_list; /* list of owned semaphores */
1c79356b 238 int semaphores_owned; /* number of semaphores owned */
1c79356b 239
316670eb
A
240 ledger_t ledger;
241
91447636
A
242 unsigned int priv_flags; /* privilege resource flags */
243#define VM_BACKING_STORE_PRIV 0x1
0c530ab8
A
244
245 MACHINE_TASK
1c79356b 246
1c79356b
A
247 integer_t faults; /* faults counter */
248 integer_t pageins; /* pageins counter */
249 integer_t cow_faults; /* copy on write fault counter */
250 integer_t messages_sent; /* messages sent counter */
251 integer_t messages_received; /* messages received counter */
252 integer_t syscalls_mach; /* mach system call counter */
253 integer_t syscalls_unix; /* unix system call counter */
316670eb
A
254 uint32_t c_switch; /* total context switches */
255 uint32_t p_switch; /* total processor switches */
256 uint32_t ps_switch; /* total pset switches */
6d2010ae 257
6d2010ae
A
258 zinfo_usage_t tkm_zinfo; /* per-task, per-zone usage statistics */
259
1c79356b
A
260#ifdef MACH_BSD
261 void *bsd_info;
262#endif
3e170ce0 263 kcdata_descriptor_t corpse_info;
2d21ac55 264 struct vm_shared_region *shared_region;
fe8ab488
A
265 volatile uint32_t t_flags; /* general-purpose task flags protected by task_lock (TL) */
266#define TF_64B_ADDR 0x00000001 /* task has 64-bit addressing */
267#define TF_64B_DATA 0x00000002 /* task has 64-bit data registers */
268#define TF_CPUMON_WARNING 0x00000004 /* task has at least one thread in CPU usage warning zone */
269#define TF_WAKEMON_WARNING 0x00000008 /* task is in wakeups monitor warning zone */
270#define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */
271#define TF_GPU_DENIED 0x00000010 /* task is not allowed to access the GPU */
3e170ce0
A
272#define TF_CORPSE 0x00000020 /* task is a corpse */
273#define TF_PENDING_CORPSE 0x00000040 /* task corpse has not been reported yet */
fe8ab488 274
91447636 275#define task_has_64BitAddr(task) \
39236c6e 276 (((task)->t_flags & TF_64B_ADDR) != 0)
91447636 277#define task_set_64BitAddr(task) \
39236c6e 278 ((task)->t_flags |= TF_64B_ADDR)
91447636 279#define task_clear_64BitAddr(task) \
39236c6e
A
280 ((task)->t_flags &= ~TF_64B_ADDR)
281#define task_has_64BitData(task) \
282 (((task)->t_flags & TF_64B_DATA) != 0)
91447636 283
3e170ce0
A
284#define task_is_a_corpse(task) \
285 (((task)->t_flags & TF_CORPSE) != 0)
286
287#define task_set_corpse(task) \
288 ((task)->t_flags |= TF_CORPSE)
289
290#define task_corpse_pending_report(task) \
291 (((task)->t_flags & TF_PENDING_CORPSE) != 0)
292
293#define task_set_corpse_pending_report(task) \
294 ((task)->t_flags |= TF_PENDING_CORPSE)
295
296#define task_clear_corpse_pending_report(task) \
297 ((task)->t_flags &= ~TF_PENDING_CORPSE)
298
b0d623f7
A
299 mach_vm_address_t all_image_info_addr; /* dyld __all_image_info */
300 mach_vm_size_t all_image_info_size; /* section location and size */
2d21ac55 301
3e170ce0 302#if KPERF
fe8ab488
A
303#define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */
304#define TASK_KPC_FORCED_ALL_CTRS 0x2 /* Bit in "t_chud" signifying KPC forced all counters */
305
b0d623f7
A
306 uint32_t t_chud; /* CHUD flags, used for Shark */
307#endif
308
316670eb
A
309 boolean_t pidsuspended; /* pid_suspend called; no threads can execute */
310 boolean_t frozen; /* frozen; private resident pages committed to swap */
39236c6e
A
311 boolean_t changing_freeze_state; /* in the process of freezing or thawing */
312 uint16_t policy_ru_cpu :4,
313 policy_ru_cpu_ext :4,
314 applied_ru_cpu :4,
315 applied_ru_cpu_ext :4;
316670eb
A
316 uint8_t rusage_cpu_flags;
317 uint8_t rusage_cpu_percentage; /* Task-wide CPU limit percentage */
318 uint64_t rusage_cpu_interval; /* Task-wide CPU limit interval */
319 uint8_t rusage_cpu_perthr_percentage; /* Per-thread CPU limit percentage */
320 uint64_t rusage_cpu_perthr_interval; /* Per-thread CPU limit interval */
321 uint64_t rusage_cpu_deadline;
322 thread_call_t rusage_cpu_callt;
39236c6e 323
fe8ab488
A
324#if CONFIG_ATM
325 struct atm_task_descriptor *atm_context; /* pointer to per task atm descriptor */
326#endif
327#if CONFIG_BANK
328 struct bank_task *bank_context; /* pointer to per task bank structure */
329#endif
39236c6e 330
fe8ab488
A
331#if IMPORTANCE_INHERITANCE
332 struct ipc_importance_task *task_imp_base; /* Base of IPC importance chain */
39236c6e 333#endif /* IMPORTANCE_INHERITANCE */
6d2010ae
A
334
335 vm_extmod_statistics_data_t extmod_statistics;
39236c6e
A
336
337#if MACH_ASSERT
338 int8_t suspends_outstanding; /* suspends this task performed in excess of resumes */
339#endif
340
341 struct task_requested_policy requested_policy;
342 struct task_effective_policy effective_policy;
343 struct task_pended_policy pended_policy;
344
345 /*
346 * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away.
347 */
3e170ce0
A
348 uint32_t low_mem_notified_warn :1, /* warning low memory notification is sent to the task */
349 low_mem_notified_critical :1, /* critical low memory notification is sent to the task */
350 purged_memory_warn :1, /* purgeable memory of the task is purged for warning level pressure */
351 purged_memory_critical :1, /* purgeable memory of the task is purged for critical level pressure */
352 low_mem_privileged_listener :1, /* if set, task would like to know about pressure changes before other tasks on the system */
353 mem_notify_reserved :27; /* reserved for future use */
4b17d6b6 354
4bd07ac2
A
355 io_stat_info_t task_io_stats;
356 uint64_t task_immediate_writes __attribute__((aligned(8)));
357 uint64_t task_deferred_writes __attribute__((aligned(8)));
358 uint64_t task_invalidated_writes __attribute__((aligned(8)));
359 uint64_t task_metadata_writes __attribute__((aligned(8)));
360
fe8ab488
A
361 /*
362 * The cpu_time_qos_stats fields are protected by the task lock
363 */
364 struct _cpu_time_qos_stats cpu_time_qos_stats;
365
4b17d6b6
A
366 /* Statistics accumulated for terminated threads from this task */
367 uint32_t task_timer_wakeups_bin_1;
368 uint32_t task_timer_wakeups_bin_2;
fe8ab488
A
369 uint64_t task_gpu_ns;
370
371 /* # of purgeable volatile VM objects owned by this task: */
372 int task_volatile_objects;
373 /* # of purgeable but not volatile VM objects owned by this task: */
374 int task_nonvolatile_objects;
375 boolean_t task_purgeable_disowning;
376 boolean_t task_purgeable_disowned;
377
3e170ce0
A
378 /*
379 * A task's coalition set is "adopted" in task_create_internal
380 * and unset in task_deallocate_internal, so each array member
381 * can be referenced without the task lock.
382 * Note: these fields are protected by coalition->lock,
383 * not the task lock.
384 */
385 coalition_t coalition[COALITION_NUM_TYPES];
386 queue_chain_t task_coalition[COALITION_NUM_TYPES];
387 uint64_t dispatchqueue_offset;
fe8ab488
A
388
389#if HYPERVISOR
390 void *hv_task_target; /* hypervisor virtual machine object associated with this task */
391#endif /* HYPERVISOR */
91447636 392};
1c79356b 393
39236c6e
A
394#define task_lock(task) lck_mtx_lock(&(task)->lock)
395#define task_lock_assert_owned(task) lck_mtx_assert(&(task)->lock, LCK_MTX_ASSERT_OWNED)
396#define task_lock_try(task) lck_mtx_try_lock(&(task)->lock)
397#define task_unlock(task) lck_mtx_unlock(&(task)->lock)
1c79356b 398
b0d623f7
A
399#define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
400#define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
401#define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data)
402#define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data)
1c79356b 403
39236c6e
A
404#define TASK_REFERENCE_LEAK_DEBUG 0
405
406#if TASK_REFERENCE_LEAK_DEBUG
407extern void task_reference_internal(task_t task);
408extern uint32_t task_deallocate_internal(task_t task);
409#else
91447636 410#define task_reference_internal(task) \
2d21ac55 411 (void)hw_atomic_add(&(task)->ref_count, 1)
9bccf70c 412
91447636
A
413#define task_deallocate_internal(task) \
414 hw_atomic_sub(&(task)->ref_count, 1)
39236c6e 415#endif
55e303ae 416
91447636
A
417#define task_reference(task) \
418MACRO_BEGIN \
419 if ((task) != TASK_NULL) \
420 task_reference_internal(task); \
421MACRO_END
1c79356b 422
91447636
A
423extern kern_return_t kernel_task_create(
424 task_t task,
425 vm_offset_t map_base,
426 vm_size_t map_size,
427 task_t *child);
55e303ae 428
1c79356b 429/* Initialize task module */
39236c6e 430extern void task_init(void);
1c79356b 431
fe8ab488
A
432/* coalition_init() calls this to initialize ledgers before task_init() */
433extern void init_task_ledgers(void);
434
91447636
A
435#define current_task_fast() (current_thread()->task)
436#define current_task() current_task_fast()
1c79356b 437
b0d623f7
A
438extern lck_attr_t task_lck_attr;
439extern lck_grp_t task_lck_grp;
440
a1c7dba1
A
441#define QOS_OVERRIDE_MODE_OVERHANG_PEAK 0
442#define QOS_OVERRIDE_MODE_IGNORE_OVERRIDE 1
443#define QOS_OVERRIDE_MODE_FINE_GRAINED_OVERRIDE 2
444#define QOS_OVERRIDE_MODE_FINE_GRAINED_OVERRIDE_BUT_IGNORE_DISPATCH 3
445#define QOS_OVERRIDE_MODE_FINE_GRAINED_OVERRIDE_BUT_SINGLE_MUTEX_OVERRIDE 4
446
447extern uint32_t qos_override_mode;
448
91447636 449#else /* MACH_KERNEL_PRIVATE */
1c79356b 450
91447636
A
451__BEGIN_DECLS
452
453extern task_t current_task(void);
454
455extern void task_reference(task_t task);
456
457__END_DECLS
1c79356b 458
9bccf70c 459#endif /* MACH_KERNEL_PRIVATE */
1c79356b 460
91447636 461__BEGIN_DECLS
1c79356b 462
91447636
A
463#ifdef XNU_KERNEL_PRIVATE
464
465/* Hold all threads in a task */
1c79356b 466extern kern_return_t task_hold(
91447636 467 task_t task);
1c79356b 468
316670eb
A
469/* Wait for task to stop running, either just to get off CPU or to cease being runnable */
470extern kern_return_t task_wait(
471 task_t task,
472 boolean_t until_not_runnable);
473
91447636 474/* Release hold on all threads in a task */
1c79356b 475extern kern_return_t task_release(
91447636 476 task_t task);
1c79356b 477
3e170ce0
A
478/* Suspend/resume a task where the kernel owns the suspend count */
479extern kern_return_t task_suspend_internal( task_t task);
480extern kern_return_t task_resume_internal( task_t task);
481
316670eb
A
482/* Suspends a task by placing a hold on its threads */
483extern kern_return_t task_pidsuspend(
484 task_t task);
485extern kern_return_t task_pidsuspend_locked(
486 task_t task);
487
488/* Resumes a previously paused task */
489extern kern_return_t task_pidresume(
490 task_t task);
491
fe8ab488
A
492extern kern_return_t task_send_trace_memory(
493 task_t task,
494 uint32_t pid,
495 uint64_t uniqueid);
496
4bd07ac2
A
497extern void tasks_system_suspend(boolean_t suspend);
498
6d2010ae
A
499#if CONFIG_FREEZE
500
501/* Freeze a task's resident pages */
502extern kern_return_t task_freeze(
503 task_t task,
504 uint32_t *purgeable_count,
505 uint32_t *wired_count,
506 uint32_t *clean_count,
507 uint32_t *dirty_count,
316670eb 508 uint32_t dirty_budget,
6d2010ae
A
509 boolean_t *shared,
510 boolean_t walk_only);
511
512/* Thaw a currently frozen task */
513extern kern_return_t task_thaw(
514 task_t task);
515
516#endif /* CONFIG_FREEZE */
517
91447636 518/* Halt all other threads in the current task */
b0d623f7
A
519extern kern_return_t task_start_halt(
520 task_t task);
521
522/* Wait for other threads to halt and free halting task resources */
523extern void task_complete_halt(
91447636
A
524 task_t task);
525
526extern kern_return_t task_terminate_internal(
527 task_t task);
528
529extern kern_return_t task_create_internal(
530 task_t parent_task,
3e170ce0 531 coalition_t *parent_coalitions,
91447636 532 boolean_t inherit_memory,
0c530ab8 533 boolean_t is_64bit,
91447636 534 task_t *child_task); /* OUT */
1c79356b 535
0b4e3aa0
A
536extern kern_return_t task_importance(
537 task_t task,
538 integer_t importance);
91447636 539
39236c6e
A
540extern void task_power_info_locked(
541 task_t task,
fe8ab488
A
542 task_power_info_t info,
543 gpu_energy_data_t gpu_energy);
544
545extern uint64_t task_gpu_utilisation(
546 task_t task);
39236c6e 547
2d21ac55
A
548extern void task_vtimer_set(
549 task_t task,
550 integer_t which);
551
552extern void task_vtimer_clear(
553 task_t task,
554 integer_t which);
555
556extern void task_vtimer_update(
557 task_t task,
558 integer_t which,
559 uint32_t *microsecs);
560
561#define TASK_VTIMER_USER 0x01
562#define TASK_VTIMER_PROF 0x02
563#define TASK_VTIMER_RLIM 0x04
564
91447636
A
565extern void task_set_64bit(
566 task_t task,
567 boolean_t is64bit);
568
569extern void task_backing_store_privileged(
570 task_t task);
571
b0d623f7
A
572extern void task_set_dyld_info(
573 task_t task,
574 mach_vm_address_t addr,
575 mach_vm_size_t size);
576
91447636
A
577/* Get number of activations in a task */
578extern int get_task_numacts(
579 task_t task);
580
b0d623f7 581extern int get_task_numactivethreads(task_t task);
3e170ce0 582extern kern_return_t task_collect_crash_info(task_t task);
0b4e3aa0 583
1c79356b 584/* JMM - should just be temporary (implementation in bsd_kern still) */
1c79356b 585extern void set_bsdtask_info(task_t,void *);
91447636 586extern vm_map_t get_task_map_reference(task_t);
6d2010ae 587extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t, boolean_t);
1c79356b 588extern pmap_t get_task_pmap(task_t);
b0d623f7 589extern uint64_t get_task_resident_size(task_t);
fe8ab488
A
590extern uint64_t get_task_compressed(task_t);
591extern uint64_t get_task_resident_max(task_t);
39236c6e
A
592extern uint64_t get_task_phys_footprint(task_t);
593extern uint64_t get_task_phys_footprint_max(task_t);
fe8ab488
A
594extern uint64_t get_task_purgeable_size(task_t);
595extern uint64_t get_task_cpu_time(task_t);
3e170ce0 596extern uint64_t get_task_dispatchqueue_offset(task_t);
39236c6e 597
3e170ce0 598extern kern_return_t task_convert_phys_footprint_limit(int, int *);
39236c6e
A
599extern kern_return_t task_set_phys_footprint_limit_internal(task_t, int, int *, boolean_t);
600extern kern_return_t task_get_phys_footprint_limit(task_t task, int *limit_mb);
9bccf70c 601
91447636 602extern boolean_t is_kerneltask(task_t task);
9bccf70c 603
2d21ac55
A
604extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast);
605
b0d623f7
A
606extern kern_return_t machine_task_get_state(
607 task_t task,
608 int flavor,
609 thread_state_t state,
610 mach_msg_type_number_t *state_count);
611
612extern kern_return_t machine_task_set_state(
613 task_t task,
614 int flavor,
615 thread_state_t state,
616 mach_msg_type_number_t state_count);
617
316670eb
A
618extern void machine_task_terminate(task_t task);
619
620struct _task_ledger_indices {
621 int cpu_time;
622 int tkm_private;
623 int tkm_shared;
624 int phys_mem;
625 int wired_mem;
fe8ab488
A
626 int internal;
627 int iokit_mapped;
628 int alternate_accounting;
3e170ce0 629 int alternate_accounting_compressed;
39236c6e 630 int phys_footprint;
fe8ab488
A
631 int internal_compressed;
632 int purgeable_volatile;
633 int purgeable_nonvolatile;
634 int purgeable_volatile_compressed;
635 int purgeable_nonvolatile_compressed;
4b17d6b6
A
636 int platform_idle_wakeups;
637 int interrupt_wakeups;
3e170ce0
A
638#if CONFIG_SCHED_SFI
639 int sfi_wait_times[MAX_SFI_CLASS_ID];
640#endif /* CONFIG_SCHED_SFI */
fe8ab488
A
641#ifdef CONFIG_BANK
642 int cpu_time_billed_to_me;
643 int cpu_time_billed_to_others;
644#endif
316670eb
A
645};
646extern struct _task_ledger_indices task_ledgers;
b0d623f7 647
39236c6e 648/* Begin task_policy */
6d2010ae 649
39236c6e
A
650/* value */
651#define TASK_POLICY_DISABLE 0x0
652#define TASK_POLICY_ENABLE 0x1
316670eb 653
39236c6e
A
654/* category */
655#define TASK_POLICY_INTERNAL 0x0
656#define TASK_POLICY_EXTERNAL 0x1
657#define TASK_POLICY_ATTRIBUTE 0x2
6d2010ae 658
39236c6e
A
659/* for tracing */
660#define TASK_POLICY_TASK 0x4
661#define TASK_POLICY_THREAD 0x8
6d2010ae 662
39236c6e
A
663/* flavors (also DBG_IMPORTANCE subclasses 0x20 - 0x3F) */
664
665/* internal or external, thread or task */
666#define TASK_POLICY_DARWIN_BG 0x21
667#define TASK_POLICY_IOPOL 0x22
668#define TASK_POLICY_IO 0x23
669#define TASK_POLICY_PASSIVE_IO 0x24
670
39236c6e
A
671/* internal, task only */
672#define TASK_POLICY_DARWIN_BG_IOPOL 0x27
673
674/* task-only attributes */
675#define TASK_POLICY_TAL 0x28
676#define TASK_POLICY_BOOST 0x29
677#define TASK_POLICY_ROLE 0x2A
678#define TASK_POLICY_SUPPRESSED_CPU 0x2B
679#define TASK_POLICY_TERMINATED 0x2C
680#define TASK_POLICY_NEW_SOCKETS_BG 0x2D
681#define TASK_POLICY_LOWPRI_CPU 0x2E
682#define TASK_POLICY_LATENCY_QOS 0x2F
683#define TASK_POLICY_THROUGH_QOS 0x30
684#define TASK_POLICY_WATCHERS_BG 0x31
685
fe8ab488
A
686#define TASK_POLICY_SFI_MANAGED 0x34
687#define TASK_POLICY_ALL_SOCKETS_BG 0x37
688
689#define TASK_POLICY_BASE_LATENCY_AND_THROUGHPUT_QOS 0x39 /* latency as value1, throughput as value2 */
690#define TASK_POLICY_OVERRIDE_LATENCY_AND_THROUGHPUT_QOS 0x3A /* latency as value1, throughput as value2 */
691
39236c6e
A
692/* thread-only attributes */
693#define TASK_POLICY_PIDBIND_BG 0x32
694#define TASK_POLICY_WORKQ_BG 0x33
fe8ab488
A
695#define TASK_POLICY_QOS 0x35
696#define TASK_POLICY_QOS_OVERRIDE 0x36
697#define TASK_POLICY_QOS_AND_RELPRIO 0x38 /* QoS as value1, relative priority as value2 */
39236c6e
A
698
699#define TASK_POLICY_MAX 0x3F
700
701/* The main entrance to task policy is this function */
702extern void proc_set_task_policy(task_t task, thread_t thread, int category, int flavor, int value);
703extern int proc_get_task_policy(task_t task, thread_t thread, int category, int flavor);
704
fe8ab488
A
705/* For attributes that have two scalars as input/output */
706extern void proc_set_task_policy2(task_t task, thread_t thread, int category, int flavor, int value1, int value2);
707extern void proc_get_task_policy2(task_t task, thread_t thread, int category, int flavor, int *value1, int *value2);
708
39236c6e
A
709/* For use by kernel threads and others who don't hold a reference on the target thread */
710extern void proc_set_task_policy_thread(task_t task, uint64_t tid, int category, int flavor, int value);
711
3e170ce0 712extern void proc_set_task_spawnpolicy(task_t task, int apptype, int qos_clamp, int role,
fe8ab488
A
713 ipc_port_t * portwatch_ports, int portwatch_count);
714
715extern void task_set_main_thread_qos(task_t task, thread_t main_thread);
39236c6e 716
3e170ce0
A
717extern int proc_darwin_role_to_task_role(int darwin_role, int* task_role);
718extern int proc_task_role_to_darwin_role(int task_role);
719
720
39236c6e
A
721/* IO Throttle tiers */
722#define THROTTLE_LEVEL_NONE -1
723#define THROTTLE_LEVEL_TIER0 0 /* IOPOL_NORMAL, IOPOL_DEFAULT, IOPOL_PASSIVE */
724
725#define THROTTLE_LEVEL_THROTTLED 1
726#define THROTTLE_LEVEL_TIER1 1 /* IOPOL_STANDARD */
727#define THROTTLE_LEVEL_TIER2 2 /* IOPOL_UTILITY */
728#define THROTTLE_LEVEL_TIER3 3 /* IOPOL_THROTTLE */
729
730#define THROTTLE_LEVEL_START 0
731#define THROTTLE_LEVEL_END 3
732
733#define THROTTLE_LEVEL_COMPRESSOR_TIER0 THROTTLE_LEVEL_TIER0
734#define THROTTLE_LEVEL_COMPRESSOR_TIER1 THROTTLE_LEVEL_TIER1
735#define THROTTLE_LEVEL_COMPRESSOR_TIER2 THROTTLE_LEVEL_TIER2
736
737#define THROTTLE_LEVEL_PAGEOUT_THROTTLED THROTTLE_LEVEL_TIER2
738#define THROTTLE_LEVEL_PAGEOUT_UNTHROTTLED THROTTLE_LEVEL_TIER1
739
fe8ab488
A
740#if CONFIG_IOSCHED
741#define IOSCHED_METADATA_TIER THROTTLE_LEVEL_TIER1
742#endif /* CONFIG_IOSCHED */
743
39236c6e
A
744extern int proc_apply_workq_bgthreadpolicy(thread_t thread);
745extern int proc_restore_workq_bgthreadpolicy(thread_t thread);
746
747extern int proc_get_darwinbgstate(task_t task, uint32_t *flagsp);
748extern boolean_t proc_task_is_tal(task_t task);
3e170ce0 749extern int task_get_apptype(task_t);
39236c6e
A
750extern integer_t task_grab_latency_qos(task_t task);
751extern void task_policy_create(task_t task, int parent_boosted);
fe8ab488
A
752extern void thread_policy_create(thread_t thread);
753
754/*
755 * for IPC importance hooks into task policy
756 */
757typedef struct task_pend_token {
758 uint32_t tpt_update_sockets :1,
759 tpt_update_timers :1,
760 tpt_update_watchers :1,
a1c7dba1
A
761 tpt_update_live_donor :1,
762 tpt_update_coal_sfi :1;
fe8ab488
A
763} *task_pend_token_t;
764
765extern void task_policy_update_complete_unlocked(task_t task, thread_t thread, task_pend_token_t pend_token);
766extern void task_update_boost_locked(task_t task, boolean_t boost_active, task_pend_token_t pend_token);
767extern void task_set_boost_locked(task_t task, boolean_t boost_active);
39236c6e
A
768
769/*
770 * Get effective policy
771 * Only for use by relevant subsystem, should never be passed into a setter!
772 */
773
774extern int proc_get_effective_task_policy(task_t task, int flavor);
775extern int proc_get_effective_thread_policy(thread_t thread, int flavor);
776
777/* temporary compatibility */
778int proc_setthread_saved_importance(thread_t thread, int importance);
779
780int proc_get_task_ruse_cpu(task_t task, uint32_t *policyp, uint8_t *percentagep, uint64_t *intervalp, uint64_t *deadlinep);
781int proc_set_task_ruse_cpu(task_t task, uint32_t policy, uint8_t percentage, uint64_t interval, uint64_t deadline, int cpumon_entitled);
782int proc_clear_task_ruse_cpu(task_t task, int cpumon_entitled);
783thread_t task_findtid(task_t, uint64_t);
784void set_thread_iotier_override(thread_t, int policy);
785
a1c7dba1
A
786boolean_t proc_thread_qos_add_override(task_t task, thread_t thread, uint64_t tid, int override_qos, boolean_t first_override_for_resource, user_addr_t resource, int resource_type);
787boolean_t proc_thread_qos_remove_override(task_t task, thread_t thread, uint64_t tid, user_addr_t resource, int resource_type);
788boolean_t proc_thread_qos_reset_override(task_t task, thread_t thread, uint64_t tid, user_addr_t resource, int resource_type);
789void proc_thread_qos_deallocate(thread_t thread);
fe8ab488 790
39236c6e
A
791#define TASK_RUSECPU_FLAGS_PROC_LIMIT 0x01
792#define TASK_RUSECPU_FLAGS_PERTHR_LIMIT 0x02
793#define TASK_RUSECPU_FLAGS_DEADLINE 0x04
794#define TASK_RUSECPU_FLAGS_FATAL_CPUMON 0x08 /* CPU usage monitor violations are fatal */
795#define TASK_RUSECPU_FLAGS_FATAL_WAKEUPSMON 0x10 /* wakeups monitor violations are fatal */
796#define TASK_RUSECPU_FLAGS_PHYS_FOOTPRINT_EXCEPTION 0x20 /* exceeding physical footprint generates EXC_RESOURCE */
6d2010ae
A
797
798/* BSD call back functions */
799extern int proc_apply_resource_actions(void * p, int type, int action);
800extern int proc_restore_resource_actions(void * p, int type, int action);
801extern int task_restore_resource_actions(task_t task, int type);
802
39236c6e
A
803extern int task_clear_cpuusage(task_t task, int cpumon_entitled);
804
805extern kern_return_t task_wakeups_monitor_ctl(task_t task, uint32_t *rate_hz, int32_t *flags);
806extern kern_return_t task_cpu_usage_monitor_ctl(task_t task, uint32_t *flags);
807
808
fe8ab488
A
809extern void task_importance_mark_donor(task_t task, boolean_t donating);
810extern void task_importance_mark_live_donor(task_t task, boolean_t donating);
811extern void task_importance_mark_receiver(task_t task, boolean_t receiving);
812extern void task_importance_mark_denap_receiver(task_t task, boolean_t denap);
813extern void task_importance_reset(task_t task);
814extern void task_atm_reset(task_t task);
490019cf
A
815extern void task_bank_reset(task_t task);
816extern void task_bank_init(task_t task);
39236c6e
A
817
818#if IMPORTANCE_INHERITANCE
fe8ab488 819
39236c6e 820extern boolean_t task_is_importance_donor(task_t task);
fe8ab488
A
821extern boolean_t task_is_marked_importance_donor(task_t task);
822extern boolean_t task_is_marked_live_importance_donor(task_t task);
823
39236c6e 824extern boolean_t task_is_importance_receiver(task_t task);
fe8ab488
A
825extern boolean_t task_is_marked_importance_receiver(task_t task);
826
827extern boolean_t task_is_importance_denap_receiver(task_t task);
828extern boolean_t task_is_marked_importance_denap_receiver(task_t task);
39236c6e 829
fe8ab488
A
830extern boolean_t task_is_importance_receiver_type(task_t task);
831
832extern int task_importance_hold_watchport_assertion(task_t target_task, uint32_t count);
39236c6e
A
833extern int task_importance_hold_internal_assertion(task_t target_task, uint32_t count);
834extern int task_importance_drop_internal_assertion(task_t target_task, uint32_t count);
835
fe8ab488
A
836extern int task_importance_hold_file_lock_assertion(task_t target_task, uint32_t count);
837extern int task_importance_drop_file_lock_assertion(task_t target_task, uint32_t count);
39236c6e 838
fe8ab488
A
839extern int task_importance_hold_legacy_external_assertion(task_t target_task, uint32_t count);
840extern int task_importance_drop_legacy_external_assertion(task_t target_task, uint32_t count);
39236c6e 841
fe8ab488 842#endif /* IMPORTANCE_INHERITANCE */
39236c6e 843
3e170ce0 844extern int task_low_mem_privileged_listener(task_t task, boolean_t new_value, boolean_t *old_value);
39236c6e
A
845extern boolean_t task_has_been_notified(task_t task, int pressurelevel);
846extern boolean_t task_used_for_purging(task_t task, int pressurelevel);
847extern void task_mark_has_been_notified(task_t task, int pressurelevel);
848extern void task_mark_used_for_purging(task_t task, int pressurelevel);
849extern void task_clear_has_been_notified(task_t task, int pressurelevel);
850extern void task_clear_used_for_purging(task_t task);
851extern int task_importance_estimate(task_t task);
852
3e170ce0 853extern int task_pid(task_t task);
39236c6e
A
854
855/* End task_policy */
316670eb 856
fe8ab488
A
857extern kern_return_t task_purge_volatile_memory(task_t task);
858
859extern void task_set_gpu_denied(task_t task, boolean_t denied);
860extern boolean_t task_is_gpu_denied(task_t task);
861
4bd07ac2
A
862#define TASK_WRITE_IMMEDIATE 0x1
863#define TASK_WRITE_DEFERRED 0x2
864#define TASK_WRITE_INVALIDATED 0x4
865#define TASK_WRITE_METADATA 0x8
866extern void task_update_logical_writes(task_t task, uint32_t io_size, int flags);
867
91447636 868#endif /* XNU_KERNEL_PRIVATE */
9bccf70c 869
91447636 870#ifdef KERNEL_PRIVATE
9bccf70c 871
91447636 872extern void *get_bsdtask_info(task_t);
2d21ac55 873extern void *get_bsdthreadtask_info(thread_t);
3e170ce0 874extern void task_bsdtask_kill(task_t);
91447636 875extern vm_map_t get_task_map(task_t);
316670eb
A
876extern ledger_t get_task_ledger(task_t);
877
878extern boolean_t get_task_pidsuspended(task_t);
879extern boolean_t get_task_frozen(task_t);
880
881/* Convert from a task to a port */
882extern ipc_port_t convert_task_to_port(task_t);
316670eb 883extern ipc_port_t convert_task_name_to_port(task_name_t);
39236c6e
A
884extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task);
885
886/* Convert from a port (in this case, an SO right to a task's resume port) to a task. */
887extern task_suspension_token_t convert_port_to_task_suspension_token(ipc_port_t port);
888
889extern boolean_t task_suspension_notify(mach_msg_header_t *);
9bccf70c 890
91447636 891#endif /* KERNEL_PRIVATE */
9bccf70c 892
91447636
A
893extern task_t kernel_task;
894
895extern void task_deallocate(
896 task_t task);
9bccf70c 897
0c530ab8
A
898extern void task_name_deallocate(
899 task_name_t task_name);
39236c6e
A
900
901extern void task_suspension_token_deallocate(
902 task_suspension_token_t token);
91447636 903__END_DECLS
9bccf70c 904
1c79356b 905#endif /* _KERN_TASK_H_ */