The Complete Guide to macOS Kernel Internals
A map of the XNU kernel behind macOS: Mach tasks and ports, the BSD layer, IOKit, system call entry, virtual memory, security layers, extensions and boot.

The kernel under macOS is called XNU, and the name is a joke that nobody has retired: it stands for "X is Not Unix". It is a hybrid. A Mach microkernel provides tasks, threads, virtual memory and message passing. A BSD layer on top of it provides processes, the POSIX system calls, file systems and the network stack. A C++ driver framework called IOKit provides the device model. All three are linked into a single kernel binary that runs in one address space with full privilege, which makes it monolithic in practice, even though Mach's design vocabulary survives in every corner. This guide is the map. It explains what each piece does, how a request travels through them, where the open-source tree keeps each one, which tools show you the live state of a Mac and which extension model has replaced kernel extensions. Each section ends where a deeper post on the same topic begins.
If you are coming from Linux, expect two things. First, there is much more indirection than you are used to: a file read crosses a BSD system call, a VFS layer and a Mach virtual memory object before it reaches a driver. Second, most of what you would write as a kernel module on Linux is, on current macOS, written as a user-space process, which is a deliberate policy rather than an accident.
What XNU is made of
The XNU source tree is organized by those three components, and the directory names tell you which is which. Apple publishes the source for each macOS release as open source, and the project lives in the apple-oss-distributions/xnu repository.
| Directory | Component | What lives there |
|---|---|---|
osfmk/ | Mach | Tasks, threads, scheduler, virtual memory, IPC ports and messages, timers, per-architecture code |
bsd/ | BSD | Processes, signals, system calls, VFS and file systems, sockets and networking, the sysctl tree |
iokit/ | IOKit | The driver framework: IOService, the registry, user clients, matching |
libkern/ | libkern | The restricted C++ runtime for kernel code (OSObject, OSString, OSArray) and C library routines |
libsa/ | Bootstrap | Support for loading extensions into the kernel |
pexpert/ | Platform expert | Platform abstraction, boot arguments, device tree access |
security/ | MAC framework | The mandatory access control hooks that sandboxing and code signing policy attach to |
san/ | Sanitizers | Kernel address sanitizer and related debugging support |
tools/ | Tooling | Debugging scripts, including macros for the kernel debugger |
The split is not strict at run time. A read() from a program is a BSD system call that calls into a VFS layer, which uses the Mach virtual memory system to cache file pages, which may in turn drive an IOKit storage driver. The source-level split matters because each component has its own conventions: Mach code uses names such as thread_t, vm_map_t and kern_return_t, BSD code uses struct proc, struct vnode and errno values, and IOKit code is C++ with names beginning IO.
You can read the kernel's identity from user space. uname shows the XNU version string, which also encodes the build type and platform:
uname -v
sysctl kern.versionDarwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000
kern.version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000The numbers on your machine will differ with the release and the chip. The pieces to read are the Darwin version, which tracks the macOS major version, the xnu- build number that identifies the exact source drop, and the suffix RELEASE_ARM64_T6000, which names the build configuration (release, not development or debug) and the platform, here the Apple silicon family identified as T6000. On an Intel Mac the suffix is RELEASE_X86_64.
Inspect a live system from user space
Before reading any source, learn what the system will tell you. A handful of tools expose the kernel's internal state without special privileges.
sysctl reads the kernel's tunable and statistics tree, which has the same shape as on BSD: kern.*, hw.*, vm.*, net.* and machdep.*. These are the quickest way to answer a question such as how much memory the machine has or when it booted:
sysctl hw.memsize hw.ncpu hw.pagesize kern.boottimehw.memsize: 34359738368
hw.ncpu: 10
hw.pagesize: 16384
kern.boottime: { sec = 1763800123, usec = 412345 } Sun Nov 22 08:08:43 2025The values depend on your Mac. The one worth remembering is hw.pagesize: on Apple silicon the kernel page size is 16 KB, not the 4 KB that Intel Macs and most Linux systems use, and software that hard-codes 4096 breaks there. Always ask with sysconf(_SC_PAGESIZE) or getpagesize().
ioreg prints the IORegistry, the live tree of every device and driver object the kernel has created. ioreg -l is the long form with all properties, ioreg -p IOService -w0 -r -c IOPlatformExpertDevice prints the platform node, and ioreg -c IOUSBHostDevice lists USB devices. The next sections come back to what the tree means.
kmutil showloaded lists loaded kernel extensions and the kernel collections that contain them, replacing the older kextstat. vm_stat prints virtual memory counters, top and ps read process tables, lsof lists open files, vmmap <pid> shows a process's address space, and sample <pid> and spindump capture stacks. For tracing, fs_usage and dtruss build on the kernel's kdebug and DTrace facilities, with the limits that System Integrity Protection places on them, covered in a later section.
Mach: tasks, threads and ports
Mach is the part of XNU with the most unusual vocabulary, and it is the foundation. Three ideas explain most of it.
A task is a container of resources: an address space, a set of ports, and one or more threads. A BSD process is a task plus a BSD struct proc that adds the POSIX identity. Each proc has a pointer to its task, and each task has a pointer back through its bsd_info field. When you call fork(), BSD creates the proc and asks Mach to create a task for it.
A thread is an unit of execution inside a task, scheduled by Mach. Threads have a priority, a scheduling class and per-thread state. Everything in the system that runs, including kernel threads, is a Mach thread.
A port is a protected message queue in the kernel, and the means by which almost everything communicates. A task holds port rights, which are capabilities: the right to send to a port, receive from it, or send once. The kernel stores rights in a per-task name space and hands out small integer names (mach_port_t) that mean nothing outside the task that holds them. The same port has a different name in every task that holds a right to it. Since the only way to talk to a kernel object is through a port, ports also name tasks, threads and virtual memory objects: mach_task_self() returns your task's own port, and holding the send right to another task's port is what lets you read its memory.
Here is a short program that uses these ideas to read basic information about the calling task. It asks the kernel, through the task's port, for its resident and virtual size:
#include <mach/mach.h>
#include <stdio.h>
int
main(void)
{
struct mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
kern_return_t kr;
kr = task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
(task_info_t)&info, &count);
if (kr != KERN_SUCCESS) {
fprintf(stderr, "task_info: %s\n", mach_error_string(kr));
return 1;
}
printf("virtual size: %llu bytes\n",
(unsigned long long)info.virtual_size);
printf("resident size: %llu bytes\n",
(unsigned long long)info.resident_size);
return 0;
}virtual size: 420123648 bytes
resident size: 1294336 bytesCompile it with cc task_info.c -o task_info. The sizes will differ on your machine and from run to run. The Mach convention is visible in the code: every call returns a kern_return_t, with KERN_SUCCESS as zero, results come back through out-parameters and a count, and mach_error_string turns a code into text. Listing the task's threads needs a second call, task_threads, which hands back an array of thread ports.
Messages are what travel on ports. mach_msg() is the single call that sends, receives or both, and the message has a header with the destination, a reply port and a size, followed by typed data that may include port rights and out-of-line memory. Most programs never call it directly: they use XPC, a layer on top of ports, or a generated interface from MIG, the Mach Interface Generator. A later post explains the message format in detail.
The BSD layer
The BSD part of XNU is derived from FreeBSD, and gives macOS its POSIX personality: process IDs, signals, file descriptors, users and groups, sockets and the shell-visible file system. It is no longer a faithful copy of any FreeBSD release. Apple has changed it heavily, and the remaining resemblance is mostly in names and structure.
A process in BSD terms is struct proc, holding the PID, the credential, the file descriptor table, signal state and the link to the Mach task. A file system is a struct vnode for each file, a struct mount for each mounted volume, and a set of operations tables. macOS's native file system is APFS, with HFS+ still readable, and the VFS layer is shared among them. Network protocols and sockets are in bsd/netinet, bsd/net and bsd/kern/uipc_*.c, with the packet filter pf and the network kernel extension and content filter interfaces on top. The sysctl tree you queried above is implemented in bsd/kern/kern_sysctl.c.
The boundary between BSD and Mach shows up in a few well-known places. Process creation is BSD's fork and posix_spawn, but the address space comes from Mach's vm_map. Signals are BSD, but delivered to Mach threads. Memory mapping with mmap is a BSD system call that calls vm_map functions to create a mapping. File-backed pages come from the unified buffer cache, which is a Mach vm_object per vnode. Knowing that a file is a vnode in BSD and a memory object in Mach explains why mmap of a file and read of the same file share cached pages.
IOKit and the IORegistry
IOKit is the object-oriented driver framework, and it is the one place in XNU where C++ is the language. Kernel C++ uses a restricted dialect: no exceptions, no RTTI, no standard library, no templates in the interface, and its own runtime type system implemented in libkern with OSObject as the root class and macros such as OSDeclareDefaultStructors and OSDefineMetaClassAndStructors instead of compiler RTTI.
A driver is a subclass of IOService. The kernel builds a tree, the IORegistry, of service objects, with providers as parents and clients as children. A bus driver publishes a nub for each device it finds, and the matching system, with a dictionary of properties in the driver's Info.plist, finds drivers whose match criteria fit. When one matches, it is attached as a client, goes through probe, start and attach, and later through stop and detach. The names are different from FreeBSD's newbus and the idea is the same.
You can browse the tree. This prints the registry's top level for the services plane:
ioreg -p IOService -l -w0 -d2 | head -12+-o Root <class IORegistryEntry, id 0x100000100, retain 29>
+-o Mac14,5 <class IOPlatformExpertDevice, id 0x10000020f, registered, matched, active, busy 0 (1019 ms), retain 40>
| {
| "IOPlatformSerialNumber" = "..."
| "compatible" = <"J314sAP","MacBookPro18,3","AppleARM">
| "model" = <"MacBookPro18,3">
| "IOPolledInterface" = "AppleARMWatchdogTimer is not serializable"The listing and identifiers differ on every machine, and some properties are redacted here. The pattern to notice is +-o Name <class ClassName, id ..., ...>: each node shows its registry name and its C++ class. A GPU, a USB controller or an NVMe disk are nodes in this tree, and user space reaches them by opening a user client on the service with IOServiceOpen, the older route, or through a DriverKit connection for current drivers. The older path still serves the system's own drivers and a large set of existing tools.
From a system call to the kernel
A user program calls a library function, which executes the processor's trap instruction. On Apple silicon that is svc #0x80 with the call number in register x16; on Intel it is syscall with the number in rax. The kernel then decides which of several dispatch tables to use based on the class encoded in the number:
| Class | Numbers | Table | Examples |
|---|---|---|---|
| Mach traps | Negative | mach_trap_table in osfmk/kern | mach_msg_trap, mach_reply_port, task_self_trap |
| BSD system calls | Positive | sysent in bsd/kern/syscalls.master | read, write, open, fork |
| Machine-dependent | Special | Per-architecture | Thread-specific calls |
So a single entry point serves both personalities of the kernel, and the sign of the number says which one you meant. BSD system calls are documented in section 2 of the manual and are the stable interface. Direct use of system call numbers is discouraged and the syscall(2) wrapper is deprecated on macOS, because the supported interface is libSystem, the C library, and Apple may renumber or change the calls underneath it. A later post compares the two tables in more detail.
Virtual memory
Mach's virtual memory design is one of its lasting contributions. An address space is a vm_map, a sorted list of entries each describing a range of addresses and the vm_object that backs it. A vm_object is a container of pages with a pager that knows how to fill them from backing storage, whether a file, the compressor or nothing at all for zero-fill memory. A page fault finds the entry, then the object, then asks the pager. Copy-on-write is built from shadow objects stacked on a parent.
Two things distinguish macOS here. The first is the compressor: instead of paging idle memory straight to disk, the VM system compresses pages in memory and swaps only when compression is not enough, which is why macOS reports "compressed" memory in Activity Monitor. The second is the page size, 16 KB on Apple silicon, noted above, which interacts with mmap alignment and with Rosetta's translated processes, which see a 4 KB view.
User-space Mach calls such as mach_vm_allocate, mach_vm_protect and mach_vm_region operate on a task's vm_map through its port. This program prints the first few regions of its own address space, which is what vmmap does for any process it can reach:
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <stdio.h>
int
main(void)
{
mach_vm_address_t addr = 0;
mach_vm_size_t size = 0;
int n;
for (n = 0; n < 4; n++) {
vm_region_basic_info_data_64_t info;
mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64;
mach_port_t object_name;
kern_return_t kr;
kr = mach_vm_region(mach_task_self(), &addr, &size,
VM_REGION_BASIC_INFO_64, (vm_region_info_t)&info,
&count, &object_name);
if (kr != KERN_SUCCESS)
break;
printf("%016llx-%016llx prot=%c%c%c\n",
(unsigned long long)addr,
(unsigned long long)(addr + size),
(info.protection & VM_PROT_READ) ? 'r' : '-',
(info.protection & VM_PROT_WRITE) ? 'w' : '-',
(info.protection & VM_PROT_EXECUTE) ? 'x' : '-');
addr += size;
}
return 0;
}0000000100a2c000-0000000100a30000 prot=r-x
0000000100a30000-0000000100a34000 prot=r--
0000000100a34000-0000000100a38000 prot=r--
0000000100a38000-0000000100a40000 prot=rw-Addresses depend on address space layout randomization and change every run, and the number of regions depends on the binary. The call updates addr to the start of the region it found at or after the address you gave it, which is why the loop advances by size. The page-sized steps on Apple silicon are multiples of 16 KB.
Scheduling
The Mach scheduler decides which thread runs on which CPU. Threads have a base priority and a scheduling mode, and the kernel adjusts priority for timesharing based on recent CPU use. Recent macOS releases use a hierarchical scheduler, the Clutch scheduler, that groups threads by their quality-of-service class and assigns them to performance or efficiency cores on Apple silicon. Quality of service is set from user space with pthread_set_qos_class_self_np or Dispatch queue attributes, and the classes (QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_USER_INITIATED, QOS_CLASS_UTILITY and QOS_CLASS_BACKGROUND) are the vocabulary by which a program tells the kernel what matters. Setting them correctly is the most effective way to influence scheduling on a modern Mac, since it is the interface the scheduler is designed around.
Security layers
macOS stacks several protection mechanisms, and kernel developers meet each of them quickly.
System Integrity Protection (SIP) restricts even root: it protects system directories and processes from modification, and limits what debugging and tracing tools may attach to. It is enforced in the kernel through the MAC framework and entitlements. That is why dtruss cannot trace a protected process unless SIP is relaxed in Recovery.
Code signing and entitlements decide what a binary may do. The kernel checks signatures when it maps executables, and Apple Mobile File Integrity (AMFI) enforces entitlement and provisioning rules. An entitlement is a key in the signature, and a capability such as com.apple.developer.endpoint-security.client is granted by Apple to the developers who request it.
The sandbox is a policy engine built on the MAC framework (security/mac_*, with the Sandbox policy module as an extension). A profile written in a Scheme-like language limits file, network and IPC access per process.
The MAC framework is TrustedBSD's mandatory access control layer: a set of hooks scattered through the kernel, such as mac_vnode_check_open, that policy modules answer. It is how the sandbox, AMFI and others intervene without patching each code path.
On Apple silicon, hardware features add to this. Pointer authentication codes sign return addresses and function pointers, and a read-only region and page-protection layer guard kernel and page table memory. The interfaces for these features are documented by Apple's platform security guide and the architecture manuals. The practical consequence for an author of kernel code is that writing to your own function pointers or patching code is not possible on those chips, by design.
Extensions: from kexts to system extensions
Historically, you extended the kernel with a kernel extension (kext): a bundle with a C++ driver loaded into the kernel. Kexts still exist and ship with the OS, but Apple has steadily deprecated third-party kexts. Loading one requires reduced security on Apple silicon and user approval, and the supported alternatives are user-space frameworks.
| Need | Modern mechanism | Runs in |
|---|---|---|
| A hardware driver for USB, PCIe, HID, serial, audio or network | DriverKit | A user-space process (a dext) |
| Observe process, file or network events for security tools | Endpoint Security | A privileged user-space process |
| Network filters, VPNs and DNS proxies | Network Extension | A system extension |
| A file system | FSKit (user-space file system), and the older macFUSE style | User space |
DriverKit gives you a C++ API (IOUserClient, IOService subclasses written with the .iig interface language) that compiles to a driver extension, a dext. The kernel provides the real device access through an in-kernel proxy driver, and the dext receives interrupts and registers by message. A crash kills the dext, not the kernel. The next posts walk through DriverKit compared with kernel extensions and writing a USB driver, and the Endpoint Security framework covers event monitoring.
Boot: from iBoot to the kernel collection
On Apple silicon the boot chain is: Boot ROM, then the Low-Level Bootloader and iBoot, which verifies and loads the kernel from a signed image. Since macOS 11 the kernel is loaded as part of a boot kernel collection, one signed file that contains XNU and the extensions that must be present at boot, alongside a system kernel collection for the rest of Apple's extensions and, optionally, an auxiliary kernel collection for approved third-party kexts. kmutil builds and manages these collections. The kernel starts, initializes the platform expert from the device tree handed to it by iBoot, brings up Mach, then BSD, then IOKit, and finally launches launchd as PID 1, which starts the rest of user space. A detailed description of the chain is in the later post on how Apple silicon boots.
Debugging and tracing the kernel
Without a development kernel there are still useful views. log show --predicate 'process == "kernel"' --last 10m prints kernel log messages from the unified log. sudo fs_usage -w -f filesys shows file system calls, sudo sysdiagnose collects a diagnostic bundle, and sudo spindump takes system-wide stack samples. DTrace works with the limits SIP imposes, and the kdebug facility behind fs_usage and Instruments gives a low-overhead event stream.
To debug a kernel you control, you need a development or debug kernel and a second machine. The kernel supports remote debugging with lldb using the kdp protocol over network or serial, and the open-source tree provides LLDB macros under tools/lldbmacros that walk kernel data structures: listing tasks, threads and ports, printing vm maps and decoding zone allocations. A panic produces a panic log and, if configured, a core file, which lldb can read with the same macros.
Building XNU yourself
Apple's source drop builds the kernel for study and experiment. The build needs the matching Xcode toolchain, the dtrace and ctfconvert tools, the Libsyscall and header packages from the same release, and its own make targets, and the project's README documents the sequence. Building the kernel is straightforward on the right host. Running it is not: replacing the kernel on a Mac requires disabling protections, and the supported route is to boot it as a virtual machine guest or on a test device. A later post covers that process and its limits.
Allocate and use a port
The port is the idea that is hardest to feel from prose, so here is the smallest complete use of one. This program allocates a receive right, inserts a send right for it, sends itself a message and receives it. Nothing leaves the process, but every step is the same one a client and a server would take.
#include <mach/mach.h>
#include <stdio.h>
#include <string.h>
typedef struct {
mach_msg_header_t header;
char text[32];
} ping_send_t;
typedef struct {
mach_msg_header_t header;
char text[32];
mach_msg_trailer_t trailer;
} ping_recv_t;
int
main(void)
{
mach_port_t port;
kern_return_t kr;
ping_send_t out;
ping_recv_t in;
kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port);
if (kr != KERN_SUCCESS)
return 1;
kr = mach_port_insert_right(mach_task_self(), port, port,
MACH_MSG_TYPE_MAKE_SEND);
if (kr != KERN_SUCCESS)
return 1;
memset(&out, 0, sizeof(out));
out.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
out.header.msgh_size = sizeof(out);
out.header.msgh_remote_port = port;
out.header.msgh_id = 1001;
strlcpy(out.text, "ping", sizeof(out.text));
kr = mach_msg(&out.header, MACH_SEND_MSG, sizeof(out), 0,
MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
if (kr != KERN_SUCCESS)
return 1;
memset(&in, 0, sizeof(in));
kr = mach_msg(&in.header, MACH_RCV_MSG, 0, sizeof(in), port,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
if (kr != KERN_SUCCESS)
return 1;
printf("id=%d text=%s\n", in.header.msgh_id, in.text);
return 0;
}id=1001 text=pingWalk through it. mach_port_allocate with MACH_PORT_RIGHT_RECEIVE creates a new port and gives the task the only receive right, which is what makes the queue the task's. mach_port_insert_right with MACH_MSG_TYPE_MAKE_SEND creates a send right from the receive right and stores it under the same name, so the task can now send to its own port. The message is a header followed by data. msgh_remote_port is the destination, msgh_bits says how to treat the destination right (MACH_MSG_TYPE_COPY_SEND copies the send right we hold) and the id is a number the receiver uses to decide what the message means, which is the convention MIG-generated code builds on. The receive buffer has a trailer after the body, which the kernel fills with information such as the sender's audit token, and which is why the receive structure is larger.
Real services find each other through the bootstrap server, which is launchd. A server registers a name, a client looks it up with bootstrap_look_up and receives a send right. Launch agents and daemons list their Mach service names in their property list, and launchd creates the receive right on their behalf and starts the process on demand when the first message arrives. That is the reason a macOS service can be idle at no cost and still answer instantly: the port exists before the process does. XPC, the layer most code uses, adds typed dictionaries, connection lifecycle and code-signing checks on top of exactly these primitives.
Read kernel statistics from C
The sysctl command is a thin front end for a system call, and your own programs can use it. sysctlbyname takes the name, a buffer for the old value and its size. Two examples cover most uses: a fixed-size integer and a structure.
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <mach/mach.h>
#include <stdio.h>
int
main(void)
{
uint64_t memsize = 0;
size_t len = sizeof(memsize);
struct timeval boot;
size_t blen = sizeof(boot);
vm_statistics64_data_t vm;
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
if (sysctlbyname("hw.memsize", &memsize, &len, NULL, 0) == 0)
printf("memory: %llu MiB\n",
(unsigned long long)(memsize >> 20));
if (sysctlbyname("kern.boottime", &boot, &blen, NULL, 0) == 0)
printf("booted at epoch second %lld\n", (long long)boot.tv_sec);
if (host_statistics64(mach_host_self(), HOST_VM_INFO64,
(host_info64_t)&vm, &count) == KERN_SUCCESS)
printf("free pages: %u, compressed pages: %u\n",
vm.free_count, vm.compressor_page_count);
return 0;
}memory: 32768 MiB
booted at epoch second 1763800123
free pages: 11873, compressed pages: 384201The values will differ. The program shows both personalities of the kernel in one file. sysctlbyname is the BSD interface and returns data from the sysctl tree. host_statistics64 is the Mach interface, taking the host port from mach_host_self() and returning the virtual memory counters, which include the compressor's page count. The counts are in pages, so multiply by hw.pagesize to get bytes, which is 16384 on Apple silicon. This is also how vm_stat works.
Some sysctl names return structures whose layout is part of the interface, such as kern.boottime. Check the header for the type before you read the value, and check the return code of every call, since a name that exists on one release may not exist on another.
The file system stack
A file operation travels down through layers that are worth naming. The BSD system call (read, open, pread) looks up the file descriptor, finds the struct vnode and calls through the vnode operations vector into the file system, which for most Macs is APFS. APFS is a copy-on-write container file system with snapshots, clones and space sharing, and it sits on a storage stack of partitions and an IOKit block-storage driver. Cached file data lives as pages in the Mach virtual memory system, associated with the vnode's memory object. A read that hits the cache never reaches the driver. On a miss, the page-in path asks the pager, which asks APFS to read the extents, which issue I/O through IOKit's storage classes to the NVMe controller driver.
Two features show up in everyday tooling. Extended attributes carry quarantine flags and Finder metadata, and xattr reads them. Firmlinks stitch the read-only system volume and the writable data volume into one tree, which is why /Users and /Applications appear to live next to /System even though they are separate volumes. A tool that walks / sees both, and one that checks free space must pick the right volume.
Networking
The network stack lives in bsd/net and bsd/netinet and is the BSD socket API with Apple's additions. Two stand out. Network kernel extensions and content filters hooked into the stack for security products are deprecated in favor of the Network Extension framework. Multipath TCP and the packet filter sit in the stack for system use. Interfaces appear in ifconfig and netstat -i, the routing table in netstat -rn, and per-socket statistics in netstat -s. Wi-Fi, Bluetooth and Thunderbolt networking come from separate IOKit families and user-space daemons, and the networking configuration is managed by configd and the System Configuration framework, not by files you edit.
Memory allocation inside the kernel
Kernel code allocates from zones, a design shared with FreeBSD's UMA through common ancestry. A zone_t holds fixed-size elements with per-CPU caches. The general kalloc interface rounds a request up to a size class and takes it from a zone, and in recent releases it separates allocations by type so that a buffer overflow in one kind of object cannot overwrite a different kind. The zprint tool shows the zones, which is the macOS counterpart of vmstat -z:
sudo zprint | head -4zone name elem size cur size max size cur #elts max #elts ...
vm.objects 184 ...
vm.pages ...
kalloc.type.var1.128 128 ...The zones and counts vary with release and workload. When you chase a leak in a kernel extension, zprint is the first tool: you compare it before and after, and a zone that only grows names the structure involved. The same discipline as on FreeBSD applies, by type and by size.
Rosetta and the second architecture
Apple silicon Macs run Intel binaries through Rosetta, a translator that lives mostly in user space, with kernel support for the details that translation needs. A translated process runs with a 4 KB page view and a translated address space, the kernel sets a flag on the task, and system calls from the translated code are routed through the translation layer into the native kernel. For a kernel programmer the consequence is that the kernel sees native threads whose user-space instruction stream is generated, and tools that inspect memory may see pages that belong to the translator's cache. Check sysctl sysctl.proc_translated in a process to learn whether it is running under translation: it returns 1 for a translated process and 0 for a native one.
Reading the open-source tree
A practical way to learn XNU is to follow one call from the library to the kernel. Take open. The libsyscall stub in the C library issues the trap with the system call number from bsd/kern/syscalls.master, a file that lists every BSD call, its number and its prototype. The kernel's open entry is in bsd/kern/vfs_syscalls.c, which allocates a file structure and calls vn_open, which does path lookup through namei and calls into the file system. Reading that chain, with the real code in a second window, teaches more than any summary. A few habits help.
Search by symbol with the repository's code search or grep -rn and expect macros: many entry points are generated from syscalls.master by scripts at build time, so a function you want may appear only as a name in that file. Read the headers under bsd/sys and osfmk/mach first, since they define the structures. Check the file's header comments, because Apple's tree contains code with several licenses and the file tells you which. And pin the version: read the tag that matches the xnu- build number from kern.version, since the layout moves between releases.
Power, thermal and the performance cores
A Mac kernel does more than schedule threads. It also manages power, which on Apple silicon means deciding which of two core types runs each thread and how fast each cluster is clocked. Performance cores and efficiency cores sit in separate clusters with separate frequency and voltage controls, and the kernel's scheduler and the performance controller work together: the scheduler places threads using their quality-of-service class, and the controller adjusts cluster frequency from the load it sees. A thread marked background tends to land on an efficiency core and stay there, which is both the reason a well-behaved background task barely moves the battery and the reason a latency-sensitive task wrongly marked background feels slow.
For observation, pmset -g prints the power management settings, pmset -g log the sleep and wake history and assertions, and powermetrics, which needs root, samples per-cluster activity, frequency and thermal pressure from the kernel. Thermal state also reaches user space as a notification and as ProcessInfo.thermalState in Foundation. The practical lesson for a systems programmer is to avoid busy loops and polling: wake-ups are the expensive thing on a laptop, so prefer blocking calls, kernel event queues (kqueue) and Dispatch sources, which let the kernel coalesce timers and keep the cores asleep.
Choose your next step
If your goal is drivers, go to DriverKit first and read the post on system extensions versus kernel extensions. If it is security tooling, the Endpoint Security framework is the supported way to observe process and file events. If it is understanding the platform, read the XNU architecture, then Mach ports and the trap tables, then the boot chain. And if you want to debug the kernel, start with the logs and sysctl before attempting a debug kernel, because most questions are answered by the live system before any source reading is needed.
Where this does not fit
This guide describes macOS, and much of it also applies to iOS, iPadOS, tvOS and watchOS, which share XNU, with differences in security policy: those systems do not allow user-installed kernel code at all, and some of the tooling above is absent. If you need to write a driver for a device, read the DriverKit material first and not the kext material, since kexts are on a deprecation path and unavailable by default on current hardware. If you want a portable kernel education, FreeBSD's source is the clearer starting point for BSD concepts, and Linux's for hardware coverage, because XNU's source release omits platform-specific and security-critical pieces. Finally, all kernel interfaces here change between macOS releases, and Apple does not promise stability for anything outside the documented system call and framework interfaces. Write your tools against public APIs and check them on each release.


