/** @file
only supports relocating IA32, x64, IPF, and EBC images.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "BasePeCoffLibInternals.h"
/**
@param Hdr The buffer in which to return the PE32, PE32+, or TE header.
@return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
@return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
**/
)
{
//
// NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
// Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
// then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
//
if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
}
//
//
}
/**
Also done many checks in PE image to make sure PE image DosHeader, PeOptionHeader,
SizeOfHeader, Section Data Region and Security Data Region be in PE image range.
@param ImageContext The context of the image being loaded.
@param Hdr The buffer in which to return the PE32, PE32+, or TE header.
@retval RETURN_SUCCESS The PE or TE Header is read.
**/
)
{
//
// Read the DOS image header to check for its existence
//
Size = sizeof (EFI_IMAGE_DOS_HEADER);
0,
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
//
// DOS image header is present, so read the PE header after the DOS image
// header
//
}
//
// data, but that should not hurt anything. Hdr.Pe32->OptionalHeader.Magic
// determines if this is a PE32 or PE32+ image. The magic is in the same
// location in both images.
//
Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
//
// Use Signature to figure out if we understand the image format
//
//
// For TeImage, SectionAlignment is undefined to be set to Zero
// ImageSize can be calculated.
//
ImageContext->ImageSize = 0;
ImageContext->SectionAlignment = 0;
ImageContext->SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// 1. Check FileHeader.SizeOfOptionalHeader filed.
//
return RETURN_UNSUPPORTED;
}
//
// 2. Check the OptionalHeader.SizeOfHeaders field.
// This field will be use like the following mode, so just compare the result.
// The DataDirectory array begin with 1, not 0, so here use < to compare not <=.
//
if (Hdr.Pe32->OptionalHeader.SizeOfHeaders < (UINT32)((UINT8 *)(&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (UINT8 *) &Hdr)) {
return RETURN_UNSUPPORTED;
}
}
//
// Read Hdr.Pe32.OptionalHeader.SizeOfHeaders data from file
//
Size = 1;
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
//
// Check the EFI_IMAGE_DIRECTORY_ENTRY_SECURITY data.
// Read the last byte to make sure the data is in the image region.
// The DataDirectory array begin with 1, not 0, so here use < to compare not <=.
//
//
// Check the member data to avoid overflow.
//
if ((UINT32) (~0) - Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress <
return RETURN_INVALID_PARAMETER;
}
//
// Read section header from file
//
Size = 1;
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
}
}
//
// Use PE32 offset
//
} else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
//
// 1. Check FileHeader.SizeOfOptionalHeader filed.
//
return RETURN_UNSUPPORTED;
}
//
// 2. Check the OptionalHeader.SizeOfHeaders field.
// This field will be use like the following mode, so just compare the result.
// The DataDirectory array begin with 1, not 0, so here use < to compare not <=.
//
if (Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders < (UINT32)((UINT8 *)(&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (UINT8 *) &Hdr)) {
return RETURN_UNSUPPORTED;
}
}
//
// Read Hdr.Pe32.OptionalHeader.SizeOfHeaders data from file
//
Size = 1;
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
//
// Check the EFI_IMAGE_DIRECTORY_ENTRY_SECURITY data.
// Read the last byte to make sure the data is in the image region.
// The DataDirectory array begin with 1, not 0, so here use < to compare not <=.
//
//
// Check the member data to avoid overflow.
//
if ((UINT32) (~0) - Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress <
return RETURN_INVALID_PARAMETER;
}
//
// Read section header from file
//
Size = 1;
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
}
}
//
// Use PE32+ offset
//
} else {
return RETURN_UNSUPPORTED;
}
} else {
return RETURN_UNSUPPORTED;
}
//
// unsupported. This library can support lots of types of images
// this does not mean the user of this library can call the entry
// point of the image.
//
return RETURN_UNSUPPORTED;
}
//
// Check each section field.
//
if (ImageContext->IsTeImage) {
SectionHeaderOffset = sizeof(EFI_TE_IMAGE_HEADER);
} else {
SectionHeaderOffset = ImageContext->PeCoffHeaderOffset + sizeof (UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + Hdr.Pe32->FileHeader.SizeOfOptionalHeader;
}
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
if (SectionHeader.SizeOfRawData > 0) {
//
// Check the member data to avoid overflow.
//
return RETURN_INVALID_PARAMETER;
}
//
// Base on the ImageRead function to check the section data field.
// Read the last byte to make sure the data is in the image region.
//
Size = 1;
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
}
//
// Check next section.
//
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
return RETURN_SUCCESS;
}
/**
Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, ImageSize,
DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and
DebugDirectoryEntryRva fields of the ImageContext structure.
If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
If any errors occur while computing the fields of ImageContext,
then the error status is returned in the ImageError field of ImageContext.
If the image is a TE image, then SectionAlignment is set to 0.
The ImageRead and Handle fields of ImageContext structure must be valid prior
to invoking this service.
Also done many checks in PE image to make sure PE image DosHeader, PeOptionHeader,
SizeOfHeader, Section Data Region and Security Data Region be in PE image range.
image that needs to be examined by this function.
@retval RETURN_INVALID_PARAMETER ImageContext is NULL.
**/
)
{
if (ImageContext == NULL) {
return RETURN_INVALID_PARAMETER;
}
//
// Assume success
//
if (RETURN_ERROR (Status)) {
return Status;
}
//
// Retrieve the base address of the image
//
if (!(ImageContext->IsTeImage)) {
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
} else {
//
// Use PE32+ offset
//
}
} else {
ImageContext->ImageAddress = (PHYSICAL_ADDRESS)(Hdr.Te->ImageBase + Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER));
}
//
// Initialize the alternate destination address to 0 indicating that it
// should not be used.
//
//
// Initialize the debug codeview pointer.
//
//
// Three cases with regards to relocations:
// - Image has base relocs, RELOCS_STRIPPED==0 => image is relocatable
// - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable
// - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but
// has no base relocs to apply
// Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.
//
// Look at the file header to determine if relocations have been stripped, and
// save this information in the image context for later use.
//
if ((!(ImageContext->IsTeImage)) && ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0)) {
} else if ((ImageContext->IsTeImage) && (Hdr.Te->DataDirectory[0].Size == 0) && (Hdr.Te->DataDirectory[0].VirtualAddress == 0)) {
} else {
}
//
// TE Image Relocation Data Directory Entry size is non-zero, but the Relocation Data Directory Virtual Address is zero.
// This case is not a valid TE image.
//
if ((ImageContext->IsTeImage) && (Hdr.Te->DataDirectory[0].Size != 0) && (Hdr.Te->DataDirectory[0].VirtualAddress == 0)) {
return RETURN_INVALID_PARAMETER;
}
if (!(ImageContext->IsTeImage)) {
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
} else {
//
// Use PE32+ offset
//
DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
}
//
// Determine the file offset of the debug directory... This means we walk
// the sections to find which section contains the RVA of the debug
// directory
//
SectionHeaderOffset = (UINTN)(
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
);
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
DebugDirectoryEntryFileOffset = DebugDirectoryEntryRva - SectionHeader.VirtualAddress + SectionHeader.PointerToRawData;
break;
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
if (DebugDirectoryEntryFileOffset != 0) {
for (Index = 0; Index < DebugDirectoryEntry->Size; Index += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) {
//
// Read next debug directory entry
//
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
}
return RETURN_SUCCESS;
}
}
}
}
} else {
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
sizeof (EFI_TE_IMAGE_HEADER) -
//
// File offset of the debug directory was found, if this is not the last
// section, then skip to the last section for calculating the image size.
//
continue;
}
}
//
// In Te image header there is not a field to describe the ImageSize.
// Actually, the ImageSize equals the RVA plus the VirtualSize of
// the last section mapped into memory (Must be rounded up to
// section headers in the Section Table must appear in order of the RVA
// values for the corresponding sections. So the ImageSize can be determined
// by the RVA and the VirtualSize of the last section header in the
// Section Table.
//
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
if (DebugDirectoryEntryFileOffset != 0) {
for (Index = 0; Index < DebugDirectoryEntry->Size; Index += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) {
//
// Read next debug directory entry
//
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
&Size,
);
if (RETURN_ERROR (Status)) {
return Status;
}
return RETURN_SUCCESS;
}
}
}
}
return RETURN_SUCCESS;
}
/**
Converts an image address to the loaded address.
@param ImageContext The context of the image being loaded.
@param Address The relative virtual address to be converted to the loaded address.
@return The converted address or NULL if the address can not be converted.
**/
VOID *
)
{
//
// Make sure that Address and ImageSize is correct for the loaded image.
//
return NULL;
}
}
/**
If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
of ImageContext as the relocation base address. The caller must allocate the relocation
fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress,
ImageSize, DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders,
DebugDirectoryEntryRva, EntryPoint, FixupDataSize, CodeView, PdbPointer, and FixupData of
the ImageContext structure must be valid prior to invoking this service.
If ImageContext is NULL, then ASSERT().
Note that if the platform does not maintain coherency between the instruction cache(s) and the data
cache(s) in hardware, then the caller is responsible for performing cache maintenance operations
image that is being relocated.
Extended status information is in the ImageError field of ImageContext.
Extended status information is in the ImageError field of ImageContext.
@retval RETURN_UNSUPPORTED A relocation record type is not supported.
Extended status information is in the ImageError field of ImageContext.
**/
)
{
//
// Assume success
//
//
// If there are no relocation entries, then we are done
//
if (ImageContext->RelocationsStripped) {
// Applies additional environment specific actions to relocate fixups
return RETURN_SUCCESS;
}
//
// If the destination address is not 0, use that rather than the
// image address as the relocation target.
//
if (ImageContext->DestinationAddress != 0) {
} else {
}
if (!(ImageContext->IsTeImage)) {
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
if (Adjust != 0) {
}
} else {
//
// Use PE32+ offset
//
if (Adjust != 0) {
}
}
//
// Find the relocation block
// is present in the image. You have to check the NumberOfRvaAndSizes in
// the optional header to verify a desired directory entry is there.
//
);
return RETURN_LOAD_ERROR;
}
} else {
//
// Set base and end to bypass processing below.
//
}
} else {
Adjust = (UINT64) (BaseAddress - Hdr.Te->StrippedSize + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->ImageBase);
if (Adjust != 0) {
}
//
// Find the relocation block
//
sizeof(EFI_TE_IMAGE_HEADER) -
);
} else {
//
// Set base and end to bypass processing below.
//
}
}
//
// If Adjust is not zero, then apply fix ups to the image
//
if (Adjust != 0) {
//
// Run the relocation information and apply the fixups
//
while (RelocBase < RelocBaseEnd) {
//
// Make sure RelocEnd is in the Image range.
//
(CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + (UINTN)ImageContext->ImageSize)) {
return RETURN_LOAD_ERROR;
}
if (!(ImageContext->IsTeImage)) {
return RETURN_LOAD_ERROR;
}
} else {
sizeof(EFI_TE_IMAGE_HEADER) -
);
}
//
// Run this relocation record
//
switch ((*Reloc) >> 12) {
break;
case EFI_IMAGE_REL_BASED_HIGH:
}
break;
case EFI_IMAGE_REL_BASED_LOW:
}
break;
}
break;
}
break;
default:
//
// The common code does not handle some of the stranger IPF relocations
// PeCoffLoaderRelocateImageEx () adds support for these complex fixups
// on IPF and is a No-Op on other architectures.
//
if (RETURN_ERROR (Status)) {
return Status;
}
}
//
// Next relocation record
//
Reloc += 1;
}
//
// Next reloc block
//
}
//
// Adjust the EntryPoint to match the linked-to address
//
if (ImageContext->DestinationAddress != 0) {
}
}
// Applies additional environment specific actions to relocate fixups
return RETURN_SUCCESS;
}
/**
specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
The EntryPoint, FixupDataSize, CodeView, PdbPointer and HiiResourceData fields of ImageContext are computed.
The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress, ImageSize,
DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
fields of the ImageContext structure must be valid prior to invoking this service.
If ImageContext is NULL, then ASSERT().
Note that if the platform does not maintain coherency between the instruction cache(s) and the data
cache(s) in hardware, then the caller is responsible for performing cache maintenance operations
image that is being loaded.
the ImageAddress and ImageSize fields of ImageContext.
Extended status information is in the ImageError field of ImageContext.
@retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
Extended status information is in the ImageError field of ImageContext.
Extended status information is in the ImageError field of ImageContext.
@retval RETURN_INVALID_PARAMETER The image address is invalid.
Extended status information is in the ImageError field of ImageContext.
**/
)
{
//
// Assume success
//
//
// Copy the provided context information into our local version, get what we
// can from the original image, and then use that to make sure everything
// is legit.
//
if (RETURN_ERROR (Status)) {
return Status;
}
//
// Make sure there is enough allocated space for the image being loaded
//
return RETURN_BUFFER_TOO_SMALL;
}
if (ImageContext->ImageAddress == 0) {
//
// Image cannot be loaded into 0 address.
//
return RETURN_INVALID_PARAMETER;
}
//
// If there's no relocations, then make sure it's not a runtime driver,
// and that it's being loaded at the linked address.
//
if (CheckContext.RelocationsStripped) {
//
// If the image does not contain relocations and it is a runtime driver
// then return an error.
//
return RETURN_LOAD_ERROR;
}
//
// If the image does not contain relocations, and the requested load address
// is not the linked address, then return an error.
//
return RETURN_INVALID_PARAMETER;
}
}
//
// Make sure the allocated space has the proper section alignment
//
if (!(ImageContext->IsTeImage)) {
return RETURN_INVALID_PARAMETER;
}
}
//
//
if (!(ImageContext->IsTeImage)) {
0,
);
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);
FirstSection = (EFI_IMAGE_SECTION_HEADER *) (
sizeof(UINT32) +
sizeof(EFI_IMAGE_FILE_HEADER) +
);
} else {
0,
);
FirstSection = (EFI_IMAGE_SECTION_HEADER *) (
sizeof(EFI_TE_IMAGE_HEADER)
);
}
if (RETURN_ERROR (Status)) {
return RETURN_LOAD_ERROR;
}
//
// Load each section of the image
//
//
// Read the section
//
}
//
// Compute sections address
//
);
//
// If the size of the section is non-zero and the base address or end address resolved to 0, then fail.
//
return RETURN_LOAD_ERROR;
}
if (ImageContext->IsTeImage) {
}
}
if (Section->SizeOfRawData > 0) {
if (!(ImageContext->IsTeImage)) {
&Size,
);
} else {
&Size,
);
}
if (RETURN_ERROR (Status)) {
return Status;
}
}
//
// If raw size is less then virtual size, zero fill the remaining
//
}
//
// Next Section
//
Section += 1;
}
//
// Get image's entry point
//
if (!(ImageContext->IsTeImage)) {
//
// Sizes of AddressOfEntryPoint are different so we need to do this safely
//
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
);
} else {
//
// Use PE32+ offset
//
);
}
} else {
(UINTN)sizeof(EFI_TE_IMAGE_HEADER) -
);
}
//
// Determine the size of the fixup data
//
// is present in the image. You have to check the NumberOfRvaAndSizes in
// the optional header to verify a desired directory entry is there.
//
if (!(ImageContext->IsTeImage)) {
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];
} else {
//
// Use PE32+ offset
//
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];
}
} else {
ImageContext->FixupDataSize = 0;
}
} else {
}
//
// Consumer must allocate a buffer for the relocation fixup log.
// Only used for runtime drivers.
//
//
// Load the Codeview information if present
//
if (ImageContext->DebugDirectoryEntryRva != 0) {
if (!(ImageContext->IsTeImage)) {
);
} else {
sizeof(EFI_TE_IMAGE_HEADER) -
);
}
if (DebugEntry != NULL) {
Section--;
} else {
}
}
if (TempDebugEntryRva != 0) {
if (!(ImageContext->IsTeImage)) {
} else {
(UINTN)sizeof (EFI_TE_IMAGE_HEADER) -
);
}
return RETURN_LOAD_ERROR;
}
if (DebugEntry->RVA == 0) {
if (!(ImageContext->IsTeImage)) {
&Size,
);
} else {
&Size,
);
//
// Should we apply fix up to this field according to the size difference between PE and TE?
// Because now we maintain TE header fields unfixed, this field will also remain as they are
// in original PE image.
//
}
if (RETURN_ERROR (Status)) {
return RETURN_LOAD_ERROR;
}
}
case CODEVIEW_SIGNATURE_NB10:
ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);
break;
case CODEVIEW_SIGNATURE_RSDS:
ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);
break;
case CODEVIEW_SIGNATURE_MTOC:
ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY);
break;
default:
break;
}
}
}
}
//
// Get Image's HII resource section
//
ImageContext->HiiResourceData = 0;
if (!(ImageContext->IsTeImage)) {
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE];
} else {
//
// Use PE32+ offset
//
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE];
}
if (DirectoryEntry->Size != 0) {
ResourceDirectoryString = (EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (Base + ResourceDirectoryEntry->u1.s.NameOffset);
String[0] == L'H' &&
//
// Resource Type "HII" found
//
//
// Move to next level - resource Name
//
ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
//
// Move to next level - resource Language
//
ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
}
}
//
// Now it ought to be resource Data
//
ResourceDataEntry = (EFI_IMAGE_RESOURCE_DATA_ENTRY *) (Base + ResourceDirectoryEntry->u2.OffsetToData);
ImageContext->HiiResourceData = (PHYSICAL_ADDRESS) (UINTN) PeCoffLoaderImageAddress (ImageContext, ResourceDataEntry->OffsetToData);
break;
}
}
}
}
}
}
}
return Status;
}
/**
runtime.
to the address specified by VirtualImageBase. RelocationData must be identical
to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure
Note that if the platform does not maintain coherency between the instruction cache(s) and the data
cache(s) in hardware, then the caller is responsible for performing cache maintenance operations
and relocated into system memory.
be fixed up for.
image was relocated using PeCoffLoaderRelocateImage().
**/
)
{
//
// Find the image's relocate dir info
//
//
// Valid DOS header so get address of PE header
//
} else {
//
// No Dos header so assume image starts with PE header.
//
}
//
// Not a valid PE image so Exit
//
return ;
}
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset
//
} else {
//
// Use PE32+ offset
//
}
//
// Find the relocation block
//
// is present in the image. You have to check the NumberOfRvaAndSizes in
// the optional header to verify a desired directory entry is there.
//
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress + RelocDir->Size);
} else {
//
// Cannot find relocations, cannot continue to relocate the image, ASSERT for this invalid image.
//
return ;
}
//
// ASSERT for the invalid image when RelocBase and RelocBaseEnd are both NULL.
//
//
// Run the whole relocation block. And re-fixup data that has not been
// modified. The FixupData is used to see if the image has been modified
// since it was relocated. This is so data sections that have been updated
// by code will not be fixed up, since that would set them back to
// defaults.
//
while (RelocBase < RelocBaseEnd) {
//
// Run this relocation record
//
switch ((*Reloc) >> 12) {
break;
case EFI_IMAGE_REL_BASED_HIGH:
}
break;
case EFI_IMAGE_REL_BASED_LOW:
}
break;
}
break;
}
break;
//
// Not valid Relocation type for UEFI image, ASSERT
//
break;
default:
//
// Only Itanium requires ConvertPeImage_Ex
//
if (RETURN_ERROR (Status)) {
return ;
}
}
//
// Next relocation record
//
Reloc += 1;
}
//
// next reloc block
//
}
}
/**
This is the default implementation of a PE_COFF_LOADER_READ_FILE function
address specified by FileHandle. The read operation copies ReadSize bytes from the
The size of the buffer actually read is returned in ReadSize.
If FileHandle is NULL, then ASSERT().
If ReadSize is NULL, then ASSERT().
If Buffer is NULL, then ASSERT().
@param FileHandle The pointer to base of the input stream
@param ReadSize On input, the size in bytes of the requested read operation.
On output, the number of bytes actually read.
@retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
the buffer.
**/
)
{
return RETURN_SUCCESS;
}
/**
Releases any environment specific resources that were allocated when the image
specified by ImageContext was loaded using PeCoffLoaderLoadImage().
this function can simply return RETURN_SUCCESS.
If ImageContext is NULL, then ASSERT().
image to be unloaded.
**/
)
{
//
// Applies additional environment specific actions to unload a
//
return RETURN_SUCCESS;
}