Skip to content

Commit 485db4c

Browse files
authored
OcAppleKernelLib: Disabled XcpmExtraMsrs MSR_MISC_PWR_MGMT patch on macOS 12+; fix IOAHCIBlockStorage patch on macOS 14.4+ thanks @vit9696 (#545)
1 parent 55bed88 commit 485db4c

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed

Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ OpenCore Changelog
44
- Updated code and added progress bar to macrecovery, thx @soyeonswife63
55
- Bundled fat binary i386/x64 10.6+ compatible `nvramdump` with LogoutHook release
66
- Added support for manual build of i386/x64 10.6+ versions of userspace tools via `FATBIN32=1 make`
7+
- Disabled `XcpmExtraMsrs MSR_MISC_PWR_MGMT` patch on macOS 12+ due to non-existence
8+
- Fixed `ThirdPartyDrives` quirk on macOS 14.4 and above
79

810
#### v1.0.0
911
- Updated builtin firmware versions for SMBIOS and the rest

Include/Acidanthera/Library/OcAppleKernelLib.h

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ typedef enum KERNEL_CACHE_TYPE_ {
129129
#define KERNEL_VERSION_BIG_SUR 20
130130
#define KERNEL_VERSION_MONTEREY 21
131131
#define KERNEL_VERSION_VENTURA 22
132+
#define KERNEL_VERSION_SONOMA 23
133+
#define KERNEL_VERSION_SEQUOIA 24
132134

133135
//
134136
// Minimum kernel versions for each release.
@@ -148,6 +150,8 @@ typedef enum KERNEL_CACHE_TYPE_ {
148150
#define KERNEL_VERSION_BIG_SUR_MIN KERNEL_VERSION (KERNEL_VERSION_BIG_SUR, 0, 0)
149151
#define KERNEL_VERSION_MONTEREY_MIN KERNEL_VERSION (KERNEL_VERSION_MONTEREY, 0, 0)
150152
#define KERNEL_VERSION_VENTURA_MIN KERNEL_VERSION (KERNEL_VERSION_VENTURA, 0, 0)
153+
#define KERNEL_VERSION_SONOMA_MIN KERNEL_VERSION (KERNEL_VERSION_SONOMA, 0, 0)
154+
#define KERNEL_VERSION_SEQUOIA_MIN KERNEL_VERSION (KERNEL_VERSION_SEQUOIA, 0, 0)
151155

152156
//
153157
// Maximum kernel versions for each release.
@@ -166,6 +170,8 @@ typedef enum KERNEL_CACHE_TYPE_ {
166170
#define KERNEL_VERSION_CATALINA_MAX (KERNEL_VERSION_BIG_SUR_MIN - 1)
167171
#define KERNEL_VERSION_BIG_SUR_MAX (KERNEL_VERSION_MONTEREY_MIN - 1)
168172
#define KERNEL_VERSION_MONTEREY_MAX (KERNEL_VERSION_VENTURA_MIN - 1)
173+
#define KERNEL_VERSION_VENTURA_MAX (KERNEL_VERSION_SONOMA_MIN - 1)
174+
#define KERNEL_VERSION_SONOMA_MAX (KERNEL_VERSION_SEQUOIA_MIN - 1)
169175

170176
//
171177
// Prelinked context used for kernel modification.

Library/OcAppleKernelLib/CommonPatches.c

+75-5
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,18 @@ PatchAppleXcpmExtraMsrs (
446446

447447
//
448448
// Now patch writes to MSR_MISC_PWR_MGMT.
449+
// On macOS Monterey (12) and above, this no longer exists.
449450
//
450-
Status = PatcherApplyGenericPatch (Patcher, &mMiscPwrMgmtRelPatch);
451-
if (EFI_ERROR (Status)) {
452-
DEBUG ((DEBUG_INFO, "OCAK: Failed to patch writes to MSR_MISC_PWR_MGMT - %r, trying dbg\n", Status));
453-
Status = PatcherApplyGenericPatch (Patcher, &mMiscPwrMgmtDbgPatch);
451+
if (OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_MONTEREY_MIN, 0)) {
452+
DEBUG ((DEBUG_INFO, "OCAK: Skipping XcpmExtraMsrs MSR_MISC_PWR_MGMT patch on %u\n", KernelVersion));
453+
} else {
454+
Status = PatcherApplyGenericPatch (Patcher, &mMiscPwrMgmtRelPatch);
454455
if (EFI_ERROR (Status)) {
455-
DEBUG ((DEBUG_WARN, "OCAK: Failed to patch writes to MSR_MISC_PWR_MGMT - %r\n", Status));
456+
DEBUG ((DEBUG_INFO, "OCAK: Failed to patch writes to XcpmExtraMsrs MSR_MISC_PWR_MGMT - %r, trying dbg\n", Status));
457+
Status = PatcherApplyGenericPatch (Patcher, &mMiscPwrMgmtDbgPatch);
458+
if (EFI_ERROR (Status)) {
459+
DEBUG ((DEBUG_WARN, "OCAK: Failed to patch writes to XcpmExtraMsrs MSR_MISC_PWR_MGMT - %r\n", Status));
460+
}
456461
}
457462
}
458463

@@ -988,6 +993,57 @@ PATCHER_GENERIC_PATCH
988993
.Limit = 4096
989994
};
990995

996+
STATIC
997+
CONST UINT8
998+
mIOAHCIBlockStoragePatch144Find[] = {
999+
0x4C, 0x8D, 0x2D, 0x00, 0x00, 0x00, 0x00, ///< lea r13, qword ("APPLE" and "APPLE SSD")
1000+
0x4C, 0x89, 0xEF, ///< mov rdi, r13
1001+
0xE8, 0x00, 0x00, 0x00, 0x00, ///< call strlen
1002+
0x4C, 0x89, 0xEF ///< mov rdi, r13
1003+
};
1004+
1005+
STATIC
1006+
CONST UINT8
1007+
mIOAHCIBlockStoragePatch144FindMask[] = {
1008+
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
1009+
0xFF, 0xFF, 0xFF,
1010+
0xFF, 0x00, 0x00, 0x00, 0x00,
1011+
0xFF, 0xFF, 0xFF
1012+
};
1013+
1014+
STATIC
1015+
CONST UINT8
1016+
mIOAHCIBlockStoragePatch144Replace[] = {
1017+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1018+
0x00, 0x00, 0x00,
1019+
0x31, 0xC0, 0x90, 0x90, 0x90, ///< xor eax, eax ; nop
1020+
0x00, 0x00, 0x00
1021+
};
1022+
1023+
STATIC
1024+
CONST UINT8
1025+
mIOAHCIBlockStoragePatch144ReplaceMask[] = {
1026+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1027+
0x00, 0x00, 0x00,
1028+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1029+
0x00, 0x00, 0x00
1030+
};
1031+
1032+
STATIC
1033+
PATCHER_GENERIC_PATCH
1034+
mIOAHCIBlockStoragePatch144 = {
1035+
.Comment = DEBUG_POINTER ("IOAHCIBlockStorage trim 14.4+"),
1036+
.Base = "__ZN24IOAHCIBlockStorageDriver23DetermineDeviceFeaturesEPt",
1037+
.Find = mIOAHCIBlockStoragePatch144Find,
1038+
.Mask = mIOAHCIBlockStoragePatch144FindMask,
1039+
.Replace = mIOAHCIBlockStoragePatch144Replace,
1040+
.ReplaceMask = mIOAHCIBlockStoragePatch144ReplaceMask,
1041+
.Size = sizeof (mIOAHCIBlockStoragePatch144Find),
1042+
.Count = 2,
1043+
.Skip = 0,
1044+
.Limit = 4096
1045+
};
1046+
9911047
STATIC
9921048
EFI_STATUS
9931049
PatchThirdPartyDriveSupport (
@@ -1002,6 +1058,20 @@ PatchThirdPartyDriveSupport (
10021058
return EFI_NOT_FOUND;
10031059
}
10041060

1061+
//
1062+
// macOS 14.4+ (Darwin 23.4.0) adopted different patch patterns similar to 13.3+, as below.
1063+
//
1064+
if (OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION (KERNEL_VERSION_SONOMA, 4, 0), 0)) {
1065+
Status = PatcherApplyGenericPatch (Patcher, &mIOAHCIBlockStoragePatch144);
1066+
if (EFI_ERROR (Status)) {
1067+
DEBUG ((DEBUG_INFO, "OCAK: [FAIL] Failed to apply patch 14.4+ com.apple.iokit.IOAHCIBlockStorage - %r\n", Status));
1068+
} else {
1069+
DEBUG ((DEBUG_INFO, "OCAK: [OK] Patch success 14.4+ com.apple.iokit.IOAHCIBlockStorage\n"));
1070+
}
1071+
1072+
return Status;
1073+
}
1074+
10051075
//
10061076
// Starting with macOS 13.3 (Darwin 22.4.0), a new set of patches are required, discovered by @vit9696.
10071077
//

0 commit comments

Comments
 (0)