explaingit

apple/darwin-xnu

11,237CAudience · developerComplexity · 5/5Setup · hard

TLDR

The source code for XNU, the hybrid kernel at the heart of macOS and iOS, combining the Mach microkernel, FreeBSD-derived subsystems, and the IOKit driver framework, published by Apple as part of the Darwin open-source project.

Mindmap

mindmap
  root((XNU kernel))
    Architecture
      Mach microkernel
      BSD subsystems
      IOKit drivers
    Code structure
      osfmk Mach
      bsd subsystems
      iokit drivers
    Build options
      Debug variant
      Release variant
      Custom kernel load
    Audience
      OS researchers
      Driver developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a debug variant of the XNU kernel and load it on a test Mac with an automatic fallback to the original kernel if boot fails.

USE CASE 2

Study how macOS and iOS manage processor scheduling, memory, and system calls at the lowest software level.

USE CASE 3

Explore the BSD-derived networking and file system code in the kernel's bsd directory for operating systems research.

USE CASE 4

Develop or debug macOS hardware drivers using the IOKit C++ framework included in the kernel source.

Tech stack

CC++Make

Getting it running

Difficulty · hard Time to first run · 1day+

Requires Apple's macOS SDK and developer toolchain, loading a custom kernel requires a separate test Mac and careful use of the fallback boot procedure.

Published by Apple as part of the Darwin open-source project, exact license terms are in the repository.

In plain English

This repository contains the source code for XNU, which is the kernel at the heart of macOS and iOS. A kernel is the lowest-level software running on a computer: it manages the processor, memory, storage, and all communication between hardware and the programs you run. Without the kernel, no application on your Mac or iPhone could function. XNU stands for X is Not Unix, which is a reference to its hybrid nature. It combines two different foundations: the Mach microkernel, which was originally developed at Carnegie Mellon University, and code from FreeBSD, a Unix-like operating system. On top of those, it includes IOKit, a C++ framework used by hardware drivers. This layered architecture is why XNU is called a hybrid kernel rather than a pure implementation of either Mach or Unix. The repository is organized into directories that correspond to these layers. The osfmk directory contains the Mach-based components. The bsd directory contains the BSD-derived subsystems. The libkern and iokit code supports hardware drivers. Other directories handle startup, system calls, platform-specific behavior, and security policies. Building XNU requires Apple's development toolchain and macOS SDK. The build system uses make, and you can produce debug, development, or release variants of the kernel. The README includes instructions for loading a custom-built kernel on a test machine in a way that automatically falls back to the original kernel if something goes wrong during boot. Apple publishes this source code as part of the Darwin open-source project. It reflects the kernel version shipping in Apple operating systems, though some components remain closed source and are not included here.

Copy-paste prompts

Prompt 1
Help me build a debug version of the XNU kernel from the darwin-xnu repository on macOS and load it on a test machine using the automatic fallback method described in the README.
Prompt 2
Walk me through the system call path in XNU's bsd directory, how does a userspace program's system call travel through the BSD layer into the Mach microkernel?
Prompt 3
Explain how IOKit works in the XNU kernel and show me the structure I would need to write a basic kernel extension that registers a virtual hardware device.
Prompt 4
What are the differences between the osfmk, bsd, and iokit directories in darwin-xnu and which one should I start reading if I want to understand macOS memory management?
Open on GitHub → Explain another repo

← apple on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.