and make further progress in the boot process.\r
\r
@param ImageContext Pointer to PE/COFF image context\r
+ @param ImageBase Base of image in memory\r
@param SectionHeaderOffset Offset of PE/COFF image section header\r
@param NumberOfSections Number of Sections\r
@param TextUpdater Function to change code permissions\r
EFIAPI\r
UpdateMmFoundationPeCoffPermissions (\r
IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ IN EFI_PHYSICAL_ADDRESS ImageBase,\r
IN UINT32 SectionHeaderOffset,\r
IN CONST UINT16 NumberOfSections,\r
IN REGION_PERMISSION_UPDATE_FUNC TextUpdater,\r
\r
@param TeData Pointer to PE/COFF image data\r
@param ImageContext Pointer to PE/COFF image context\r
+ @param ImageBase Pointer to ImageBase variable\r
@param SectionHeaderOffset Offset of PE/COFF image section header\r
@param NumberOfSections Number of Sections\r
\r
GetStandaloneMmCorePeCoffSections (\r
IN VOID *TeData,\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ OUT EFI_PHYSICAL_ADDRESS *ImageBase,\r
IN OUT UINT32 *SectionHeaderOffset,\r
IN OUT UINT16 *NumberOfSections\r
);\r
EFIAPI\r
UpdateMmFoundationPeCoffPermissions (\r
IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ IN EFI_PHYSICAL_ADDRESS ImageBase,\r
IN UINT32 SectionHeaderOffset,\r
IN CONST UINT16 NumberOfSections,\r
IN REGION_PERMISSION_UPDATE_FUNC TextUpdater,\r
// if it is a writeable section then mark it appropriately as well.\r
//\r
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) == 0) {\r
- Base = ImageContext->ImageAddress + SectionHeader.VirtualAddress;\r
+ Base = ImageBase + SectionHeader.VirtualAddress;\r
\r
TextUpdater (Base, SectionHeader.Misc.VirtualSize);\r
\r
EFI_STATUS\r
GetPeCoffSectionInformation (\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ OUT EFI_PHYSICAL_ADDRESS *ImageBase,\r
OUT UINT32 *SectionHeaderOffset,\r
OUT UINT16 *NumberOfSections\r
)\r
return Status;\r
}\r
\r
+ *ImageBase = ImageContext->ImageAddress;\r
if (!ImageContext->IsTeImage) {\r
ASSERT (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE);\r
\r
} else {\r
*SectionHeaderOffset = (UINTN)(sizeof (EFI_TE_IMAGE_HEADER));\r
*NumberOfSections = Hdr.Te->NumberOfSections;\r
- ImageContext->ImageAddress -= (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);\r
+ *ImageBase -= (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);\r
}\r
return RETURN_SUCCESS;\r
}\r
GetStandaloneMmCorePeCoffSections (\r
IN VOID *TeData,\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
+ OUT EFI_PHYSICAL_ADDRESS *ImageBase,\r
IN OUT UINT32 *SectionHeaderOffset,\r
IN OUT UINT16 *NumberOfSections\r
)\r
\r
DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", TeData));\r
\r
- Status = GetPeCoffSectionInformation (ImageContext, SectionHeaderOffset, NumberOfSections);\r
+ Status = GetPeCoffSectionInformation (ImageContext, ImageBase,\r
+ SectionHeaderOffset, NumberOfSections);\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Section information - %r\n", Status));\r
return Status;\r
VOID *HobStart;\r
VOID *TeData;\r
UINTN TeDataSize;\r
+ EFI_PHYSICAL_ADDRESS ImageBase;\r
\r
// Get Secure Partition Manager Version Information\r
Status = GetSpmVersion ();\r
Status = GetStandaloneMmCorePeCoffSections (\r
TeData,\r
&ImageContext,\r
+ &ImageBase,\r
&SectionHeaderOffset,\r
&NumberOfSections\r
);\r
goto finish;\r
}\r
\r
+ //\r
+ // ImageBase may deviate from ImageContext.ImageAddress if we are dealing\r
+ // with a TE image, in which case the latter points to the actual offset\r
+ // of the image, whereas ImageBase refers to the address where the image\r
+ // would start if the stripped PE headers were still in place. In either\r
+ // case, we need to fix up ImageBase so it refers to the actual current\r
+ // load address.\r
+ //\r
+ ImageBase += (UINTN)TeData - ImageContext.ImageAddress;\r
+\r
// Update the memory access permissions of individual sections in the\r
// Standalone MM core module\r
Status = UpdateMmFoundationPeCoffPermissions (\r
&ImageContext,\r
+ ImageBase,\r
SectionHeaderOffset,\r
NumberOfSections,\r
ArmSetMemoryRegionNoExec,\r
goto finish;\r
}\r
\r
+ if (ImageContext.ImageAddress != (UINTN)TeData) {\r
+ ImageContext.ImageAddress = (UINTN)TeData;\r
+ ArmSetMemoryRegionNoExec (ImageBase, SIZE_4KB);\r
+ ArmClearMemoryRegionReadOnly (ImageBase, SIZE_4KB);\r
+\r
+ Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
//\r
// Create Hoblist based upon boot information passed by privileged software\r
//\r