]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
ShellPkg/[hex]edit: Fix mouse freeze issue
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / HeapGuard.c
index 92753c7269acc0315277436912e65b95db748801..19245049c28b847c66665c5ea08a4a967632dd0b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI Heap Guard functions.\r
 \r
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017-2018, 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
@@ -728,6 +728,20 @@ IsPageTypeToGuard (
   return IsMemoryTypeToGuard (MemoryType, AllocateType, GUARD_HEAP_TYPE_PAGE);\r
 }\r
 \r
+/**\r
+  Check to see if the heap guard is enabled for page and/or pool allocation.\r
+\r
+  @return TRUE/FALSE.\r
+**/\r
+BOOLEAN\r
+IsHeapGuardEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages,\r
+                              GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_PAGE);\r
+}\r
+\r
 /**\r
   Set head Guard and tail Guard for the given memory range.\r
 \r
@@ -891,13 +905,6 @@ AdjustMemoryS (
 \r
   Target = Start + Size - SizeRequested;\r
 \r
-  //\r
-  // At least one more page needed for Guard page.\r
-  //\r
-  if (Size < (SizeRequested + EFI_PAGES_TO_SIZE (1))) {\r
-    return 0;\r
-  }\r
-\r
   if (!IsGuardPage (Start + Size)) {\r
     // No Guard at tail to share. One more page is needed.\r
     Target -= EFI_PAGES_TO_SIZE (1);\r
@@ -1135,10 +1142,6 @@ CoreConvertPagesWithGuard (
     OldPages = NumberOfPages;\r
 \r
     AdjustMemoryF (&Start, &NumberOfPages);\r
-    if (NumberOfPages == 0) {\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
     //\r
     // It's safe to unset Guard page inside memory lock because there should\r
     // be no memory allocation occurred in updating memory page attribute at\r
@@ -1147,6 +1150,9 @@ CoreConvertPagesWithGuard (
     // marking it usable (from non-present to present).\r
     //\r
     UnsetGuardForMemory (OldStart, OldPages);\r
+    if (NumberOfPages == 0) {\r
+      return EFI_SUCCESS;\r
+    }\r
   } else {\r
     AdjustMemoryA (&Start, &NumberOfPages);\r
   }\r