macOS combines a user-friendly interface with the power and stability of UNIX, making it accessible to both experienced and casual users. However, for those interested in exploring macOS internals, some forum posts, articles, and videos often misrepresent its technical foundation.
macOS is based on FreeBSD
The most common myth is that macOS is built on FreeBSD or even “it is just a FreeBSD version with a pretty UI”. While macOS does incorporate components from FreeBSD and shares some similarities with BSD systems, this is a misleading characterization. It implies that Apple directly developed macOS from FreeBSD, similar to how Linux distributions are built or how Google developed Android on the Linux kernel. In reality, macOS is built on Darwin, a more complex foundation that integrates FreeBSD components alongside Apple’s own innovations. Darwin utilizes userland tools, libraries, and certain kernel elements derived from FreeBSD, but it’s far more than just a rebranded BSD.
In fact, macOS and Darwin are based on the NEXTSTEP operating system (or rather its evolution), developed by NeXT Inc., a company founded by Steve Jobs. Apple acquired NeXT in 1996 in an effort to replace the aging Macintosh operating system, now referred to as “Classic” Mac OS, with the more advanced foundation that evolved into modern macOS.
macOS kernel is a modified version of FreeBSD kernel
Wrong. Darwin’s kernel, XNU (short for “X is Not Unix”), is built around the Mach kernel at its core. Mach originated as a research project at Carnegie Mellon University (CMU) and is a pure implementation of the microkernel philosophy. Its design focuses on separating operating system services from the kernel to enhance modularity, flexibility, and portability. When Apple integrated into XNU, they made significant modifications, combining it with code derived from FreeBSD, particularly in areas like process management, file systems, networking, and Unix APIs, creating a hybrid kernel that leverages both microkernel and monolithic kernel advantages.
XNU consists of following components:
- OSFMK (Mach Kernel)
- BSD Layer
- I/O Kit
OSFMK (Mach Kernel)
Mach kernel in XNU is a heavily modified version of OSFMK 7.3 from Open Software Foundation which was based on Mach 3.0 from CMU and contains some code from Mach 4.0 from University of Utah. Apple converted a microkernel into a hybrid kernel by moving BSD layer along with some others into kernel space.
In summary, while macOS kernel XNU contains modified components from FreeBSD kernel, it isn’t just FreeBSD kernel, it is basically a combination of a heavily modified version of Mach, BSD layer with FreeBSD kernel derived code and Apple’s own components.
BSD Layer
BSD Layer in XNU is based on the code derived from FreeBSD. This layer provides a full Unix environment on top of Mach kernel. This layer provides following functionality:
- POSIX APIs: Implements the POSIX standard API, providing compatibility with Unix-like systems.
- Process Management: Manages user processes, including resource allocation, process IDs, and user permissions.
- File Systems: Handles file system operations such as reading, writing, and managing storage devices (supports file systems like HFS+ and APFS).
- Networking: Implements a comprehensive networking stack, supporting protocols like TCP/IP.
I/O Kit
The I/O Kit is an object-oriented framework designed to manage hardware devices and drivers. It offers a flexible, extensible architecture for developing and loading device drivers, using object-oriented principles. The framework efficiently manages system resources like memory and power, ensuring optimal performance and extended battery life, particularly in mobile devices. By abstracting hardware complexities, it enables developers to write device drivers at a higher level using C++, simplifying the development process.
macOS has a microkernel
Wrong. XNU is not a pure microkernel; it is considered a hybrid kernel. While it incorporates elements of the Mach microkernel, XNU blends both microkernel and monolithic kernel designs.
In a traditional microkernel architecture, core functions like memory management, process management, and inter-process communication (IPC) are handled by the microkernel, while higher-level services (like the file system and device drivers) run in user space, outside of the kernel. This design enhances modularity but can introduce performance overhead due to frequent context switches and IPC between user and kernel space.
However, in XNU, Apple modified this approach by integrating the BSD layer directly into the kernel space. This minimizes the overhead typically associated with microkernels by reducing context switching and IPC, leading to improved performance.
As a result, XNU is referred to as a hybrid kernel, because it combines the modularity of a microkernel (from Mach) with the performance characteristics of a monolithic kernel (from FreeBSD and Apple’s customizations).
Summary
In summary, you can create a formula like this:
macOS = Darwin + Aqua + Cocoa Framework + Quartz + Core Animation + many other components created by Apple
Darwin = XNU Kernel + File Systems + Network Stack + CoreOS Services + Security Framework + BSD Userland
XNU Kernel = OSFMK (Mach) + BSD Layer + I/O Kit + Kernel Extensions (Kext)
Leave a Reply