X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMem%2FPage.c;h=6d5a259eb669dc7a462e0c217ecd28ba6325d07e;hb=fdc4b0b147b386e966e99893526181dfae9eaeef;hp=5c82d3178a9209cda18a87da22ef2e21011e0cd0;hpb=d613c2a88b3db6b7b451d0b90b08343666792d04;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index 5c82d3178a..6d5a259eb6 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1,7 +1,7 @@ /** @file UEFI Memory page management functions. -Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2012, 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 @@ -557,7 +557,7 @@ CoreAddMemoryDescriptor ( // Make sure the memory type in the gMemoryTypeInformation[] array is valid // Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type); - if (Type < 0 || Type > EfiMaxMemoryType) { + if ((UINT32)Type > EfiMaxMemoryType) { continue; } if (gMemoryTypeInformation[Index].NumberOfPages != 0) { @@ -581,7 +581,7 @@ CoreAddMemoryDescriptor ( // Make sure the memory type in the gMemoryTypeInformation[] array is valid // Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[FreeIndex].Type); - if (Type < 0 || Type > EfiMaxMemoryType) { + if ((UINT32)Type > EfiMaxMemoryType) { continue; } @@ -624,7 +624,7 @@ CoreAddMemoryDescriptor ( // Make sure the memory type in the gMemoryTypeInformation[] array is valid // Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type); - if (Type < 0 || Type > EfiMaxMemoryType) { + if ((UINT32)Type > EfiMaxMemoryType) { continue; } if (gMemoryTypeInformation[Index].NumberOfPages != 0) { @@ -747,7 +747,7 @@ CoreConvertPages ( // // Update counters for the number of pages allocated to each memory type // - if (Entry->Type >= 0 && Entry->Type < EfiMaxMemoryType) { + if ((UINT32)Entry->Type < EfiMaxMemoryType) { if ((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress && Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress) || (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) { if (NumberOfPages > mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages) { @@ -758,7 +758,7 @@ CoreConvertPages ( } } - if (NewType >= 0 && NewType < EfiMaxMemoryType) { + if ((UINT32)NewType < EfiMaxMemoryType) { if ((Start >= mMemoryTypeStatistics[NewType].BaseAddress && Start <= mMemoryTypeStatistics[NewType].MaximumAddress) || (Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) { mMemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages; @@ -1011,7 +1011,7 @@ FindFreePages ( // // Attempt to find free pages in the preferred bin based on the requested memory type // - if (NewType >= 0 && NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) { + if ((UINT32)NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) { Start = CoreFindFreePagesI ( mMemoryTypeStatistics[NewType].MaximumAddress, mMemoryTypeStatistics[NewType].BaseAddress, @@ -1094,7 +1094,7 @@ CoreAllocatePages ( UINT64 MaxAddress; UINTN Alignment; - if (Type < AllocateAnyPages || Type >= (UINTN) MaxAllocateType) { + if ((UINT32)Type >= MaxAllocateType) { return EFI_INVALID_PARAMETER; } @@ -1103,6 +1103,10 @@ CoreAllocatePages ( return EFI_INVALID_PARAMETER; } + if (Memory == NULL) { + return EFI_INVALID_PARAMETER; + } + Alignment = EFI_DEFAULT_PAGE_ALLOCATION_ALIGNMENT; if (MemoryType == EfiACPIReclaimMemory || @@ -1464,8 +1468,10 @@ CoreGetMemoryMap ( } } MemoryMap->Attribute = Entry->Attribute; - if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) { - MemoryMap->Attribute |= EFI_MEMORY_RUNTIME; + if (MemoryMap->Type < EfiMaxMemoryType) { + if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) { + MemoryMap->Attribute |= EFI_MEMORY_RUNTIME; + } } // @@ -1516,11 +1522,6 @@ CoreGetMemoryMap ( Status = EFI_SUCCESS; Done: - - CoreReleaseMemoryLock (); - - CoreReleaseGcdMemoryLock (); - // // Update the map key finally // @@ -1528,6 +1529,10 @@ Done: *MapKey = mMemoryMapKey; } + CoreReleaseMemoryLock (); + + CoreReleaseGcdMemoryLock (); + *MemoryMapSize = BufferSize; return Status;