#include <mach/task.h>
mach/task.h
Module task
function_kernelrpc_mach_ports_register3
extern kern_return_t _kernelrpc_mach_ports_register3( task_t target_task, mach_port_t port1, mach_port_t port2, mach_port_t port3 )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/ipc_tt.c
Kernel implementation of mach_ports_register for exactly TASK_PORT_REGISTER_MAX (3) ports: stashes the three send rights on the target task, replacing and releasing any previously registered rights; individual ports may be MACH_PORT_NULL. Ports carrying immovable send rights are refused with KERN_INVALID_RIGHT so they cannot later be retrieved by mach_ports_lookup. Returns KERN_INVALID_ARGUMENT if the task is null or its IPC space is no longer active.
function_kernelrpc_mach_ports_lookup3
extern kern_return_t _kernelrpc_mach_ports_lookup3( task_t target_task, mach_port_t *port1, mach_port_t *port2, mach_port_t *port3 )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/ipc_tt.c
Kernel implementation of mach_ports_lookup: returns copies of the target task's three registered send rights in port1..port3 (MACH_PORT_NULL for unused slots). Returns KERN_INVALID_ARGUMENT if the task is null or its IPC space is no longer active.
functiontask_set_info
extern 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 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 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 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 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 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 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 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 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 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.
functiontask_policy_set
extern 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 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_zone_info
extern 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_get_state
extern 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 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 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 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 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_get_mach_voucher
extern 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 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 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.
functionmach_task_is_self
extern kern_return_t mach_task_is_self( task_name_t task, boolean_t *is_self /* out */ )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/task.c, osfmk/kern/ipc_tt.c
Returns TRUE if the given task port refers to the calling task. Accepts any flavor of task port (control, read, inspect, or name right). The library wrapper first compares the name against mach_task_self_ and otherwise issues the _kernelrpc_mach_task_is_self MIG call, in which the kernel compares the port's task with current_task(). Returns FALSE if the port is invalid or denotes another task. Useful because a task may hold several differently-named ports for itself.
functiontask_register_hardened_exception_handler
extern 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 },
{ "_kernelrpc_mach_ports_register3", 3403 },
{ "_kernelrpc_mach_ports_lookup3", 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 },
{ "mach_task_is_self", 3455 },
{ "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 }