grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grub EFI "too little memory"


From: Andrei E. Warkentin
Subject: Re: grub EFI "too little memory"
Date: Tue, 17 Jun 2008 14:09:28 -0500


Exactly on target.  Then we need a more robust and permanent solution I think right?

How about asking with 0 sized buffer first knowing it will fail then asking with a rounded-up buffer the 2nd time.
I can coded it, but I can't check it in of course.




You shouldn't assume memory map size (in fact, it can change during the runtime if you use AllocatePool/FreePool/AllocatePages/FreePages), and should be something like...

UINTN currentMemoryMapSize = 0;
UINTN expectedMemoryMapSize = 0;
EFI_MEMORY_DESCRIPTOR *memoryMap = NULL;
UINTN mapKey;
UINTN descriptorSize;
UINT32 descriptorVersion;
EFI_STATUS status = EFI_BUFFER_TOO_SMALL;
while(status == EFI_BUFFER_TOO_SMALL)
{
 status = gBS->GetMemoryMap(&expectedMemoryMapSize, &memoryMap, &mapKey, &descriptorSize, &descriptorVersion);
if(status !=  EFI_BUFFER_TOO_SMALL)
{
break;
}

// May have allocated already...
if(currentMemorySize)
{
status = gBS->FreePool(memoryMap);
if(EFI_ERROR(status))
{
break;
}
}

// As per spec, allocate more than requested to handle growth of memory map due to allocation).
expectedMemorySize = expectedMemorySize * 2;
status = gBS->AllocatePool(EfiLoaderData, expectedMemoryMapSize, (VOID**) &memoryMap);
currentMemoryMapSize = expectedMemoryMapSize;
if(EFI_ERROR(status))
{
break;
}

// Make sure we retry to get the memory map.
status = EFI_BUFFER_TOO_SMALL;
}
if(EFI_ERROR(status) || currentMemoryMapSize == 0)
{

// No memory map, assorted errors....
}

// Loop over the memoryMapSize array using descriptorSize (_NOT_ sizeof(EFI_MEMORY_DESCRIPTOR)), as that could break for future EFI versions where the descriptor size might increase with expansion).

// Free pool. 






_______________________________________________
Grub-devel mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/grub-devel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]