OcAppleKernelLib: Added MinKernel/MaxKernel to Emulate (#128)

Also, DummyPowerManagement, usually paired with CPUID spoofing, has been moved to Emulate section.
This commit is contained in:
PMheart 2020-10-03 13:10:24 +08:00 committed by GitHub
parent e93624ab16
commit d5c140bfef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 169 additions and 64 deletions

1
.gitignore vendored
View File

@ -26,6 +26,7 @@ Utilities/TestRsaPreprocess/RsaPreprocess
Utilities/TestSmbios/Smbios
Utilities/TestPeCoff/PeCoff
*.o
*.o.tmp
*.exe
DICT
fuzz-*.log

Binary file not shown.

View File

@ -1937,20 +1937,25 @@ blocking.
\textbf{Description}: Sequence of \texttt{EAX}, \texttt{EBX}, \texttt{ECX},
\texttt{EDX} values to replace \texttt{CPUID (1)} call in XNU kernel.
This property serves for two needs:
This property primarily serves for three needs:
\begin{itemize}
\tightlist
\item Enabling support of an unsupported CPU model.
\item Enabling support of an unsupported CPU model (e.g. Intel Pentium).
\item Enabling support of a CPU model that is not yet supported by a specific version of macOS which usually is old.
\item Enabling XCPM support for an unsupported CPU variant.
\end{itemize}
\emph{Note 1}: It may also be the case that the CPU model is supported but there is no power management supported
(e.g. virtual machines). In this case, \texttt{MinKernel} and \texttt{MaxKernel} can be set to restrict CPU virtualisation and dummy power
management patches to the particular macOS kernel version.
Normally it is only the value of \texttt{EAX} that needs to be taken care of,
\emph{Note 2}: Normally it is only the value of \texttt{EAX} that needs to be taken care of,
since it represents the full CPUID. The remaining bytes are to be left as zeroes.
Byte order is Little Endian, so for example, \texttt{C3 06 03 00} stands for CPUID
\texttt{0x0306C3} (Haswell).
For XCPM support it is recommended to use the following combinations.
\emph{Note 3}: For XCPM support it is recommended to use the following combinations.
\begin{itemize}
\tightlist
@ -1962,7 +1967,7 @@ blocking.
\texttt{Cpuid1Mask}: \texttt{FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00}
\end{itemize}
Keep in mind, that the following configurations are unsupported (at least out of the box):
\emph{Note 4}: Keep in mind, that the following configurations are unsupported by XCPM (at least out of the box):
\begin{itemize}
\tightlist
@ -1983,6 +1988,37 @@ blocking.
When each \texttt{Cpuid1Mask} bit is set to 0, the original CPU bit is used,
otherwise set bits take the value of \texttt{Cpuid1Data}.
\item
\texttt{DummyPowerManagement}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Requirement}: 10.4\\
\textbf{Description}: Disables \texttt{AppleIntelCpuPowerManagement}.
\emph{Note 1}: This option is a preferred alternative to
\texttt{NullCpuPowerManagement.kext} for CPUs without native power
management driver in macOS.
\emph{Note 2}: While this option is usually needed to disable \texttt{AppleIntelCpuPowerManagement}
merely on unsupported platforms, it can still be enabled if one wishes to
disable this kext per se regardless of other situations (e.g. with \texttt{Cpuid1Data} left blank).
\item
\texttt{MaxKernel}\\
\textbf{Type}: \texttt{plist\ string}\\
\textbf{Failsafe}: Empty string\\
\textbf{Description}: Emulates CPUID and applies \texttt{DummyPowerManagement} on specified macOS version or older.
\emph{Note}: Refer to \hyperlink{kernmatch}{\texttt{Add} \texttt{MaxKernel} description} for matching logic.
\item
\texttt{MinKernel}\\
\textbf{Type}: \texttt{plist\ string}\\
\textbf{Failsafe}: Empty string\\
\textbf{Description}: Emulates CPUID and applies \texttt{DummyPowerManagement} on specified macOS version or newer.
\emph{Note}: Refer to \hyperlink{kernmatch}{\texttt{Add} \texttt{MaxKernel} description} for matching logic.
\end{enumerate}
\subsection{Force Properties}\label{kernelpropsforce}
@ -2299,17 +2335,6 @@ blocking.
at firmware stage (e.g. macOS bootloader), see \texttt{AppleRtcRam} protocol
description if this is desired.
\item
\texttt{DummyPowerManagement}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Requirement}: 10.4\\
\textbf{Description}: Disables \texttt{AppleIntelCpuPowerManagement}.
\emph{Note}: This option is a preferred alternative to
\texttt{NullCpuPowerManagement.kext} for CPUs without native power
management driver in macOS.
\item
\texttt{ExtendBTFeatureFlags}\\
\textbf{Type}: \texttt{plist\ boolean}\\

