@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
+ or not
\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,
+ IN BOOLEAN NeedGuard
);\r
\r
/**\r
EfiRuntimeServicesData,\r
EFI_SIZE_TO_PAGES (RUNTIME_PAGE_ALLOCATION_GRANULARITY),\r
&Mem,\r
- TRUE\r
+ TRUE,
+ FALSE
);\r
ASSERT_EFI_ERROR (Status);\r
if(!EFI_ERROR (Status)) {\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
+ or not
\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,
+ IN BOOLEAN NeedGuard
)\r
{\r
UINTN RequestedAddress;\r
case AllocateAnyPages:\r
RequestedAddress = (UINTN)(-1);\r
case AllocateMaxAddress:\r
+ if (NeedGuard) {
+ *Memory = InternalAllocMaxAddressWithGuard (
+ &mSmmMemoryMap,
+ NumberOfPages,
+ RequestedAddress,
+ MemoryType
+ );
+ if (*Memory == (UINTN)-1) {
+ return EFI_OUT_OF_RESOURCES;
+ } else {
+ ASSERT (VerifyMemoryGuard (*Memory, NumberOfPages) == TRUE);
+ return EFI_SUCCESS;
+ }
+ }
+
*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
+ or not
\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,
+ IN BOOLEAN NeedGuard
)\r
{\r
- return SmmInternalAllocatePagesEx (Type, MemoryType, NumberOfPages, Memory, FALSE);\r
+ return SmmInternalAllocatePagesEx (Type, MemoryType, NumberOfPages, Memory,
+ FALSE, NeedGuard);
}\r
\r
/**\r
)\r
{\r
EFI_STATUS Status;\r
+ BOOLEAN NeedGuard;
\r
- Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory);\r
+ NeedGuard = IsPageTypeToGuard (MemoryType, Type);
+ Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,
+ NeedGuard);
if (!EFI_ERROR (Status)) {\r
SmmCoreUpdateProfile (\r
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),\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
@retval EFI_NOT_FOUND Could not find the entry that covers the range.\r
@retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r
EFIAPI\r
SmmInternalFreePages (\r
IN EFI_PHYSICAL_ADDRESS Memory,\r
- IN UINTN NumberOfPages\r
+ IN UINTN NumberOfPages,
+ IN BOOLEAN IsGuarded
)\r
{\r
+ if (IsGuarded) {
+ return SmmInternalFreePagesExWithGuard (Memory, NumberOfPages, FALSE);
+ }
return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE);\r
}\r
\r
)\r
{\r
EFI_STATUS Status;\r
+ BOOLEAN IsGuarded;
\r
- Status = SmmInternalFreePages (Memory, NumberOfPages);\r
+ IsGuarded = IsHeapGuardEnabled () && IsMemoryGuarded (Memory);
+ Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
if (!EFI_ERROR (Status)) {\r
SmmCoreUpdateProfile (\r
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),\r