#include <mach/exc_server.h>

mach/exc_server.h Kernel.framework

includes: Kernel/string.h, Kernel/mach/ndr.h, Kernel/mach/boolean.h, Kernel/mach/kern_return.h, Kernel/mach/notify.h, mach/mach_types.h, mach/message.h, Kernel/mach/mig_errors.h, mach/port.h, Availability.h, Kernel/mach/std_types.h, Kernel/mach/mig.h, Kernel/mach/mig.h, mach/mach_types.h
5 functions · 2 unions · 1 macro · 1 struct · 1 variable

macro_exc_server_

#define _exc_server_ 

functioncatch_exception_raise

extern MIG_SERVER_ROUTINE kern_return_t catch_exception_raise(
	mach_port_t exception_port,
	mach_port_t thread,
	mach_port_t task,
	exception_type_t exception,
	exception_data_t code,
	mach_msg_type_number_t codeCnt
)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Handles the occurrence of an exception within a thread.
A catch_exception_raise function is called by exc_server as the result of a kernel message indicating that an exception occurred within a thread. The exception_port parameter specifies the port named via a previous call to thread_set_exception_ports or task_set_exception_ports as the port that responds when the thread takes an exception. The alternate message forms (the format being selected when the exception port was set) allow for selected thread state to be included.
Notes. When an exception occurs in a thread, the thread sends an exception message to its exception port, blocking in the kernel waiting for the receipt of a reply. It is assumed that some task is listening (most likely with mach_msg_server) to this port, using the exc_server function to decode the messages and then call the linked in catch_exception_raise. It is the job of catch_exception_raise to handle the exception and decide the course of action for thread. If the thread should continue from the point of exception, catch_exception_raise would return KERN_SUCCESS. This causes a reply message to be sent to the kernel, which will allow the thread to continue from the point of the exception. If some other action should be taken by thread, the following actions should be performed by catch_exception_raise: thread_suspend This keeps the thread from proceeding after the next step. thread_abort This aborts the message receive operation currently blocking the thread. thread_set_state (if using the catch_exception_raise form). Set the thread's state so that it continues doing something else. thread_resume Let the thread start running from its new state. Returning a value other than KERN_SUCCESS insures that no reply message will be sent. sent. (Actually, the kernel uses a send once right to send the exception message, which thread_abort destroys, so replying to the message is harmless.) The thread can always be destroyed with thread_terminate. A thread can have two exception ports active for it: its thread type specific exception port and the task type specific exception port. The kernel will try sending an exception message to both ports looking for a reply message with a return value of KERN_SUCCESS. The kernel tries the thread specific port first, then the task specific port. If the return value from the first exception message the kernel sends has a return value of KERN_SUCCESS, the thread continues (with a possibly modified state). If the return value is not KERN_SUCCESS, the kernel tries the second port. If that return value is KERN_SUCCESS, the thread continues; otherwise, the thread is terminated. To get the effect of a non-success return value, the server interface should return MIG_DESTROY_REQUEST. This causes exc_server and mach_msg_server to destroy the kernel's request (as opposed to sending a reply with a KERN_SUCCESS value).
GNU Mach reference · 7.1.8 Exceptions · © FSF, GFDL
kern_return_t catch_exception_raise(mach_port_t exception_port, thread_t thread, task_t task, int exception, int code, int subcode)
XXX Fixme

functioncatch_exception_raise_state

extern MIG_SERVER_ROUTINE kern_return_t catch_exception_raise_state(
	mach_port_t exception_port,
	exception_type_t exception,
	const exception_data_t code,
	mach_msg_type_number_t codeCnt,
	int *flavor,
	const thread_state_t old_state,
	mach_msg_type_number_t old_stateCnt,
	thread_state_t new_state,
	mach_msg_type_number_t *new_stateCnt
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/mach/exc.defs
Server-interface routine of the exc MIG subsystem for exception ports registered with behavior EXCEPTION_STATE. Like catch_exception_raise, but receives the victim thread's state (flavor, old_state, old_stateCnt) in place of thread and task ports, and returns replacement state in new_state/new_stateCnt; on KERN_SUCCESS the kernel sets the thread's state from new_state (per the possibly-updated flavor) and continues it.

functioncatch_exception_raise_state_identity

extern MIG_SERVER_ROUTINE kern_return_t catch_exception_raise_state_identity(
	mach_port_t exception_port,
	mach_port_t thread,
	mach_port_t task,
	exception_type_t exception,
	exception_data_t code,
	mach_msg_type_number_t codeCnt,
	int *flavor,
	thread_state_t old_state,
	mach_msg_type_number_t old_stateCnt,
	thread_state_t new_state,
	mach_msg_type_number_t *new_stateCnt
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/mach/exc.defs
Server-interface routine of the exc MIG subsystem for exception ports registered with behavior EXCEPTION_STATE_IDENTITY. Combines catch_exception_raise and catch_exception_raise_state: receives the victim thread and task ports as well as the thread state, and returns replacement state in new_state/new_stateCnt.

functionexc_server

extern boolean_t exc_server(mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Handle kernel-reported thread exception.
The exc_server function is the MIG generated server handling function to handle messages from the kernel relating to the occurrence of an exception in a thread. Such messages are delivered to the exception port set via thread_set_exception_ports or task_set_exception_ports. When an exception occurs in a thread, the thread sends an exception message to its exception port, blocking in the kernel waiting for the receipt of a reply. The exc_server function performs all necessary argument handling for this kernel message and calls catch_exception_raise, catch_exception_raise_state or catch_exception_raise_state_identity, which should handle the exception. If the called routine returns KERN_SUCCESS, a reply message will be sent, allowing the thread to continue from the point of the exception; otherwise, no reply message is sent and the called routine must have dealt with the exception thread directly.
TRUEThe message was handled and the appropriate function was called.
FALSEThe message did not apply to the exception mechanism and no other action was taken.

functionexc_server_routine

extern mig_routine_t exc_server_routine(mach_msg_header_t *InHeadP)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/mach/exc.defs
Returns the MIG dispatch function for the exc subsystem request whose msgh_id is found in InHeadP, or a null pointer if the message is not a request of the subsystem. Alternative to the combined demultiplexer for servers that look up and invoke the handler themselves.

structcatch_exc_subsystem

Description of this subsystem, for use in direct RPC
size 152, align 8
mig_server_routine_tserverServer routine
mach_msg_id_tstartMin routine number
mach_msg_id_tendMax routine number + 1
unsigned intmaxsizeMax msg size
vm_address_treservedReserved
struct routine_descriptor[3]routine

variablecatch_exc_subsystem

extern const struct catch_exc_subsystem { mig_server_routine_t server; /* Server routine */ mach_msg_id_t start; /* Min routine number */ mach_msg_id_t end; /* Max routine number + 1 */ unsigned int maxsize; /* Max msg size */ vm_address_t reserved; /* Reserved */ struct routine_descriptor /* Array of routine descriptors */ routine[3]; } catch_exc_subsystem

union__RequestUnion__catch_exc_subsystem

size 5284, align 4
__Request__exception_raise_tRequest_exception_raise
__Request__exception_raise_state_tRequest_exception_raise_state
__Request__exception_raise_state_identity_tRequest_exception_raise_state_identity

union__ReplyUnion__catch_exc_subsystem

size 5236, align 4
__Reply__exception_raise_tReply_exception_raise
__Reply__exception_raise_state_tReply_exception_raise_state
__Reply__exception_raise_state_identity_tReply_exception_raise_state_identity