#include <mach/task.h> also included by
<mach/mach.h>mach/task.h
macro_task_user_
#define _task_user_
macrotask_MSG_COUNT
#define task_MSG_COUNT 66
functiontask_create
extern kern_return_t task_create( task_t target_task, ledger_array_t ledgers, mach_msg_type_number_t ledgersCnt, boolean_t inherit_memory, task_t *child_task /* out */ )
Sandbox builds task.defs with KERNEL_SERVER defined when generating the map
of MIG routine names to message IDs.
The MIG routine names need to be kept stable so as to not break Sandbox
profiles.
OBSOLETE interfaces, removed from kernel
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create a new task.
The task_create function creates a new task from parent_task and returns the name of the new task in child_task. The child task acquires shared or copied parts of the parent's address space (see vm_inherit). The child task initially contains no threads. The child task inherits the parent's security ID.
The child task receives the following "special" ports, which are created or copied for it at task creation: [task-self send right] The port by which the kernel knows the new child task and allows it to be manipulated. The child task holds a send right for this port. The port name is also returned to the calling task.
[bootstrap send right] The port to which the child task can send a message requesting return of any system service ports that it needs (for example, a port to the Network Name Server or the Environment Manager). The child task inherits a send right for this port from the parent task. The task can use task_set_special_port to change this port.
[host-self send right] The port by which the child task requests information about its host. The child task inherits a send right for this port from the parent task.
[ledger send rights] The ports naming the ledgers from which the task draws its resources.
The child task also inherits the following ports: [sample send right] The port to which PC sampling messages are to be sent.
[exception send rights] Ports to which exception messages are sent.
[registered send rights] Ports to system services.
Notes. The ledgers functionality mentioned above is not currently implemented.
GNU Mach reference · 7.2.1 Task Creation · © FSF, GFDL
kern_return_t task_create(task_t parent_task, boolean_t inherit_memory, task_t *child_task)
The function task_create creates a new task from parent_task; the resulting task (child_task) acquires shared or copied parts of the parent's address space (see vm_inherit). The child task initially contains no threads.
If inherit_memory is set, the child task's address space is built from the parent task according to its memory inheritance values; otherwise, the child task is given an empty address space.
The child task gets the three special ports created or copied for it at task creation. The TASK_KERNEL_PORT is created and send rights for it are given to the child and returned to the caller. The TASK_BOOTSTRAP_PORT and the TASK_EXCEPTION_PORT are inherited from the parent task. The new task can get send rights to these ports with the call task_get_special_port.
The function returns KERN_SUCCESS if a new task has been created, KERN_INVALID_ARGUMENT if parent_task is not a valid task port and KERN_RESOURCE_SHORTAGE if some critical kernel resource is unavailable.
functiontask_terminate
extern kern_return_t task_terminate(task_t target_task)
Destroy the target task, causing all of its threads
to be destroyed, all of its IPC rights to be deallocated,
and all of its address space to be deallocated.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Terminate the target task and deallocate its resources.
The task_terminate function kills task and all its threads, if any. The kernel frees all resources that are in use by the task. The kernel destroys any port for which the task holds the receive right.
GNU Mach reference · 7.2.2 Task Termination · © FSF, GFDL
kern_return_t task_terminate(task_t target_task)
The function task_terminate destroys the task specified by target_task and all its threads. All resources that are used only by this task are freed. Any port to which this task has receive and ownership rights is destroyed.
The function returns KERN_SUCCESS if the task has been killed, KERN_INVALID_ARGUMENT if target_task is not a task.
functiontask_threads
extern kern_return_t task_threads( task_inspect_t target_task, thread_act_array_t *act_list, /* out */ mach_msg_type_number_t *act_listCnt )
Returns the set of threads belonging to the target task.
[Polymorphic] This routine returns thread port with the same
flavor as that of the task port passed in.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return the target task's list of threads.
The task_threads function returns a list of the threads within task. The calling task or thread also receives a send right to the kernel port for each listed thread.
GNU Mach reference · 7.2.3 Task Information · © FSF, GFDL
kern_return_t task_threads(task_t target_task, thread_array_t *thread_list, mach_msg_type_number_t *thread_count)
The function task_threads gets send rights to the kernel port for each thread contained in target_task. thread_list is an array that is created as a result of this call. The caller may wish to vm_deallocate this array when the data is no longer needed.
The function returns KERN_SUCCESS if the call succeeded and KERN_INVALID_ARGUMENT if target_task is not a task.
functionmach_ports_register
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t mach_ports_register( task_t target_task, mach_port_array_t init_port_set, mach_msg_type_number_t init_port_setCnt )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Register an array of well-known ports on behalf of the target task.
The mach_ports_register function registers an array of well-known system ports for the specified task. The task holds only send rights for the registered ports. The valid well-known system ports are: The port for the Name Server The port for the Environment Manager The port for the Service server
Each port must be placed in a specific slot in the array. The slot numbers are defined (in mach.h) by the global constants NAME_SERVER_SLOT, ENVIRONMENT_SLOT, and SERVICE_SLOT.
A task can retrieve the currently registered ports by using the mach_ports_lookup function.
Notes. When a new task is created (with task_create), the child task can inherit the parent's registered ports. Note that child tasks do not automatically acquire rights to these ports. They must use mach_ports_lookup to get them. It is intended that port registration be used only for task initialization, and then only by run-time support modules.
A parent task has three choices when passing registered ports to child tasks: The parent task can do nothing. In this case, all child tasks inherit access to the same ports that the parent has. The parent task can use mach_ports_register to modify its set of registered ports before creating child tasks. In this case, the child tasks get access to the modified set of ports. After creating its child tasks. the parent can use mach_ports_register again to reset its registered ports. The parent task can first create a specific child task and then use mach_ports_register to modify the child's inherited set of ports, before starting the child's thread(s). The parent must specify the child's task port, rather than its own, on the call to mach_ports_register.
Tasks other than the Name Server and the Environment Manager should not need access to the Service port. The Name Server port is the same for all tasks on a given machine. The Environment port is the only port likely to have different values for different tasks.
Registered ports are restricted to those ports that are used by the run-time system to initialize a task. A parent task can pass other ports to its child tasks through: An initial message (see mach_msg). The Name Server, for public ports. The Environment Manager, for private ports. The task bootstrap port (see task_get_special_port).
functionmach_ports_lookup
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t mach_ports_lookup( task_t target_task, mach_port_array_t *init_port_set, mach_msg_type_number_t *init_port_setCnt )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Provide caller with an array of the target task's well-known ports.
The mach_ports_lookup function returns an array of the well-known system ports that are currently registered for the specified task. Note that the task holds only send rights for the ports.
Registered ports are those ports that are used by the run-time system to initialize a task. To register system ports for a task, use the mach_ports_register function.
functiontask_info
extern kern_return_t task_info( task_name_t target_task, task_flavor_t flavor, task_info_t task_info_out, /* out */ mach_msg_type_number_t *task_info_outCnt )
Returns information about the target task.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return per-task information according to specified flavor.
The task_info function returns an information structure of type flavor.
Notes. At any given time, a task has one default scheduling policy assigned to it (as returned by TASK_BASIC_INFO). As such, only one of the scheduling flavors will return valid information.
| KERN_INVALID_POLICY | A request was made for the default scheduling policy attributes for the task but the requested policy is not the task's default policy. |
GNU Mach reference · 7.2.3 Task Information · © FSF, GFDL
kern_return_t task_info(task_t target_task, int flavor, task_info_t task_info, mach_msg_type_number_t *task_info_count)
The function task_info returns the selected information array for a task, as specified by flavor. task_info is an array of integers that is supplied by the caller, and filled with specified information. task_info_count is supplied as the maximum number of integers in task_info. On return, it contains the actual number of integers in task_info. The maximum number of integers returned by any flavor is TASK_INFO_MAX.
The type of information returned is defined by flavor, which can be one of the following: TASK_BASIC_INFOThe function returns basic information about the task, as defined by task_basic_info_t. This includes the user and system time and memory consumption. The number of integers returned is TASK_BASIC_INFO_COUNT. TASK_EVENTS_INFOThe function returns information about events for the task as defined by thread_sched_info_t. This includes statistics about virtual memory and IPC events like pageouts, pageins and messages sent and received. The number of integers returned is TASK_EVENTS_INFO_COUNT. TASK_THREAD_TIMES_INFOThe function returns information about the total time for live threads as defined by task_thread_times_info_t. The number of integers returned is TASK_THREAD_TIMES_INFO_COUNT.
The function returns KERN_SUCCESS if the call succeeded and KERN_INVALID_ARGUMENT if target_task is not a thread or flavor is not recognized. The function returns MIG_ARRAY_TOO_LARGE if the returned info array is too large for task_info. In this case, task_info is filled as much as possible and task_infoCnt is set to the number of elements that would have been returned if there were enough room.
functiontask_set_info
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_info( task_t target_task, task_flavor_t flavor, task_info_t task_info_in, mach_msg_type_number_t task_info_inCnt )
Set task information.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set task-specific information state.
The task_set_info interface provides the caller with the means to set the target task's user_data field. This field may be used to specify arbitrarily task-specific data.
Notes. Currently, this interface is used exclusively to provide freshly colocated user tasks with the short-circuited RPC glue vector.
functiontask_suspend
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_suspend( task_read_t target_task )
Increment the suspend count for the target task.
No threads within a task may run when the suspend
count for that task is non-zero.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Suspend the target task.
The task_suspend function increments the suspend count for task and stops all threads within the task. As long as the suspend count is positive, no newly-created threads can execute. The function does not return until all of the task's threads have been suspended.
Notes. To resume a suspended task and its threads, use task_resume. If the suspend count is greater than one, task_resume must be repeated that number of times.
GNU Mach reference · 7.2.4 Task Execution · © FSF, GFDL
kern_return_t task_suspend(task_t target_task)
The function task_suspend increments the task's suspend count and stops all threads in the task. As long as the suspend count is positive newly created threads will not run. This call does not return until all threads are suspended.
The count may become greater than one, with the effect that it will take more than one resume call to restart the task.
The function returns KERN_SUCCESS if the task has been suspended and KERN_INVALID_ARGUMENT if target_task is not a task.
functiontask_resume
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_resume( task_read_t target_task )
Decrement the suspend count for the target task,
if the count is currently non-zero. If the resulting
suspend count is zero, then threads within the task
that also have non-zero suspend counts may execute.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Decrement the target task's suspend count.
The task_resume function decrements the suspend count for task. If the task's suspend count goes to zero, the function resumes any suspended threads within the task. To resume a given thread, the thread's own suspend count must also be zero.
Notes. An attempt to lower the suspend count below zero is ignored.
GNU Mach reference · 7.2.4 Task Execution · © FSF, GFDL
kern_return_t task_resume(task_t target_task)
The function task_resume decrements the task's suspend count. If it becomes zero, all threads with zero suspend counts in the task are resumed. The count may not become negative.
The function returns KERN_SUCCESS if the task has been resumed, KERN_FAILURE if the suspend count is already at zero and KERN_INVALID_ARGUMENT if target_task is not a task.
functiontask_get_special_port
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_get_special_port( task_inspect_t task, int which_port, mach_port_t *special_port /* out */ )
Returns the current value of the selected special port
associated with the target task.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return a send write to the indicated special port.
The task_get_special_port function returns a send right for a special port belonging to task.
If one task has a send right for the kernel port of another task, it can use the port to perform kernel operations for the other task. Send rights for a kernel port normally are held only by the task to which the port belongs, or by the task's parent task. Using the mach_msg function, however, any task can pass a send right for its kernel port to another task.
Notes. The current implementation does not support the TASK_HOST_NAME_PORT features associated with this interface.
GNU Mach reference · 7.2.5 Task Special Ports · © FSF, GFDL
kern_return_t task_get_special_port(task_t task, int which_port, mach_port_t *special_port)
The function task_get_special_port returns send rights to one of a set of special ports for the task specified by task.
The special ports associated with a task are the kernel port (TASK_KERNEL_PORT), the bootstrap port (TASK_BOOTSTRAP_PORT) and the exception port (TASK_EXCEPTION_PORT). The bootstrap port is a port to which a task may send a message requesting other system service ports. This port is not used by the kernel. The task's exception port is the port to which messages are sent by the kernel when an exception occurs and the thread causing the exception has no exception port of its own.
The following macros to call task_get_special_port for a specific port are defined in mach/task_special_ports.h: task_get_exception_port and task_get_bootstrap_port.
The function returns KERN_SUCCESS if the port was returned and KERN_INVALID_ARGUMENT if task is not a task or which_port is an invalid port selector.
functiontask_set_special_port
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_special_port( task_t task, int which_port, mach_port_t special_port )
Set one of the special ports associated with the
target task.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set the indicated special port.
The task_set_special_port function sets a special port belonging to task.
Notes. The current implementation does not support the TASK_HOST_NAME_PORT features associated with this interface.
GNU Mach reference · 7.2.5 Task Special Ports · © FSF, GFDL
kern_return_t task_set_special_port(task_t task, int which_port, mach_port_t special_port)
The function thread_set_special_port sets one of a set of special ports for the task specified by task.
The special ports associated with a task are the kernel port (TASK_KERNEL_PORT), the bootstrap port (TASK_BOOTSTRAP_PORT) and the exception port (TASK_EXCEPTION_PORT). The bootstrap port is a port to which a thread may send a message requesting other system service ports. This port is not used by the kernel. The task's exception port is the port to which messages are sent by the kernel when an exception occurs and the thread causing the exception has no exception port of its own.
The function returns KERN_SUCCESS if the port was set and KERN_INVALID_ARGUMENT if task is not a task or which_port is an invalid port selector.
functionthread_create
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t thread_create( task_t parent_task, thread_act_t *child_act /* out */ )
Create a new thread within the target task, returning
the port representing the first thr_act in that new thread. The
initial execution state of the thread is undefined.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create a thread within a task.
The thread_create function creates a new thread within parent_task. The new thread has a suspend count of one and no processor state.
The new thread holds a send right for its thread kernel port. A send right for the thread's kernel port is also returned to the calling task or thread in child_thread. The new thread's exception ports are set to MACH_PORT_NULL.
Notes. To get a new thread running, first use thread_set_state to set a processor state for the thread. Then, use thread_resume to schedule the thread for execution. Alternately, use thread_create_running.
GNU Mach reference · 7.1.1 Thread Creation · © FSF, GFDL
kern_return_t thread_create(task_t parent_task, thread_t *child_thread)
The function thread_create creates a new thread within the task specified by parent_task. The new thread has no processor state, and has a suspend count of 1. To get a new thread to run, first thread_create is called to get the new thread's identifier, (child_thread). Then thread_set_state is called to set a processor state, and finally thread_resume is called to get the thread scheduled to execute.
When the thread is created send rights to its thread kernel port are given to it and returned to the caller in child_thread. The new thread's exception port is set to MACH_PORT_NULL.
The function returns KERN_SUCCESS if a new thread has been created, KERN_INVALID_ARGUMENT if parent_task is not a valid task and KERN_RESOURCE_SHORTAGE if some critical kernel resource is not available.
functionthread_create_running
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t thread_create_running( task_t parent_task, thread_state_flavor_t flavor, thread_state_t new_state, mach_msg_type_number_t new_stateCnt, thread_act_t *child_act /* out */ )
Create a new thread within the target task, returning
the port representing that new thread. The new thread
is not suspended; its initial execution state is given
by flavor and new_state. Returns the port representing
the new thread.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Optimized creation of a running thread.
The thread_create_running function creates a new thread within parent_task. The new thread has is not suspended. Its initial state is given by state. flavor specifies the type of state to set.
The format of the state to set is machine specific; it is defined in \*L \*O.
The new thread holds a send right for its thread kernel port. A send right for the thread's kernel port is also returned to the calling task or thread in child_thread. The new thread's exception ports are set to MACH_PORT_NULL.
Notes. This is an optimized form of the sequence: thread_create, thread_set_state and thread_resume.
functiontask_set_exception_ports
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_exception_ports( task_t task, exception_mask_t exception_mask, mach_port_t new_port, exception_behavior_t behavior, thread_state_flavor_t new_flavor )
Set an exception handler for a task on one or more exception types.
These handlers are invoked for all threads in the task if there are
no thread-specific exception handlers or those handlers returned an
error.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set target task's exception ports.
The task_set_exception_ports function sets a specified set of exception ports belonging to task. A task exception port is used when a thread specific exception port returns a non-success reply.
Notes. If the value of the EXC_MACH_SYSCALL exception class exception port is the host name port, Mach kernel traps are executed by the kernel as expected; any other value causes the attempted execution of these system call numbers to be considered an exception.
functiontask_get_exception_ports
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_get_exception_ports( task_t task, exception_mask_t exception_mask, exception_mask_array_t masks, /* out */ mach_msg_type_number_t *masksCnt, exception_handler_array_t old_handlers, /* out */ exception_behavior_array_t old_behaviors, /* out */ exception_flavor_array_t old_flavors /* out */ )
Lookup some of the old exception handlers for a task
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return send rights to the target task's exception ports.
The task_get_exception_ports function returns send rights for a specified set of exception ports belonging to task. A task exception port is used when a thread specific exception port returns a non-success reply. The call returns a set of quadruples for each unique set of in effect for the task where the exception type mask indicates for which exception types the other values apply.
functiontask_swap_exception_ports
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_swap_exception_ports( task_t task, exception_mask_t exception_mask, mach_port_t new_port, exception_behavior_t behavior, thread_state_flavor_t new_flavor, exception_mask_array_t masks, /* out */ mach_msg_type_number_t *masksCnt, exception_handler_array_t old_handlers, /* out */ exception_behavior_array_t old_behaviors, /* out */ exception_flavor_array_t old_flavors /* out */ )
Set an exception handler for a thread on one or more exception types.
At the same time, return the previously defined exception handlers for
those types.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set target task's exception ports, returning the previous exception ports.
The task_swap_exception_ports function sets a specified set of exception ports belonging to task, returning the old set. A task exception port is used when a thread specific exception port returns a non-success reply.
Notes. If the value of the EXC_MACH_SYSCALL exception class exception port is the host name port, Mach kernel traps are executed by the kernel as expected; any other value causes the attempted execution of these system call numbers to be considered an exception.
functionlock_set_create
extern kern_return_t lock_set_create( task_t task, lock_set_t *new_lock_set, /* out */ int n_ulocks, int policy )
OBSOLETE interfaces, removed from kernel
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create a new lock set.
The lock_set_create function creates a new lock set representing a collection of associated locks. The lock set is associated with the specified task. A send right naming the lock set is returned to the caller.
| KERN_SUCCESS | The lock set was created. |
| KERN_INVALID_ARGUMENT | Either the task or policy argument is invalid, or the locks argument has a value that is less than or equal to zero. |
| KERN_RESOURCE_SHORTAGE | The kernel could not allocate the lock set. |
functionlock_set_destroy
extern kern_return_t lock_set_destroy(task_t task, lock_set_t lock_set)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Destroy a lock set and its associated locks.
The lock_set_destroy function will destroy a lock set and all of its associated locks. Threads that are blocked on locks represented by the destroyed lock set are unblocked and will receive a KERN_LOCK_SET_DESTROYED error message indicating that the lock set was destroyed. The lock_set_destroy function will only succeed if the specified task is associated with the specified lock set.
| KERN_INVALID_ARGUMENT | The specified lock set or task is invalid. |
| KERN_INVALID_RIGHT | The specified task does not own the specified lock set. |
| KERN_LOCK_SET_DESTROYED | The specified lock set does not exist. |
| KERN_SUCCESS | The lock set was destroyed. |
functionsemaphore_create
extern kern_return_t semaphore_create( task_t task, semaphore_t *semaphore, /* out */ int policy, int value )
Create and destroy semaphore synchronizers on a
per-task basis (i.e. the task owns them).
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create a new semaphore.
The semaphore_create function creates a new semaphore, associates the created semaphore with the specified task, and returns a send right naming the new semaphore. In order to support a robust producer/consumer communication service, Interrupt Service Routines (ISR) must be able to signal semaphores. The semaphore synchronizer service is designed to allow user-level device drivers to perform signal operations, eliminating the need for event counters. Device drivers which utilize semaphores are responsible for creating (via semaphore_create) and exporting (via device_get_status) semaphores for user level access. Device driver semaphore creation is done at device initialization time. Device drivers may support multiple semaphores.
| KERN_INVALID_ARGUMENT | The task argument or the policy argument was invalid, or the initial value of the semaphore was invalid. |
| KERN_RESOURCE_SHORTAGE | The kernel could not allocate the semaphore. |
| KERN_SUCCESS | The semaphore was successfully created. |
functionsemaphore_destroy
extern kern_return_t semaphore_destroy(task_t task, semaphore_t semaphore)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Destroy a semaphore.
The semaphore_destroy function destroys a semaphore. All send rights naming the semaphore become dead names. Threads waiting on the semaphore become unblocked with the return from the semaphore_wait call indicating that the semaphore was destroyed. A call to semaphore_destroy succeeds only if the semaphore is associated with the specified task.
| KERN_INVALID_ARGUMENT | Either, or both, the task or semaphore arguments were invalid. |
| KERN_INVALID_RIGHT | The specified task does not own the specified semaphore. |
| KERN_TERMINATED | The specified semaphore was previously destroyed. |
| KERN_SUCCESS | The semaphore was destroyed. |
functiontask_policy_set
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_policy_set( task_policy_set_t task, task_policy_flavor_t flavor, task_policy_t policy_info, mach_msg_type_number_t policy_infoCnt )
Set/get policy information for a task.
(Approved Mac OS X microkernel interface)
functiontask_policy_get
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_policy_get( task_policy_get_t task, task_policy_flavor_t flavor, task_policy_t policy_info, /* out */ mach_msg_type_number_t *policy_infoCnt, boolean_t *get_default /* inout */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task_policy.c
Returns scheduling policy information for the target task. policy_infoCnt is an in/out size in integer units. If get_default is TRUE on entry, the flavor's default values are returned instead of the task's current settings. Flavors:
TASK_CATEGORY_POLICY task role (TASK_FOREGROUND_APPLICATION, ...)
TASK_BASE_QOS_POLICY base latency and throughput QoS tiers
TASK_OVERRIDE_QOS_POLICY override latency and throughput QoS tiers
TASK_SUPPRESSION_POLICY App Nap suppression settings
TASK_POLICY_STATE requested/effective policy bits and importance counts; privileged callers only (KERN_PROTECTION_FAILURE otherwise)
Returns KERN_INVALID_ARGUMENT for the kernel task, an unknown flavor, or a count that is too small.
functiontask_sample
extern kern_return_t task_sample(task_t task, mach_port_t reply)
OBSOLETE interfaces, removed from kernel.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Sample the target task's thread program counters periodically.
The task_sample function causes the program counter (PC) of the specified sample_task (actually, all of the threads within sample_task) to be sampled periodically (whenever one of the threads happens to be running at the time of the kernel's "hardclock" interrupt). The set of PC sample values obtained are saved in buffers which are sent to the specified reply_port in receive_samples messages.
functiontask_policy
extern kern_return_t task_policy( task_t task, policy_t policy, policy_base_t base, mach_msg_type_number_t baseCnt, boolean_t set_limit, boolean_t change )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set target task's default scheduling policy state.
The task_policy function sets the default scheduling attributes for task. These attributes are used when creating new threads. Changing the default attributes for a task does not affect the attributes of the contained threads unless change_threads is TRUE. At no time will a thread ever have scheduling attributes that exceed the thread's limits.
| KERN_INVALID_POLICY | The processor set does not currently enable policy. |
| KERN_POLICY_LIMIT | The specified scheduling attributes exceeds the thread's limits. |
functiontask_set_emulation
extern kern_return_t task_set_emulation( task_t target_port, vm_address_t routine_entry_pt, int routine_number )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Establish a user-level handler for a system call.
The task_set_emulation function establishes a handler within the task for a particular system call. When a thread executes a system call with this particular number, the system call will be redirected to the specified routine within the task's address space. This is expected to be an address within the transparent emulation library. These emulation handler addresses are inherited by child processes.
Notes. This interface is machine word length specific because of the virtual address parameter.
GNU Mach reference · 7.2.6 Syscall Emulation · © FSF, GFDL
kern_return_t task_set_emulation(task_t task, vm_address_t routine_entry_pt, int routine_number)
The function task_set_emulation establishes a user-level handler for the specified system call. System call emulation handlers are inherited by the children of task.
functiontask_get_emulation_vector
extern kern_return_t task_get_emulation_vector( task_t task, int *vector_start, /* out */ emulation_vector_t *emulation_vector, /* out */ mach_msg_type_number_t *emulation_vectorCnt )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return an array identifying the target task's user-level system call handlers.
The task_get_emulation_vector function returns the user-level syscall handler entrypoint addresses.
Notes. This interface is machine word length specific because of the virtual addresses in the emulation_vector parameter.
GNU Mach reference · 7.2.6 Syscall Emulation · © FSF, GFDL
kern_return_t task_get_emulation_vector(task_t task, int *vector_start, emulation_vector_t *emulation_vector, mach_msg_type_number_t *emulation_vector_count)
The function task_get_emulation_vector gets the user-level handler entry points for all emulated system calls.
functiontask_set_emulation_vector
extern kern_return_t task_set_emulation_vector( task_t task, int vector_start, emulation_vector_t emulation_vector, mach_msg_type_number_t emulation_vectorCnt )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Establish the target task's user-level system call handlers.
The task_set_emulation_vector function establishes a handler within the task for a set of system calls. When a thread executes a system call with one of these numbers, the system call will be redirected to the corresponding routine within the task's address space.
These emulation handler addresses are inherited by child processes.
Notes. This interface is machine word length specific because of the virtual addresses in the emulation_vector parameter.
GNU Mach reference · 7.2.6 Syscall Emulation · © FSF, GFDL
kern_return_t task_set_emulation_vector(task_t task, int vector_start, emulation_vector_t emulation_vector, mach_msg_type_number_t emulation_vector_count)
The function task_set_emulation_vector establishes user-level handlers for the specified system calls. Non-emulated system calls are specified with an entry of EML_ROUTINE_NULL. System call emulation handlers are inherited by the children of task.
functiontask_set_ras_pc
extern kern_return_t task_set_ras_pc( task_t target_task, vm_address_t basepc, vm_address_t boundspc )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/mach/task.defs
Obsolete interface, removed from the kernel. The routine is still declared and a client-side MIG stub is generated, but the kernel server skips it (osfmk/mach/task.defs), so calls fail with MIG_BAD_ID. Historically registered a restartable atomic sequence (RAS) for the task: a code range [basepc, boundspc) that the kernel would restart from the beginning if a thread was preempted inside it, providing atomicity without locks on uniprocessors.
functiontask_zone_info
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_zone_info( task_inspect_t target_task, mach_zone_name_array_t *names, /* out */ mach_msg_type_number_t *namesCnt, task_zone_info_array_t *info, /* out */ mach_msg_type_number_t *infoCnt )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/mach/task.defs
Obsolete interface, removed from the kernel. The routine is still declared and a client-side MIG stub is generated, but the kernel server skips it (osfmk/mach/task.defs), so calls fail with MIG_BAD_ID. Historically returned kernel zone allocator names and usage statistics; zone usage was never tracked per task. Use mach_zone_info (mach_debug subsystem, host_priv port) to obtain zone statistics.
functiontask_assign
extern kern_return_t task_assign( task_t task, processor_set_t new_set, boolean_t assign_threads )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Assign a task to a processor set.
The task_assign function assigns task to the set processor_set. After the assignment is completed, newly created threads within this task will be assigned to this processor set. Any previous assignment of the task is nullified.
If assign_threads is TRUE, existing threads within the task will also be assigned to the processor set.
functiontask_assign_default
extern kern_return_t task_assign_default(task_t task, boolean_t assign_threads)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Assign a task to the default processor set.
The task_assign_default function assigns task to the default processor set. After the assignment is completed, newly created threads within this task will be assigned to this processor set. Any previous assignment of the task is nullified.
If assign_threads is TRUE, existing threads within the task will also be assigned to the processor set.
Notes. This variant of task_assign exists because the control port for the default processor set is privileged, and therefore not available to most tasks.
functiontask_get_assignment
extern kern_return_t task_get_assignment( task_inspect_t task, processor_set_name_t *assigned_set /* out */ )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return the processor set to which a task is assigned.
The task_get_assignment function returns the name port to the processor set to which task is currently assigned. This port can only be used to obtain information about the processor set.
functiontask_set_policy
extern kern_return_t task_set_policy( task_t task, processor_set_t pset, policy_t policy, policy_base_t base, mach_msg_type_number_t baseCnt, policy_limit_t limit, mach_msg_type_number_t limitCnt, boolean_t change )
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set target task's default scheduling policy state. (Protected Interface.)
The task_set_policy function sets the scheduling attributes, both base and limit, for task. policy may be any policy implemented by the processor set whether or not it is enabled.
| KERN_INVALID_PROCESSOR_SET | processor_set is not the task's processor set control port. |
functiontask_get_state
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_get_state( task_read_t task, thread_state_flavor_t flavor, thread_state_t old_state, /* out */ mach_msg_type_number_t *old_stateCnt )
Read the selected state which is to be installed on new
threads in the task as they are created.
functiontask_set_state
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_state( task_t task, thread_state_flavor_t flavor, thread_state_t new_state, mach_msg_type_number_t new_stateCnt )
Set the selected state information to be installed on
all subsequently created threads in the task.
functiontask_set_phys_footprint_limit
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_phys_footprint_limit( task_t task, int new_limit, int *old_limit /* out */ )
Change the task's physical footprint limit (in MB).
functiontask_suspend2
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_suspend2( task_read_t target_task, task_suspension_token_t *suspend_token /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c (task_suspend2_mig)
Suspends the target task and returns a suspension token holding a reference on the suspended task. Unlike task_suspend, where all callers share one legacy hold on the task, each task_suspend2 call produces its own suspension count, represented by a unique send-once right to the task's resume port; the suspension is undone by passing the token to task_resume2, and dropping the token (its no-senders notification) also releases the hold, so a dying suspender cannot leave the task suspended forever. On failure *suspend_token is TASK_NULL. Returns KERN_INVALID_ARGUMENT for the kernel task or a null task.
functiontask_resume2
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_resume2( task_suspension_token_t suspend_token )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c (task_resume2_mig)
Resumes a task suspended by task_suspend2, using the suspension token that call returned. Releases one suspension hold and consumes the token's task reference (the send-once right to the resume port). Returns KERN_INVALID_ARGUMENT for a null or kernel task and KERN_FAILURE if the task holds no outstanding user suspensions; the token is consumed regardless.
functiontask_purgable_info
extern kern_return_t task_purgable_info( task_inspect_t task, task_purgable_info_t *stats /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c, osfmk/vm/vm_purgeable.c
Returns statistics on the task's purgeable memory: counts and byte totals of volatile and nonvolatile purgeable objects, filled in from the VM purgeable-queue accounting (vm_purgeable_stats) into the task_purgable_info_t structure. Returns KERN_INVALID_ARGUMENT if the task or stats pointer is null.
functiontask_get_mach_voucher
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_get_mach_voucher( task_read_t task, mach_voucher_selector_t which, ipc_voucher_t *voucher /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Placeholder for a per-task voucher interface. Ignores the which selector, returns a null voucher and KERN_SUCCESS; KERN_INVALID_TASK if the task is null. Tasks do not carry vouchers; voucher adoption is per thread (thread_get_mach_voucher, thread_set_mach_voucher).
functiontask_set_mach_voucher
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_mach_voucher( task_t task, ipc_voucher_t voucher )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Placeholder for a per-task voucher interface. Performs no action and returns KERN_SUCCESS; KERN_INVALID_TASK if the task is null. Tasks do not carry vouchers; voucher adoption is per thread (thread_set_mach_voucher).
functiontask_swap_mach_voucher
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_swap_mach_voucher( task_t task, ipc_voucher_t new_voucher, ipc_voucher_t *old_voucher /* inout */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Not supported. Releases the reference on the voucher passed in *old_voucher (which MIG would otherwise leak) and returns KERN_NOT_SUPPORTED.
functiontask_generate_corpse
extern kern_return_t task_generate_corpse( task_read_t task, mach_port_t *corpse_task_port /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/corpses/corpse.c
Forks a corpse from the target task: an inert copy of the task carrying its threads' final state and collected crash information (kcdata), suitable for post-mortem inspection with task_map_corpse_info_64 and the usual task/thread inspection interfaces. Waits for the corpse's threads to halt, then returns a send right to the corpse's task port; when all send rights are released the corpse is reaped. Returns KERN_INVALID_ARGUMENT for the kernel task or a task that is itself a corpse fork, KERN_NOT_SUPPORTED if corpses are disabled, and KERN_RESOURCE_SHORTAGE on allocation failure or when the maximum number of corpses exists.
functiontask_map_corpse_info
extern kern_return_t task_map_corpse_info( task_t task, task_read_t corspe_task, vm_address_t *kcd_addr_begin, /* out */ uint32_t *kcd_size /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/corpses/corpse.c
32-bit variant of task_map_corpse_info_64: maps the corpse's collected crash information into the given task's address space and returns the mapping's address and size, truncated to vm_address_t and uint32_t. The implementation notes it is a temporary function; use task_map_corpse_info_64.
functiontask_register_dyld_image_infos
extern kern_return_t task_register_dyld_image_infos( task_t task, dyld_kernel_image_info_array_t dyld_images, mach_msg_type_number_t dyld_imagesCnt )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Emits a kdebug tracepoint (DBG_DYLD_UUID_MAP_A event group) for each dyld_kernel_image_info in the array, recording image UUID, load address, and file identity so trace tools can symbolicate. Called by dyld as images are loaded. If kdebug tracing of these events is not enabled the call discards the data and returns KERN_SUCCESS. Returns KERN_INVALID_TASK unless task is the calling task and KERN_INVALID_ADDRESS for a null array.
functiontask_unregister_dyld_image_infos
extern kern_return_t task_unregister_dyld_image_infos( task_t task, dyld_kernel_image_info_array_t dyld_images, mach_msg_type_number_t dyld_imagesCnt )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Counterpart of task_register_dyld_image_infos: emits a kdebug tracepoint (DBG_DYLD_UUID_UNMAP_A event group) for each dyld_kernel_image_info in the array as images are unloaded. Same conditions and returns as task_register_dyld_image_infos.
functiontask_get_dyld_image_infos
extern kern_return_t task_get_dyld_image_infos( task_read_t task, dyld_kernel_image_info_array_t *dyld_images, /* out */ mach_msg_type_number_t *dyld_imagesCnt )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Unimplemented stub; returns KERN_NOT_SUPPORTED. The kernel does not keep the registered dyld image info list. Use proc_info or task_info(TASK_DYLD_INFO) and read the dyld_all_image_infos structure from the task's address space instead.
functiontask_register_dyld_set_dyld_state
extern kern_return_t task_register_dyld_set_dyld_state(task_t task, uint8_t dyld_state)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Unimplemented stub; ignores its arguments and returns KERN_NOT_SUPPORTED.
functiontask_register_dyld_get_process_state
extern kern_return_t task_register_dyld_get_process_state( task_t task, dyld_kernel_process_info_t *dyld_process_state /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Unimplemented stub; ignores its arguments and returns KERN_NOT_SUPPORTED.
functiontask_map_corpse_info_64
extern kern_return_t task_map_corpse_info_64( task_t task, task_read_t corspe_task, mach_vm_address_t *kcd_addr_begin, /* out */ mach_vm_size_t *kcd_size /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/corpses/corpse.c
Maps the crash information (kcdata) collected for corpse_task into the target task's address space, returning the mapping's start address in *kcd_addr_begin and its fixed size (CORPSEINFO_ALLOCATION_SIZE) in *kcd_size. The mapping is created copy-on-write from the corpse's data and tagged VM_MEMORY_CORPSEINFO. Returns KERN_INVALID_ARGUMENT if task is null or itself a corpse, if corpse_task is not a corpse, or if the corpse has no collected data; otherwise errors from the VM map operation.
functiontask_inspect
extern kern_return_t task_inspect( task_inspect_t task, task_inspect_flavor_t flavor, task_inspect_info_t info_out, /* out */ mach_msg_type_number_t *info_outCnt )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Returns hardware performance counts for the target task. The only flavor is TASK_INSPECT_BASIC_COUNTS, which fills a struct task_inspect_basic_counts with the task's lifetime retired-instruction and cycle counts. info_outCnt is an in/out size in integer units; KERN_INVALID_ARGUMENT is returned if it is smaller than TASK_INSPECT_BASIC_COUNTS_COUNT, for an unknown flavor, or for a null task. On kernels built without per-task CPI counters (CONFIG_PERVASIVE_CPI, Apple silicon) returns KERN_NOT_SUPPORTED.
functiontask_get_exc_guard_behavior
extern kern_return_t task_get_exc_guard_behavior( task_inspect_t task, task_exc_guard_behavior_t *behavior /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Returns the task's EXC_GUARD behavior: a bitmask (TASK_EXC_GUARD_VM_DELIVER, TASK_EXC_GUARD_VM_ONCE, TASK_EXC_GUARD_VM_CORPSE, TASK_EXC_GUARD_MP_*, ...) controlling whether virtual-memory and mach-port guard violations deliver an EXC_GUARD exception, deliver it only once, generate a corpse, or are fatal. Returns KERN_INVALID_TASK for a null task.
functiontask_set_exc_guard_behavior
extern kern_return_t task_set_exc_guard_behavior( task_t task, task_exc_guard_behavior_t behavior )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Sets the task's EXC_GUARD behavior bitmask, controlling delivery of guard exceptions for mach-port and virtual-memory violations. Bits outside TASK_EXC_GUARD_ALL yield KERN_INVALID_VALUE; the value is further masked to the behaviors permitted by the boot configuration. On release kernels the behavior may only be strengthened: clearing an already-set restricted bit, or setting a restricted one, returns KERN_DENIED. KERN_INVALID_TASK for a null task.
functiontask_dyld_process_info_notify_register
extern kern_return_t task_dyld_process_info_notify_register( task_read_t target_task, mach_port_t notify )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Registers a notification port on the target task for dyld process-info events: inserts the send right into the task's dyld notifier array (at most DYLD_MAX_PROCESS_INFO_NOTIFY_COUNT entries) and records its name in the task's dyld_all_image_infos structure, so dyld can message the port when the image list changes; dead rights found in the array are cleaned out. Consumes the right on success. Returns KERN_INVALID_TASK for a null or kernel task, KERN_INVALID_RIGHT for an invalid or immovable send right, KERN_DENIED if security policy forbids the call, KERN_NO_SPACE when all notifier slots are in use, and KERN_RIGHT_EXISTS if the port is already registered.
functiontask_create_identity_token
extern kern_return_t task_create_identity_token( task_t task, task_id_token_t *token /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task_ident.c
Creates a task identity token: a port that stably represents the identity of the task (its proc identity, or the task unique id for a corpse) without holding any task right. The token can later be converted to a task port of a chosen flavor with task_identity_token_get_task_port, and fails to convert once the process has exited or been replaced by exec. Returns KERN_INVALID_ARGUMENT for a null, kernel, or already-inactive task.
functiontask_identity_token_get_task_port
extern kern_return_t task_identity_token_get_task_port( task_id_token_t token, task_flavor_t flavor, mach_port_t *task_port /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task_ident.c
Converts a task identity token into a send right to a port of the requested flavor for the task it identifies:
TASK_FLAVOR_CONTROL task port
TASK_FLAVOR_READ read port
TASK_FLAVOR_INSPECT inspect port
TASK_FLAVOR_NAME name port
Returns KERN_NOT_FOUND if the identified process no longer exists (or has exec'd), KERN_INVALID_ARGUMENT for a null token, a flavor above TASK_FLAVOR_MAX, or a corpse token with a flavor other than TASK_FLAVOR_CONTROL; control and read conversions are additionally subject to task conversion and MAC policy checks.
functiontask_dyld_process_info_notify_deregister
extern kern_return_t task_dyld_process_info_notify_deregister( task_read_t target_task, mach_port_name_t notify )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Removes a notification port previously registered on the target task by task_dyld_process_info_notify_register. notify names a receive right in the caller's IPC space; the matching send right is removed from the task's dyld notifier array and released, and its name is cleared from the task's dyld_all_image_infos structure. Returns KERN_INVALID_TASK for a null or kernel task, KERN_INVALID_NAME for an invalid name, KERN_INVALID_RIGHT if the name is not a receive right, KERN_DENIED if security policy forbids the call, and KERN_FAILURE if no matching entry is found.
functiontask_get_exception_ports_info
extern kern_return_t task_get_exception_ports_info( mach_port_t port, exception_mask_t exception_mask, exception_mask_array_t masks, /* out */ mach_msg_type_number_t *masksCnt, exception_handler_info_array_t old_handlers_info, /* out */ exception_behavior_array_t old_behaviors, /* out */ exception_flavor_array_t old_flavors /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/ipc_tt.c
Variant of task_get_exception_ports that returns information about the task's exception handlers instead of send rights, and therefore accepts a task read port. For each exception type selected in exception_mask, entries with identical port, behavior, and flavor are coalesced into one array slot whose mask carries all matching types; masksCnt is in/out. Each exception_handler_info_t (ipc_info_port_t) holds hashed kernel identifiers for the handler port and for the task holding its receive right, usable to correlate handlers across tasks without granting any right. Returns KERN_INVALID_ARGUMENT for an invalid port or bits outside EXC_MASK_VALID, KERN_FAILURE if the task's IPC space is inactive.
functiontask_test_sync_upcall
extern kern_return_t task_test_sync_upcall(task_t task, mach_port_t port)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Kernel test routine, available only on DEVELOPMENT and DEBUG kernels; release kernels return KERN_NOT_SUPPORTED. Performs a synchronous kernel upcall (message send and reply) on the given send port to exercise turnstile/priority push from kernel to the server thread, then releases the right. Returns KERN_INVALID_ARGUMENT unless task is the calling task and the port is valid.
functiontask_set_corpse_forking_behavior
extern kern_return_t task_set_corpse_forking_behavior( task_t task, task_corpse_forking_behavior_t behavior )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Available only on DEVELOPMENT and DEBUG kernels; release kernels return KERN_NOT_SUPPORTED. Sets or clears the task's TF_NO_CORPSE_FORKING flag according to the TASK_CORPSE_FORKING_DISABLED_MEM_DIAG bit in behavior, suppressing corpse forking for the task (used by memory diagnostics). KERN_INVALID_TASK for a null task.
functiontask_test_async_upcall_propagation
extern kern_return_t task_test_async_upcall_propagation( task_t task, mach_port_t port, int qos, int iotier )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/task.c
Kernel test routine, available only on DEVELOPMENT and DEBUG kernels; release kernels return KERN_NOT_SUPPORTED. Applies the given QoS (THREAD_QOS_DEFAULT..THREAD_QOS_USER_INTERACTIVE) and I/O throttle tier to the send port, then performs an asynchronous kernel upcall with importance donation enabled to test propagation of thread attributes through IPC. Returns KERN_INVALID_ARGUMENT unless task is the calling task, the port is valid, and qos and iotier are in range.
functiontask_map_kcdata_object_64
extern kern_return_t task_map_kcdata_object_64( task_t task, kcdata_object_t kcdata_object, mach_vm_address_t *kcd_addr_begin, /* out */ mach_vm_size_t *kcd_size /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/corpses/corpse.c
Maps the kcdata buffer underlying a kcdata object (such as the lightweight-corpse backtrace info delivered with an EXC_CORPSE_NOTIFY exception) into the target task's address space, returning the mapping's start address in *kcd_addr_begin and its fixed size (BTINFO_ALLOCATION_SIZE) in *kcd_size; the mapping is tagged VM_MEMORY_BTINFO. Returns KERN_INVALID_ARGUMENT if task is null or a corpse, the object is null, or it has no data; otherwise errors from the VM map operation. Compare task_map_corpse_info_64.
functiontask_register_hardened_exception_handler
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_register_hardened_exception_handler( task_t task, uint32_t signed_pc_key, exception_mask_t exceptions_allowed, exception_behavior_t behaviors_allowed, thread_state_flavor_t flavors_allowed, mach_port_t new_exception_port )
When used in conjunction with thread_adopt_exception_handler, we call this a
hardened mach exception handler, and it adds additional security guarantees to this exception port:
1. Enforces only a subset of exceptions, behaviours, and flavors
may be used with this port
2. The `new_exception_port` must be created using MPO_EXCEPTION_PORT (implicitly immovable)
3. When using *STATE* behaviors of exception handling, only the PC is allowed to be set.
4. Setting the PC in an exception handler must be signed using a diversifier of
signed_pc_key (if non-zero). You can pre-sign your PC
state and then throw away the key to ensure that only a limited
set of PC's may be used with this exception handler
5. Calling `[task,thread,host]_set_exception_ports` if you have the IPC_ONLY_ONE_EXCEPTION_PORT
entitlement is disallowed, and you must use this hardened exception flow.
If used with the traditional set_exception_ports functions, these
security guarantees do not apply.
You can only call this once per task.
See tests/ipc/hardened_exceptions.c for examples.
macrosubsystem_to_name_map_task
#define subsystem_to_name_map_task { "task_create", 3400 },
{ "task_terminate", 3401 },
{ "task_threads", 3402 },
{ "mach_ports_register", 3403 },
{ "mach_ports_lookup", 3404 },
{ "task_info", 3405 },
{ "task_set_info", 3406 },
{ "task_suspend", 3407 },
{ "task_resume", 3408 },
{ "task_get_special_port", 3409 },
{ "task_set_special_port", 3410 },
{ "thread_create", 3411 },
{ "thread_create_running", 3412 },
{ "task_set_exception_ports", 3413 },
{ "task_get_exception_ports", 3414 },
{ "task_swap_exception_ports", 3415 },
{ "lock_set_create", 3416 },
{ "lock_set_destroy", 3417 },
{ "semaphore_create", 3418 },
{ "semaphore_destroy", 3419 },
{ "task_policy_set", 3420 },
{ "task_policy_get", 3421 },
{ "task_sample", 3422 },
{ "task_policy", 3423 },
{ "task_set_emulation", 3424 },
{ "task_get_emulation_vector", 3425 },
{ "task_set_emulation_vector", 3426 },
{ "task_set_ras_pc", 3427 },
{ "task_zone_info", 3428 },
{ "task_assign", 3429 },
{ "task_assign_default", 3430 },
{ "task_get_assignment", 3431 },
{ "task_set_policy", 3432 },
{ "task_get_state", 3433 },
{ "task_set_state", 3434 },
{ "task_set_phys_footprint_limit", 3435 },
{ "task_suspend2", 3436 },
{ "task_resume2", 3437 },
{ "task_purgable_info", 3438 },
{ "task_get_mach_voucher", 3439 },
{ "task_set_mach_voucher", 3440 },
{ "task_swap_mach_voucher", 3441 },
{ "task_generate_corpse", 3442 },
{ "task_map_corpse_info", 3443 },
{ "task_register_dyld_image_infos", 3444 },
{ "task_unregister_dyld_image_infos", 3445 },
{ "task_get_dyld_image_infos", 3446 },
{ "task_register_dyld_shared_cache_image_info", 3447 },
{ "task_register_dyld_set_dyld_state", 3448 },
{ "task_register_dyld_get_process_state", 3449 },
{ "task_map_corpse_info_64", 3450 },
{ "task_inspect", 3451 },
{ "task_get_exc_guard_behavior", 3452 },
{ "task_set_exc_guard_behavior", 3453 },
{ "task_dyld_process_info_notify_register", 3456 },
{ "task_create_identity_token", 3457 },
{ "task_identity_token_get_task_port", 3458 },
{ "task_dyld_process_info_notify_deregister", 3459 },
{ "task_get_exception_ports_info", 3460 },
{ "task_test_sync_upcall", 3461 },
{ "task_set_corpse_forking_behavior", 3462 },
{ "task_test_async_upcall_propagation", 3463 },
{ "task_map_kcdata_object_64", 3464 },
{ "task_register_hardened_exception_handler", 3465 }