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.
http://www.uefi.org/specs/
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
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel