2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * @OSF_FREE_COPYRIGHT@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr.
62 * This file contains the structure definitions for tasks.
66 * Copyright (c) 1993 The University of Utah and
67 * the Computer Systems Laboratory (CSL). All rights reserved.
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.
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.
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.
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,
88 * Copyright (c) 2005 SPARTA, Inc.
94 #include <kern/kern_types.h>
95 #include <mach/mach_types.h>
96 #include <sys/cdefs.h>
98 #ifdef XNU_KERNEL_PRIVATE
99 #include <kern/kern_cdata.h>
100 #include <mach/sfi_class.h>
101 #include <kern/queue.h>
102 #include <sys/kern_sysctl.h>
103 #endif /* XNU_KERNEL_PRIVATE */
105 #ifdef MACH_KERNEL_PRIVATE
107 #include <mach/boolean.h>
108 #include <mach/port.h>
109 #include <mach/time_value.h>
110 #include <mach/message.h>
111 #include <mach/mach_param.h>
112 #include <mach/task_info.h>
113 #include <mach/exception_types.h>
114 #include <mach/vm_statistics.h>
115 #include <machine/task.h>
118 #include <machine/monotonic.h>
119 #endif /* MONOTONIC */
121 #include <kern/cpu_data.h>
122 #include <kern/queue.h>
123 #include <kern/exception.h>
124 #include <kern/locks.h>
125 #include <security/_label.h>
126 #include <ipc/ipc_port.h>
128 #include <kern/thread.h>
129 #include <mach/coalition.h>
130 #include <stdatomic.h>
131 #include <os/refcnt.h>
134 #include <atm/atm_internal.h>
137 struct _cpu_time_qos_stats
{
138 uint64_t cpu_time_qos_default
;
139 uint64_t cpu_time_qos_maintenance
;
140 uint64_t cpu_time_qos_background
;
141 uint64_t cpu_time_qos_utility
;
142 uint64_t cpu_time_qos_legacy
;
143 uint64_t cpu_time_qos_user_initiated
;
144 uint64_t cpu_time_qos_user_interactive
;
147 struct task_writes_counters
{
148 uint64_t task_immediate_writes
;
149 uint64_t task_deferred_writes
;
150 uint64_t task_invalidated_writes
;
151 uint64_t task_metadata_writes
;
154 struct task_watchports
;
155 #include <bank/bank_internal.h>
158 /* Synchronization/destruction information */
159 decl_lck_mtx_data(, lock
); /* Task's lock */
160 os_refcnt_t ref_count
; /* Number of references to me */
161 boolean_t active
; /* Task has not been terminated */
162 boolean_t halting
; /* Task is being halted */
163 boolean_t message_app_suspended
; /* Let iokit know when pidsuspended */
169 vm_map_t map
; /* Address space description */
170 queue_chain_t tasks
; /* global list of tasks */
171 struct task_watchports
*watchports
; /* watchports passed in spawn */
172 turnstile_inheritor_t returnwait_inheritor
; /* inheritor for task_wait */
174 #if defined(CONFIG_SCHED_MULTIQ)
175 sched_group_t sched_group
;
176 #endif /* defined(CONFIG_SCHED_MULTIQ) */
178 /* Threads in this task */
179 queue_head_t threads
;
180 struct restartable_ranges
*restartable_ranges
;
182 processor_set_t pset_hint
;
183 struct affinity_space
*affinity_space
;
186 uint32_t active_thread_count
;
187 int suspend_count
; /* Internal scheduling only */
189 /* User-visible scheduling information */
190 integer_t user_stop_count
; /* outstanding stops */
191 integer_t legacy_stop_count
; /* outstanding legacy stops */
193 integer_t priority
; /* base priority for threads */
194 integer_t max_priority
; /* maximum priority for threads */
196 integer_t importance
; /* priority offset (BSD 'nice' value) */
198 /* Task security and audit tokens */
199 security_token_t sec_token
;
200 audit_token_t audit_token
;
203 uint64_t total_user_time
; /* terminated threads only */
204 uint64_t total_system_time
;
205 uint64_t total_ptime
;
206 uint64_t total_runnable_time
;
209 decl_lck_mtx_data(, itk_lock_data
);
210 struct ipc_port
*itk_self
; /* not a right, doesn't hold ref */
211 struct ipc_port
*itk_nself
; /* not a right, doesn't hold ref */
212 struct ipc_port
*itk_sself
; /* a send right */
213 struct exception_action exc_actions
[EXC_TYPES_COUNT
];
214 /* a send right each valid element */
215 struct ipc_port
*itk_host
; /* a send right */
216 struct ipc_port
*itk_bootstrap
; /* a send right */
217 struct ipc_port
*itk_seatbelt
; /* a send right */
218 struct ipc_port
*itk_gssd
; /* yet another send right */
219 struct ipc_port
*itk_debug_control
; /* send right for debugmode communications */
220 struct ipc_port
*itk_task_access
; /* and another send right */
221 struct ipc_port
*itk_resume
; /* a receive right to resume this task */
222 struct ipc_port
*itk_registered
[TASK_PORT_REGISTER_MAX
];
223 /* all send rights */
225 struct ipc_space
*itk_space
;
228 /* Synchronizer ownership information */
229 queue_head_t semaphore_list
; /* list of owned semaphores */
230 int semaphores_owned
; /* number of semaphores owned */
232 unsigned int priv_flags
; /* privilege resource flags */
233 #define VM_BACKING_STORE_PRIV 0x1
237 integer_t faults
; /* faults counter */
238 integer_t decompressions
; /* decompression counter */
239 integer_t pageins
; /* pageins counter */
240 integer_t cow_faults
; /* copy on write fault counter */
241 integer_t messages_sent
; /* messages sent counter */
242 integer_t messages_received
; /* messages received counter */
243 integer_t syscalls_mach
; /* mach system call counter */
244 integer_t syscalls_unix
; /* unix system call counter */
245 uint32_t c_switch
; /* total context switches */
246 uint32_t p_switch
; /* total processor switches */
247 uint32_t ps_switch
; /* total pset switches */
252 kcdata_descriptor_t corpse_info
;
253 uint64_t crashed_thread_id
;
254 queue_chain_t corpse_tasks
;
256 struct label
* crash_label
;
258 struct vm_shared_region
*shared_region
;
259 volatile uint32_t t_flags
; /* general-purpose task flags protected by task_lock (TL) */
261 #define TF_64B_ADDR 0x00000001 /* task has 64-bit addressing */
262 #define TF_64B_DATA 0x00000002 /* task has 64-bit data registers */
263 #define TF_CPUMON_WARNING 0x00000004 /* task has at least one thread in CPU usage warning zone */
264 #define TF_WAKEMON_WARNING 0x00000008 /* task is in wakeups monitor warning zone */
265 #define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */
266 #define TF_GPU_DENIED 0x00000010 /* task is not allowed to access the GPU */
267 #define TF_CORPSE 0x00000020 /* task is a corpse */
268 #define TF_PENDING_CORPSE 0x00000040 /* task corpse has not been reported yet */
269 #define TF_CORPSE_FORK 0x00000080 /* task is a forked corpse */
270 #define TF_PLATFORM 0x00000400 /* task is a platform binary */
271 #define TF_CA_CLIENT_WI 0x00000800 /* task has CA_CLIENT work interval */
272 #define TF_DARKWAKE_MODE 0x00001000 /* task is in darkwake mode */
273 #define TF_NO_SMT 0x00002000 /* task threads must not be paired with SMT threads */
276 * Task is running within a 64-bit address space.
278 #define task_has_64Bit_addr(task) \
279 (((task)->t_flags & TF_64B_ADDR) != 0)
280 #define task_set_64Bit_addr(task) \
281 ((task)->t_flags |= TF_64B_ADDR)
282 #define task_clear_64Bit_addr(task) \
283 ((task)->t_flags &= ~TF_64B_ADDR)
286 * Task is using 64-bit machine state.
288 #define task_has_64Bit_data(task) \
289 (((task)->t_flags & TF_64B_DATA) != 0)
290 #define task_set_64Bit_data(task) \
291 ((task)->t_flags |= TF_64B_DATA)
292 #define task_clear_64Bit_data(task) \
293 ((task)->t_flags &= ~TF_64B_DATA)
295 #define task_is_a_corpse(task) \
296 (((task)->t_flags & TF_CORPSE) != 0)
298 #define task_set_corpse(task) \
299 ((task)->t_flags |= TF_CORPSE)
301 #define task_corpse_pending_report(task) \
302 (((task)->t_flags & TF_PENDING_CORPSE) != 0)
304 #define task_set_corpse_pending_report(task) \
305 ((task)->t_flags |= TF_PENDING_CORPSE)
307 #define task_clear_corpse_pending_report(task) \
308 ((task)->t_flags &= ~TF_PENDING_CORPSE)
310 #define task_is_a_corpse_fork(task) \
311 (((task)->t_flags & TF_CORPSE_FORK) != 0)
313 uint32_t t_procflags
; /* general-purpose task flags protected by proc_lock (PL) */
315 #define TPF_DID_EXEC 0x00000001 /* task has been execed to a new task */
316 #define TPF_EXEC_COPY 0x00000002 /* task is the new copy of an exec */
317 #ifdef CONFIG_32BIT_TELEMETRY
318 #define TPF_LOG_32BIT_TELEMETRY 0x00000004 /* task should log identifying information */
321 #define task_did_exec_internal(task) \
322 (((task)->t_procflags & TPF_DID_EXEC) != 0)
324 #define task_is_exec_copy_internal(task) \
325 (((task)->t_procflags & TPF_EXEC_COPY) != 0)
327 uint8_t t_returnwaitflags
;
329 #define TRW_LRETURNWAIT 0x01 /* task is waiting for fork/posix_spawn/exec to complete */
330 #define TRW_LRETURNWAITER 0x02 /* task is waiting for TRW_LRETURNWAIT to get cleared */
332 mach_vm_address_t all_image_info_addr
; /* dyld __all_image_info */
333 mach_vm_size_t all_image_info_size
; /* section location and size */
336 #define TASK_KPC_FORCED_ALL_CTRS 0x2 /* Bit in "t_kpc" signifying this task forced all counters */
337 uint32_t t_kpc
; /* kpc flags */
340 boolean_t pidsuspended
; /* pid_suspend called; no threads can execute */
341 boolean_t frozen
; /* frozen; private resident pages committed to swap */
342 boolean_t changing_freeze_state
; /* in the process of freezing or thawing */
343 uint16_t policy_ru_cpu
:4,
344 policy_ru_cpu_ext
:4,
346 applied_ru_cpu_ext
:4;
347 uint8_t rusage_cpu_flags
;
348 uint8_t rusage_cpu_percentage
; /* Task-wide CPU limit percentage */
349 uint8_t rusage_cpu_perthr_percentage
; /* Per-thread CPU limit percentage */
351 int8_t suspends_outstanding
; /* suspends this task performed in excess of resumes */
353 uint64_t rusage_cpu_interval
; /* Task-wide CPU limit interval */
354 uint64_t rusage_cpu_perthr_interval
; /* Per-thread CPU limit interval */
355 uint64_t rusage_cpu_deadline
;
356 thread_call_t rusage_cpu_callt
;
358 queue_head_t task_watchers
; /* app state watcher threads */
359 int num_taskwatchers
;
361 #endif /* CONFIG_EMBEDDED */
364 struct atm_task_descriptor
*atm_context
; /* pointer to per task atm descriptor */
366 struct bank_task
*bank_context
; /* pointer to per task bank structure */
368 #if IMPORTANCE_INHERITANCE
369 struct ipc_importance_task
*task_imp_base
; /* Base of IPC importance chain */
370 #endif /* IMPORTANCE_INHERITANCE */
372 vm_extmod_statistics_data_t extmod_statistics
;
374 struct task_requested_policy requested_policy
;
375 struct task_effective_policy effective_policy
;
378 * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away.
380 uint32_t low_mem_notified_warn
:1, /* warning low memory notification is sent to the task */
381 low_mem_notified_critical
:1, /* critical low memory notification is sent to the task */
382 purged_memory_warn
:1, /* purgeable memory of the task is purged for warning level pressure */
383 purged_memory_critical
:1, /* purgeable memory of the task is purged for critical level pressure */
384 low_mem_privileged_listener
:1, /* if set, task would like to know about pressure changes before other tasks on the system */
385 mem_notify_reserved
:27; /* reserved for future use */
387 uint32_t memlimit_is_active
:1, /* if set, use active attributes, otherwise use inactive attributes */
388 memlimit_is_fatal
:1, /* if set, exceeding current memlimit will prove fatal to the task */
389 memlimit_active_exc_resource
:1, /* if set, suppress exc_resource exception when task exceeds active memory limit */
390 memlimit_inactive_exc_resource
:1, /* if set, suppress exc_resource exception when task exceeds inactive memory limit */
391 memlimit_attrs_reserved
:28; /* reserved for future use */
393 io_stat_info_t task_io_stats
;
395 struct task_writes_counters task_writes_counters_internal
;
396 struct task_writes_counters task_writes_counters_external
;
399 * The cpu_time_qos_stats fields are protected by the task lock
401 struct _cpu_time_qos_stats cpu_time_eqos_stats
;
402 struct _cpu_time_qos_stats cpu_time_rqos_stats
;
404 /* Statistics accumulated for terminated threads from this task */
405 uint32_t task_timer_wakeups_bin_1
;
406 uint32_t task_timer_wakeups_bin_2
;
407 uint64_t task_gpu_ns
;
408 uint64_t task_energy
;
411 /* Read and written under task_lock */
412 struct mt_task task_monotonic
;
413 #endif /* MONOTONIC */
415 uint8_t task_can_transfer_memory_ownership
;
416 uint8_t task_objects_disowning
;
417 uint8_t task_objects_disowned
;
418 /* # of purgeable volatile VM objects owned by this task: */
419 int task_volatile_objects
;
420 /* # of purgeable but not volatile VM objects owned by this task: */
421 int task_nonvolatile_objects
;
422 int task_owned_objects
;
423 queue_head_t task_objq
;
424 decl_lck_mtx_data(, task_objq_lock
); /* protects "task_objq" */
426 unsigned int task_thread_limit
:16;
428 unsigned int task_legacy_footprint
:1;
429 unsigned int task_extra_footprint_limit
:1;
430 unsigned int task_ios13extended_footprint_limit
:1;
431 #endif /* __arm64__ */
432 unsigned int task_region_footprint
:1;
433 unsigned int task_has_crossed_thread_limit
:1;
436 * A task's coalition set is "adopted" in task_create_internal
437 * and unset in task_deallocate_internal, so each array member
438 * can be referenced without the task lock.
439 * Note: these fields are protected by coalition->lock,
442 coalition_t coalition
[COALITION_NUM_TYPES
];
443 queue_chain_t task_coalition
[COALITION_NUM_TYPES
];
444 uint64_t dispatchqueue_offset
;
446 #if DEVELOPMENT || DEBUG
447 boolean_t task_unnested
;
448 int task_disconnected_count
;
452 void *hv_task_target
; /* hypervisor virtual machine object associated with this task */
453 #endif /* HYPERVISOR */
455 #if CONFIG_SECLUDED_MEMORY
456 uint8_t task_can_use_secluded_mem
;
457 uint8_t task_could_use_secluded_mem
;
458 uint8_t task_could_also_use_secluded_mem
;
459 uint8_t task_suppressed_secluded
;
460 #endif /* CONFIG_SECLUDED_MEMORY */
462 task_exc_guard_behavior_t task_exc_guard
;
464 queue_head_t io_user_clients
;
466 mach_vm_address_t mach_header_vm_address
;
468 uint32_t loadTag
; /* dext ID used for logging identity */
472 * EXC_GUARD default delivery behavior for optional Mach port and VM guards.
473 * Applied to new tasks at creation time.
475 extern task_exc_guard_behavior_t task_exc_guard_default
;
478 task_violated_guard(mach_exception_code_t
, mach_exception_subcode_t
, void *);
480 #define task_lock(task) lck_mtx_lock(&(task)->lock)
481 #define task_lock_assert_owned(task) LCK_MTX_ASSERT(&(task)->lock, LCK_MTX_ASSERT_OWNED)
482 #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock)
483 #define task_unlock(task) lck_mtx_unlock(&(task)->lock)
485 #define task_objq_lock_init(task) lck_mtx_init(&(task)->task_objq_lock, &vm_object_lck_grp, &vm_object_lck_attr)
486 #define task_objq_lock(task) lck_mtx_lock(&(task)->task_objq_lock)
487 #define task_objq_lock_assert_owned(task) LCK_MTX_ASSERT(&(task)->task_objq_lock, LCK_MTX_ASSERT_OWNED)
488 #define task_objq_lock_try(task) lck_mtx_try_lock(&(task)->task_objq_lock)
489 #define task_objq_unlock(task) lck_mtx_unlock(&(task)->task_objq_lock)
491 #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
492 #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
493 #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data)
494 #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data)
496 /* task clear return wait flags */
497 #define TCRW_CLEAR_INITIAL_WAIT 0x1
498 #define TCRW_CLEAR_FINAL_WAIT 0x2
499 #define TCRW_CLEAR_ALL_WAIT (TCRW_CLEAR_INITIAL_WAIT | TCRW_CLEAR_FINAL_WAIT)
501 #define TASK_REFERENCE_LEAK_DEBUG 0
503 #if TASK_REFERENCE_LEAK_DEBUG
504 extern void task_reference_internal(task_t task
);
505 extern os_ref_count_t
task_deallocate_internal(task_t task
);
507 #define task_reference_internal(task) os_ref_retain(&(task)->ref_count)
508 #define task_deallocate_internal(task) os_ref_release(&(task)->ref_count)
511 #define task_reference(task) \
513 if ((task) != TASK_NULL) \
514 task_reference_internal(task); \
517 extern kern_return_t
kernel_task_create(
519 vm_offset_t map_base
,
523 /* Initialize task module */
524 extern void task_init(void);
526 /* coalition_init() calls this to initialize ledgers before task_init() */
527 extern void init_task_ledgers(void);
529 #define current_task_fast() (current_thread()->task)
530 #define current_task() current_task_fast()
532 extern bool task_is_driver(task_t task
);
534 extern lck_attr_t task_lck_attr
;
535 extern lck_grp_t task_lck_grp
;
537 struct task_watchport_elem
{
539 ipc_port_t twe_port
; /* (Space lock) */
542 struct task_watchports
{
543 os_refcnt_t tw_refcount
; /* (Space lock) */
544 task_t tw_task
; /* (Space lock) & tw_refcount == 0 */
545 thread_t tw_thread
; /* (Space lock) & tw_refcount == 0 */
546 uint32_t tw_elem_array_count
; /* (Space lock) */
547 struct task_watchport_elem tw_elem
[]; /* (Space lock) & (Portlock) & (mq lock) */
550 #define task_watchports_retain(x) (os_ref_retain(&(x)->tw_refcount))
551 #define task_watchports_release(x) (os_ref_release(&(x)->tw_refcount))
553 #define task_watchport_elem_init(elem, task, port) \
555 (elem)->twe_task = (task); \
556 (elem)->twe_port = (port); \
559 #define task_watchport_elem_clear(elem) task_watchport_elem_init((elem), NULL, NULL)
562 task_add_turnstile_watchports(
565 ipc_port_t
*portwatch_ports
,
566 uint32_t portwatch_count
);
569 task_watchport_elem_deallocate(
570 struct task_watchport_elem
*watchport_elem
);
573 task_has_watchports(task_t task
);
575 #else /* MACH_KERNEL_PRIVATE */
579 extern task_t
current_task(void);
581 extern void task_reference(task_t task
);
582 extern bool task_is_driver(task_t task
);
587 #define TRW_LRETURNWAIT 0x01 /* task is waiting for fork/posix_spawn/exec to complete */
588 #define TRW_LRETURNWAITER 0x02 /* task is waiting for TRW_LRETURNWAIT to get cleared */
590 /* task clear return wait flags */
591 #define TCRW_CLEAR_INITIAL_WAIT 0x1
592 #define TCRW_CLEAR_FINAL_WAIT 0x2
593 #define TCRW_CLEAR_ALL_WAIT (TCRW_CLEAR_INITIAL_WAIT | TCRW_CLEAR_FINAL_WAIT)
597 #define TPF_EXEC_COPY 0x00000002 /* task is the new copy of an exec */
602 #endif /* MACH_KERNEL_PRIVATE */
606 #ifdef KERNEL_PRIVATE
607 extern boolean_t
task_is_app_suspended(task_t task
);
610 #ifdef XNU_KERNEL_PRIVATE
612 /* Hold all threads in a task */
613 extern kern_return_t
task_hold(
616 /* Wait for task to stop running, either just to get off CPU or to cease being runnable */
617 extern kern_return_t
task_wait(
619 boolean_t until_not_runnable
);
621 /* Release hold on all threads in a task */
622 extern kern_return_t
task_release(
625 /* Suspend/resume a task where the kernel owns the suspend count */
626 extern kern_return_t
task_suspend_internal( task_t task
);
627 extern kern_return_t
task_resume_internal( task_t task
);
629 /* Suspends a task by placing a hold on its threads */
630 extern kern_return_t
task_pidsuspend(
633 /* Resumes a previously paused task */
634 extern kern_return_t
task_pidresume(
637 extern kern_return_t
task_send_trace_memory(
642 extern void task_remove_turnstile_watchports(
645 extern void task_transfer_turnstile_watchports(
648 thread_t new_thread
);
650 #if DEVELOPMENT || DEBUG
652 extern kern_return_t
task_disconnect_page_mappings(
656 extern void tasks_system_suspend(boolean_t suspend
);
660 /* Freeze a task's resident pages */
661 extern kern_return_t
task_freeze(
663 uint32_t *purgeable_count
,
664 uint32_t *wired_count
,
665 uint32_t *clean_count
,
666 uint32_t *dirty_count
,
667 uint32_t dirty_budget
,
668 uint32_t *shared_count
,
669 int *freezer_error_code
,
670 boolean_t eval_only
);
672 /* Thaw a currently frozen task */
673 extern kern_return_t
task_thaw(
676 #endif /* CONFIG_FREEZE */
678 /* Halt all other threads in the current task */
679 extern kern_return_t
task_start_halt(
682 /* Wait for other threads to halt and free halting task resources */
683 extern void task_complete_halt(
686 extern kern_return_t
task_terminate_internal(
689 extern kern_return_t
task_create_internal(
691 coalition_t
*parent_coalitions
,
692 boolean_t inherit_memory
,
694 boolean_t is_64bit_data
,
697 uint8_t t_returnwaitflags
,
698 task_t
*child_task
); /* OUT */
700 extern kern_return_t
task_set_special_port_internal(
705 extern kern_return_t
task_info(
707 task_flavor_t flavor
,
708 task_info_t task_info_out
,
709 mach_msg_type_number_t
*task_info_count
);
711 extern void task_power_info_locked(
713 task_power_info_t info
,
714 gpu_energy_data_t gpu_energy
,
715 task_power_info_v2_t infov2
,
716 uint64_t *runnable_time
);
718 extern uint64_t task_gpu_utilisation(
721 extern uint64_t task_energy(
724 extern uint64_t task_cpu_ptime(
726 extern void task_update_cpu_time_qos_stats(
728 uint64_t *eqos_stats
,
729 uint64_t *rqos_stats
);
731 extern void task_vtimer_set(
735 extern void task_vtimer_clear(
739 extern void task_vtimer_update(
742 uint32_t *microsecs
);
744 #define TASK_VTIMER_USER 0x01
745 #define TASK_VTIMER_PROF 0x02
746 #define TASK_VTIMER_RLIM 0x04
748 extern void task_set_64bit(
751 boolean_t is_64bit_data
);
753 extern boolean_t
task_get_64bit_data(
756 extern void task_set_platform_binary(
758 boolean_t is_platform
);
759 extern bool task_set_ca_client_wi(
761 boolean_t ca_client_wi
);
763 extern void task_set_dyld_info(
765 mach_vm_address_t addr
,
766 mach_vm_size_t size
);
768 extern void task_set_mach_header_address(
770 mach_vm_address_t addr
);
772 /* Get number of activations in a task */
773 extern int get_task_numacts(
777 extern kern_return_t
task_collect_crash_info(
780 struct label
*crash_label
,
783 void task_port_notify(mach_msg_header_t
*msg
);
784 void task_wait_till_threads_terminate_locked(task_t task
);
786 /* JMM - should just be temporary (implementation in bsd_kern still) */
787 extern void set_bsdtask_info(task_t
, void *);
788 extern uint32_t set_task_loadTag(task_t task
, uint32_t loadTag
);
789 extern vm_map_t
get_task_map_reference(task_t
);
790 extern vm_map_t
swap_task_map(task_t
, thread_t
, vm_map_t
);
791 extern pmap_t
get_task_pmap(task_t
);
792 extern uint64_t get_task_resident_size(task_t
);
793 extern uint64_t get_task_compressed(task_t
);
794 extern uint64_t get_task_resident_max(task_t
);
795 extern uint64_t get_task_phys_footprint(task_t
);
796 #if CONFIG_LEDGER_INTERVAL_MAX
797 extern uint64_t get_task_phys_footprint_interval_max(task_t
, int reset
);
798 #endif /* CONFIG_FOOTPRINT_INTERVAL_MAX */
799 extern uint64_t get_task_phys_footprint_lifetime_max(task_t
);
800 extern uint64_t get_task_phys_footprint_limit(task_t
);
801 extern uint64_t get_task_purgeable_size(task_t
);
802 extern uint64_t get_task_cpu_time(task_t
);
803 extern uint64_t get_task_dispatchqueue_offset(task_t
);
804 extern uint64_t get_task_dispatchqueue_serialno_offset(task_t
);
805 extern uint64_t get_task_dispatchqueue_label_offset(task_t
);
806 extern uint64_t get_task_uniqueid(task_t task
);
807 extern int get_task_version(task_t task
);
809 extern uint64_t get_task_internal(task_t
);
810 extern uint64_t get_task_internal_compressed(task_t
);
811 extern uint64_t get_task_purgeable_nonvolatile(task_t
);
812 extern uint64_t get_task_purgeable_nonvolatile_compressed(task_t
);
813 extern uint64_t get_task_iokit_mapped(task_t
);
814 extern uint64_t get_task_alternate_accounting(task_t
);
815 extern uint64_t get_task_alternate_accounting_compressed(task_t
);
816 extern uint64_t get_task_memory_region_count(task_t
);
817 extern uint64_t get_task_page_table(task_t
);
818 extern uint64_t get_task_network_nonvolatile(task_t
);
819 extern uint64_t get_task_network_nonvolatile_compressed(task_t
);
820 extern uint64_t get_task_wired_mem(task_t
);
821 extern uint32_t get_task_loadTag(task_t task
);
823 extern kern_return_t
task_convert_phys_footprint_limit(int, int *);
824 extern kern_return_t
task_set_phys_footprint_limit_internal(task_t
, int, int *, boolean_t
, boolean_t
);
825 extern kern_return_t
task_get_phys_footprint_limit(task_t task
, int *limit_mb
);
827 /* Jetsam memlimit attributes */
828 extern boolean_t
task_get_memlimit_is_active(task_t task
);
829 extern boolean_t
task_get_memlimit_is_fatal(task_t task
);
830 extern void task_set_memlimit_is_active(task_t task
, boolean_t memlimit_is_active
);
831 extern void task_set_memlimit_is_fatal(task_t task
, boolean_t memlimit_is_fatal
);
832 extern boolean_t
task_has_triggered_exc_resource(task_t task
, boolean_t memlimit_is_active
);
833 extern void task_mark_has_triggered_exc_resource(task_t task
, boolean_t memlimit_is_active
);
835 extern void task_set_thread_limit(task_t task
, uint16_t thread_limit
);
838 extern boolean_t
is_kerneltask(task_t task
);
839 extern boolean_t
is_corpsetask(task_t task
);
841 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
843 extern kern_return_t
machine_task_get_state(
846 thread_state_t state
,
847 mach_msg_type_number_t
*state_count
);
849 extern kern_return_t
machine_task_set_state(
852 thread_state_t state
,
853 mach_msg_type_number_t state_count
);
855 extern void machine_task_terminate(task_t task
);
857 struct _task_ledger_indices
{
865 int alternate_accounting
;
866 int alternate_accounting_compressed
;
869 int internal_compressed
;
870 int purgeable_volatile
;
871 int purgeable_nonvolatile
;
872 int purgeable_volatile_compressed
;
873 int purgeable_nonvolatile_compressed
;
874 int tagged_nofootprint
;
875 int tagged_footprint
;
876 int tagged_nofootprint_compressed
;
877 int tagged_footprint_compressed
;
878 int network_volatile
;
879 int network_nonvolatile
;
880 int network_volatile_compressed
;
881 int network_nonvolatile_compressed
;
882 int media_nofootprint
;
884 int media_nofootprint_compressed
;
885 int media_footprint_compressed
;
886 int graphics_nofootprint
;
887 int graphics_footprint
;
888 int graphics_nofootprint_compressed
;
889 int graphics_footprint_compressed
;
890 int neural_nofootprint
;
891 int neural_footprint
;
892 int neural_nofootprint_compressed
;
893 int neural_footprint_compressed
;
894 int platform_idle_wakeups
;
895 int interrupt_wakeups
;
897 int sfi_wait_times
[MAX_SFI_CLASS_ID
];
898 #endif /* CONFIG_SCHED_SFI */
899 int cpu_time_billed_to_me
;
900 int cpu_time_billed_to_others
;
903 int logical_writes_to_external
;
904 int energy_billed_to_me
;
905 int energy_billed_to_others
;
906 #if DEBUG || DEVELOPMENT
908 int pages_grabbed_kern
;
909 int pages_grabbed_iopl
;
910 int pages_grabbed_upl
;
913 extern struct _task_ledger_indices task_ledgers
;
915 /* requires task to be unlocked, returns a referenced thread */
916 thread_t
task_findtid(task_t task
, uint64_t tid
);
917 int pid_from_task(task_t task
);
919 extern kern_return_t
task_wakeups_monitor_ctl(task_t task
, uint32_t *rate_hz
, int32_t *flags
);
920 extern kern_return_t
task_cpu_usage_monitor_ctl(task_t task
, uint32_t *flags
);
921 extern void task_rollup_accounting_info(task_t new_task
, task_t parent_task
);
922 extern kern_return_t
task_io_monitor_ctl(task_t task
, uint32_t *flags
);
923 extern void task_set_did_exec_flag(task_t task
);
924 extern void task_clear_exec_copy_flag(task_t task
);
925 extern boolean_t
task_is_exec_copy(task_t
);
926 extern boolean_t
task_did_exec(task_t task
);
927 #ifdef CONFIG_32BIT_TELEMETRY
928 extern boolean_t
task_consume_32bit_log_flag(task_t task
);
929 extern void task_set_32bit_log_flag(task_t task
);
930 #endif /* CONFIG_32BIT_TELEMETRY */
931 extern boolean_t
task_is_active(task_t task
);
932 extern boolean_t
task_is_halting(task_t task
);
933 extern void task_clear_return_wait(task_t task
, uint32_t flags
);
934 extern void task_wait_to_return(void) __attribute__((noreturn
));
935 extern event_t
task_get_return_wait_event(task_t task
);
937 extern void task_atm_reset(task_t task
);
938 extern void task_bank_reset(task_t task
);
939 extern void task_bank_init(task_t task
);
942 extern void task_prep_arcade(task_t task
, thread_t thread
);
943 #endif /* CONFIG_ARCADE */
945 extern int task_pid(task_t task
);
946 extern boolean_t
task_has_assertions(task_t task
);
947 /* End task_policy */
949 extern void task_set_gpu_denied(task_t task
, boolean_t denied
);
950 extern boolean_t
task_is_gpu_denied(task_t task
);
952 extern queue_head_t
* task_io_user_clients(task_t task
);
953 extern void task_set_message_app_suspended(task_t task
, boolean_t enable
);
955 extern void task_copy_fields_for_exec(task_t dst_task
, task_t src_task
);
957 extern void task_copy_vmobjects(task_t task
, vm_object_query_t query
, int len
, int64_t* num
);
959 #endif /* XNU_KERNEL_PRIVATE */
961 #ifdef KERNEL_PRIVATE
963 extern void *get_bsdtask_info(task_t
);
964 extern void *get_bsdthreadtask_info(thread_t
);
965 extern void task_bsdtask_kill(task_t
);
966 extern vm_map_t
get_task_map(task_t
);
967 extern ledger_t
get_task_ledger(task_t
);
969 extern boolean_t
get_task_pidsuspended(task_t
);
970 extern boolean_t
get_task_suspended(task_t
);
971 extern boolean_t
get_task_frozen(task_t
);
973 /* Convert from a task to a port */
974 extern ipc_port_t
convert_task_to_port(task_t
);
975 extern ipc_port_t
convert_task_name_to_port(task_name_t
);
976 extern ipc_port_t
convert_task_inspect_to_port(task_inspect_t
);
977 extern ipc_port_t
convert_task_suspension_token_to_port(task_suspension_token_t task
);
979 /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */
980 extern task_suspension_token_t
convert_port_to_task_suspension_token(ipc_port_t port
);
982 extern boolean_t
task_suspension_notify(mach_msg_header_t
*);
984 #define TASK_WRITE_IMMEDIATE 0x1
985 #define TASK_WRITE_DEFERRED 0x2
986 #define TASK_WRITE_INVALIDATED 0x4
987 #define TASK_WRITE_METADATA 0x8
988 extern void task_update_logical_writes(task_t task
, uint32_t io_size
, int flags
, void *vp
);
990 #if CONFIG_SECLUDED_MEMORY
991 extern void task_set_can_use_secluded_mem(
993 boolean_t can_use_secluded_mem
);
994 extern void task_set_could_use_secluded_mem(
996 boolean_t could_use_secluded_mem
);
997 extern void task_set_could_also_use_secluded_mem(
999 boolean_t could_also_use_secluded_mem
);
1000 extern boolean_t
task_can_use_secluded_mem(
1002 boolean_t is_allocate
);
1003 extern boolean_t
task_could_use_secluded_mem(task_t task
);
1004 extern boolean_t
task_could_also_use_secluded_mem(task_t task
);
1005 #endif /* CONFIG_SECLUDED_MEMORY */
1007 extern void task_set_darkwake_mode(task_t
, boolean_t
);
1008 extern boolean_t
task_get_darkwake_mode(task_t
);
1011 extern void task_set_legacy_footprint(task_t task
);
1012 extern void task_set_extra_footprint_limit(task_t task
);
1013 extern void task_set_ios13extended_footprint_limit(task_t task
);
1014 #endif /* __arm64__ */
1017 extern struct label
*get_task_crash_label(task_t task
);
1018 #endif /* CONFIG_MACF */
1020 extern int get_task_cdhash(task_t task
, char cdhash
[]);
1022 #endif /* KERNEL_PRIVATE */
1024 extern task_t kernel_task
;
1026 extern void task_deallocate(
1029 extern void task_name_deallocate(
1030 task_name_t task_name
);
1032 extern void task_inspect_deallocate(
1033 task_inspect_t task_inspect
);
1035 extern void task_suspension_token_deallocate(
1036 task_suspension_token_t token
);
1038 extern boolean_t
task_self_region_footprint(void);
1039 extern void task_self_region_footprint_set(boolean_t newval
);
1040 extern void task_ledgers_footprint(ledger_t ledger
,
1041 ledger_amount_t
*ledger_resident
,
1042 ledger_amount_t
*ledger_compressed
);
1043 extern void task_set_memory_ownership_transfer(
1049 #endif /* _KERN_TASK_H_ */