TianoCore EDK2 master
Loading...
Searching...
No Matches
BasePeCoffLibInternals.h File Reference
#include <Base.h>
#include <Library/PeCoffLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/PeCoffExtraActionLib.h>
#include <IndustryStandard/PeImage.h>

Go to the source code of this file.

Macros

#define RV_X(x, s, n)   (((x) >> (s)) & ((1<<(n))-1))
 
#define RISCV_IMM_BITS   12
 
#define RISCV_IMM_REACH   (1LL<<RISCV_IMM_BITS)
 
#define RISCV_CONST_HIGH_PART(VALUE)    (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
 

Functions

RETURN_STATUS PeCoffLoaderRelocateImageEx (IN UINT16 *Reloc, IN OUT CHAR8 *Fixup, IN OUT CHAR8 **FixupData, IN UINT64 Adjust)
 
RETURN_STATUS PeHotRelocateImageEx (IN UINT16 *Reloc, IN OUT CHAR8 *Fixup, IN OUT CHAR8 **FixupData, IN UINT64 Adjust)
 
BOOLEAN PeCoffLoaderImageFormatSupported (IN UINT16 Machine)
 
UINT16 PeCoffLoaderGetPeHeaderMagicValue (IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr)
 
RETURN_STATUS PeCoffLoaderGetPeHeader (IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr)
 
VOID * PeCoffLoaderImageAddress (IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, IN UINTN Address, IN UINTN TeStrippedOffset)
 

Detailed Description

Declaration of internal functions in PE/COFF Lib.

Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file BasePeCoffLibInternals.h.

Macro Definition Documentation

◆ RISCV_CONST_HIGH_PART

#define RISCV_CONST_HIGH_PART (   VALUE)     (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))

Definition at line 26 of file BasePeCoffLibInternals.h.

◆ RISCV_IMM_BITS

#define RISCV_IMM_BITS   12

Definition at line 24 of file BasePeCoffLibInternals.h.

◆ RISCV_IMM_REACH

#define RISCV_IMM_REACH   (1LL<<RISCV_IMM_BITS)

Definition at line 25 of file BasePeCoffLibInternals.h.

◆ RV_X

#define RV_X (   x,
  s,
 
)    (((x) >> (s)) & ((1<<(n))-1))

Definition at line 23 of file BasePeCoffLibInternals.h.

Function Documentation

◆ PeCoffLoaderGetPeHeader()

RETURN_STATUS PeCoffLoaderGetPeHeader ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT ImageContext,
OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr 
)

Retrieves the PE or TE Header from a PE/COFF or TE image.

Parameters
ImageContextThe context of the image being loaded.
HdrThe buffer in which to return the PE32, PE32+, or TE header.
Return values
RETURN_SUCCESSThe PE or TE Header is read.
OtherThe error status from reading the PE/COFF or TE image using the ImageRead function.

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.

Parameters
ImageContextThe context of the image being loaded.
HdrThe buffer in which to return the PE32, PE32+, or TE header.
Return values
RETURN_SUCCESSThe PE or TE Header is read.
OtherThe error status from reading the PE/COFF or TE image using the ImageRead function.

Definition at line 61 of file BasePeCoff.c.

◆ PeCoffLoaderGetPeHeaderMagicValue()

UINT16 PeCoffLoaderGetPeHeaderMagicValue ( IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr)

Retrieves the magic value from the PE/COFF header.

Parameters
HdrThe buffer in which to return the PE32, PE32+, or TE header.
Returns
EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+

◆ PeCoffLoaderImageAddress()

VOID * PeCoffLoaderImageAddress ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT ImageContext,
IN UINTN  Address,
IN UINTN  TeStrippedOffset 
)

Converts an image address to the loaded address.

Parameters
ImageContextThe context of the image being loaded.
AddressThe address to be converted to the loaded address.
TeStrippedOffsetStripped offset for TE image.
Returns
The converted address or NULL if the address can not be converted.

Definition at line 907 of file BasePeCoff.c.

◆ PeCoffLoaderImageFormatSupported()

BOOLEAN PeCoffLoaderImageFormatSupported ( IN UINT16  Machine)

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.

Parameters
MachineMachine type from the PE Header.
Returns
TRUE if this PE/COFF loader can load the image

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.

Parameters
[in]MachineMachine type from the PE Header.
Returns
TRUE if this PE/COFF loader can load the image

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.

The IA32/X64 version PE/COFF loader/relocater both support IA32, X64 and EBC images.

Parameters
MachineThe machine type from the PE Header.
Returns
TRUE if this PE/COFF loader can load the image

Definition at line 179 of file PeCoffLoaderEx.c.

◆ PeCoffLoaderRelocateImageEx()

RETURN_STATUS PeCoffLoaderRelocateImageEx ( IN UINT16 *  Reloc,
IN OUT CHAR8 *  Fixup,
IN OUT CHAR8 **  FixupData,
IN UINT64  Adjust 
)

Performs an Itanium-based specific relocation fixup and is a no-op on other instruction sets.

Parameters
RelocThe pointer to the relocation record.
FixupThe pointer to the address to fix up.
FixupDataThe pointer to a buffer to log the fixups.
AdjustThe offset to adjust the fixup.
Returns
Status code.

Performs an ARM-based specific relocation fixup and is a no-op on other instruction sets.

Parameters
RelocThe pointer to the relocation record.
FixupThe pointer to the address to fix up.
FixupDataThe pointer to a buffer to log the fixups.
AdjustThe offset to adjust the fixup.
Returns
Status code.

Performs an LoongArch specific relocation fixup and is a no-op on other instruction sets.

Parameters
[in]RelocPointer to the relocation record.
[in,out]FixupPointer to the address to fix up.
[in,out]FixupDataPointer to a buffer to log the fixups.
[in]AdjustThe offset to adjust the fixup.
Returns
Status code.

Performs an RISC-V specific relocation fixup and is a no-op on other instruction sets. RISC-V splits 32-bit fixup into 20bit and 12-bit with two relocation types. We have to know the lower 12-bit fixup first then we can deal carry over on high 20-bit fixup. So we log the high 20-bit in FixupData.

Parameters
RelocThe pointer to the relocation record.
FixupThe pointer to the address to fix up.
FixupDataThe pointer to a buffer to log the fixups.
AdjustThe offset to adjust the fixup.
Returns
Status code.

Definition at line 131 of file PeCoffLoaderEx.c.

◆ PeHotRelocateImageEx()

RETURN_STATUS PeHotRelocateImageEx ( IN UINT16 *  Reloc,
IN OUT CHAR8 *  Fixup,
IN OUT CHAR8 **  FixupData,
IN UINT64  Adjust 
)

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.

Parameters
RelocThe pointer to the relocation record.
FixupThe pointer to the address to fix up.
FixupDataThe pointer to a buffer to log the fixups.
AdjustThe offset to adjust the fixup.
Returns
Status code.

Performs an ARM-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.

Parameters
RelocThe pointer to the relocation record.
FixupThe pointer to the address to fix up.
FixupDataThe pointer to a buffer to log the fixups.
AdjustThe offset to adjust the fixup.
Returns
Status code.

Performs an LOONGARCH-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.

Parameters
[in]RelocThe pointer to the relocation record.
[in,out]FixupThe pointer to the address to fix up.
[in,out]FixupDataThe pointer to a buffer to log the fixups.
[in]AdjustThe offset to adjust the fixup.
Returns
Status code.

Definition at line 204 of file PeCoffLoaderEx.c.