]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
MdeModulePkg/PiSmmCore: Implement heap guard feature for SMM mode
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.h
index 6cc824b0475b4aa8d797c75c991b2cc91f8d2055..fbbecfae520f7d5ed59283e5c4defa7b68961446 100644 (file)
@@ -33,6 +33,7 @@
 #include <Protocol/SmmLegacyBoot.h>\r
 #include <Protocol/SmmReadyToBoot.h>\r
 #include <Protocol/SmmEndOfS3Resume.h>\r
+#include <Protocol/SmmMemoryAttribute.h>
 \r
 #include <Guid/Apriori.h>\r
 #include <Guid/EventGroup.h>\r
@@ -60,6 +61,7 @@
 #include <Library/SmmMemLib.h>\r
 \r
 #include "PiSmmCorePrivateData.h"\r
+#include "HeapGuard.h"
 \r
 //\r
 // Used to build a table of SMI Handlers that the SMM Core registers\r
@@ -318,6 +320,7 @@ SmmAllocatePages (
   @param  NumberOfPages          The number of pages to allocate\r
   @param  Memory                 A pointer to receive the base allocated memory\r
                                  address\r
+  @param  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
@@ -331,7 +334,8 @@ SmmInternalAllocatePages (
   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
 /**\r
@@ -357,6 +361,8 @@ SmmFreePages (
 \r
   @param  Memory                 Base address of memory being freed\r
   @param  NumberOfPages          The number of pages to free\r
+  @param  IsGuarded              Flag to indicate if the memory is 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
@@ -367,7 +373,8 @@ EFI_STATUS
 EFIAPI\r
 SmmInternalFreePages (\r
   IN      EFI_PHYSICAL_ADDRESS      Memory,\r
-  IN      UINTN                     NumberOfPages\r
+  IN      UINTN                     NumberOfPages,
+  IN      BOOLEAN                   IsGuarded
   );\r
 \r
 /**\r
@@ -1255,4 +1262,74 @@ typedef enum {
 \r
 extern LIST_ENTRY  mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];\r
 \r
+/**
+  Internal Function. Allocate n pages from given free page node.
+
+  @param  Pages                  The free page node.
+  @param  NumberOfPages          Number of pages to be allocated.
+  @param  MaxAddress             Request to allocate memory below this address.
+
+  @return Memory address of allocated pages.
+
+**/
+UINTN
+InternalAllocPagesOnOneNode (
+  IN OUT FREE_PAGE_LIST   *Pages,
+  IN     UINTN            NumberOfPages,
+  IN     UINTN            MaxAddress
+  );
+
+/**
+  Update SMM memory map entry.
+
+  @param[in]  Type                   The type of allocation to perform.
+  @param[in]  Memory                 The base of memory address.
+  @param[in]  NumberOfPages          The number of pages to allocate.
+  @param[in]  AddRegion              If this memory is new added region.
+**/
+VOID
+ConvertSmmMemoryMapEntry (
+  IN EFI_MEMORY_TYPE       Type,
+  IN EFI_PHYSICAL_ADDRESS  Memory,
+  IN UINTN                 NumberOfPages,
+  IN BOOLEAN               AddRegion
+  );
+
+/**
+  Internal function.  Moves any memory descriptors that are on the
+  temporary descriptor stack to heap.
+
+**/
+VOID
+CoreFreeMemoryMapStack (
+  VOID
+  );
+
+/**
+  Frees previous allocated pages.
+
+  @param[in]  Memory                 Base address of memory being freed.
+  @param[in]  NumberOfPages          The number of pages to free.
+  @param[in]  AddRegion              If this memory is new added region.
+
+  @retval EFI_NOT_FOUND          Could not find the entry that covers the range.
+  @retval EFI_INVALID_PARAMETER  Address not aligned, Address is zero or NumberOfPages is zero.
+  @return EFI_SUCCESS            Pages successfully freed.
+
+**/
+EFI_STATUS
+SmmInternalFreePagesEx (
+  IN EFI_PHYSICAL_ADDRESS  Memory,
+  IN UINTN                 NumberOfPages,
+  IN BOOLEAN               AddRegion
+  );
+
+/**
+  Hook function used to set all Guard pages after entering SMM mode.
+**/
+VOID
+SmmEntryPointMemoryManagementHook (
+  VOID
+  );
+
 #endif\r