今天看mac talk 看到作者吹牛逼,突然对drawin的实现有点兴趣,整理了下xnu内核源代码目录 和 功能模块的对应关系,以及内核实现结构,后续细看下。

xnu结构对应模块图

                |—————————————————————————————————————————
                |
                |
                |
                |
                |
                |
                |
                |_________________________________________
                        ↑       (user space)      |
                        |                         | 
                        | libkdd                  | libsyscall
                        | (解析内核数据)            | (调用内核功能)
                        |                         ↓
                |———————————————————————————————————————————
                |                                        
                |     libkern(IOKit)
                |     
                |     bsd (BSD)
libsa --------> |     
                |     |————————————————————————|
                |     |                        |
 (内核启动程序)   |     |     osfmk (Mach)       |
                |     |________________________|
                |_________________________________________
                            (kernal程序)

                |——————————————————————————————————————————————————
                |  
                |       kext (kernal extension) 
                |
                |__________________________________________________

                |——————————————————————————————————————————————————
                |  
                |       硬件
                |
                |__________________________________________________

drawin-xnu 目录结构

开发以及配置

config

configurations for exported apis for supported architecture and platform

SETUP

Basic set of tools used for configuring the kernel, versioning and kextsymbol management.

EXTERNAL_HEADERS

Headers sourced from other projects to avoid dependency cycles when building. These headers should be regularly synced when source is updated.

tools

A set of utilities for testing, debugging and profiling kernel.

主体组件

kext

(kernal extension) Mac OS X内核扩展, 它们通常用于设备驱动程序,运行于系统的核心基底。

libkern

C++ IOKit library code for handling of drivers and kexts

C++ IOKit library
处理驱动(drivers)和 内核扩展(kexts)

libsa

kernel bootstrap code for startup

内核启动代码

libsyscall

syscall library interface for userspace programs

用户空间使用的 系统库调用接口

libkdd

kernal data deserializer

source for user library for parsing kernel data like kernel chunked data.

用户区使用的接口, 用于解析通过IPC传来的内核数据

osfmk (mach)

Mach kernel based subsystems

bsd

BSD subsystems code

BSD 子系统

平台兼容

pexpert

Platform specific code like interrupt handling, atomics etc.

makedefs

top level rules and defines for kernel build.

安全

security

Mandatory Access Check policy interfaces and related implementation

ref

xnu简介

apple open source xnu