@@ -446,13 +446,18 @@ PatchAppleXcpmExtraMsrs (
446
446
447
447
//
448
448
// Now patch writes to MSR_MISC_PWR_MGMT.
449
+ // On macOS Monterey (12) and above, this no longer exists.
449
450
//
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 );
454
455
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
+ }
456
461
}
457
462
}
458
463
@@ -988,6 +993,57 @@ PATCHER_GENERIC_PATCH
988
993
.Limit = 4096
989
994
};
990
995
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
+
991
1047
STATIC
992
1048
EFI_STATUS
993
1049
PatchThirdPartyDriveSupport (
@@ -1002,6 +1058,20 @@ PatchThirdPartyDriveSupport (
1002
1058
return EFI_NOT_FOUND ;
1003
1059
}
1004
1060
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
+
1005
1075
//
1006
1076
// Starting with macOS 13.3 (Darwin 22.4.0), a new set of patches are required, discovered by @vit9696.
1007
1077
//
0 commit comments