Binary file not shown.

View File

@ -1,7 +1,7 @@
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Thu Sep 24 19:29:02 2020
%DIF ADD ../Configuration.tex Fri Oct 2 09:04:03 2020
%DIF ADD ../Configuration.tex Sat Oct 3 11:24:40 2020
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
@ -1997,20 +1997,27 @@ blocking.
\textbf{Description}: Sequence of \texttt{EAX}, \texttt{EBX}, \texttt{ECX},
\texttt{EDX} values to replace \texttt{CPUID (1)} call in XNU kernel.
This property serves for two needs:
This property \DIFdelbegin \DIFdel{serves for two }\DIFdelend \DIFaddbegin \DIFadd{primarily serves for three }\DIFaddend needs:
\begin{itemize}
\tightlist
\item Enabling support of an unsupported CPU model.
\item Enabling XCPM support for an unsupported CPU variant.
\item Enabling support of an unsupported CPU model \DIFdelbegin \DIFdel{.
}\DIFdelend \DIFaddbegin \DIFadd{(e.g. Intel Pentium).
}\DIFaddend \item Enabling \DIFaddbegin \DIFadd{support of a CPU model that is not yet supported by a specific version of macOS which usually is old.
}\item \DIFadd{Enabling }\DIFaddend XCPM support for an unsupported CPU variant.
\end{itemize}
Normally it is only the value of \texttt{EAX} that needs to be taken care of,
\DIFaddbegin \emph{\DIFadd{Note 1}}\DIFadd{: It may also be the case that the CPU model is supported but there is no power management supported
(e.g. virtual machines). In this case, }\texttt{\DIFadd{MinKernel}} \DIFadd{and }\texttt{\DIFadd{MaxKernel}} \DIFadd{can be set to restrict CPU virtualisation and dummy power
management patches to the particular macOS kernel version.
}
\emph{\DIFadd{Note 2}}\DIFadd{: }\DIFaddend Normally it is only the value of \texttt{EAX} that needs to be taken care of,
since it represents the full CPUID. The remaining bytes are to be left as zeroes.
Byte order is Little Endian, so for example, \texttt{C3 06 03 00} stands for CPUID
\texttt{0x0306C3} (Haswell).
For XCPM support it is recommended to use the following combinations.
\DIFaddbegin \emph{\DIFadd{Note 3}}\DIFadd{: }\DIFaddend For XCPM support it is recommended to use the following combinations.
\begin{itemize}
\tightlist
@ -2022,7 +2029,7 @@ blocking.
\texttt{Cpuid1Mask}: \texttt{FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00}
\end{itemize}
Keep in mind, that the following configurations are unsupported (at least out of the box):
\DIFaddbegin \emph{\DIFadd{Note 4}}\DIFadd{: }\DIFaddend Keep in mind, that the following configurations are unsupported \DIFaddbegin \DIFadd{by XCPM }\DIFaddend (at least out of the box):
\begin{itemize}
\tightlist
@ -2043,7 +2050,45 @@ blocking.
When each \texttt{Cpuid1Mask} bit is set to 0, the original CPU bit is used,
otherwise set bits take the value of \texttt{Cpuid1Data}.
\end{enumerate}
\DIFaddbegin \item
\texttt{\DIFadd{DummyPowerManagement}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{false}}\\
\textbf{\DIFadd{Requirement}}\DIFadd{: 10.4}\\
\textbf{\DIFadd{Description}}\DIFadd{: Disables }\texttt{\DIFadd{AppleIntelCpuPowerManagement}}\DIFadd{.
}
\emph{\DIFadd{Note 1}}\DIFadd{: This option is a preferred alternative to
}\texttt{\DIFadd{NullCpuPowerManagement.kext}} \DIFadd{for CPUs without native power
management driver in macOS.
}
\emph{\DIFadd{Note 2}}\DIFadd{: While this option is usually needed to disable }\texttt{\DIFadd{AppleIntelCpuPowerManagement}}
\DIFadd{merely on unsupported platforms, it can still be enabled if one wishes to
disable this kext per se regardless of other situations (e.g. with }\texttt{\DIFadd{Cpuid1Data}} \DIFadd{left blank).
}
\item
\texttt{\DIFadd{MaxKernel}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ string}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: Empty string}\\
\textbf{\DIFadd{Description}}\DIFadd{: Emulates CPUID and applies }\texttt{\DIFadd{DummyPowerManagement}} \DIFadd{on specified macOS version or older.
}
\emph{\DIFadd{Note}}\DIFadd{: Refer to }\hyperlink{kernmatch}{\texttt{Add} \texttt{MaxKernel} description} \DIFadd{for matching logic.
}
\item
\texttt{\DIFadd{MinKernel}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ string}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: Empty string}\\
\textbf{\DIFadd{Description}}\DIFadd{: Emulates CPUID and applies }\texttt{\DIFadd{DummyPowerManagement}} \DIFadd{on specified macOS version or newer.
}
\emph{\DIFadd{Note}}\DIFadd{: Refer to }\hyperlink{kernmatch}{\texttt{Add} \texttt{MaxKernel} description} \DIFadd{for matching logic.
}
\DIFaddend \end{enumerate}
\subsection{Force Properties}\label{kernelpropsforce}
@ -2360,31 +2405,22 @@ blocking.
description if this is desired.
\item
\texttt{DummyPowerManagement}\\
\texttt{\DIFdelbegin \DIFdel{DummyPowerManagement}\DIFdelend \DIFaddbegin \DIFadd{ExtendBTFeatureFlags}\DIFaddend }\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Requirement}: \DIFdelbegin \DIFdel{10.6 (64-bit)}\DIFdelend \DIFaddbegin \DIFadd{10.4}\DIFaddend \\
\textbf{Description}: Disables \texttt{AppleIntelCpuPowerManagement}.
\textbf{Requirement}: \DIFdelbegin \DIFdel{10.6 (64-bit)}\DIFdelend \DIFaddbegin \DIFadd{10.8}\DIFaddend \\
\textbf{Description}: \DIFdelbegin \DIFdel{Disables }\DIFdelend \DIFaddbegin \DIFadd{Set }\DIFaddend \texttt{\DIFdelbegin \DIFdel{AppleIntelCpuPowerManagement}\DIFdelend \DIFaddbegin \DIFadd{FeatureFlags}\DIFaddend } \DIFaddbegin \DIFadd{to }\texttt{\DIFadd{0x0F}} \DIFadd{for full
functionality of Bluetooth, including Continuity}\DIFaddend .
\emph{Note}: This option is a preferred alternative to
\texttt{NullCpuPowerManagement.kext} for CPUs without native power
management driver in macOS.
\item
\DIFaddbegin \texttt{\DIFadd{ExtendBTFeatureFlags}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{false}}\\
\textbf{\DIFadd{Requirement}}\DIFadd{: 10.8}\\
\textbf{\DIFadd{Description}}\DIFadd{: Set }\texttt{\DIFadd{FeatureFlags}} \DIFadd{to }\texttt{\DIFadd{0x0F}} \DIFadd{for full
functionality of Bluetooth, including Continuity.
}
\emph{\DIFadd{Note}}\DIFadd{: This option is a substitution for BT4LEContinuityFixup.kext,
\emph{Note}: This option is a \DIFdelbegin \DIFdel{preferred alternative to
}\texttt{\DIFdel{NullCpuPowerManagement.kext}} %DIFAUXCMD
\DIFdel{for CPUs without native power
management driver in macOS.}\DIFdelend \DIFaddbegin \DIFadd{substitution for BT4LEContinuityFixup.kext,
which does not function properly due to late patching progress.
}
}\DIFaddend
\item
\DIFaddend \texttt{ExternalDiskIcons}\\
\texttt{ExternalDiskIcons}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Requirement}: \DIFdelbegin \DIFdel{10.6 (64-bit)}\DIFdelend \DIFaddbegin \DIFadd{10.4}\DIFaddend \\

