| XNU | |
|---|---|
The XNU kernel | |
| Developer | Apple Inc. |
| Written in | C,C++,assembly language |
| OS family | Unix-like,Unix[1] |
| Working state | Current |
| Source model | Open-source |
| Initial release | December 1996; 28 years ago (1996-12) |
| Repository | |
| Supported 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 ("X is Not Unix") is the computeroperating system (OS)kernel developed atApple Inc. since December 1996 for use in the Mac OS X (nowmacOS) operating system and released asfree and open-source software as part of theDarwin OS, which, in addition to being the basis for macOS, is also the basis foriOS,iPadOS,watchOS,visionOS, andtvOS.[2]
XNU was originally developed byNeXT for theNeXTSTEP operating system. It was ahybrid kernel derived from version 2.5 of theMach kernel developed atCarnegie Mellon University, which incorporated the bulk of the4.3BSD kernel modified to run atop Mach primitives, along with anapplication programming interface (API) inObjective-C for writing drivers named DriverKit.[3]
After Apple acquired NeXT, the kernel was updated with code derived fromOSF MK 7.3 fromOSF,[4] and theFreeBSD project, and the DriverKit was replaced with new API on a restricted subset ofC++[5] (based onEmbedded C++)[6] named IOKit.
By keeping the BSD kernel into the third part of XNU,[7] XNU became UNIX-based when macOS achieved UNIX certification under the Single UNIX Specification (SUS) by The Open Group.[8] Despite this, Apple retained the original 'XNU' name, which stands for 'X is Not Unix,' a relic from its NeXTSTEP origins before macOS was UNIX-certified. This has led to confusion, as the name suggests that XNU is separate from UNIX, even though macOS, as a whole, is officially recognized as a UNIX operating system.[1]
XNU is ahybrid kernel, containing features of bothmonolithic kernels andmicrokernels, attempting to make the best use of both technologies, such as themessage passing ability of microkernels enabling greater modularity and larger portions of the OS to benefit frommemory protection, and retaining the speed of monolithic kernels for some critical tasks.
As of 2021[update], XNU runs onARM64 andx86-64 processors, both one processor andsymmetric multiprocessing (SMP) models.PowerPC support was removed as of the version inMac OS X Snow Leopard. Support forIA-32 was removed as of the version inMac OS X Lion; support for 32-bit ARM was removed as of the version iniOS 11.
The basis of the XNU kernel is a heavily modified (hybrid)Open Software Foundation Mach kernel (OSF MK) 7.3.[4] OSF MK 7.3 is a microkernel[9] that includes applicable code from theUniversity of Utah Mach 4 kernel and from the many Mach 3.0 variantsforked from the originalCarnegie Mellon University Mach 3.0 microkernel.
OSF MK 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[citation needed] 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 OSF MK 7.3 from the OSF, and attempted to streamline some tasks by buildingBSD functions into the kernel along with the Mach code. The result is a heavily modified (hybrid) OSF MK 7.3 kernel.
TheBerkeley Software Distribution (BSD) part of the kernel provides the Portable Operating System Interface (POSIX)application programming interface (API, BSD system calls), theUnix process model atop Mach tasks, basic security policies, user and group ids, permissions, the networkprotocol stack (protocols), thevirtual file system code (including afile system independentjournaling layer), several local file systems such asHierarchical File System (HFS,HFS Plus (HFS+)) andApple File System (APFS), theNetwork File System (NFS) client and server, cryptographic framework,UNIX System Vinter-process communication (IPC), audit subsystem,mandatory access control, and some of the locking primitives.[10] The BSD code present in XNU has been most recently synchronised with that from theFreeBSD kernel. Although much of it has been significantly modified, code sharing still occurs between Apple and the FreeBSD Project as of 2009[update].[11]
XNU inMac OS X Snow Leopard, v10.6, (Darwin version 10) comes in two varieties, a32-bit version calledK32 and a64-bit version calledK64.[12] K32 can run 64-bit applications inuserland.[13] What was new in Mac OS X 10.6 was the ability to run XNU in 64-bitkernel space. K32 was the default kernel for 10.6Server when used on all machines exceptMac Pro andXserve models from 2008 onwards[14] and can run 64-bit applications. K64 has several benefits compared to K32:[15]
Booting while holding down6 and4 forces the machine to boot K64 on machines supporting 64-bit kernels.[16] K64 will run 32-bit applications but it will not run 32-bitkernel extensions (KEXTs), so these must be ported to K64 to be able to load.
XNU inOS X Mountain Lion (10.8) and later only provides a 64-bit kernel.
IOKit is thedevice driver framework, written in a subset ofC++ based onEmbedded C++.[17] Using itsobject-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 inuser 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) andFireWirehost controllers, and drivers forvirtual machine software such asVirtualBox,Parallels Desktop for Mac, andVMware Fusion. InmacOS Catalina and later releases, DriverKit allows some of those types of drivers to run in user mode.[18]
Finally, this is worth repeating: please keep in mind that you do not need to run the 64-bit kernel in order to run 64-bit applications or install more than 4 GB of RAM in your Mac. Applications run just fine in 64-bit mode on top of the 32-bit kernel, and even in earlier versions of Mac OS X it's been possible to install and take advantage of much more than 4GB of RAM.
I/O Kit uses a restricted subset of C++