/** @file\r
- Memory Only PE COFF loader. \r
+ Provides services to load and relocate a PE/COFF image.\r
\r
- Copyright (c) 2006 - 2007, Intel Corporation \r
- All rights reserved. This program and the accompanying materials \r
- are licensed and made available under the terms and conditions of the BSD License \r
- which accompanies this distribution. The full text of the license may be found at \r
- http://opensource.org/licenses/bsd-license.php \r
+Copyright (c) 2006 - 2007, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
\r
**/\r
\r
#include <IndustryStandard/PeImage.h>\r
//\r
// Return status codes from the PE/COFF Loader services\r
-// BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes\r
//\r
#define IMAGE_ERROR_SUCCESS 0\r
#define IMAGE_ERROR_IMAGE_READ 1 \r
OUT VOID *Buffer\r
);\r
\r
-//\r
-// Context structure used while PE/COFF image is being loaded and relocated\r
-//\r
+///\r
+/// Context structure used while PE/COFF image is being loaded and relocated\r
+///\r
typedef struct {\r
+ ///\r
+ /// Is set by PeCoffLoaderGetImageInfo() to the ImageBase in the PE/COFF header\r
+ ///\r
PHYSICAL_ADDRESS ImageAddress;\r
+ ///\r
+ /// Is set by PeCoffLoaderGetImageInfo() to the SizeOfImage in the PE/COFF header.\r
+ /// Image size includes the size of Debug Entry if it is present.\r
+ ///\r
UINT64 ImageSize;\r
+ ///\r
+ /// Is set to zero by PeCoffLoaderGetImageInfo(). If DestinationAddress is non zero,\r
+ /// PeCoffLoaderRelocateImage() will relocate the image using this base address.\r
+ /// If the DestinationAddress is zero, the ImageAddress will be used as the base\r
+ /// address of relocation.\r
+ ///\r
PHYSICAL_ADDRESS DestinationAddress;\r
+ ///\r
+ /// PeCoffLoaderLoadImage() sets EntryPoint to to the entry point of the PE/COFF image.\r
+ ///\r
PHYSICAL_ADDRESS EntryPoint;\r
+ ///\r
+ /// Passed in by the caller to PeCoffLoaderGetImageInfo() and PeCoffLoaderLoadImage()\r
+ /// to abstract accessing the image from the library.\r
+ ///\r
PE_COFF_LOADER_READ_FILE ImageRead;\r
+ ///\r
+ /// Used as the FileHandle passed into the ImageRead function when it's called.\r
+ ///\r
VOID *Handle;\r
+ ///\r
+ /// Caller allocated buffer of size FixupDataSize that can be optionally allocated\r
+ /// prior to calling PeCoffLoaderRelocateImage(). \r
+ /// This buffer is filled with the information used to fix up the image. \r
+ /// The fixups have been applied to the image and this entry is just for information.\r
+ ///\r
VOID *FixupData;\r
+ ///\r
+ /// Is set by PeCoffLoaderGetImageInfo() to the Section Alignment in the PE/COFF header\r
+ /// If the image is a TE image, then this field is set to 0.\r
+ ///\r
UINT32 SectionAlignment;\r
+ ///\r
+ /// Set by PeCoffLoaderGetImageInfo() to offset to the PE/COFF header.\r
+ /// If the PE/COFF image does not start with a DOS header, this value is zero; \r
+ /// otherwise, it's the offset to the PE/COFF header.\r
+ ///\r
UINT32 PeCoffHeaderOffset;\r
+ ///\r
+ /// Set by PeCoffLoaderGetImageInfo() to the Relative Virtual Address of the debug directory\r
+ /// if it exists in the image\r
+ ///\r
UINT32 DebugDirectoryEntryRva;\r
+ ///\r
+ /// Set by PeCoffLoaderLoadImage() to CodeView area of the PE/COFF Debug directory.\r
+ ///\r
VOID *CodeView;\r
+ ///\r
+ /// Set by PeCoffLoaderLoadImage() to point to the PDB entry contained in the CodeView area.\r
+ /// The PdbPointer points to the filename of the PDB file used for source-level debug of \r
+ /// the image by a debugger.\r
+ ///\r
CHAR8 *PdbPointer;\r
+ ///\r
+ /// Is set by PeCoffLoaderGetImageInfo() to the Section Alignment in the PE/COFF header.\r
+ ///\r
UINTN SizeOfHeaders;\r
+ ///\r
+ /// Not used by this library class. Other library classes that layer on top of this library\r
+ /// class fill in this value as part of their GetImageInfo call. \r
+ /// This allows the caller of the library to know what type of memory needs to be allocated\r
+ /// to load and relocate the image.\r
+ ///\r
UINT32 ImageCodeMemoryType;\r
+ ///\r
+ /// Not used by this library class. Other library classes that layer on top of this library \r
+ /// class fill in this value as part of their GetImageInfo call.\r
+ /// This allows the caller of the library to know what type of memory needs to be allocated\r
+ /// to load and relocate the image\r
+ ///\r
UINT32 ImageDataMemoryType;\r
+ ///\r
+ /// Set by any of the library functions if they encounter an error. \r
+ ///\r
UINT32 ImageError;\r
+ ///\r
+ /// Set by PeCoffLoaderLoadImage() to indicate the size of FixupData that the caller must\r
+ /// allocate before calling PeCoffLoaderRelocateImage()\r
+ ///\r
UINTN FixupDataSize;\r
+ ///\r
+ /// Set by PeCoffLoaderGetImageInfo() to the machine type stored in the PE/COFF header\r
+ ///\r
UINT16 Machine;\r
+ ///\r
+ /// Set by PeCoffLoaderGetImageInfo() to the subsystem type stored in the PE/COFF header.\r
+ ///\r
UINT16 ImageType;\r
+ ///\r
+ /// Set by PeCoffLoaderGetImageInfo() to TRUE if the PE/COFF image does not contain\r
+ /// relocation information.\r
+ ///\r
BOOLEAN RelocationsStripped;\r
+ ///\r
+ /// Set by PeCoffLoaderGetImageInfo() to TRUE if the image is a TE image. \r
+ /// For a definition of the TE Image format, see the Platform Initialization Pre-EFI\r
+ /// Initialization Core Interface Specification.\r
+ ///\r
BOOLEAN IsTeImage;\r
} PE_COFF_LOADER_IMAGE_CONTEXT;\r
\r
/**\r
Retrieves information about a PE/COFF image.\r
\r
- Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
- PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
- fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
- If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
- a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r
- computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
- ImageContext. \r
+ Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, ImageSize, \r
+ DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and \r
+ DebugDirectoryEntryRva fields of the ImageContext structure. \r
+ If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. \r
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext \r
+ structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED. \r
+ If any errors occur while computing the fields of ImageContext, \r
+ then the error status is returned in the ImageError field of ImageContext. \r
+ If the image is a TE image, then SectionAlignment is set to 0.\r
\r
@param ImageContext Pointer to the image context structure that describes the PE/COFF\r
image that needs to be examined by this function.\r
EFIAPI\r
PeCoffLoaderGetImageInfo (\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- )\r
-;\r
+ );\r
\r
/**\r
Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
EFIAPI\r
PeCoffLoaderRelocateImage (\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- )\r
-;\r
+ );\r
\r
/**\r
Loads a PE/COFF image into memory.\r
EFIAPI\r
PeCoffLoaderLoadImage (\r
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- )\r
-;\r
+ );\r
\r
\r
/**\r
IN UINTN FileOffset,\r
IN OUT UINTN *ReadSize,\r
OUT VOID *Buffer\r
- )\r
-;\r
+ );\r
\r
\r
/**\r
IN PHYSICAL_ADDRESS VirtImageBase,\r
IN UINTN ImageSize,\r
IN VOID *RelocationData\r
- )\r
-;\r
+ );\r
\r
/**\r
Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
EFIAPI\r
PeCoffLoaderUnloadImage (\r
IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- )\r
-;\r
+ );\r
#endif\r