]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
MdeModulePkg/Core: Refine handling NULL detection in NX setting
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / MemoryProtection.c
index 455ed35f9a36541272ea21effd7d13f23f5caf84..a2ea445eefa6046084d1f1bbed2a9ee757c9f8ac 100644 (file)
@@ -19,7 +19,7 @@
 \r
   Once the image is unloaded, the protection is removed automatically.\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
@@ -846,23 +846,23 @@ InitializeDxeNxMemoryProtectionPolicy (
 \r
     Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);\r
     if (Attributes != 0) {\r
+      SetUefiImageMemoryAttributes (\r
+        MemoryMapEntry->PhysicalStart,\r
+        LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),\r
+        Attributes);\r
+\r
       if (MemoryMapEntry->PhysicalStart == 0 &&\r
           PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0) {\r
 \r
         ASSERT (MemoryMapEntry->NumberOfPages > 0);\r
         //\r
-        // Skip page 0 if NULL pointer detection is enabled to avoid attributes\r
-        // overwritten.\r
+        // Add EFI_MEMORY_RP attribute for page 0 if NULL pointer detection is\r
+        // enabled.\r
         //\r
         SetUefiImageMemoryAttributes (\r
-          MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE,\r
-          LShiftU64 (MemoryMapEntry->NumberOfPages - 1, EFI_PAGE_SHIFT),\r
-          Attributes);\r
-      } else {\r
-        SetUefiImageMemoryAttributes (\r
-          MemoryMapEntry->PhysicalStart,\r
-          LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),\r
-          Attributes);\r
+          0,\r
+          EFI_PAGES_TO_SIZE (1),\r
+          EFI_MEMORY_RP | Attributes);\r
       }\r
     }\r
     MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);\r