|
From: | Andrei E. Warkentin |
Subject: | Re: grub EFI "too little memory" |
Date: | Tue, 17 Jun 2008 14:09:28 -0500 |
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.
|
[Prev in Thread] | Current Thread | [Next in Thread] |