PeCoffLib.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
IA-32, x86, IPF, and EBC processor types. The library functions are memory-based
and can be ported easily to any environment.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that 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.
**/
#ifndef __BASE_PE_COFF_LIB_H__
#define __BASE_PE_COFF_LIB_H__
#include <IndustryStandard/PeImage.h>
//
//
#define IMAGE_ERROR_SUCCESS 0
#define IMAGE_ERROR_IMAGE_READ 1
#define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2
#define IMAGE_ERROR_INVALID_MACHINE_TYPE 3
#define IMAGE_ERROR_INVALID_SUBSYSTEM 4
#define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5
#define IMAGE_ERROR_INVALID_IMAGE_SIZE 6
#define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7
#define IMAGE_ERROR_SECTION_NOT_LOADED 8
#define IMAGE_ERROR_FAILED_RELOCATION 9
#define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10
/**
the buffer specified by Buffer. The size of the buffer actually read is returned in ReadSize.
A function of this type must be registered in the ImageRead field of a PE_COFF_LOADER_IMAGE_CONTEXT
structure for the PE/COFF Loader Library service to function correctly. This function abstracts access
to a PE/COFF image so it can be implemented in an environment specific manner. For example, SEC and PEI
stored on FLASH, disk, or network devices.
If FileHandle is not a valid handle, then ASSERT().
If ReadSize is NULL, then ASSERT().
If Buffer is NULL, then ASSERT().
@param ReadSize On input, the size in bytes of the requested read operation.
On output, the number of bytes actually read.
read and the size
could not be read due to a device error.
**/
typedef
);
///
///
typedef struct {
///
///
///
/// Image size includes the size of Debug Entry if it is present.
///
///
/// Is set to zero by PeCoffLoaderGetImageInfo(). If DestinationAddress is non-zero,
/// PeCoffLoaderRelocateImage() will relocate the image using this base address.
/// If the DestinationAddress is zero, the ImageAddress will be used as the base
/// address of relocation.
///
///
///
///
/// Passed in by the caller to PeCoffLoaderGetImageInfo() and PeCoffLoaderLoadImage()
/// to abstract accessing the image from the library.
///
///
/// Used as the FileHandle passed into the ImageRead function when it's called.
///
///
/// Caller allocated buffer of size FixupDataSize that can be optionally allocated
/// prior to calling PeCoffLoaderRelocateImage().
/// This buffer is filled with the information used to fix up the image.
/// The fixups have been applied to the image and this entry is just for information.
///
///
/// If the image is a TE image, then this field is set to 0.
///
///
///
///
/// Set by PeCoffLoaderGetImageInfo() to the Relative Virtual Address of the debug directory,
/// if it exists in the image
///
///
///
///
/// Set by PeCoffLoaderLoadImage() to point to the PDB entry contained in the CodeView area.
/// The PdbPointer points to the filename of the PDB file used for source-level debug of
/// the image by a debugger.
///
///
///
///
/// Not used by this library class. Other library classes that layer on top of this library
/// class fill in this value as part of their GetImageInfo call.
/// This allows the caller of the library to know what type of memory needs to be allocated
/// to load and relocate the image.
///
///
/// Not used by this library class. Other library classes that layer on top of this library
/// class fill in this value as part of their GetImageInfo call.
/// This allows the caller of the library to know what type of memory needs to be allocated
/// to load and relocate the image.
///
///
/// Set by any of the library functions if they encounter an error.
///
///
/// Set by PeCoffLoaderLoadImage() to indicate the size of FixupData that the caller must
/// allocate before calling PeCoffLoaderRelocateImage().
///
///
///
///
///
///
/// relocation information.
///
///
/// Set by PeCoffLoaderGetImageInfo() to TRUE if the image is a TE image.
/// For a definition of the TE Image format, see the Platform Initialization Pre-EFI
/// Initialization Core Interface Specification.
///
///
/// Set by PeCoffLoaderLoadImage() to the HII resource offset
/// Otherwise, the entry remains to be 0.
///
///
/// Private storage for implementation specific data.
///
/**
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.
@param ImageContext The pointer to the image context structure that
examined by this function.
@retval RETURN_INVALID_PARAMETER ImageContext is 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.
**/
);
/**
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.
**/
);
/**
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 The data is read from FileOffset from the Handle into
the buffer.
**/
);
/**
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().
**/
);
/**
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.
**/
);
#endif