]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg/Csm: Set CSM memory executable
authorRuiyu Ni <ruiyu.ni@intel.com>
Mon, 6 Aug 2018 09:56:37 +0000 (17:56 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 16 Aug 2018 03:38:29 +0000 (11:38 +0800)
Commit b22a62be5cdc8fd19d87ec1ecfa5b28fb9be50ad
* IntelFrameworkModule/LegacyBios:Use reserved memory for legacy data
allocates reserved memory for holding legacy code/data.

But with PcdDxeNxMemoryProtectionPolicy set to certain value to
forbid execution when code is in certain type of memory, it's
possible that a platform forbids execution when code is in reserved
memory. The patch calls GCD service to allow such case otherwise
CPU exception may occur.

Code execution in BSCode area should be enabled by platform by
default.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jian Wang <jian.j.wang@intel.com>
IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c

index 8f14687b28335988844407e9e5fb3dd10afa80d0..de859555f18a17ae81d6eac0b07ae09932298039 100644 (file)
@@ -43,7 +43,7 @@ UINTN                 mStructureTablePages     = 0;
 BOOLEAN               mEndOfDxe                = FALSE;\r
 \r
 /**\r
-  Allocate memory for legacy usage.\r
+  Allocate memory for legacy usage. The memory is executable.\r
 \r
   @param  AllocateType               The type of allocation to perform.\r
   @param  MemoryType                 The type of memory to allocate.\r
@@ -51,8 +51,8 @@ BOOLEAN               mEndOfDxe                = FALSE;
   @param  Pages                      Number of pages to allocate\r
   @param  Result                     Result of allocation\r
 \r
-  @retval EFI_SUCCESS                Legacy16 code loaded\r
-  @retval Other                      No protocol installed, unload driver.\r
+  @retval EFI_SUCCESS                Legacy memory is allocated successfully.\r
+  @retval Other                      Legacy memory is not allocated.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -64,8 +64,9 @@ AllocateLegacyMemory (
   OUT EFI_PHYSICAL_ADDRESS      *Result\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  MemPage;\r
+  EFI_STATUS                      Status;\r
+  EFI_PHYSICAL_ADDRESS            MemPage;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;\r
 \r
   //\r
   // Allocate Pages of memory less <= StartPageAddress\r
@@ -81,12 +82,29 @@ AllocateLegacyMemory (
   // Do not ASSERT on Status error but let caller decide since some cases\r
   // memory is already taken but that is ok.\r
   //\r
+  if (!EFI_ERROR (Status)) {\r
+    if (MemoryType != EfiBootServicesCode) {\r
+      //\r
+      // Make sure that the buffer can be used to store code.\r
+      //\r
+      Status = gDS->GetMemorySpaceDescriptor (MemPage, &MemDesc);\r
+      if (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) != 0) {\r
+        Status = gDS->SetMemorySpaceAttributes (\r
+                        MemPage,\r
+                        EFI_PAGES_TO_SIZE (Pages),\r
+                        MemDesc.Attributes & (~EFI_MEMORY_XP)\r
+                        );\r
+      }\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->FreePages (MemPage, Pages);\r
+      }\r
+    }\r
+  }\r
+\r
   if (!EFI_ERROR (Status)) {\r
     *Result = (EFI_PHYSICAL_ADDRESS) (UINTN) MemPage;\r
   }\r
-  //\r
-  // If reach here the status = EFI_SUCCESS\r
-  //\r
+\r
   return Status;\r
 }\r
 \r