Revision: 14447
http://sourceforge.net/p/edk2/code/14447
Author: oliviermartin
Date: 2013-06-27 18:18:24 +0000 (Thu, 27 Jun 2013)
Log Message:
-----------
ArmPkg/BdsLib: Fixed manipulation of the Memory Map returned by GetMemoryMap()
The UEFI specification mandates that software uses the DescriptorSize returned
by the GetMemoryMap() function to find the start of each EFI_MEMORY_DESCRIPTOR
in the MemoryMap array. This allows for future expansion of the
EFI_MEMORY_DESCRIPTOR.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <[email protected]>
Modified Paths:
--------------
trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
Modified: trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
===================================================================
--- trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c 2013-06-27 18:17:19 UTC
(rev 14446)
+++ trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c 2013-06-27 18:18:24 UTC
(rev 14447)
@@ -354,6 +354,7 @@
UINT64 CpuReleaseAddr;
UINTN MemoryMapSize;
EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;
UINTN MapKey;
UINTN DescriptorSize;
UINT32 DescriptorVersion;
@@ -483,24 +484,32 @@
MemoryMapSize = 0;
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey,
&DescriptorSize, &DescriptorVersion);
if (Status == EFI_BUFFER_TOO_SMALL) {
+ // The UEFI specification advises to allocate more memory for the
MemoryMap buffer between successive
+ // calls to GetMemoryMap(), since allocation of the new buffer may
potentially increase memory map size.
Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
MemoryMap = AllocatePages (Pages);
+ if (MemoryMap == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto FAIL_COMPLETE_FDT;
+ }
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey,
&DescriptorSize, &DescriptorVersion);
}
// Go through the list and add the reserved region to the Device Tree
if (!EFI_ERROR(Status)) {
- for (Index = 0; Index < (MemoryMapSize / sizeof(EFI_MEMORY_DESCRIPTOR));
Index++) {
- if (IsLinuxReservedRegion ((EFI_MEMORY_TYPE)MemoryMap[Index].Type)) {
+ MemoryMapPtr = MemoryMap;
+ for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
+ if (IsLinuxReservedRegion ((EFI_MEMORY_TYPE)MemoryMapPtr->Type)) {
DEBUG((DEBUG_VERBOSE, "Reserved region of type %d [0x%X, 0x%X]\n",
- MemoryMap[Index].Type,
- (UINTN)MemoryMap[Index].PhysicalStart,
- (UINTN)(MemoryMap[Index].PhysicalStart +
MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE)));
- err = fdt_add_mem_rsv(fdt, MemoryMap[Index].PhysicalStart,
MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE);
+ MemoryMapPtr->Type,
+ (UINTN)MemoryMapPtr->PhysicalStart,
+ (UINTN)(MemoryMapPtr->PhysicalStart + MemoryMapPtr->NumberOfPages
* EFI_PAGE_SIZE)));
+ err = fdt_add_mem_rsv(fdt, MemoryMapPtr->PhysicalStart,
MemoryMapPtr->NumberOfPages * EFI_PAGE_SIZE);
if (err != 0) {
Print(L"Warning: Fail to add 'memreserve' (err:%d)\n", err);
}
}
+ MemoryMapPtr = (EFI_MEMORY_DESCRIPTOR*)((UINTN)MemoryMapPtr +
DescriptorSize);
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits