#include <mach/mach.h>

mach/mach.h

Includes all the types that a normal user of Mach programs should need
17 functions · 3 macros · 1 typedef

macroMACH_IPC_FLAVOR

#define MACH_IPC_FLAVOR UNTYPED

functionpanic_init

extern void panic_init(mach_port_t)
Standard prototypes

functionpanic

extern void panic(const char *, ...)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/panic.c
Reports a fatal user-space error. Writes "panic: <s>" to the standard error stream, requests host_reboot(RB_DEBUGGER) on the host port previously registered with panic_init (effective only if that is the privileged host port), and then calls abort(); does not return. Despite the printf-like prototype, the current implementation formats only the format string itself and ignores the variadic arguments.

functionslot_name

extern void slot_name(cpu_type_t, cpu_subtype_t, char **, char **)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/slot_name.c, libsyscall/mach/mach/mach.h
Historical CMU routine that converts machine slot values to human-readable strings: given a cpu type and subtype, stores pointers to static name strings for the CPU type and subtype through the last two parameters. The prototype survives in mach.h, but slot_name.c in current xnu retains only unrelated legacy stubs; the implementation is no longer present in the xnu sources. See mach_host.h cpu naming interfaces for current alternatives.

functionmig_reply_setup

extern void mig_reply_setup(mach_msg_header_t *, mach_msg_header_t *)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mig_reply_setup.c
Initializes a MIG reply message header from a request message. Sets the reply's msgh_bits from the request's local bits (remote disposition only), msgh_size to sizeof(mig_reply_error_t), msgh_remote_port to the request's msgh_local_port (the reply port), msgh_local_port to MACH_PORT_NULL, and msgh_id to the request id plus 100, following the MIG reply-id convention; also stores the NDR record. Does not set a value in the RetCode field.

functionmach_msg_destroy

__WATCHOS_PROHIBITED __TVOS_PROHIBITED
extern void mach_msg_destroy(mach_msg_header_t *)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach_msg.c
Deallocates all port rights and out-of-line memory carried in a message. Useful in two contexts: disposing of a received request a server does not want, and mimicking the side effects of a send when the reply cannot be delivered (the client died), as if the message were sent and destroyed inside the kernel. Releases the msgh_remote_port and msgh_voucher_port rights according to their dispositions and, if MACH_MSGH_BITS_COMPLEX is set, walks the descriptors: port and ool-ports rights are destroyed (guarded ports are unguarded first), and out-of-line memory with the deallocate bit set is released with vm_deallocate. The msgh_local_port field is not touched; the receive operation already consumed the destination port right.

functionmach_msg_receive

__WATCHOS_PROHIBITED __TVOS_PROHIBITED
extern mach_msg_return_t mach_msg_receive(mach_msg_header_t *)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach_msg.c
Receives a message. Equivalent to mach_msg with MACH_RCV_MSG, receiving on the port named by msg->msgh_local_port into msg with receive limit msg->msgh_size and no timeout. Interrupted receives are restarted transparently by mach_msg.

functionmach_msg_send

__WATCHOS_PROHIBITED __TVOS_PROHIBITED
extern mach_msg_return_t mach_msg_send(mach_msg_header_t *)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach_msg.c
Sends a message. Equivalent to mach_msg with MACH_SEND_MSG, send size msg->msgh_size, and no timeout. Interrupted sends are restarted transparently by mach_msg.

functionmach_msg_server_once

