從內核上初步對比macOS和Linux

macOS內核源碼官方鏈接

內核概述(我覺得有意思的部分)
OS X:完整操作系統
內核:Darwin 包含 XNU (混合式內核,包含1. Mach微內核,2. BSD層建立在Mach之上,3. I/O kit). 有趣的是,XNU's Not Unix.
XNU給用戶態主要提供BSD的接口,不僅有POSIX兼容的系統調用,也有BSD獨有的調用。同時也提供少量Mach接口(竟然稱之爲API)
由於純微內核只有學術價值,因此OS X使用的是混合內核。
XNU不是BSD的完整實現,比如BSD的brk()是缺失的;XNU的kext和BSD的kmod不兼容。
沒有像Linux那樣用戶可見的文件系統procfs,但還是可以使用sysctl命令
I/O kit是C++實現的,但只用到C++的嚴格子集

開機流程,自行對比Linux
The kernel first initializes all the data structures needed to support Mach and BSD. Next, the kernel initializes the I/O Kit, which connects the kernel with the set of extensions that correspond to the machine’s hardware configuration. The kernel then finds and mounts the root filesystem. Finally, it launches the first process on the system, launchd, which is responsible for bootstrapping the system as well as launching daemons on behalf of the system or users.
(摘自《Mac OS X for UNIX Geek》一書)

和Linux軟硬件對比的個人總結
EFI對應BIOS
NVRAM對應CMOS
boot.efi對應grub
launched對應init
kext對應ko

對比宏內核和微內核的架構
宏內核:

微內核:

(圖片來源:《Mac OS X for UNIX Geek》)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章