This topic was published by DevynCJohnson and viewed 1995 times since "". The last page revision was "".
- Topics - 444
The source code for XNU is well organized. This allows developers to easily find and add code. It can greatly benefit developers to know the structure of the source code. For this article, I will be using XNU version 2782.1.97.
XNU version 2782.1.97 can be obtained for free from https://opensource.apple.com/source/xnu/xnu-2782.1.97/
The source code for XNU can be obtained from multiple places as seen below.
- Official Tarballs – http://www.opensource.apple.com/tarballs/xnu/
- Official Site – https://opensource.apple.com/source/xnu/
- GitHub – https://github.com/opensource-apple/xnu/
Information on the Apple Public Source License can be seen at http://www.opensource.apple.com/license/apsl/
In the root of the extracted tarball, the below listed directories and files will be seen.
- APPLE_LICENSE - This plain-text file contains the Apple Public Source License.
- bsd - The BSD components of the kernel are found here. This includes HFS, NFS, cryptography tools, etc.
- config - This directory contains parameters that are used to configure the XNU source code to be built for a particular platform. For instance, many of the "*x86-64.exports" files contain special settings needed to make the XNU kernel work on the x86-64 architecture.
- EXTERNAL_HEADERS - General coding headers are kept here like "stdint.h" and similar headers.
- iokit - The components of IO Kit are stored here. Various code for I/O (Input/Output) operations are kept here as well as code needed for the whole IO Kit framework.
- libkern - The general kernel library is here (not to be confused with the headers folder). Some code included here is Zlib, stdio, atomic operations, cryptography utilities, etc.
- libsa - The code located in here provides tools used to patch vtables, remangle symbols, search binary code, etc.
- libsyscall - The system calls are coded under "libsyscall".
- makedefs - Various global "Make" values are stored here.
- Makefile - This file is the shell script used to build the XNU kernel.
- osfmk - The low-level code is stored here such as inter-process communication (IPC), profiling, semaphores, etc. The "man" directory contains documentation in the form of HTML files. Also, the Mach portion of the kernel resides here.
- pexpert - "Porting Expert" is the directory that contains developmental code that is being ported to another architecture.
- README - This is a plain-text file explaining how to build the XNU kernel.
- security - Security-related features for the kernel are coded here.
- SETUP - Some of the main files needed for configuring and compiling the kernel.
- tools - Tools needed for XNU kernel debugging are kept under the "tools" directory.
The XNU kernel folder structure has remained relatively constant. The kernel developers have made some modifications, but overall, this setup is the same throughout all kernel versions. The driver folder's layout also remains about the same.
Tip: Never move a file in the kernel source unless you know what you are doing. Otherwise, the compilation with fail due to a "missing" file.
- XNU Kernel Reading Guide - http://dcjtech.info/topic/os-x-darwin-and-friends/#xnu