Mac OS X : Structure of the Kernel

We often hear all sort of things when it comes to Mac OS X Kernel, that it’s written in C++, it’s a microkernel.. blabla…
But, what is it really ?

The kernel of Mac OS X isn’t a microkernel, it’s a hybrid kernel called XNU, which is an acronym for X is not UNIX.
XNU is under APSL license, you can download it at opensource.apple.com.

Here is a little description of the composition of XNU.

1 – Mach

A part of XNU is based on Mach 3.0, which is historically the fist microkernel.
Mach is written in C and manages especially the low aspects levels of the system :

  • Multitasking, kernel threads.
  • Protected memory
  • Virtual memory
  • IPC (Inter-Process Communication)
  • The management of the interruptions
  • Support of Kernel Debugging with tools like ddb & kdp.

2 – BSD

The second important part of the system is based on BSD 4.4 by implementing functionality of FreeBSD, NetBSD and OpenBSD :
The BSD part is also written in C, it’s a bit higher level than Mach and manage the following :

  • Process
  • API POSIX, BSD systems call
  • Sockets, Firewall, TCP/IP stack
  • System V IPC
  • Crypto Framework
  • Synchronization mechanisms
  • Users ID, permissions, security policy.

3 – I/O Kit

Finally the third important part, I/O Kit is a layer of abstraction which manages the interactions between the hardware and the kernel.
I/O Kit is written in Embedded C++, a simplified version of C++ which remove things like :
- Exception handling
- Multiple inheritance
- Templates

Here a nonexhaustive list of what I/O Kit allows :

  • Management of USB, FireWire, ATA… etc
  • Plug and Play management
  • Thread and memory management
  • I/O Registry, a database which contains informations about objects
  • I/O Catalog, a database which contains data about all the classes of I/O Kit available on the system.

To summarize, a diagram which shows the proportion of each component of XNU :

XNU composition diagram

To conclude, no the Kernel of OS X isn’t a microkernel, it’s an hybrid one.
It’s not written in C++, only the part which handle the hardware is written in a simplified C++, the kernel itself is mainly written in C.

8 thoughts on “Mac OS X : Structure of the Kernel

    • Oui j’ai lu cet article, il est bien plus complet et bien rédigé, à lire !

      Le but de mon article était de donner un aperçu global de XNU.
      Ecrire quelque chose de vraiment complet sur XNU est long de part sa richesse et du nombre de composant qui le forme.

  1. Je sais pertinemment que XNU est le noyau de Mac OS X et de Darwin. Mais sur pas mal de sites, on nous dit que le noyau de Mac OS X est Darwin. Je pense bien qu’il a confusion chez eux.
    Cependant, lorsqu’on fait ‘uname -s’ le shell nous renvoie “Darwin”, ce qui veut dire que le nom du noyau est Darwin.

    Apple nous induit en erreur, mais qu’elle est réellement la définition de Darwin par rapport à XNU et Mac OS X ?

    Dans ma tête, je vois Mac OS X comme Ubuntu : l’équivalent de XNU est Linux, l’équivalent de Darwin est Debian et l’équivalent de Mac OS X est Ubuntu.
    C’est bien ça ?

  2. This is funny article as it is against itself.

    XNU is server-client architectured operating system.
    XNU has a microkernel called Mach. The Mach is a microkernel. XNU is not a kernel but a full blown operating system what has Mach microkernel. I/O kit and BSD parts.

    The blog post itself says that Mach is a microkernel.
    Then it says that XNU is itself a kernel.

    So article says that kernel has a kernel inside of it.
    It is like saying operating system has a operating system inside of it or computer is inside a computer or human is inside a human.

  3. Thanks a bunch for sharing this with all folks you really understand what you’re talking approximately! Bookmarked. Kindly also consult with my web site =). We could have a hyperlink trade agreement among us!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>