Apple Internals: Swift in the Kernel – By Josh Maine

After WWDC, I saw Devon Maloney posted a slide saying Apple has “started writing parts of the core operating system kernel in Swift” for the 27 releases. First steps toward a memory-safe kernel. What does this even mean?!

Naturally I dropped what I was doing and went grepping through the iOS 27 kernelcache. Alas, nothing came of it. All is not lost though: I found the Embedded Swift runtime in macOS 27, sitting in com.apple.kec.pthread of all places. Then I went poking around the root filesystem and it turns out Apple gave the whole effort a name: KernelKit.

Let's dissect it.

Where this is going: the C/C++ core (Mach, BSD, IOKit) is untouched. Swift shows up only as a small Embedded runtime inside specific KernelKit kexts at the extension layer.

A new directory in /System

On the macOS 27 root volume ( 26A5353q ), right next to /System/DriverKit, are two kexts:

/System/KernelKit/ └── System/Library/Extensions/ ├── Libm.kext/ │ ├── Libm │ ├── Libm_kasan │ └── Info.plist └── pthread.kext/ ├── pthread ├── pthread_development ├── pthread_kasan └── Info.plist

The Info.plist for the pthread one is where it gets fun:

"CFBundleSupportedPlatforms" => ["KernelKit.MacOSX"] "DTPlatformName" => "kernelkit.macosx" "DTSDKName" => "kernelkit.macosx27.0.internal" "DTXcode" => "2700"

And version.plist:

"ProjectName" => "libpthread_kernelkit" "BuildAliasOf" => "libpthread"

So there's an internal SDK called kernelkit.macosx27.0.internal, and libpthread_kernelkit is a separate Xcode target building from the same libpthread sources as the regular kext. Libm gets the same treatment: ProjectName: Libm_kernelkit.

If this is giving you DriverKit déjà vu, you are on to something: its own directory under /System, its own SDK, its own Mach-O platform constant, the same playbook seven years later.

New Mach-O platform IDs

The LC_BUILD_VERSION for these binaries says:

cmd LC_BUILD_VERSION platform 25 minos 27.0 sdk 27.0

The Mach-O platform enum currently goes up to 24 ( visionOSExc…

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论