#include <mach/mach_init.h> also included by <mach/mach.h>

mach/mach_init.h

Items provided by the Mach environment initialization.
7 macros · 4 functions · 3 variables

macro_MACH_INIT_

#define _MACH_INIT_ 1

functionmach_host_self

extern mach_port_t mach_host_self(void)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Returns the host self port
The mach_host_self function returns send rights to the task's host self port. By default, this is the name port for the current host but can be a different value if so set.

functionmach_thread_self

extern mach_port_t mach_thread_self(void)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Returns the thread self port.
The mach_thread_self function returns send rights to the thread's own kernel port.
GNU Mach reference · 7.1.3 Thread Information · © FSF, GFDL
thread_t mach_thread_self()
The mach_thread_self system call returns the calling thread's thread port. mach_thread_self has an effect equivalent to receiving a send right for the thread port. mach_thread_self returns the name of the send right. In particular, successive calls will increase the calling task's user-reference count for the send right. As a special exception, the kernel will overrun the user reference count of the thread name port, so that this function can not fail for that reason. Because of this, the user should not deallocate the port right if an overrun might have happened. Otherwise the reference count could drop to zero and the send right be destroyed while the user still expects to be able to use it. As the kernel does not make use of the number of extant send rights anyway, this is safe to do (the thread port itself is not destroyed, even when there are no send rights anymore). The function returns MACH_PORT_NULL if a resource shortage prevented the reception of the send right or if the thread port is currently null and MACH_PORT_DEAD if the thread port is currently dead.

functionmach_task_is_self

__API_AVAILABLE(macos(11.3), ios(14.5), tvos(14.5), watchos(7.3))
extern boolean_t mach_task_is_self(task_name_t task)
MIG routine from mach/task.defs
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.

functionhost_page_size

extern kern_return_t host_page_size(host_t, vm_size_t *)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Provide the system's virtual page size.
The host_page_size function returns the page size for the given host.

variablemach_task_self_

extern __swift_nonisolated_unsafe mach_port_t mach_task_self_

macromach_task_self

#define mach_task_self() mach_task_self_
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return a send right to the caller's task_self port.
The mach_task_self function returns send rights to the task's kernel port.
Notes. This function call is redefined in the mach_init.h file to return the caller's mach_task_self_ environment variable, which is cached on behalf of the caller's task at runtime. (The mach_init.h file is itself included via the mach.h file.
GNU Mach reference · 7.2.3 Task Information · © FSF, GFDL
task_t mach_task_self()
The mach_task_self system call returns the calling thread's task port. mach_task_self has an effect equivalent to receiving a send right for the task port. mach_task_self returns the name of the send right. In particular, successive calls will increase the calling task's user-reference count for the send right. As a special exception, the kernel will overrun the user reference count of the task name port, so that this function can not fail for that reason. Because of this, the user should not deallocate the port right if an overrun might have happened. Otherwise the reference count could drop to zero and the send right be destroyed while the user still expects to be able to use it. As the kernel does not make use of the number of extant send rights anyway, this is safe to do (the task port itself is not destroyed, even when there are no send rights anymore). The function returns MACH_PORT_NULL if a resource shortage prevented the reception of the send right, MACH_PORT_NULL if the task port is currently null, MACH_PORT_DEAD if the task port is currently dead.

macrocurrent_task

#define current_task() mach_task_self()

variablebootstrap_port

extern mach_port_t bootstrap_port

macroNAME_SERVER_SLOT

#define NAME_SERVER_SLOT 0

macroENVIRONMENT_SLOT

#define ENVIRONMENT_SLOT 1

macroSERVICE_SLOT

#define SERVICE_SLOT 2

macroMACH_PORTS_SLOTS_USED

#define MACH_PORTS_SLOTS_USED 3

variablevprintf_stderr_func

fprintf_stderr uses vprintf_stderr_func to produce error messages, this can be overridden by a user application to point to a user-specified output function
extern int (*vprintf_stderr_func)(const char *format, va_list ap)