Binary file not shown.

View File

@ -441,6 +441,12 @@
</array>
<key>Emulate</key>
<dict>
<key>DummyPowerManagement</key>
<false/>
<key>MaxKernel</key>
<string></string>
<key>MinKernel</key>
<string></string>
<key>Cpuid1Data</key>
<data></data>
<key>Cpuid1Mask</key>
@ -670,8 +676,6 @@
<true/>
<key>DisableRtcChecksum</key>
<false/>
<key>DummyPowerManagement</key>
<false/>
<key>ExtendBTFeatureFlags</key>
<false/>
<key>ExternalDiskIcons</key>

View File

@ -441,6 +441,12 @@
</array>
<key>Emulate</key>
<dict>
<key>DummyPowerManagement</key>
<false/>
<key>MaxKernel</key>
<string></string>
<key>MinKernel</key>
<string></string>
<key>Cpuid1Data</key>
<data></data>
<key>Cpuid1Mask</key>
@ -670,8 +676,6 @@
<true/>
<key>DisableRtcChecksum</key>
<false/>
<key>DummyPowerManagement</key>
<false/>
<key>ExtendBTFeatureFlags</key>
<false/>
<key>ExternalDiskIcons</key>

View File

@ -210,8 +210,11 @@
/// Kernel emulation preferences.
///
#define OC_KERNEL_EMULATE_FIELDS(_,__) \
_(UINT32 , Cpuid1Data , [4] , {0} , () ) \
_(UINT32 , Cpuid1Mask , [4] , {0} , () )
_(UINT32 , Cpuid1Data , [4] , {0} , () ) \
_(UINT32 , Cpuid1Mask , [4] , {0} , () ) \
_(BOOLEAN , DummyPowerManagement, , FALSE , () ) \
_(OC_STRING , MaxKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
_(OC_STRING , MinKernel , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) )
OC_DECLARE (OC_KERNEL_EMULATE)
///
@ -257,7 +260,6 @@
_(BOOLEAN , DisableIoMapper , , FALSE , ()) \
_(BOOLEAN , DisableLinkeditJettison , , FALSE , ()) \
_(BOOLEAN , DisableRtcChecksum , , FALSE , ()) \
_(BOOLEAN , DummyPowerManagement , , FALSE , ()) \
_(BOOLEAN , ExtendBTFeatureFlags , , FALSE , ()) \
_(BOOLEAN , ExternalDiskIcons , , FALSE , ()) \
_(BOOLEAN , IncreasePciBarSize , , FALSE , ()) \

