XNU

Last updated

XNU
The XNU Kernel Graphic.svg
The XNU kernel
Developer Apple Inc.
Written in C, C++
OS family Unix-like, Unix
Working stateCurrent
Source model Open-source
Initial releaseDecember 1996;27 years ago (1996-12)
Repository
PlatformsCurrent: 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.com/apple-oss-distributions/xnu

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]

Contents

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.

Kernel design

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, 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 .

Mach

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[ 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 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.

BSD

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. [8]

K32/K64

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

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]

See also

Related Research Articles

<span class="mw-page-title-main">Microkernel</span> Kernel that provides fewer services than a traditional kernel

In computer science, a microkernel is the near-minimum amount of software that can provide the mechanisms needed to implement an operating system (OS). These mechanisms include low-level address space management, thread management, and inter-process communication (IPC).

Mach is a kernel developed at Carnegie Mellon University by Richard Rashid and Avie Tevanian to support operating system research, primarily distributed and parallel computing. Mach is often considered one of the earliest examples of a microkernel. However, not all versions of Mach are microkernels. Mach's derivatives are the basis of the operating system kernel in GNU Hurd and of Apple's XNU kernel used in macOS, iOS, iPadOS, tvOS, and watchOS.

Darwin is the core Unix-like operating system of macOS, iOS, watchOS, tvOS, iPadOS, audioOS, visionOS, and bridgeOS. It previously existed as an independent open-source operating system, first released by Apple Inc. in 2000. It is composed of code derived from NeXTSTEP, FreeBSD, other BSD operating systems, Mach, and other free software projects' code, as well as code developed by Apple.

<span class="mw-page-title-main">QNX</span> Real-time operating system (RTOS) software

QNX is a commercial Unix-like real-time operating system, aimed primarily at the embedded systems market.

L4 is a family of second-generation microkernels, used to implement a variety of types of operating systems (OS), though mostly for Unix-like, Portable Operating System Interface (POSIX) compliant types.

<span class="mw-page-title-main">64-bit computing</span> Computer architecture bit width

In computer architecture, 64-bit integers, memory addresses, or other data units are those that are 64 bits wide. Also, 64-bit central processing units (CPU) and arithmetic logic units (ALU) are those that are based on processor registers, address buses, or data buses of that size. A computer that uses such a processor is a 64-bit computer.

x86-64 64-bit version of x86 architecture

x86-64 is a 64-bit version of the x86 instruction set, first announced in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mode.

<span class="mw-page-title-main">Mac OS X 10.0</span> First major release of Mac OS X

Mac OS X 10.0 is the first major release of macOS, Apple's desktop and server operating system. It was released on March 24, 2001, for a price of $129 after a public beta.

<span class="mw-page-title-main">Workplace OS</span> Defunct 1990s operating system

Workplace OS is IBM's ultimate operating system prototype of the 1990s. It is the product of an exploratory research program in 1991 which yielded a design called the Grand Unifying Theory of Systems (GUTS), proposing to unify the world's systems as generalized "personalities" cohabitating concurrently upon a universally sophisticated platform of object-oriented frameworks upon one microkernel. Using personalities, a single machine would be able to run applications from multiple conventional operating systems like Unix or OS/2.

<span class="mw-page-title-main">Architecture of macOS</span> Layers of the operating system

The architecture of macOS describes the layers of the operating system that is the culmination of Apple Inc.'s decade-long research and development process to replace the classic Mac OS.

A hybrid kernel is an operating system kernel whose architecture attempts to combine aspects and benefits of microkernel and monolithic kernel architectures used in operating systems.

<span class="mw-page-title-main">Minix 3</span> Unix-like operating system

Minix 3 is a small, Unix-like operating system. It is published under a BSD-3-Clause license and is a successor project to the earlier versions, Minix 1 and 2.

<span class="mw-page-title-main">Mac OS X Snow Leopard</span> Seventh major version of macOS, released in 2009

Mac OS X Snow Leopard is the seventh major release of macOS, Apple's desktop and server operating system for Macintosh computers.

