/** @file\r
UEFI Memory page management functions.\r
\r
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
UINTN InformationIndex;\r
BOOLEAN Special;\r
BOOLEAN Runtime;\r
-} EFI_MEMORY_TYPE_STAISTICS;\r
+} EFI_MEMORY_TYPE_STATISTICS;\r
\r
//\r
// MemoryMap - The current memory map\r
LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);\r
BOOLEAN mMemoryTypeInformationInitialized = FALSE;\r
\r
-EFI_MEMORY_TYPE_STAISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {\r
+EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {\r
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiReservedMemoryType\r
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderCode\r
{ 0, MAX_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiLoaderData\r
// Make sure the memory type in the gMemoryTypeInformation[] array is valid\r
//\r
Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);\r
- if (Type < 0 || Type > EfiMaxMemoryType) {\r
+ if ((UINT32)Type > EfiMaxMemoryType) {\r
continue;\r
}\r
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {\r
// Make sure the memory type in the gMemoryTypeInformation[] array is valid\r
//\r
Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[FreeIndex].Type);\r
- if (Type < 0 || Type > EfiMaxMemoryType) {\r
+ if ((UINT32)Type > EfiMaxMemoryType) {\r
continue;\r
}\r
\r
// Make sure the memory type in the gMemoryTypeInformation[] array is valid\r
//\r
Type = (EFI_MEMORY_TYPE) (gMemoryTypeInformation[Index].Type);\r
- if (Type < 0 || Type > EfiMaxMemoryType) {\r
+ if ((UINT32)Type > EfiMaxMemoryType) {\r
continue;\r
}\r
if (gMemoryTypeInformation[Index].NumberOfPages != 0) {\r
//\r
// Update counters for the number of pages allocated to each memory type\r
//\r
- if (Entry->Type >= 0 && Entry->Type < EfiMaxMemoryType) {\r
+ if ((UINT32)Entry->Type < EfiMaxMemoryType) {\r
if ((Start >= mMemoryTypeStatistics[Entry->Type].BaseAddress && Start <= mMemoryTypeStatistics[Entry->Type].MaximumAddress) ||\r
(Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {\r
if (NumberOfPages > mMemoryTypeStatistics[Entry->Type].CurrentNumberOfPages) {\r
}\r
}\r
\r
- if (NewType >= 0 && NewType < EfiMaxMemoryType) {\r
+ if ((UINT32)NewType < EfiMaxMemoryType) {\r
if ((Start >= mMemoryTypeStatistics[NewType].BaseAddress && Start <= mMemoryTypeStatistics[NewType].MaximumAddress) ||\r
(Start >= mDefaultBaseAddress && Start <= mDefaultMaximumAddress) ) {\r
mMemoryTypeStatistics[NewType].CurrentNumberOfPages += NumberOfPages;\r
//\r
// Attempt to find free pages in the preferred bin based on the requested memory type\r
//\r
- if (NewType >= 0 && NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) {\r
+ if ((UINT32)NewType < EfiMaxMemoryType && MaxAddress >= mMemoryTypeStatistics[NewType].MaximumAddress) {\r
Start = CoreFindFreePagesI (\r
mMemoryTypeStatistics[NewType].MaximumAddress, \r
mMemoryTypeStatistics[NewType].BaseAddress, \r
UINT64 MaxAddress;\r
UINTN Alignment;\r
\r
- if (Type < AllocateAnyPages || Type >= (UINTN) MaxAllocateType) {\r
+ if ((UINT32)Type >= MaxAllocateType) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ if (Memory == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
Alignment = EFI_DEFAULT_PAGE_ALLOCATION_ALIGNMENT;\r
\r
if (MemoryType == EfiACPIReclaimMemory ||\r
}\r
}\r
MemoryMap->Attribute = Entry->Attribute;\r
- if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) {\r
- MemoryMap->Attribute |= EFI_MEMORY_RUNTIME;\r
+ if (MemoryMap->Type < EfiMaxMemoryType) {\r
+ if (mMemoryTypeStatistics[MemoryMap->Type].Runtime) {\r
+ MemoryMap->Attribute |= EFI_MEMORY_RUNTIME;\r
+ }\r
}\r
\r
//\r
Status = EFI_SUCCESS;\r
\r
Done:\r
-\r
- CoreReleaseMemoryLock ();\r
-\r
- CoreReleaseGcdMemoryLock ();\r
-\r
//\r
// Update the map key finally\r
//\r
*MapKey = mMemoryMapKey;\r
}\r
\r
+ CoreReleaseMemoryLock ();\r
+\r
+ CoreReleaseGcdMemoryLock ();\r
+\r
*MemoryMapSize = BufferSize;\r
\r
return Status;\r