View File

@ -263,8 +263,11 @@ mKernelBlockSchema = OC_SCHEMA_DICT (NULL, mKernelBlockSchemaEntry);
STATIC
OC_SCHEMA
mKernelEmulateSchema[] = {
OC_SCHEMA_DATAF_IN ("Cpuid1Data", OC_GLOBAL_CONFIG, Kernel.Emulate.Cpuid1Data),
OC_SCHEMA_DATAF_IN ("Cpuid1Mask", OC_GLOBAL_CONFIG, Kernel.Emulate.Cpuid1Mask),
OC_SCHEMA_DATAF_IN ("Cpuid1Data", OC_GLOBAL_CONFIG, Kernel.Emulate.Cpuid1Data),
OC_SCHEMA_DATAF_IN ("Cpuid1Mask", OC_GLOBAL_CONFIG, Kernel.Emulate.Cpuid1Mask),
OC_SCHEMA_BOOLEAN_IN ("DummyPowerManagement", OC_GLOBAL_CONFIG, Kernel.Emulate.DummyPowerManagement),
OC_SCHEMA_STRING_IN ("MaxKernel", OC_GLOBAL_CONFIG, Kernel.Emulate.MaxKernel),
OC_SCHEMA_STRING_IN ("MinKernel", OC_GLOBAL_CONFIG, Kernel.Emulate.MinKernel),
};
STATIC
@ -319,7 +322,6 @@ mKernelQuirksSchema[] = {
OC_SCHEMA_BOOLEAN_IN ("DisableIoMapper", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableIoMapper),
OC_SCHEMA_BOOLEAN_IN ("DisableLinkeditJettison", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableLinkeditJettison),
OC_SCHEMA_BOOLEAN_IN ("DisableRtcChecksum", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableRtcChecksum),
OC_SCHEMA_BOOLEAN_IN ("DummyPowerManagement", OC_GLOBAL_CONFIG, Kernel.Quirks.DummyPowerManagement),
OC_SCHEMA_BOOLEAN_IN ("ExtendBTFeatureFlags", OC_GLOBAL_CONFIG, Kernel.Quirks.ExtendBTFeatureFlags),
OC_SCHEMA_BOOLEAN_IN ("ExternalDiskIcons", OC_GLOBAL_CONFIG, Kernel.Quirks.ExternalDiskIcons),
OC_SCHEMA_BOOLEAN_IN ("IncreasePciBarSize", OC_GLOBAL_CONFIG, Kernel.Quirks.IncreasePciBarSize),

View File

@ -210,6 +210,9 @@ OcKernelApplyPatches (
));
}
//
// Handle Quirks/Emulate here...
//
if (!IsKernelPatch) {
if (Config->Kernel.Quirks.AppleCpuPmCfgLock) {
OcKernelApplyQuirk (KernelQuirkAppleCpuPmCfgLock, CacheType, DarwinVersion, Context, NULL);
@ -246,13 +249,27 @@ OcKernelApplyPatches (
OcKernelApplyQuirk (KernelQuirkCustomSmbiosGuid2, CacheType, DarwinVersion, Context, NULL);
}
if (Config->Kernel.Quirks.DummyPowerManagement) {
OcKernelApplyQuirk (KernelQuirkDummyPowerManagement, CacheType, DarwinVersion, Context, NULL);
}
if (Config->Kernel.Quirks.ExtendBTFeatureFlags) {
OcKernelApplyQuirk (KernelQuirkExtendBTFeatureFlags, CacheType, DarwinVersion, Context, NULL);
}
if (Config->Kernel.Emulate.DummyPowerManagement) {
MaxKernel = OcParseDarwinVersion (OC_BLOB_GET (&Config->Kernel.Emulate.MaxKernel));
MinKernel = OcParseDarwinVersion (OC_BLOB_GET (&Config->Kernel.Emulate.MinKernel));
if (OcMatchDarwinVersion (DarwinVersion, MinKernel, MaxKernel)) {
OcKernelApplyQuirk (KernelQuirkDummyPowerManagement, CacheType, DarwinVersion, Context, NULL);
} else {
DEBUG ((
DEBUG_INFO,
"OC: %a patcher skips DummyPowerManagement patch due to version %u <= %u <= %u\n",
PRINT_KERNEL_CACHE_TYPE (CacheType),
Target,
MinKernel,
DarwinVersion,
MaxKernel
));
}
}
} else {
if (Config->Kernel.Quirks.AppleXcpmCfgLock) {
OcKernelApplyQuirk (KernelQuirkAppleXcpmCfgLock, CacheType, DarwinVersion, NULL, &KernelPatcher);
@ -274,13 +291,27 @@ OcKernelApplyPatches (
|| Config->Kernel.Emulate.Cpuid1Data[1] != 0
|| Config->Kernel.Emulate.Cpuid1Data[2] != 0
|| Config->Kernel.Emulate.Cpuid1Data[3] != 0) {
PatchKernelCpuId (
&KernelPatcher,
CpuInfo,
Config->Kernel.Emulate.Cpuid1Data,
Config->Kernel.Emulate.Cpuid1Mask,
DarwinVersion
);
MaxKernel = OcParseDarwinVersion (OC_BLOB_GET (&Config->Kernel.Emulate.MaxKernel));
MinKernel = OcParseDarwinVersion (OC_BLOB_GET (&Config->Kernel.Emulate.MinKernel));
if (OcMatchDarwinVersion (DarwinVersion, MinKernel, MaxKernel)) {
PatchKernelCpuId (
&KernelPatcher,
CpuInfo,
Config->Kernel.Emulate.Cpuid1Data,
Config->Kernel.Emulate.Cpuid1Mask,
DarwinVersion
);
} else {
DEBUG ((
DEBUG_INFO,
"OC: %a patcher skips CPUID patch due to version %u <= %u <= %u\n",
PRINT_KERNEL_CACHE_TYPE (CacheType),
Target,
MinKernel,
DarwinVersion,
MaxKernel
));
}
}
if (Config->Kernel.Quirks.LapicKernelPanic) {