From 18d3e280624f0748237b82fdf7e10b1e25797a01 Mon Sep 17 00:00:00 2001 From: Liming Gao Date: Thu, 2 Jan 2014 07:16:09 +0000 Subject: Update the heap migration logic to avoid memory overflow. Signed-off-by: Liming Gao Reviewed-by: Star Zeng git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15036 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'MdeModulePkg/Core') diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index b5e2a82455..635c70f753 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -661,6 +661,7 @@ PeiDispatcher ( PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData; EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi; UINT64 NewStackSize; + UINTN HeapTemporaryRamSize; EFI_PHYSICAL_ADDRESS BaseOfNewHeap; EFI_PHYSICAL_ADDRESS TopOfNewStack; EFI_PHYSICAL_ADDRESS TopOfOldStack; @@ -1018,7 +1019,9 @@ PeiDispatcher ( // // Migrate Heap // - CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, PeiTemporaryRamSize); + HeapTemporaryRamSize = (UINTN) (Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - Private->HobList.HandoffInformationTable->EfiMemoryBottom); + ASSERT (BaseOfNewHeap + HeapTemporaryRamSize <= Private->FreePhysicalMemoryTop); + CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, HeapTemporaryRamSize); // // Migrate Stack -- cgit v1.2.3