-
Notifications
You must be signed in to change notification settings - Fork 628
Fix sticking at KernelCache validating on Tahoe #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0a855d3
4094786
cdad012
660e9f6
dcebbbe
1d74eed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,11 @@ | |
| #include <Headers/kern_devinfo.hpp> | ||
| #include <IOKit/IOService.h> | ||
|
|
||
| #include <sys/vnode.h> | ||
| #include <sys/mount.h> | ||
| #include <sys/uio.h> | ||
| #include <sys/namei.h> | ||
|
|
||
| #include <Availability.h> | ||
| #include <IOKit/IOPlatformExpert.h> | ||
|
|
||
|
|
@@ -302,6 +307,73 @@ IOReturn RAD::wrapAMDRadeonX6000AmdRadeonFramebufferGetAttribute(IOService *fram | |
| return ret; | ||
| } | ||
|
|
||
| bool fileExistsAtPath(const char *path) { | ||
| vnode_t vp = NULL; | ||
| vfs_context_t ctx = vfs_context_current(); | ||
| int error = vnode_lookup(path, 0, &vp, ctx); | ||
|
|
||
| if (error == 0 && vp != NULL) { | ||
| vnode_put(vp); | ||
| DBGLOG("rad", "File exists: %s", path); | ||
| return true; | ||
| } | ||
|
|
||
| DBGLOG("rad", "File NOT found: %s (error: %d)", path, error); | ||
| return false; | ||
| } | ||
|
|
||
| bool RAD::isNormalSys() { | ||
| const char* modeStr = "Unknown"; | ||
| switch (lilu.getRunMode()) { | ||
| case 1: modeStr = "Normal Boot"; break; | ||
| case 2: modeStr = "Recovery/Installer"; break; | ||
| case 4: modeStr = "Safe Mode"; break; | ||
| } | ||
|
|
||
| IOLog("WEG: isNormalSys() called | RunMode: %s (%d)\n", modeStr, lilu.getRunMode()); | ||
|
|
||
| // Ignore all detections when forcibly enabling -radconnector | ||
| if (lilu.getRunMode() == 1 && checkKernelArgument("-radconnector")) { | ||
| IOLog("WEG: -radconnector detected in Recovery, FORCING override enable\n"); | ||
| return true; | ||
| } | ||
|
|
||
| // Directly reject abnormal startup environments | ||
| if (lilu.getRunMode() != 1) { | ||
| IOLog("WEG: Not in Normal Boot mode, but RunMode=%d → blocking override\n", lilu.getRunMode()); | ||
| return false; | ||
| } | ||
|
|
||
| // When using BaseSystemKernelExtensions as the Kernel Cache, the linker is also not overwritten. | ||
| // Because in the second stage of the OTA (when the macOS Installer finishes booting and the volume | ||
| // label returns to Macintosh HD), it still uses BaseSystemKernelExtensions.kc, but Lilu mistakenly determines | ||
| // it as a normal boot. This causes it to still freeze during the KC verification stage. | ||
| if (fileExistsAtPath("/System/Library/KernelCollections/BaseSystemKernelExtensions.kc")) { | ||
| IOLog("WEG: BaseSystemKernelExtensions.kc EXISTS -> BLOCK override (prevent freeze)\n"); | ||
| return false; | ||
| } | ||
|
|
||
| IOLog("WEG: Normal boot -> ALLOW connector override\n"); | ||
| return true; | ||
| } | ||
|
|
||
| bool RAD::ifNeedOverrideConnector(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) { | ||
| // No need to overwrite the connector when booting BaseSystem on macOS Tahoe. | ||
| // This step is unnecessary and will cause macOS Tahoe recovery mode to freeze when booting. | ||
| // Committed by laobamac | ||
| if (getKernelVersion() >= KernelVersion::Tahoe) { | ||
| if (!isNormalSys()) { | ||
| IOLog("WEG: skip override.\n"); | ||
| return false; | ||
| } else { | ||
| IOLog("WEG: allow override.\n"); | ||
| return true; | ||
| } | ||
| } else { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| bool RAD::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) { | ||
| if (kextRadeonX6000Framebuffer.loadIndex == index) { | ||
| KernelPatcher::RouteRequest requests[] = { | ||
|
|
@@ -333,7 +405,13 @@ bool RAD::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t ad | |
| } | ||
|
|
||
| if (kextRadeonSupport.loadIndex == index) { | ||
| processConnectorOverrides(patcher, address, size, true); | ||
| // The abnormal start-up system does not cover the connector on Tahoe. | ||
| if (ifNeedOverrideConnector(patcher, index, address, size) != false) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After we fix Lilu to correctly detect normal mode I believe the change here should look as follows: if (getKernelVersion() < KernelVersion::Tahoe
|| checkKernelArgument("-radconnector")
|| lilu.getRunMode() == LiluAPI::RunningNormal) {
processConnectorOverrides(patcher, address, size, true);
DBGLOG("rad", "processing override connector");
} else {
DBGLOG("rad", "skipping override connector");
}No other changes should be necessary.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I understand, do you mean to put the method that recognizes BaseSystemKernelExtendes.kc into Lilu's getRunMode?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we could go this way if no better is found. Please make sure we guard it with macOS 26, so that we definitely do not regress on older operating systems. Ideally we want a lighter approach.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But when Lilu.kext checks the running status, the root file system may not have been loaded yet, and using vfs_lookup at this time will cause a panic.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I think we should find some other approach. Do you have an
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unfortunately, ioreg only recorded BootKernelExtensions.kc. And there is no other obvious difference except BaseSystemKernelExtendes.kc.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, could you upload one for me to think about it as well? If it contains private data, you could also e-mail me to vit9696 at pm dot me ^^
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OK, Wait for me a moment, I will restart into Recovery and save one |
||
| processConnectorOverrides(patcher, address, size, true); | ||
| IOLog("WEG: Override Connector.\n"); | ||
| } | ||
| else | ||
| IOLog("WEG: WON'T Override Connector.\n"); | ||
|
|
||
| if (getKernelVersion() > KernelVersion::Mojave || | ||
| (getKernelVersion() == KernelVersion::Mojave && getKernelMinorVersion() >= 5)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we want this to be fixed on Lilu side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of now, only this patch has encountered issues on macOS Tahoe. Perhaps modifying WhateverGreen is already simple enough, there is no need to modify Lilu temporarily