__WATCHOS_PROHIBITED __TVOS_PROHIBITED
extern mach_msg_return_t mach_msg_server_once(
	boolean_t (*) (mach_msg_header_t *, mach_msg_header_t *),
	mach_msg_size_t,
	mach_port_t,
	mach_msg_options_t
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach_msg.c
A simple generic server function that processes a single request and returns; allows more flexibility than mach_msg_server. Allocates request and reply buffers (max_size plus space for the requested trailer), receives one message on rcv_name with MACH_RCV_VOUCHER (honoring MACH_RCV_LARGE by reallocating a larger buffer), adopts the message's voucher, and invokes the demux routine to build the reply. The reply is sent unless its RetCode is MIG_NO_REPLY or the reply port is null; on any other failing RetCode the request is destroyed first. MACH_SEND_TIMEOUT is added when replying to a send right (a send-once right cannot block). Recoverable send failures (MACH_SEND_INVALID_DEST, MACH_SEND_TIMED_OUT, MACH_SEND_INTERRUPTED) destroy the unsent reply and report MACH_MSG_SUCCESS. Errors from mach_msg are returned; errors from the demux routine are not.

functionmach_msg_server

__WATCHOS_PROHIBITED __TVOS_PROHIBITED
extern mach_msg_return_t mach_msg_server(
	boolean_t (*) (mach_msg_header_t *, mach_msg_header_t *),
	mach_msg_size_t,
	mach_port_t,
	mach_msg_options_t
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach_msg.c
A simple generic server loop. Repeatedly receives requests on rcv_name with MACH_RCV_VOUCHER, adopts each message's voucher, invokes the demux routine to generate a reply, and sends the reply, using a combined send/receive to stay on the kernel's fast RPC path. Replies are suppressed when the demux RetCode is MIG_NO_REPLY or the reply port is null; on any other failing RetCode the request is destroyed. MACH_SEND_TIMEOUT is added when replying to a send right rather than a send-once right, and recoverable send failures (MACH_SEND_INVALID_DEST, MACH_SEND_TIMED_OUT, MACH_SEND_INTERRUPTED) destroy the unsent reply and continue the loop. MACH_RCV_LARGE in options causes the request buffer to be grown as needed. Returns only when a receive fails, with that mach_msg error.

functionmach_msg_server_importance

__WATCHOS_PROHIBITED __TVOS_PROHIBITED
extern mach_msg_return_t mach_msg_server_importance(
	boolean_t (*) (mach_msg_header_t *, mach_msg_header_t *),
	mach_msg_size_t,
	mach_port_t,
	mach_msg_options_t
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach_msg.c
Identical to mach_msg_server; the current implementation simply calls it. Historically a variant that handled importance-promotion assertions for adaptive daemons around each request; that handling is now performed by the voucher adoption done in mach_msg_server itself, and this entry point remains for compatibility.

functionclock_get_res

extern kern_return_t clock_get_res(mach_port_t, clock_res_t *)
Prototypes for compatibility

functionclock_set_res

extern kern_return_t clock_set_res(mach_port_t, clock_res_t)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libsyscall/mach/mach/mach.h, osfmk/mach/clock_priv.defs
Obsolete compatibility prototype, declared in mach.h alongside clock_get_res; intended to set the resolution, in nanoseconds (clock_res_t), of the clock named by the port. No implementation exists in current libsyscall, and the underlying privileged clock-attribute interface (clock_set_attributes) has been removed from the kernel, so clock resolution cannot be changed. clock_get_res remains available to read the resolution.

functionclock_sleep

extern kern_return_t clock_sleep(mach_port_t, int, mach_timespec_t, mach_timespec_t *)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Sleep until a given time.
The clock_sleep system trap delays the invoking thread until a specified time. This sleep may be aborted by thread_abort. Not all clocks provide this service but the REALTIME clock must. If the specified time is in the past, the call returns immediately with the wake time being the current time. If the clock's time is changed (clock_set_time), the sleep will be interrupted. The thread will waken at the service time nearest the specified sleep time as governed by the current clock alarm resolution.
KERN_FAILUREThe clock does not support a sleep service.
KERN_ABORTEDThe sleep was interrupted by thread_abort or terminated via use of clock_set_time.

macroVOUCHER_MACH_MSG_API_VERSION

#define VOUCHER_MACH_MSG_API_VERSION 20140205

typedefvoucher_mach_msg_state_t

@typedef voucher_mach_msg_state_t @abstract Opaque object encapsulating state changed by voucher_mach_msg_adopt().
typedef struct voucher_mach_msg_state_s *voucher_mach_msg_state_t

macroVOUCHER_MACH_MSG_STATE_UNCHANGED

@const VOUCHER_MACH_MSG_STATE_UNCHANGED @discussion Constant indicating no state change occurred.
#define VOUCHER_MACH_MSG_STATE_UNCHANGED ((voucher_mach_msg_state_t)~0ul)

functionvoucher_mach_msg_set

extern boolean_t voucher_mach_msg_set(mach_msg_header_t *msg)
@function voucher_mach_msg_set @abstract Change specified message header to contain current mach voucher with a COPY_SEND disposition. Does not change message if it already has non-zero MACH_MSGH_BITS_VOUCHER. @discussion Borrows reference to current thread voucher so message should be sent immediately (without intervening calls that might change that voucher). @param msg The message to modify. @result True if header was changed.

functionvoucher_mach_msg_clear

extern void voucher_mach_msg_clear(mach_msg_header_t *msg)
@function voucher_mach_msg_clear @abstract Removes changes made to specified message header by voucher_mach_msg_set() and any mach_msg() send operations (successful or not). If the message is not needed further, mach_msg_destroy() should be called instead. @discussion Not intended to be called if voucher_mach_msg_set() returned false. Releases reference to message mach voucher if an extra reference was acquired due to an unsuccessful send operation (pseudo-receive). @param msg The message to modify.

functionvoucher_mach_msg_adopt

extern voucher_mach_msg_state_t voucher_mach_msg_adopt(mach_msg_header_t *msg)
@function voucher_mach_msg_adopt @abstract Adopt the voucher contained in the specified message on the current thread and return the previous thread voucher state. @discussion Ownership of the mach voucher in the message is transferred to the current thread and the message header voucher fields are cleared. @param msg The message to query and modify. @result The previous thread voucher state or VOUCHER_MACH_MSG_STATE_UNCHANGED if no state change occurred.

functionvoucher_mach_msg_revert

extern void voucher_mach_msg_revert(voucher_mach_msg_state_t state)
@function voucher_mach_msg_revert @abstract Restore thread voucher state previously modified by voucher_mach_msg_adopt(). @discussion Current thread voucher reference is released. No change to thread voucher state if passed VOUCHER_MACH_MSG_STATE_UNCHANGED. @param state The thread voucher state to restore.