Fix a bug that Pages*EFI_PAGES_SIZE might be a negative number.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7854 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2009-03-10 14:34:42 +00:00
parent ff565d71e1
commit 6203199177
1 changed files with 5 additions and 5 deletions

View File

@ -128,6 +128,7 @@ PeiAllocatePages (
EFI_PEI_HOB_POINTERS Hob; EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS *FreeMemoryTop; EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;
UINTN RemainingPages;
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
Hob.Raw = PrivateData->HobList.Raw; Hob.Raw = PrivateData->HobList.Raw;
@ -159,11 +160,10 @@ PeiAllocatePages (
// //
// Verify that there is sufficient memory to satisfy the allocation // Verify that there is sufficient memory to satisfy the allocation
// //
if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));
*(FreeMemoryBottom)) { if ((INTN) (RemainingPages - EFI_SIZE_TO_PAGES (sizeof (EFI_HOB_MEMORY_ALLOCATION))) < Pages) {
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", 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%x pages memory resource to be allocated.\n", \ DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));
EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom)))));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} else { } else {
// //