21typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) (
28UpdatePeCoffPermissions (
30 IN REGION_PERMISSION_UPDATE_FUNC NoExecUpdater,
31 IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater
39 UINT32 SectionHeaderOffset;
40 UINTN NumberOfSections;
50 CopyMem (&TmpContext, ImageContext,
sizeof (TmpContext));
57 "%a: PeCoffLoaderGetImageInfo () failed (Status = %r)\n",
70 "%a: ignoring XIP TE image at 0x%lx\n",
72 ImageContext->ImageAddress
86 "%a: non-TE Image at 0x%lx has SectionAlignment < 4 KB (%lu)\n",
88 ImageContext->ImageAddress,
93 Base = ImageContext->ImageAddress & ~(EFI_PAGE_SIZE - 1);
94 Size = ImageContext->ImageAddress - Base + ImageContext->ImageSize;
95 return NoExecUpdater (Base,
ALIGN_VALUE (Size, EFI_PAGE_SIZE));
104 Hdr.Union = &HdrData;
116 "%a: TmpContext.ImageRead () failed (Status = %r)\n",
123 ASSERT (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE);
127 NumberOfSections = (
UINTN)(Hdr.Pe32->FileHeader.NumberOfSections);
129 switch (Hdr.Pe32->OptionalHeader.
Magic) {
131 SectionHeaderOffset += Hdr.Pe32->FileHeader.SizeOfOptionalHeader;
134 SectionHeaderOffset += Hdr.Pe32Plus->FileHeader.SizeOfOptionalHeader;
143 for (Index = 0; Index < NumberOfSections; Index++) {
158 "%a: TmpContext.ImageRead () failed (Status = %r)\n",
165 Base = TmpContext.
ImageAddress + SectionHeader.VirtualAddress;
171 "%a: Mapping section %d of image at 0x%lx with RO-XN permissions and size 0x%x\n",
175 SectionHeader.Misc.VirtualSize
177 ReadOnlyUpdater (Base, SectionHeader.Misc.VirtualSize);
181 "%a: Mapping section %d of image at 0x%lx with RW-XN permissions and size 0x%x\n",
185 SectionHeader.Misc.VirtualSize
191 "%a: Mapping section %d of image at 0x%lx with RO-X permissions and size 0x%x\n",
195 SectionHeader.Misc.VirtualSize
197 ReadOnlyUpdater (Base, SectionHeader.Misc.VirtualSize);
198 NoExecUpdater (Base, SectionHeader.Misc.VirtualSize);
222 UpdatePeCoffPermissions (
224 ArmClearMemoryRegionNoExec,
225 ArmSetMemoryRegionReadOnly
245 UpdatePeCoffPermissions (
247 ArmSetMemoryRegionNoExec,
248 ArmClearMemoryRegionReadOnly
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define RETURN_ERROR(StatusCode)
#define ALIGN_VALUE(Value, Alignment)
#define DEBUG(Expression)
RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
#define EFI_IMAGE_SCN_MEM_EXECUTE
0x20000000
#define EFI_IMAGE_SCN_MEM_WRITE
0x80000000
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
VOID EFIAPI PeCoffLoaderUnloadImageExtraAction(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
VOID EFIAPI PeCoffLoaderRelocateImageExtraAction(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
UINT64 EFI_PHYSICAL_ADDRESS
PE_COFF_LOADER_READ_FILE ImageRead
UINT32 PeCoffHeaderOffset
PHYSICAL_ADDRESS ImageAddress