Loading AI tools
Computer operating system kernel From Wikipedia, the free encyclopedia
XNU ("X is Not Unix") is the computer operating system (OS) kernel developed at Apple Inc. since December 1996 for use in the Mac OS X (now macOS) operating system and released as free and open-source software as part of the Darwin OS, which, in addition to being the basis for macOS, is also the basis for Apple TV Software, iOS, iPadOS, watchOS, visionOS, and tvOS.[1]
![]() The XNU kernel | |
Developer | Apple Inc. |
---|---|
Written in | C, C++ |
OS family | Unix-like, Unix |
Working state | Current |
Source model | Open-source |
Initial release | December 1996 |
Repository | |
Platforms | Current: x86-64, 64-bit ARM, 32-bit ARM (32-bit ARM support is closed-source) Historical: PowerPC (32-bit and 64-bit), IA-32 |
Kernel type | Hybrid |
License | Apple Public Source License 2.0 |
Preceded by | Mach, Nukernel |
Official website | github |
XNU was originally developed by NeXT for the NeXTSTEP operating system. It was a hybrid kernel derived from version 2.5 of the Mach kernel developed at Carnegie Mellon University, which incorporated the bulk of the 4.3BSD kernel modified to run atop Mach primitives, along with an application programming interface (API) in Objective-C for writing drivers named DriverKit.[2]
After Apple acquired NeXT, the kernel was updated with code derived from OSFMK 7.3 from OSF,[3] and the FreeBSD project, and the DriverKit was replaced with new API on a restricted subset of C++[4] (based on Embedded C++)[5] named IOKit.
XNU is a hybrid kernel, containing features of both monolithic kernels and microkernels, attempting to make the best use of both technologies, such as the message passing ability of microkernels enabling greater modularity and larger portions of the OS to benefit from memory protection, and retaining the speed of monolithic kernels for some critical tasks.
As of 2021[update], XNU runs on ARM64 and x86-64 processors, both one processor and symmetric multiprocessing (SMP) models. PowerPC support was removed as of the version in Mac OS X Snow Leopard. Support for IA-32 was removed as of the version in Mac OS X Lion; support for 32-bit ARM was removed as of the version in iOS 11.
The basis of the XNU kernel is a heavily modified (hybrid) Open Software Foundation Mach kernel (OSFMK) 7.3.[3] OSFMK 7.3 is a microkernel[6] that includes applicable code from the University of Utah Mach 4 kernel and from the many Mach 3.0 variants forked from the original Carnegie Mellon University Mach 3.0 microkernel.
OSFMK 7.3 is able to run the core of an operating system as separated processes, which allows a great flexibility (it could run several operating systems in parallel above the Mach core), but this often reduces performance because of time-consuming kernel/user mode context switches and overhead stemming from mapping or copying messages between the address spaces of the kernel and that of the service daemons.
Apple licensed OSFMK 7.3 from the OSF, and attempted to streamline some tasks by building BSD functions into the kernel along with the Mach code. The result is a heavily modified (hybrid) OSFMK 7.3 kernel.
The Berkeley Software Distribution (BSD) part of the kernel provides the Portable Operating System Interface (POSIX) application programming interface (API, BSD system calls), the Unix process model atop Mach tasks, basic security policies, user and group ids, permissions, the network protocol stack (protocols), the virtual file system code (including a file system independent journaling layer), several local file systems such as Hierarchical File System (HFS, HFS Plus (HFS+)) and Apple File System (APFS), the Network File System (NFS) client and server, cryptographic framework, UNIX System V inter-process communication (IPC), audit subsystem, mandatory access control, and some of the locking primitives.[7] The BSD code present in XNU has been most recently synchronised with that from the FreeBSD kernel. Although much of it has been significantly modified, code sharing still occurs between Apple and the FreeBSD Project as of 2009[update].[8]
XNU in Mac OS X Snow Leopard, v10.6, (Darwin version 10) comes in two varieties, a 32-bit version called K32 and a 64-bit version called K64.[9] K32 can run 64-bit applications in userland.[10] What was new in Mac OS X 10.6 was the ability to run XNU in 64-bit kernel space. K32 was the default kernel for 10.6 Server when used on all machines except Mac Pro and Xserve models from 2008 onwards[11] and can run 64-bit applications. K64 has several benefits compared to K32:[12]
Booting while holding down 6 and 4 forces the machine to boot K64 on machines supporting 64-bit kernels.[13] K64 will run 32-bit applications but it will not run 32-bit kernel extensions (KEXTs), so these must be ported to K64 to be able to load.
XNU in OS X Mountain Lion (10.8) and later only provides a 64-bit kernel.
IOKit is the device driver framework, written in a subset of C++ based on Embedded C++.[14] Using its object-oriented design, features common to any class of driver are provided within the framework, helping device drivers be written in less time and code. IOKit is multi-threaded, symmetric multiprocessing (SMP)-safe, and allows for hot-pluggable devices and automatic, dynamic device configuration.
Many drivers can be written to run in user mode, which further enhances the stability of the system. If a driver running in user mode crashes, it will not crash the kernel. However, if a driver running in kernel mode crashes it will crash the kernel. Examples of drivers running in kernel mode include disk adapter and network adapter drivers, graphics drivers, drivers for Universal Serial Bus (USB) and FireWire host controllers, and drivers for virtual machine software such as VirtualBox, Parallels Desktop for Mac, and VMware Fusion. In macOS Catalina and later releases, DriverKit allows some of those types of drivers to run in user mode.[15]