XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
XNU patch: the IOAESAccelerator stand-in is an instance of IOCryptoAcceleratorFamily's own class (defining one in the kernel made the family's a duplicate)
Heyang Zhoude542865efa9
diff --git a/xnu-patches/0001-linux64-stage-hook.patch b/xnu-patches/0001-linux64-stage-hook.patchindex ad2474c..6a3886c 100644--- a/xnu-patches/0001-linux64-stage-hook.patch+++ b/xnu-patches/0001-linux64-stage-hook.patch@@ -386,10 +386,10 @@ index 0cc7f6e..c07d35c 100644DEBUG_INFO("region = %d\n", currentRegion->type);cnt = 0;diff --git a/iokit/Kernel/IOPlatformExpert.cpp b/iokit/Kernel/IOPlatformExpert.cpp-index 76555f6..e496969 100644+index 76555f6..d56d67f 100644--- a/iokit/Kernel/IOPlatformExpert.cpp+++ b/iokit/Kernel/IOPlatformExpert.cpp-@@ -1540,6 +1540,68 @@ IOPlatformExpert::registerNVRAMController(IONVRAMController * caller)+@@ -1540,6 +1540,59 @@ IOPlatformExpert::registerNVRAMController(IONVRAMController * caller)publishResource("IONVRAM");}@@ -414,15 +414,6 @@ index 76555f6..e496969 100644+}+static uintptr_t linux64_aks_table[0x40];+-+/*-+ * LINUX64 (xnulinux): no AES engine either. AppleImage4's finalize waits for an "IOAESAccelerator" service (it only-+ * waits, then releases it); a class of that name, registered, matches by class and by name.-+ */-+class IOAESAccelerator : public IOService-+{-+ OSDeclareDefaultStructors(IOAESAccelerator);-+};-+OSDefineMetaClassAndStructors(IOAESAccelerator, IOService);++static void+linux64_register_stand_in(IOService *parent, IOService *s, const char *name)@@ -458,7 +449,7 @@ index 76555f6..e496969 100644IOReturnIOPlatformExpert::callPlatformFunction(const OSSymbol *functionName,bool waitForFunction,-@@ -1564,7 +1626,36 @@ IOPlatformExpert::callPlatformFunction(const OSSymbol *functionName,+@@ -1564,7 +1617,47 @@ IOPlatformExpert::callPlatformFunction(const OSSymbol *functionName,}if (waitForFunction) {@@ -475,7 +466,18 @@ index 76555f6..e496969 100644+ */+ scrd_done = true;+ linux64_register_stand_in(this, OSTypeAlloc(IOService), "sep-endpoint,scrd");-+ linux64_register_stand_in(this, OSTypeAlloc(IOAESAccelerator), "IOAESAccelerator");++ /*++ * No AES engine either: AppleImage4's finalize waits for an IOAESAccelerator service (it only waits, then++ * releases it). The class is IOCryptoAcceleratorFamily's: an instance of it, registered, with no driver.++ */++ OSObject *aes = OSMetaClass::allocClassWithName("IOAESAccelerator");++ IOService *aess = OSDynamicCast(IOService, aes);++ if (aess) {++ linux64_register_stand_in(this, aess, "IOAESAccelerator");++ } else {++ IOLog("LINUX64: cannot make an IOAESAccelerator (%p)\n", aes);++ OSSafeReleaseNULL(aes);++ }+ }+ IOLog("LINUX64: AKSKernelServices from the hosted stand-in\n");+ return kIOReturnSuccess;@@ -496,7 +498,7 @@ index 76555f6..e496969 100644} else {_resources = getResourceService();}-@@ -2341,6 +2432,8 @@ IOPlatformDevice::getResources( void )+@@ -2341,6 +2434,8 @@ IOPlatformDevice::getResources( void )* the kernel with a suitable message.*********************************************************************/@@ -505,7 +507,7 @@ index 76555f6..e496969 100644class IOPanicPlatform : IOPlatformExpert {OSDeclareDefaultStructors(IOPanicPlatform);-@@ -2361,6 +2454,19 @@ IOPanicPlatform::start(IOService * provider)+@@ -2361,6 +2456,19 @@ IOPanicPlatform::start(IOService * provider)platform_name = provider->getName();}