47 IN UINT32 SectionHeaderOffset,
48 IN CONST UINT16 NumberOfSections,
49 IN REGION_PERMISSION_UPDATE_FUNC TextUpdater,
50 IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater,
51 IN REGION_PERMISSION_UPDATE_FUNC ReadWriteUpdater
61 ASSERT (ImageContext !=
NULL);
66 for (Index = 0; Index < NumberOfSections; Index++) {
72 Status = ImageContext->ImageRead (
82 "%a: ImageContext->ImageRead () failed (Status = %r)\n",
91 "%a: Section %d of image at 0x%lx has 0x%x permissions\n",
94 ImageContext->ImageAddress,
95 SectionHeader.Characteristics
99 "%a: Section %d of image at 0x%lx has %a name\n",
102 ImageContext->ImageAddress,
107 "%a: Section %d of image at 0x%lx has 0x%x address\n",
110 ImageContext->ImageAddress,
111 ImageContext->ImageAddress + SectionHeader.VirtualAddress
115 "%a: Section %d of image at 0x%lx has 0x%x data\n",
118 ImageContext->ImageAddress,
119 SectionHeader.PointerToRawData
127 Base = ImageBase + SectionHeader.VirtualAddress;
129 TextUpdater (Base, SectionHeader.Misc.VirtualSize);
132 ReadWriteUpdater (Base, SectionHeader.Misc.VirtualSize);
135 "%a: Mapping section %d of image at 0x%lx with RW-XN permissions\n",
138 ImageContext->ImageAddress
143 "%a: Mapping section %d of image at 0x%lx with RO-XN permissions\n",
146 ImageContext->ImageAddress
152 "%a: Ignoring section %d of image at 0x%lx with 0x%x permissions\n",
155 ImageContext->ImageAddress,
156 SectionHeader.Characteristics
181 IN OUT VOID **TeData,
190 EFI_FV_FILETYPE_SECURITY_CORE,
195 if (EFI_ERROR (Status)) {
198 "Unable to locate Standalone MM FFS file - 0x%x\n",
205 if (EFI_ERROR (Status)) {
207 if (EFI_ERROR (Status)) {
210 "Unable to locate Standalone MM Section data - %r\n",
217 DEBUG ((DEBUG_INFO,
"Found Standalone MM PE data - 0x%x\n", *TeData));
235 OUT UINT32 *SectionHeaderOffset,
236 OUT UINT16 *NumberOfSections
239 RETURN_STATUS Status;
245 ASSERT (ImageContext !=
NULL);
246 ASSERT (SectionHeaderOffset !=
NULL);
247 ASSERT (NumberOfSections !=
NULL);
253 "%a: PeCoffLoaderGetImageInfo () failed (Status == %r)\n",
260 if (ImageContext->SectionAlignment < EFI_PAGE_SIZE) {
265 if (!ImageContext->IsTeImage) {
268 "%a: non-TE Image at 0x%lx has SectionAlignment < 4 KB (%lu)\n",
270 ImageContext->ImageAddress,
271 ImageContext->SectionAlignment
276 ImageContext->SectionAlignment = EFI_PAGE_SIZE;
285 Hdr.Union = &HdrData;
288 Status = ImageContext->ImageRead (
289 ImageContext->Handle,
290 ImageContext->PeCoffHeaderOffset,
298 "%a: TmpContext->ImageRead () failed (Status = %r)\n",
305 *ImageBase = ImageContext->ImageAddress;
306 if (!ImageContext->IsTeImage) {
307 ASSERT (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE);
309 *SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
311 *NumberOfSections = Hdr.Pe32->FileHeader.NumberOfSections;
313 switch (Hdr.Pe32->OptionalHeader.
Magic) {
315 *SectionHeaderOffset += Hdr.Pe32->FileHeader.SizeOfOptionalHeader;
318 *SectionHeaderOffset += Hdr.Pe32Plus->FileHeader.SizeOfOptionalHeader;
351 IN OUT UINT32 *SectionHeaderOffset,
352 IN OUT UINT16 *NumberOfSections
359 ImageContext->Handle = TeData;
362 DEBUG ((DEBUG_INFO,
"Found Standalone MM PE data - 0x%x\n", TeData));
370 if (EFI_ERROR (Status)) {
371 DEBUG ((DEBUG_ERROR,
"Unable to locate Standalone MM Core PE-COFF Section information - %r\n", Status));
377 "Standalone MM Core PE-COFF SectionHeaderOffset - 0x%x, NumberOfSections - %d\n",
378 *SectionHeaderOffset,
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define RETURN_ERROR(StatusCode)
#define RETURN_UNSUPPORTED
#define DEBUG(Expression)
RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
RETURN_STATUS EFIAPI PeCoffLoaderImageReadFromMemory(IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
#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
EFI_STATUS EFIAPI FfsFindSectionData(IN EFI_SECTION_TYPE SectionType, IN EFI_PEI_FILE_HANDLE FileHandle, OUT VOID **SectionData)
EFI_STATUS EFIAPI FfsFindNextFile(IN EFI_FV_FILETYPE SearchType, IN EFI_PEI_FV_HANDLE VolumeHandle, IN OUT EFI_PEI_FILE_HANDLE *FileHandle)
EFI_STATUS EFIAPI GetStandaloneMmCorePeCoffSections(IN VOID *TeData, IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, OUT EFI_PHYSICAL_ADDRESS *ImageBase, IN OUT UINT32 *SectionHeaderOffset, IN OUT UINT16 *NumberOfSections)
EFI_STATUS EFIAPI LocateStandaloneMmCorePeCoffData(IN EFI_FIRMWARE_VOLUME_HEADER *BfvAddress, IN OUT VOID **TeData, IN OUT UINTN *TeDataSize)
STATIC EFI_STATUS GetPeCoffSectionInformation(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, OUT EFI_PHYSICAL_ADDRESS *ImageBase, OUT UINT32 *SectionHeaderOffset, OUT UINT16 *NumberOfSections)
EFI_STATUS EFIAPI UpdateMmFoundationPeCoffPermissions(IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT32 SectionHeaderOffset, IN CONST UINT16 NumberOfSections, IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater, IN REGION_PERMISSION_UPDATE_FUNC ReadWriteUpdater)
UINT64 EFI_PHYSICAL_ADDRESS
UINT16 StrippedSize
Number of bytes we removed from the header.
UINT8 NumberOfSections
From the original file header.