MdePkg: Clean up source files
1. Do not use tab characters 2. No trailing white space in one line 3. All files must end with CRLF Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
PeCoffLoaderGetPeHeader() routine will do basic check for PE/COFF header.
|
||||
PeCoffLoaderGetImageInfo() routine will do basic check for whole PE/COFF image.
|
||||
|
||||
Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2018, 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
|
||||
@@ -61,8 +61,8 @@ PeCoffLoaderGetPeHeaderMagicValue (
|
||||
)
|
||||
{
|
||||
//
|
||||
// NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
|
||||
// in the PE/COFF Header. If the MachineType is Itanium(IA64) and the
|
||||
// NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
|
||||
// in the PE/COFF Header. If the MachineType is Itanium(IA64) and the
|
||||
// Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
|
||||
// then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
|
||||
//
|
||||
@@ -77,12 +77,12 @@ PeCoffLoaderGetPeHeaderMagicValue (
|
||||
|
||||
|
||||
/**
|
||||
Retrieves the PE or TE Header from a PE/COFF or TE image.
|
||||
Retrieves the PE or TE Header from a PE/COFF or TE image.
|
||||
|
||||
Caution: This function may receive untrusted input.
|
||||
PE/COFF image is external input, so this routine will
|
||||
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.
|
||||
PE/COFF image is external input, so this routine will
|
||||
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.
|
||||
@@ -211,7 +211,7 @@ PeCoffLoaderGetPeHeader (
|
||||
|
||||
//
|
||||
// TE Image Data Directory Entry size is non-zero, but the Data Directory Virtual Address is zero.
|
||||
// This case is not a valid TE image.
|
||||
// This case is not a valid TE image.
|
||||
//
|
||||
if ((Hdr.Te->DataDirectory[0].Size != 0 && Hdr.Te->DataDirectory[0].VirtualAddress == 0) ||
|
||||
(Hdr.Te->DataDirectory[1].Size != 0 && Hdr.Te->DataDirectory[1].VirtualAddress == 0)) {
|
||||
@@ -235,7 +235,7 @@ PeCoffLoaderGetPeHeader (
|
||||
|
||||
//
|
||||
// 2. Check the FileHeader.SizeOfOptionalHeader field.
|
||||
// OptionalHeader.NumberOfRvaAndSizes is not bigger than 16, so
|
||||
// OptionalHeader.NumberOfRvaAndSizes is not bigger than 16, so
|
||||
// OptionalHeader.NumberOfRvaAndSizes * sizeof (EFI_IMAGE_DATA_DIRECTORY) will not overflow.
|
||||
//
|
||||
HeaderWithoutDataDir = sizeof (EFI_IMAGE_OPTIONAL_HEADER32) - sizeof (EFI_IMAGE_DATA_DIRECTORY) * EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES;
|
||||
@@ -349,7 +349,7 @@ PeCoffLoaderGetPeHeader (
|
||||
}
|
||||
//
|
||||
// 2. Check the FileHeader.SizeOfOptionalHeader field.
|
||||
// OptionalHeader.NumberOfRvaAndSizes is not bigger than 16, so
|
||||
// OptionalHeader.NumberOfRvaAndSizes is not bigger than 16, so
|
||||
// OptionalHeader.NumberOfRvaAndSizes * sizeof (EFI_IMAGE_DATA_DIRECTORY) will not overflow.
|
||||
//
|
||||
HeaderWithoutDataDir = sizeof (EFI_IMAGE_OPTIONAL_HEADER64) - sizeof (EFI_IMAGE_DATA_DIRECTORY) * EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES;
|
||||
@@ -513,7 +513,7 @@ PeCoffLoaderGetPeHeader (
|
||||
//
|
||||
// Section data should bigger than the Pe header.
|
||||
//
|
||||
if (SectionHeader.VirtualAddress < ImageContext->SizeOfHeaders ||
|
||||
if (SectionHeader.VirtualAddress < ImageContext->SizeOfHeaders ||
|
||||
SectionHeader.PointerToRawData < ImageContext->SizeOfHeaders) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;
|
||||
return RETURN_UNSUPPORTED;
|
||||
@@ -561,22 +561,22 @@ PeCoffLoaderGetPeHeader (
|
||||
/**
|
||||
Retrieves information about a PE/COFF image.
|
||||
|
||||
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 the PE/COFF image accessed through the ImageRead service in the ImageContext
|
||||
structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED.
|
||||
If any errors occur while computing the fields of ImageContext,
|
||||
then the error status is returned in the ImageError field of ImageContext.
|
||||
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 the PE/COFF image accessed through the ImageRead service in the ImageContext
|
||||
structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED.
|
||||
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
|
||||
The ImageRead and Handle fields of ImageContext structure must be valid prior
|
||||
to invoking this service.
|
||||
|
||||
Caution: This function may receive untrusted input.
|
||||
PE/COFF image is external input, so this routine will
|
||||
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.
|
||||
PE/COFF image is external input, so this routine will
|
||||
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 pointer to the image context structure that describes the PE/COFF
|
||||
image that needs to be examined by this function.
|
||||
@@ -829,7 +829,7 @@ PeCoffLoaderGetImageInfo (
|
||||
// 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.
|
||||
// Section Table.
|
||||
//
|
||||
if ((++Index) == (UINTN)Hdr.Te->NumberOfSections) {
|
||||
ImageContext->ImageSize = (SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize) - TeStrippedOffset;
|
||||
@@ -884,7 +884,7 @@ PeCoffLoaderGetImageInfo (
|
||||
VOID *
|
||||
PeCoffLoaderImageAddress (
|
||||
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
|
||||
IN UINTN Address,
|
||||
IN UINTN Address,
|
||||
IN UINTN TeStrippedOffset
|
||||
)
|
||||
{
|
||||
@@ -906,12 +906,12 @@ PeCoffLoaderImageAddress (
|
||||
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 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
|
||||
@@ -966,9 +966,9 @@ PeCoffLoaderRelocateImage (
|
||||
// If there are no relocation entries, then we are done
|
||||
//
|
||||
if (ImageContext->RelocationsStripped) {
|
||||
// Applies additional environment specific actions to relocate fixups
|
||||
// Applies additional environment specific actions to relocate fixups
|
||||
// to a PE/COFF image if needed
|
||||
PeCoffLoaderRelocateImageExtraAction (ImageContext);
|
||||
PeCoffLoaderRelocateImageExtraAction (ImageContext);
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1048,7 +1048,7 @@ PeCoffLoaderRelocateImage (
|
||||
//
|
||||
// Set base and end to bypass processing below.
|
||||
//
|
||||
RelocBase = RelocBaseEnd = NULL;
|
||||
RelocBase = RelocBaseEnd = NULL;
|
||||
}
|
||||
RelocBaseOrg = RelocBase;
|
||||
|
||||
@@ -1084,7 +1084,7 @@ PeCoffLoaderRelocateImage (
|
||||
if (FixupBase == NULL) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
|
||||
return RETURN_LOAD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Run this relocation record
|
||||
@@ -1171,11 +1171,11 @@ PeCoffLoaderRelocateImage (
|
||||
ImageContext->EntryPoint += (UINT64) ImageContext->DestinationAddress;
|
||||
}
|
||||
}
|
||||
|
||||
// Applies additional environment specific actions to relocate fixups
|
||||
|
||||
// Applies additional environment specific actions to relocate fixups
|
||||
// to a PE/COFF image if needed
|
||||
PeCoffLoaderRelocateImageExtraAction (ImageContext);
|
||||
|
||||
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1186,10 +1186,10 @@ PeCoffLoaderRelocateImage (
|
||||
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
|
||||
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
|
||||
@@ -1501,7 +1501,7 @@ PeCoffLoaderLoadImage (
|
||||
}
|
||||
|
||||
if (TempDebugEntryRva != 0) {
|
||||
ImageContext->CodeView = PeCoffLoaderImageAddress (ImageContext, TempDebugEntryRva, TeStrippedOffset);
|
||||
ImageContext->CodeView = PeCoffLoaderImageAddress (ImageContext, TempDebugEntryRva, TeStrippedOffset);
|
||||
if (ImageContext->CodeView == NULL) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
|
||||
return RETURN_LOAD_ERROR;
|
||||
@@ -1583,7 +1583,7 @@ PeCoffLoaderLoadImage (
|
||||
Base = PeCoffLoaderImageAddress (ImageContext, DirectoryEntry->VirtualAddress, 0);
|
||||
if (Base != NULL) {
|
||||
ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) Base;
|
||||
Offset = sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) + sizeof (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY) *
|
||||
Offset = sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) + sizeof (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY) *
|
||||
(ResourceDirectory->NumberOfNamedEntries + ResourceDirectory->NumberOfIdEntries);
|
||||
if (Offset > DirectoryEntry->Size) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;
|
||||
@@ -1619,7 +1619,7 @@ PeCoffLoaderLoadImage (
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
|
||||
Offset = ResourceDirectoryEntry->u2.s.OffsetToDirectory + sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) +
|
||||
Offset = ResourceDirectoryEntry->u2.s.OffsetToDirectory + sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) +
|
||||
sizeof (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY) * (ResourceDirectory->NumberOfNamedEntries + ResourceDirectory->NumberOfIdEntries);
|
||||
if (Offset > DirectoryEntry->Size) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;
|
||||
@@ -1636,7 +1636,7 @@ PeCoffLoaderLoadImage (
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
|
||||
Offset = ResourceDirectoryEntry->u2.s.OffsetToDirectory + sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) +
|
||||
Offset = ResourceDirectoryEntry->u2.s.OffsetToDirectory + sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) +
|
||||
sizeof (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY) * (ResourceDirectory->NumberOfNamedEntries + ResourceDirectory->NumberOfIdEntries);
|
||||
if (Offset > DirectoryEntry->Size) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;
|
||||
@@ -1665,33 +1665,33 @@ PeCoffLoaderLoadImage (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
|
||||
runtime.
|
||||
|
||||
This function reapplies relocation fixups to the PE/COFF image specified by ImageBase
|
||||
and ImageSize so the image will execute correctly when the PE/COFF image is mapped
|
||||
to the address specified by VirtualImageBase. RelocationData must be identical
|
||||
to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure
|
||||
runtime.
|
||||
|
||||
This function reapplies relocation fixups to the PE/COFF image specified by ImageBase
|
||||
and ImageSize so the image will execute correctly when the PE/COFF image is mapped
|
||||
to the address specified by VirtualImageBase. RelocationData must be identical
|
||||
to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure
|
||||
after this PE/COFF image was relocated with PeCoffLoaderRelocateImage().
|
||||
|
||||
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
|
||||
prior to transferring control to a PE/COFF image that is loaded using this library.
|
||||
|
||||
@param ImageBase The base address of a PE/COFF image that has been loaded
|
||||
@param ImageBase The base address of a PE/COFF image that has been loaded
|
||||
and relocated into system memory.
|
||||
@param VirtImageBase The request virtual address that the PE/COFF image is to
|
||||
be fixed up for.
|
||||
@param ImageSize The size, in bytes, of the PE/COFF image.
|
||||
@param RelocationData A pointer to the relocation data that was collected when the PE/COFF
|
||||
@param RelocationData A pointer to the relocation data that was collected when the PE/COFF
|
||||
image was relocated using PeCoffLoaderRelocateImage().
|
||||
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
@@ -1784,7 +1784,7 @@ PeCoffLoaderRelocateImageForRuntime (
|
||||
ASSERT (FALSE);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ASSERT for the invalid image when RelocBase and RelocBaseEnd are both NULL.
|
||||
//
|
||||
@@ -1886,14 +1886,14 @@ PeCoffLoaderRelocateImageForRuntime (
|
||||
|
||||
/**
|
||||
Reads contents of a PE/COFF image from a buffer in system memory.
|
||||
|
||||
This is the default implementation of a PE_COFF_LOADER_READ_FILE function
|
||||
that assumes FileHandle pointer to the beginning of a PE/COFF image.
|
||||
This function reads contents of the PE/COFF image that starts at the system memory
|
||||
address specified by FileHandle. The read operation copies ReadSize bytes from the
|
||||
PE/COFF image starting at byte offset FileOffset into the buffer specified by Buffer.
|
||||
|
||||
This is the default implementation of a PE_COFF_LOADER_READ_FILE function
|
||||
that assumes FileHandle pointer to the beginning of a PE/COFF image.
|
||||
This function reads contents of the PE/COFF image that starts at the system memory
|
||||
address specified by FileHandle. The read operation copies ReadSize bytes from the
|
||||
PE/COFF image starting at byte offset FileOffset into the buffer specified by Buffer.
|
||||
The size of the buffer actually read is returned in ReadSize.
|
||||
|
||||
|
||||
The caller must make sure the FileOffset and ReadSize within the file scope.
|
||||
|
||||
If FileHandle is NULL, then ASSERT().
|
||||
@@ -1902,11 +1902,11 @@ PeCoffLoaderRelocateImageForRuntime (
|
||||
|
||||
@param FileHandle The pointer to base of the input stream
|
||||
@param FileOffset Offset into the PE/COFF image to begin the read operation.
|
||||
@param ReadSize On input, the size in bytes of the requested read operation.
|
||||
@param ReadSize On input, the size in bytes of the requested read operation.
|
||||
On output, the number of bytes actually read.
|
||||
@param Buffer Output buffer that contains the data read from the PE/COFF image.
|
||||
|
||||
@retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
|
||||
@retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
|
||||
the buffer.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
@@ -1928,15 +1928,15 @@ PeCoffLoaderImageReadFromMemory (
|
||||
|
||||
/**
|
||||
Unloads a loaded PE/COFF image from memory and releases its taken resource.
|
||||
Releases any environment specific resources that were allocated when the image
|
||||
specified by ImageContext was loaded using PeCoffLoaderLoadImage().
|
||||
|
||||
Releases any environment specific resources that were allocated when the image
|
||||
specified by ImageContext was loaded using PeCoffLoaderLoadImage().
|
||||
|
||||
For NT32 emulator, the PE/COFF image loaded by system needs to release.
|
||||
For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
|
||||
For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
|
||||
this function can simply return RETURN_SUCCESS.
|
||||
|
||||
|
||||
If ImageContext is NULL, then ASSERT().
|
||||
|
||||
|
||||
@param ImageContext The pointer to the image context structure that describes the PE/COFF
|
||||
image to be unloaded.
|
||||
|
||||
@@ -1949,7 +1949,7 @@ PeCoffLoaderUnloadImage (
|
||||
)
|
||||
{
|
||||
//
|
||||
// Applies additional environment specific actions to unload a
|
||||
// Applies additional environment specific actions to unload a
|
||||
// PE/COFF image if needed
|
||||
//
|
||||
PeCoffLoaderUnloadImageExtraAction (ImageContext);
|
||||
|
Reference in New Issue
Block a user