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
@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
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
// 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