Binary-code compatibility is a property of a computer system, meaning that it can run the same executable code, typically machine code for a general-purpose computer central processing unit (CPU), that another computer system can run. Source-code compatibility, on the other hand, means that recompilation or interpretation is necessary before the program can be run on the compatible system.

<span class="mw-page-title-main">Kernel (operating system)</span> Core of a computer operating system

The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system. The kernel is also responsible for preventing and mitigating conflicts between different processes. It is the portion of the operating system code that is always resident in memory and facilitates interactions between hardware and software components. A full kernel controls all hardware resources via device drivers, arbitrates conflicts between processes concerning such resources, and optimizes the utilization of common resources e.g. CPU & cache usage, file systems, and network sockets. On most systems, the kernel is one of the first programs loaded on startup. It handles the rest of the startup as well as memory, peripherals, and input/output (I/O) requests from software, translating them into data-processing instructions for the central processing unit.

<span class="mw-page-title-main">Unix-like</span> Operating system that behaves similarly to Unix, e.g. Linux

A Unix-like operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-like application is one that behaves like the corresponding Unix command or shell. Although there are general philosophies for Unix design, there is no technical standard defining the term, and opinions can differ about the degree to which a particular operating system or application is Unix-like.

<span class="mw-page-title-main">Classic Mac OS</span> Original operating system of Apple Mac (1984–2001)

Mac OS is the series of operating systems developed for the Macintosh family of personal computers by Apple Computer, Inc. from 1984 to 2001, starting with System 1 and ending with Mac OS 9. The Macintosh operating system is credited with having popularized the graphical user interface concept. It was included with every Macintosh that was sold during the era in which it was developed, and many updates to the system software were done in conjunction with the introduction of new Macintosh systems.

<span class="mw-page-title-main">NextBSD</span> Operating system

NextBSD was an operating system initially based on the trunk version of FreeBSD as of August 2015. It was a fork of FreeBSD which implemented new features developed on branches, but not yet implemented in FreeBSD. As of 2019, the website is defunct, with the last commits on GitHub dating to October 2019. The Wayback Machine captures of the website after December 15, 2017 are domain squatter pages, and as of March 17, 2021, the site is redirects to a fake "Apple Support" page.

References

  1. "Porting UNIX/Linux Applications to Mac OS X: Glossary". Apple Computer. 2005. Retrieved June 7, 2017.
  2. "XNU GitHub source code README". GitHub . December 16, 2021.
  3. 1 2 Magee, Jim. WWDC 2000 Session 106 – Mac OS X: Kernel. 14 minutes in. Archived from the original on December 21, 2021.
  4. "The libkern C++ Runtime". IOKit Device Driver Design Guidelines.
  5. Amit Singh. "What is Mac OS X?". Archived from the original on April 19, 2019. Retrieved March 4, 2015.
  6. Wells, Douglas M. (1994). A Trusted, Scalable, Real-Time Operating System Environment (PDF). 1994 IEEE Dual-Use Technologies and Applications Conference. S2CID   5205380. Archived from the original (PDF) on August 22, 2017.
  7. Watson, Robert (August 2, 2008). "Re: freebsd-advocacy Digest, Vol 248, Issue 1". freebsd-advocacy (Mailing list). Retrieved October 24, 2013.
  8. "FreeBSD Quarterly Status Report (Grand Central Dispatch – FreeBSD port)". April 2009. Retrieved October 24, 2013.
  9. Mac OS X 10.6 Snow Leopard: the Ars Technica review, page 5
  10. Siracusa, John (August 31, 2009). "Mac OS X 10.6 Snow Leopard: the Ars Technica review". Ars Technica . 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.
  11. Mac OS X Server v10.6: Macs that use the 64-bit kernel
  12. "What's New in Mac OS X: Mac OS X v10.6". Apple Developer. Apple, Inc.
  13. Mac OS X Server v10.6: Starting up with the 32-bit or 64-bit kernel
  14. Amit Singh. "XNU: The Kernel". What is Mac OS X?. I/O Kit. Archived from the original on April 19, 2019. Retrieved September 9, 2011. I/O Kit uses a restricted subset of C++
  15. "DriverKit". Apple Developer.