未验证 提交 d8c59684 编写于 作者: Z zhen-zen 提交者: GitHub

OcAfterBootCompatLib: Allow specification of max slide for unavailable range (#76)

上级 5d4567c7
......@@ -1459,6 +1459,26 @@ To view their current state use \texttt{pmset -g} command in Terminal.
slide values are usable!} message in the debug log. If the message is present,
this option is to be enabled.
\item
\texttt{ProvideMaxSlide}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{0}\\
\textbf{Description}: Provide maximum KASLR slide when higher ones are unavailable.
This option overrides the maximum slide instead of \texttt{TOTAL\_SLIDE\_NUM}
(256) when \texttt{ProvideCustomSlide} is enabled. It is believed that modern
firmwares allocate pool memory from top to bottom, effectively resulting in
free memory at the time of slide scanning being later used as temporary
memory during kernel loading. In case those memory are unavailable, this
option can stop evaluating higher slides.
\emph{Note}: The necessity of this quirk is determined by random boot failure
when \texttt{ProvideCustomSlide} is enabled and the randomized slide fall
into the unavailable range. When \texttt{AppleDebug} is enabled, usually the
debug log may contain messages like \texttt{AAPL: [EB|`LD:LKC] \} Err(0x9)}.
To find the optimal value, manually append \texttt{slide=X} to \texttt{boot-args}
and log the largest one that won't cause boot failure.
\item
\texttt{RebuildAppleMemoryMap}\\
\textbf{Type}: \texttt{plist\ boolean}\\
......
......@@ -36,6 +36,10 @@ typedef struct OC_ABC_SETTINGS_ {
///
BOOLEAN ProvideCustomSlide;
///
/// Provide max KASLR slide for firmwares with polluted higher memory ranges.
///
UINT8 ProvideMaxSlide;
///
/// Remove runtime flag from MMIO areas and prevent virtual address assignment for known
/// MMIO regions. This may improve the amount of slides available, but may not work on
/// unknown configurations.
......
......@@ -124,6 +124,7 @@
_(BOOLEAN , ProtectSecureBoot , , FALSE , ()) \
_(BOOLEAN , ProtectUefiServices , , FALSE , ()) \
_(BOOLEAN , ProvideCustomSlide , , FALSE , ()) \
_(UINT8 , ProvideMaxSlide , , 0 , ()) \
_(BOOLEAN , RebuildAppleMemoryMap , , FALSE , ()) \
_(BOOLEAN , SetupVirtualMap , , FALSE , ()) \
_(BOOLEAN , SignalAppleOS , , FALSE , ()) \
......
......@@ -300,6 +300,10 @@ typedef struct SLIDE_SUPPORT_STATE_ {
///
UINT32 CsrActiveConfig;
///
/// Max slide value provided.
///
UINT8 ProvideMaxSlide;
///
/// Valid slides to choose from when using custom slide.
///
UINT8 ValidSlides[TOTAL_SLIDE_NUM];
......
......@@ -91,7 +91,7 @@ GenerateSlideValue (
do {
DivU64x32Remainder (GetPseudoRandomNumber64 (), SlideSupport->ValidSlideCount, &Slide);
} while (Slide == 0);
} while (SlideSupport->ValidSlides[Slide] == 0);
return SlideSupport->ValidSlides[Slide];
}
......@@ -362,6 +362,14 @@ ShouldUseCustomSlideOffset (
FallbackSlide = (UINT8) Slide;
}
//
// Stop evalutating slides after exceeding ProvideMaxSlide, may break when
// no slides are available.
//
if (SlideSupport->ProvideMaxSlide > 0 && Slide > SlideSupport->ProvideMaxSlide) {
break;
}
if ((StartAddr + AvailableSize) != EndAddr) {
//
// The slide region is not continuous.
......@@ -736,6 +744,8 @@ AppleSlideGetVariable (
OUT VOID *Data
)
{
BootCompat->SlideSupport.ProvideMaxSlide = BootCompat->Settings.ProvideMaxSlide;
if (VariableName != NULL && VendorGuid != NULL && DataSize != NULL
&& CompareGuid (VendorGuid, &gAppleBootVariableGuid)) {
......
......@@ -124,10 +124,11 @@ OcAbcInitialize (
DEBUG ((
DEBUG_INFO,
"OCABC: FEXITBS %d PRMRG %d CSLIDE %d PRSRV %d RBMAP %d VMAP %d APPLOS %d RTPERMS %d\n",
"OCABC: FEXITBS %d PRMRG %d CSLIDE %d MSLIDE %d PRSRV %d RBMAP %d VMAP %d APPLOS %d RTPERMS %d\n",
Settings->ForceExitBootServices,
Settings->ProtectMemoryRegions,
Settings->ProvideCustomSlide,
Settings->ProvideMaxSlide,
Settings->ProtectUefiServices,
Settings->RebuildAppleMemoryMap,
Settings->SetupVirtualMap,
......
......@@ -179,6 +179,7 @@ mBooterQuirksSchema[] = {
OC_SCHEMA_BOOLEAN_IN ("ProtectSecureBoot", OC_GLOBAL_CONFIG, Booter.Quirks.ProtectSecureBoot),
OC_SCHEMA_BOOLEAN_IN ("ProtectUefiServices", OC_GLOBAL_CONFIG, Booter.Quirks.ProtectUefiServices),
OC_SCHEMA_BOOLEAN_IN ("ProvideCustomSlide", OC_GLOBAL_CONFIG, Booter.Quirks.ProvideCustomSlide),
OC_SCHEMA_INTEGER_IN ("ProvideMaxSlide", OC_GLOBAL_CONFIG, Booter.Quirks.ProvideMaxSlide),
OC_SCHEMA_BOOLEAN_IN ("RebuildAppleMemoryMap", OC_GLOBAL_CONFIG, Booter.Quirks.RebuildAppleMemoryMap),
OC_SCHEMA_BOOLEAN_IN ("SetupVirtualMap", OC_GLOBAL_CONFIG, Booter.Quirks.SetupVirtualMap),
OC_SCHEMA_BOOLEAN_IN ("SignalAppleOS", OC_GLOBAL_CONFIG, Booter.Quirks.SignalAppleOS),
......
......@@ -373,6 +373,7 @@ OcLoadBooterUefiSupport (
AbcSettings.ForceExitBootServices = Config->Booter.Quirks.ForceExitBootServices;
AbcSettings.ProtectMemoryRegions = Config->Booter.Quirks.ProtectMemoryRegions;
AbcSettings.ProvideCustomSlide = Config->Booter.Quirks.ProvideCustomSlide;
AbcSettings.ProvideMaxSlide = Config->Booter.Quirks.ProvideMaxSlide;
AbcSettings.ProtectUefiServices = Config->Booter.Quirks.ProtectUefiServices;
AbcSettings.RebuildAppleMemoryMap = Config->Booter.Quirks.RebuildAppleMemoryMap;
AbcSettings.SetupVirtualMap = Config->Booter.Quirks.SetupVirtualMap;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册