mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2025-02-27 02:51:50 +01:00
Restore AllocSmallBlocks() needed when MemMap is too big.
This commit is contained in:
parent
3fd62f2756
commit
381bc886e5
@ -375,10 +375,10 @@
|
|||||||
<BuildOptions>
|
<BuildOptions>
|
||||||
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
||||||
}
|
}
|
||||||
# OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf {
|
OpenCorePkg/Library/OcMemoryLib/OcMemoryLib.inf {
|
||||||
# <BuildOptions>
|
<BuildOptions>
|
||||||
# *_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
||||||
# }
|
}
|
||||||
OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf {
|
OpenCorePkg/Library/OcMiscLib/OcMiscLib.inf {
|
||||||
<BuildOptions>
|
<BuildOptions>
|
||||||
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
*_*_*_CC_FLAGS = $(OC_INCLUDE_FLAG)
|
||||||
|
@ -77,6 +77,7 @@ void f_p1void(void* p)
|
|||||||
int MemoryTracker_tests()
|
int MemoryTracker_tests()
|
||||||
{
|
{
|
||||||
#ifdef MEMORY_TRACKER_ENABLED
|
#ifdef MEMORY_TRACKER_ENABLED
|
||||||
|
// Work in progress !!!!!!!!!!!!!!
|
||||||
void* p; (void)p;
|
void* p; (void)p;
|
||||||
|
|
||||||
// int t1_v = 3;
|
// int t1_v = 3;
|
||||||
@ -126,6 +127,8 @@ int MemoryTracker_tests()
|
|||||||
// MT_delete(p, "return g_ta.testAlloc2()"_XS8);
|
// MT_delete(p, "return g_ta.testAlloc2()"_XS8);
|
||||||
// MT_outputDanglingPtr();
|
// MT_outputDanglingPtr();
|
||||||
// printf("------------------\n");
|
// printf("------------------\n");
|
||||||
|
#else
|
||||||
|
breakpoint(0); // to avoid warning.
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -142,76 +142,48 @@ extern EFI_DXE_SERVICES *gDS;
|
|||||||
|
|
||||||
EFI_PHYSICAL_ADDRESS ExtraSpace = EFI_SYSTEM_TABLE_MAX_ADDRESS;
|
EFI_PHYSICAL_ADDRESS ExtraSpace = EFI_SYSTEM_TABLE_MAX_ADDRESS;
|
||||||
|
|
||||||
//VOID
|
void PrintMemoryMap()
|
||||||
//PrintMemoryMap()
|
|
||||||
//{
|
|
||||||
// apd<EFI_MEMORY_DESCRIPTOR*> MemMap;
|
|
||||||
// UINTN MemMapSize;
|
|
||||||
// UINTN MapKey, DescriptorSize;
|
|
||||||
// UINT32 DescriptorVersion;
|
|
||||||
// EFI_STATUS Status;
|
|
||||||
//
|
|
||||||
// MemMapSize = 0;
|
|
||||||
// DescriptorSize = 0;
|
|
||||||
// Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
|
||||||
// if (Status != EFI_BUFFER_TOO_SMALL) {
|
|
||||||
// DBG("PrintMemoryMap: GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// MemMapSize += EFI_PAGE_SIZE;
|
|
||||||
// MemMap = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(MemMapSize);
|
|
||||||
//
|
|
||||||
// Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
|
||||||
// if ( EFI_ERROR(Status) ) {
|
|
||||||
// DBG("PrintMemoryMap: GetMemoryMap failed=%s\n", efiStrError(Status));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// OcPrintMemoryMap(MemMapSize, MemMap, DescriptorSize);
|
|
||||||
//}
|
|
||||||
|
|
||||||
VOID
|
|
||||||
PrintMemoryMap (
|
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
EFI_MEMORY_DESCRIPTOR *MemMap;
|
apd<EFI_MEMORY_DESCRIPTOR*> MemMap;
|
||||||
EFI_MEMORY_DESCRIPTOR *MemMapPtr;
|
UINTN MemMapSize;
|
||||||
UINTN MemMapSize = 0;
|
UINTN MapKey, DescriptorSize;
|
||||||
UINTN MapKey = 0, DescriptorSize = 0;
|
UINT32 DescriptorVersion;
|
||||||
UINT32 DescriptorVersion = 0;
|
EFI_STATUS Status;
|
||||||
UINT64 Bytes;
|
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
|
||||||
|
|
||||||
MemMapSize = 0;
|
MemMapSize = 0;
|
||||||
MemMap = NULL;
|
DescriptorSize = 0;
|
||||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
// ASSERT (Status == EFI_BUFFER_TOO_SMALL);
|
if (Status != EFI_BUFFER_TOO_SMALL) {
|
||||||
|
DBG("PrintMemoryMap: GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
|
||||||
|
return;
|
||||||
|
}
|
||||||
MemMapSize += EFI_PAGE_SIZE;
|
MemMapSize += EFI_PAGE_SIZE;
|
||||||
Status = gBS->AllocatePool (EfiBootServicesData, MemMapSize, (VOID**)&MemMap);
|
MemMap = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(MemMapSize);
|
||||||
// ASSERT (Status == EFI_SUCCESS);
|
|
||||||
if (EFI_ERROR(Status)) return;
|
|
||||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
|
||||||
// ASSERT (Status == EFI_SUCCESS);
|
|
||||||
MemMapPtr = MemMap;
|
|
||||||
|
|
||||||
// ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);
|
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
|
if ( EFI_ERROR(Status) ) {
|
||||||
|
DBG("PrintMemoryMap: GetMemoryMap failed=%s\n", efiStrError(Status));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef JIEF_DEBUG
|
||||||
|
EFI_MEMORY_DESCRIPTOR* MemMapPtr = MemMap;
|
||||||
|
|
||||||
for (UINTN Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {
|
for (UINTN Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {
|
||||||
Bytes = LShiftU64 (MemMap->NumberOfPages, 12);
|
UINT64 Bytes = LShiftU64 (MemMapPtr->NumberOfPages, 12);
|
||||||
DEBUG ((EFI_D_ERROR, "%lX-%lX %lX %lX %X\n",
|
DEBUG ((EFI_D_ERROR, "%llX-%llX %llX %llX %X\n",
|
||||||
MemMap->PhysicalStart,
|
MemMapPtr->PhysicalStart,
|
||||||
MemMap->PhysicalStart + Bytes - 1,
|
MemMapPtr->PhysicalStart + Bytes - 1,
|
||||||
MemMap->NumberOfPages,
|
MemMapPtr->NumberOfPages,
|
||||||
MemMap->Attribute,
|
MemMapPtr->Attribute,
|
||||||
(UINTN)MemMap->Type));
|
MemMapPtr->Type));
|
||||||
MemMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMap + DescriptorSize);
|
MemMapPtr = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMapPtr + DescriptorSize);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
gBS->FreePool(MemMapPtr);
|
OcPrintMemoryMap(MemMapSize, MemMap, DescriptorSize);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AllocSmallBlocks(UINTN NumberOfPagesMax)
|
void AllocSmallBlocks(UINTN NumberOfPagesMax)
|
||||||
{
|
{
|
||||||
EFI_MEMORY_DESCRIPTOR *MemMap;
|
EFI_MEMORY_DESCRIPTOR *MemMap;
|
||||||
@ -256,32 +228,32 @@ void AllocSmallBlocks(UINTN NumberOfPagesMax)
|
|||||||
FreePool(MemMap);
|
FreePool(MemMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void AllocSmallBlocks()
|
void AllocSmallBlocks()
|
||||||
//{
|
{
|
||||||
// CONST EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
|
CONST EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
|
||||||
//
|
|
||||||
////PrintMemoryMap();
|
//PrintMemoryMap();
|
||||||
//
|
|
||||||
// UINTN size = 64;
|
UINTN size = 64;
|
||||||
// UINTN nb = 0;
|
UINTN nb = 0;
|
||||||
//
|
|
||||||
// AllocSmallBlocks(size); // 252KB
|
AllocSmallBlocks(size); // 252KB
|
||||||
//
|
|
||||||
// MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
||||||
// nb = MemoryAttributesTable->NumberOfEntries;
|
nb = MemoryAttributesTable->NumberOfEntries;
|
||||||
//
|
|
||||||
////PrintMemoryMap();
|
//PrintMemoryMap();
|
||||||
// while ( size <= 2048 && nb > 100 ) { // XNU seems to handle max 128 entries. So let's shrink a little bit under 128
|
while ( size <= 2048 && nb > 100 ) { // XNU seems to handle max 128 entries. So let's shrink a little bit under 128
|
||||||
// size *= 2;
|
size *= 2;
|
||||||
// AllocSmallBlocks(size);
|
AllocSmallBlocks(size);
|
||||||
// MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
MemoryAttributesTable = OcGetMemoryAttributes (NULL);
|
||||||
// nb = MemoryAttributesTable->NumberOfEntries;
|
nb = MemoryAttributesTable->NumberOfEntries;
|
||||||
////PrintMemoryMap();
|
//PrintMemoryMap();
|
||||||
// }
|
}
|
||||||
// if ( size > 2048 ) {
|
if ( size > 2048 ) {
|
||||||
// DBG("Cannot shrink memory map enough. Nb entries = %lld\n", nb);
|
DBG("Cannot shrink memory map enough. Nb entries = %lld\n", nb);
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
|
static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
|
||||||
@ -1782,9 +1754,9 @@ void LOADER_ENTRY::StartLoader()
|
|||||||
}
|
}
|
||||||
gBS->FreePages (ExtraSpace, 90000);
|
gBS->FreePages (ExtraSpace, 90000);
|
||||||
|
|
||||||
|
AllocSmallBlocks(); // shrink memory map;
|
||||||
|
|
||||||
#ifdef JIEF_DEBUG
|
#ifdef JIEF_DEBUG
|
||||||
AllocSmallBlocks(); // shrink memory map;
|
|
||||||
PrintMemoryMap();
|
PrintMemoryMap();
|
||||||
displayFreeMemory("Just before launching image"_XS8);
|
displayFreeMemory("Just before launching image"_XS8);
|
||||||
#endif
|
#endif
|
||||||
@ -3286,9 +3258,9 @@ DBG("strlen '<' =%ld or %lld\n", L_STR_LEN("<"), AsciiStrLen("<"));
|
|||||||
gSettings.Boot.FastBoot = false; //Hmm... will never be here
|
gSettings.Boot.FastBoot = false; //Hmm... will never be here
|
||||||
}
|
}
|
||||||
#ifdef JIEF_DEBUG
|
#ifdef JIEF_DEBUG
|
||||||
MainMenu.TimeoutSeconds=1;
|
//MainMenu.TimeoutSeconds=1;
|
||||||
DefaultEntry = NULL;
|
//DefaultEntry = NULL;
|
||||||
DefaultIndex = MainMenu.Entries.length()-1; // this should be "Exit Clover"
|
//DefaultIndex = MainMenu.Entries.length()-1; // this should be "Exit Clover"
|
||||||
#endif
|
#endif
|
||||||
AfterTool = false;
|
AfterTool = false;
|
||||||
gEvent = 0; //clear to cancel loop
|
gEvent = 0; //clear to cancel loop
|
||||||
|
Loading…
Reference in New Issue
Block a user