1. Change 0 == Length style to Length == 0
2. Clean BasePeCoff library instance, only keep one copy PeCoffLoaderEx.c file for IA32, X64 and IPF arch 3. Clean the confused comments git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5927 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
/** @file
|
||||
Tiano PE/COFF loader.
|
||||
|
||||
This PE/COFF loader supports loading any PE32 or PE32+ image type, but
|
||||
Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but
|
||||
only supports relocating IA32, X64, IPF, and EBC images.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
Copyright (c) 2006 - 2008, Intel Corporation
|
||||
All rights reserved. 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
|
||||
@@ -15,9 +13,6 @@
|
||||
|
||||
**/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "BasePeCoffLibInternals.h"
|
||||
|
||||
/**
|
||||
@@ -120,8 +115,12 @@ PeCoffLoaderGetPeHeader (
|
||||
ImageContext->IsTeImage = TRUE;
|
||||
ImageContext->Machine = Hdr.Te->Machine;
|
||||
ImageContext->ImageType = (UINT16)(Hdr.Te->Subsystem);
|
||||
//
|
||||
// For TeImage, SectionAlignment is undefined to be set to Zero
|
||||
// ImageSize can be calculated.
|
||||
//
|
||||
ImageContext->ImageSize = 0;
|
||||
ImageContext->SectionAlignment = 4096;
|
||||
ImageContext->SectionAlignment = 0;
|
||||
ImageContext->SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
|
||||
|
||||
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
|
||||
@@ -173,9 +172,9 @@ PeCoffLoaderGetPeHeader (
|
||||
/**
|
||||
Retrieves information about a PE/COFF image.
|
||||
|
||||
Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
|
||||
PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
|
||||
fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
|
||||
Computes the PeCoffHeaderOffset, 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
|
||||
@@ -209,7 +208,7 @@ PeCoffLoaderGetImageInfo (
|
||||
UINT32 NumberOfRvaAndSizes;
|
||||
UINT16 Magic;
|
||||
|
||||
if (NULL == ImageContext) {
|
||||
if (ImageContext == NULL) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
//
|
||||
@@ -412,11 +411,10 @@ 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 +
|
||||
ImageContext->SectionAlignment - 1) & ~(ImageContext->SectionAlignment - 1);
|
||||
ImageContext->ImageSize = (SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize);
|
||||
}
|
||||
|
||||
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
|
||||
@@ -908,7 +906,7 @@ PeCoffLoaderLoadImage (
|
||||
Size = (UINTN) Section->SizeOfRawData;
|
||||
}
|
||||
|
||||
if (Section->SizeOfRawData) {
|
||||
if (Section->SizeOfRawData > 0) {
|
||||
if (!(ImageContext->IsTeImage)) {
|
||||
Status = ImageContext->ImageRead (
|
||||
ImageContext->Handle,
|
||||
@@ -1213,12 +1211,15 @@ PeCoffLoaderRelocateImageForRuntime (
|
||||
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress + RelocDir->Size);
|
||||
} else {
|
||||
//
|
||||
// Cannot find relocations, cannot continue
|
||||
// Cannot find relocations, cannot continue to relocate the image, ASSERT for this invalid image.
|
||||
//
|
||||
ASSERT (FALSE);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ASSERT for the invalid image when RelocBase and RelocBaseEnd are both NULL.
|
||||
//
|
||||
ASSERT (RelocBase != NULL && RelocBaseEnd != NULL);
|
||||
|
||||
//
|
||||
@@ -1286,7 +1287,7 @@ PeCoffLoaderRelocateImageForRuntime (
|
||||
|
||||
case EFI_IMAGE_REL_BASED_HIGHADJ:
|
||||
//
|
||||
// Not implemented, but not used in UEFI 2.0
|
||||
// Not valid Relocation type for UEFI image, ASSERT
|
||||
//
|
||||
ASSERT (FALSE);
|
||||
break;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#/** @file
|
||||
# Component description file for Base PE/COFF Library
|
||||
#
|
||||
# PE/COFF Loader Library implementation.
|
||||
# Copyright (c) 2006, Intel Corporation.
|
||||
# Base PE/COFF Loader Library implementation.
|
||||
# Copyright (c) 2006 - 2008, Intel Corporation.
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -33,23 +33,15 @@
|
||||
BasePeCoffLibInternals.h
|
||||
BasePeCoff.c
|
||||
|
||||
[Sources.Ia32]
|
||||
Ia32/PeCoffLoaderEx.c
|
||||
|
||||
[Sources.X64]
|
||||
x64/PeCoffLoaderEx.c
|
||||
[Sources.Ia32, Sources.X64, Sources.EBC]
|
||||
PeCoffLoaderEx.c
|
||||
|
||||
[Sources.IPF]
|
||||
Ipf/PeCoffLoaderEx.c
|
||||
|
||||
[Sources.EBC]
|
||||
Ebc/PeCoffLoaderEx.c
|
||||
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
|
||||
[LibraryClasses]
|
||||
DebugLib
|
||||
BaseMemoryLib
|
||||
|
@@ -1,90 +0,0 @@
|
||||
/** @file
|
||||
EBC Specific relocation fixups.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. 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
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
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"
|
||||
|
||||
/**
|
||||
Performs an EBC specific relocation fixup.
|
||||
|
||||
@param Reloc Pointer to the relocation record.
|
||||
@param Fixup Pointer to the address to fix up.
|
||||
@param FixupData Pointer to a buffer to log the fixups.
|
||||
@param Adjust The offset to adjust the fixup.
|
||||
|
||||
@retval EFI_UNSUPPORTED Unsupported now.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PeCoffLoaderRelocateImageEx (
|
||||
IN UINT16 *Reloc,
|
||||
IN OUT CHAR8 *Fixup,
|
||||
IN OUT CHAR8 **FixupData,
|
||||
IN UINT64 Adjust
|
||||
)
|
||||
{
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns TRUE if the machine type of PE/COFF image is supported. Supported
|
||||
does not mean the image can be executed it means the PE/COFF loader supports
|
||||
loading and relocating of the image type. It's up to the caller to support
|
||||
the entry point.
|
||||
|
||||
This function implies the basic PE/COFF loader/relocator supports IA32, EBC,
|
||||
& X64 images. Calling the entry point in a correct mannor is up to the
|
||||
consumer of this library.
|
||||
|
||||
@param Machine Machine type from the PE Header.
|
||||
|
||||
@return TRUE if this PE/COFF loader can load the image
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
PeCoffLoaderImageFormatSupported (
|
||||
IN UINT16 Machine
|
||||
)
|
||||
{
|
||||
if ((Machine == EFI_IMAGE_MACHINE_IA32) || (Machine == EFI_IMAGE_MACHINE_X64) ||
|
||||
(Machine == EFI_IMAGE_MACHINE_EBC)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Performs an Itanium-based specific re-relocation fixup and is a no-op on other
|
||||
instruction sets. This is used to re-relocated the image into the EFI virtual
|
||||
space for runtime calls.
|
||||
|
||||
@param Reloc Pointer to the relocation record.
|
||||
@param Fixup Pointer to the address to fix up.
|
||||
@param FixupData Pointer to a buffer to log the fixups.
|
||||
@param Adjust The offset to adjust the fixup.
|
||||
|
||||
@return Always return UNSUPPORTED.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PeHotRelocateImageEx (
|
||||
IN UINT16 *Reloc,
|
||||
IN OUT CHAR8 *Fixup,
|
||||
IN OUT CHAR8 **FixupData,
|
||||
IN UINT64 Adjust
|
||||
)
|
||||
{
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
IA-32 Specific relocation fixups.
|
||||
Specific relocation fixups for none Itanium architecture.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation<BR>
|
||||
Copyright (c) 2006 - 2008, Intel Corporation<BR>
|
||||
All rights reserved. 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
|
@@ -1,90 +0,0 @@
|
||||
/** @file
|
||||
x64 Specific relocation fixups.
|
||||
|
||||
Copyright (c) 2005 - 2006 Intel Corporation. <BR>
|
||||
All rights reserved. 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
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
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"
|
||||
|
||||
/**
|
||||
Performs an x64 specific relocation fixup.
|
||||
|
||||
@param Reloc Pointer to the relocation record
|
||||
@param Fixup Pointer to the address to fix up
|
||||
@param FixupData Pointer to a buffer to log the fixups
|
||||
@param Adjust The offset to adjust the fixup
|
||||
|
||||
@retval RETURN_SUCCESS Success to perform relocation
|
||||
@retval RETURN_UNSUPPORTED Unsupported.
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PeCoffLoaderRelocateImageEx (
|
||||
IN UINT16 *Reloc,
|
||||
IN OUT CHAR8 *Fixup,
|
||||
IN OUT CHAR8 **FixupData,
|
||||
IN UINT64 Adjust
|
||||
)
|
||||
{
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns TRUE if the machine type of PE/COFF image is supported. Supported
|
||||
does not mean the image can be executed it means the PE/COFF loader supports
|
||||
loading and relocating of the image type. It's up to the caller to support
|
||||
the entry point.
|
||||
|
||||
This function implies the basic PE/COFF loader/relocator supports IA32, EBC,
|
||||
& X64 images. Calling the entry point in a correct mannor is up to the
|
||||
consumer of this library.
|
||||
|
||||
@param Machine Machine type from the PE Header.
|
||||
|
||||
@return TRUE if this PE/COFF loader can load the image
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
PeCoffLoaderImageFormatSupported (
|
||||
IN UINT16 Machine
|
||||
)
|
||||
{
|
||||
if ((Machine == EFI_IMAGE_MACHINE_IA32) || (Machine == EFI_IMAGE_MACHINE_X64) ||
|
||||
(Machine == EFI_IMAGE_MACHINE_EBC)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Performs an X64 specific re-relocation fixup and is a no-op on other
|
||||
instruction sets. This is used to re-relocated the image into the EFI virtual
|
||||
space for runtime calls.
|
||||
|
||||
@param Reloc Pointer to the relocation record.
|
||||
@param Fixup Pointer to the address to fix up.
|
||||
@param FixupData Pointer to a buffer to log the fixups.
|
||||
@param Adjust The offset to adjust the fixup.
|
||||
|
||||
@return EFI_UNSUPPORTED.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
PeHotRelocateImageEx (
|
||||
IN UINT16 *Reloc,
|
||||
IN OUT CHAR8 *Fixup,
|
||||
IN OUT CHAR8 **FixupData,
|
||||
IN UINT64 Adjust
|
||||
)
|
||||
{
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
Reference in New Issue
Block a user