Skip to content

Glossary

Mach trap

A syscall into the Mach microkernel side of XNU — tasks, threads, ports, IPC, and virtual memory primitives. Negative syscall numbers, kern_return_t semantics.

A Mach trap is the syscall convention used to talk directly to XNU's Mach microkernel core. Every cross-task IPC, every task-port manipulation, every low-level VM primitive on macOS goes through one.

Defining traits:

  • Negative syscall number in x16 (e.g. task_for_pid is -45, mach_msg2_trap is -31). On x86_64 it's encoded as SYSCALL_CLASS_MACH << 24 | index in EAX.
  • kern_return_t semantics. No errno. The trap returns 0 (KERN_SUCCESS) or one of the KERN_* / MACH_* error codes directly.
  • No automatic descriptor management. Mach ports are passed in registers; lifecycle is the caller's responsibility.

There are ~70 of them in current XNU — far fewer than BSD syscalls. The table is in osfmk/kern/syscall_sw.c. Dispatch goes through mach_call_munger64() in osfmk/arm64/bsd_arm64.c.

Mach traps are the foundation for Mach ports, which in turn are the foundation for every form of IPC on macOS — including XPC, NSXPC, and IOKit user clients.