@param[out] Memory A pointer to receive the base allocated memory\r
address.\r
@param[in] AddRegion If this memory is new added region.\r
+ @param[in] NeedGuard Flag to indicate Guard page is needed\r
+ or not\r
\r
@retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
@retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
IN EFI_MEMORY_TYPE MemoryType,\r
IN UINTN NumberOfPages,\r
OUT EFI_PHYSICAL_ADDRESS *Memory,\r
- IN BOOLEAN AddRegion\r
+ IN BOOLEAN AddRegion,\r
+ IN BOOLEAN NeedGuard\r
);\r
\r
/**\r
Status = SmmInternalAllocatePagesEx (\r
AllocateAnyPages,\r
EfiRuntimeServicesData,\r
- EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION),\r
+ EFI_SIZE_TO_PAGES (RUNTIME_PAGE_ALLOCATION_GRANULARITY),\r
&Mem,\r
- TRUE\r
+ TRUE,\r
+ FALSE\r
);\r
ASSERT_EFI_ERROR (Status);\r
if(!EFI_ERROR (Status)) {\r
//\r
// Enque the free memmory map entries into the list\r
//\r
- for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) {\r
+ for (Index = 0; Index< RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {\r
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;\r
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);\r
}\r
@param[out] Memory A pointer to receive the base allocated memory\r
address.\r
@param[in] AddRegion If this memory is new added region.\r
+ @param[in] NeedGuard Flag to indicate Guard page is needed\r
+ or not\r
\r
@retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
@retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
IN EFI_MEMORY_TYPE MemoryType,\r
IN UINTN NumberOfPages,\r
OUT EFI_PHYSICAL_ADDRESS *Memory,\r
- IN BOOLEAN AddRegion\r
+ IN BOOLEAN AddRegion,\r
+ IN BOOLEAN NeedGuard\r
)\r
{\r
UINTN RequestedAddress;\r
case AllocateAnyPages:\r
RequestedAddress = (UINTN)(-1);\r
case AllocateMaxAddress:\r
+ if (NeedGuard) {\r
+ *Memory = InternalAllocMaxAddressWithGuard (\r
+ &mSmmMemoryMap,\r
+ NumberOfPages,\r
+ RequestedAddress,\r
+ MemoryType\r
+ );\r
+ if (*Memory == (UINTN)-1) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ } else {\r
+ ASSERT (VerifyMemoryGuard (*Memory, NumberOfPages) == TRUE);\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+\r
*Memory = InternalAllocMaxAddress (\r
&mSmmMemoryMap,\r
NumberOfPages,\r
@param[in] NumberOfPages The number of pages to allocate.\r
@param[out] Memory A pointer to receive the base allocated memory\r
address.\r
+ @param[in] NeedGuard Flag to indicate Guard page is needed\r
+ or not\r
\r
@retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
@retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
IN EFI_ALLOCATE_TYPE Type,\r
IN EFI_MEMORY_TYPE MemoryType,\r
IN UINTN NumberOfPages,\r
- OUT EFI_PHYSICAL_ADDRESS *Memory\r
+ OUT EFI_PHYSICAL_ADDRESS *Memory,\r
+ IN BOOLEAN NeedGuard\r
)\r
{\r
- return SmmInternalAllocatePagesEx (Type, MemoryType, NumberOfPages, Memory, FALSE);\r
+ return SmmInternalAllocatePagesEx (Type, MemoryType, NumberOfPages, Memory,\r
+ FALSE, NeedGuard);\r
}\r
\r
/**\r
)\r
{\r
EFI_STATUS Status;\r
+ BOOLEAN NeedGuard;\r
\r
- Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory);\r
+ NeedGuard = IsPageTypeToGuard (MemoryType, Type);\r
+ Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,\r
+ NeedGuard);\r
if (!EFI_ERROR (Status)) {\r
SmmCoreUpdateProfile (\r
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),\r
@param[in] AddRegion If this memory is new added region.\r
\r
@retval EFI_NOT_FOUND Could not find the entry that covers the range.\r
- @retval EFI_INVALID_PARAMETER Address not aligned.\r
+ @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r
@return EFI_SUCCESS Pages successfully freed.\r
\r
**/\r
LIST_ENTRY *Node;\r
FREE_PAGE_LIST *Pages;\r
\r
- if ((Memory & EFI_PAGE_MASK) != 0) {\r
+ if (((Memory & EFI_PAGE_MASK) != 0) || (Memory == 0) || (NumberOfPages == 0)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
\r
@param[in] Memory Base address of memory being freed.\r
@param[in] NumberOfPages The number of pages to free.\r
+ @param[in] IsGuarded Is the memory to free guarded or not.\r
\r
@retval EFI_NOT_FOUND Could not find the entry that covers the range.\r
- @retval EFI_INVALID_PARAMETER Address not aligned.\r
+ @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r
@return EFI_SUCCESS Pages successfully freed.\r
\r
**/\r
EFIAPI\r
SmmInternalFreePages (\r
IN EFI_PHYSICAL_ADDRESS Memory,\r
- IN UINTN NumberOfPages\r
+ IN UINTN NumberOfPages,\r
+ IN BOOLEAN IsGuarded\r
)\r
{\r
+ if (IsGuarded) {\r
+ return SmmInternalFreePagesExWithGuard (Memory, NumberOfPages, FALSE);\r
+ }\r
return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE);\r
}\r
\r
@param NumberOfPages The number of pages to free.\r
\r
@retval EFI_NOT_FOUND Could not find the entry that covers the range.\r
- @retval EFI_INVALID_PARAMETER Address not aligned.\r
+ @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r
@return EFI_SUCCESS Pages successfully freed.\r
\r
**/\r
)\r
{\r
EFI_STATUS Status;\r
+ BOOLEAN IsGuarded;\r
\r
- Status = SmmInternalFreePages (Memory, NumberOfPages);\r
+ IsGuarded = IsHeapGuardEnabled () && IsMemoryGuarded (Memory);\r
+ Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);\r
if (!EFI_ERROR (Status)) {\r
SmmCoreUpdateProfile (\r
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),\r