X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPei%2FMemory%2FMemoryServices.c;h=36bdc73ebdc59153a2b911c67e3940ca196df634;hb=48b77f5ea9091d78098ba0d6168d4b638914f280;hp=c7a06a3c5275322cbf6a8cd74079495f547af3f8;hpb=e94728b359f4e20da7fdef88a1d5123327557655;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index c7a06a3c52..36bdc73ebd 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -1,7 +1,7 @@ /** @file EFI PEI Core memory services -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -123,7 +123,7 @@ PeiInstallPeiMemory ( @retval EFI_OUT_OF_RESOURCES The pages could not be allocated. @retval EFI_INVALID_PARAMETER Type is not equal to EfiLoaderCode, EfiLoaderData, EfiRuntimeServicesCode, EfiRuntimeServicesData, EfiBootServicesCode, EfiBootServicesData, - EfiACPIReclaimMemory, or EfiACPIMemoryNVS. + EfiACPIReclaimMemory, EfiReservedMemoryType, or EfiACPIMemoryNVS. **/ EFI_STATUS @@ -148,6 +148,7 @@ PeiAllocatePages ( (MemoryType != EfiBootServicesCode) && (MemoryType != EfiBootServicesData) && (MemoryType != EfiACPIReclaimMemory) && + (MemoryType != EfiReservedMemoryType) && (MemoryType != EfiACPIMemoryNVS)) { return EFI_INVALID_PARAMETER; } @@ -178,16 +179,20 @@ PeiAllocatePages ( // Check to see if on 4k boundary, If not aligned, make the allocation aligned. // *(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF; - + // - // Verify that there is sufficient memory to satisfy the allocation + // Verify that there is sufficient memory to satisfy the allocation. + // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs to be considered. // - RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom)); + if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < (UINTN) ALIGN_VALUE (sizeof (EFI_HOB_MEMORY_ALLOCATION), 8)) { + DEBUG ((EFI_D_ERROR, "AllocatePages failed: No space to build memory allocation hob.\n")); + return EFI_OUT_OF_RESOURCES; + } + RemainingPages = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom - ALIGN_VALUE (sizeof (EFI_HOB_MEMORY_ALLOCATION), 8)) >> EFI_PAGE_SHIFT; // - // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page. - // So the number of remaining pages needs to be greater than that of the request pages. + // The number of remaining pages needs to be greater than or equal to that of the request pages. // - if (RemainingPages <= Pages) { + if (RemainingPages < Pages) { DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages)); DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages)); return EFI_OUT_OF_RESOURCES;