From 64ca68027bf23acc61f31e520b38b5c63ec36c45 Mon Sep 17 00:00:00 2001 From: xli24 Date: Fri, 26 Feb 2010 09:26:52 +0000 Subject: [PATCH] Add parameter checking for PEI service AllocatePages(), according to PI1.2 errata A. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10112 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index 7e1bb55242..b0dba662f4 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -110,20 +110,20 @@ PeiInstallPeiMemory ( } /** + The purpose of the service is to publish an interface that allows + PEIMs to allocate memory ranges that are managed by the PEI Foundation. - Memory allocation service on permanent memory, - not usable prior to the memory installation. + @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. + @param MemoryType The type of memory to allocate. + @param Pages The number of contiguous 4 KB pages to allocate. + @param Memory Pointer to a physical address. On output, the address is set to the base + of the page range that was allocated. - - @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation. - @param MemoryType Type of memory to allocate. - @param Pages Number of pages to allocate. - @param Memory Pointer of memory allocated. - - @retval EFI_SUCCESS The allocation was successful - @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available - @retval EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement - to allocate the number of pages. + @retval EFI_SUCCESS The memory range was successfully allocated. + @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. **/ EFI_STATUS @@ -141,6 +141,17 @@ PeiAllocatePages ( EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; UINTN RemainingPages; + if ((MemoryType != EfiLoaderCode) && + (MemoryType != EfiLoaderData) && + (MemoryType != EfiRuntimeServicesCode) && + (MemoryType != EfiRuntimeServicesData) && + (MemoryType != EfiBootServicesCode) && + (MemoryType != EfiBootServicesData) && + (MemoryType != EfiACPIReclaimMemory) && + (MemoryType != EfiACPIMemoryNVS)) { + return EFI_INVALID_PARAMETER; + } + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Hob.Raw = PrivateData->HobList.Raw; -- 2.39.2