TianoCore EDK2 master
Loading...
Searching...
No Matches
ElfLib.c File Reference
#include "ElfLibInternal.h"

Go to the source code of this file.

Functions

BOOLEAN IsElfFormat (IN CONST UINT8 *ImageBase)
 
EFI_STATUS CalculateElfFileSize (IN ELF_IMAGE_CONTEXT *ElfCt, OUT UINTN *FileSize)
 
EFI_STATUS GetElfSegmentInfo (IN UINT8 *ImageBase, IN UINT32 EiClass, IN UINT32 Index, OUT SEGMENT_INFO *SegInfo)
 
EFI_STATUS EFIAPI ParseElfImage (IN VOID *ImageBase, OUT ELF_IMAGE_CONTEXT *ElfCt)
 
EFI_STATUS EFIAPI LoadElfImage (IN ELF_IMAGE_CONTEXT *ElfCt)
 
EFI_STATUS EFIAPI GetElfSectionName (IN ELF_IMAGE_CONTEXT *ElfCt, IN UINT32 SectionIndex, OUT CHAR8 **SectionName)
 
EFI_STATUS EFIAPI GetElfSectionPos (IN ELF_IMAGE_CONTEXT *ElfCt, IN UINT32 Index, OUT UINTN *Offset, OUT UINTN *Size)
 

Detailed Description

ELF library

Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file ElfLib.c.

Function Documentation

◆ CalculateElfFileSize()

EFI_STATUS CalculateElfFileSize ( IN ELF_IMAGE_CONTEXT ElfCt,
OUT UINTN FileSize 
)

Calculate a ELF file size.

Parameters
[in]ElfCtELF image context pointer.
[out]FileSizeReturn the file size.
Return values
EFI_INVALID_PARAMETERElfCt or SecPos is NULL.
EFI_NOT_FOUNDCould not find the section.
EFI_SUCCESSSection posistion was filled successfully.

Definition at line 120 of file ElfLib.c.

◆ GetElfSectionName()

EFI_STATUS EFIAPI GetElfSectionName ( IN ELF_IMAGE_CONTEXT ElfCt,
IN UINT32  SectionIndex,
OUT CHAR8 **  SectionName 
)

Get a ELF section name from its index.

Parameters
[in]ElfCtELF image context pointer.
[in]SectionIndexELF section index.
[out]SectionNameThe pointer to the section name.
Return values
EFI_INVALID_PARAMETERElfCt or SecName is NULL.
EFI_NOT_FOUNDCould not find the section.
EFI_SUCCESSSection name was filled successfully.

Definition at line 392 of file ElfLib.c.

◆ GetElfSectionPos()

EFI_STATUS EFIAPI GetElfSectionPos ( IN ELF_IMAGE_CONTEXT ElfCt,
IN UINT32  Index,
OUT UINTN Offset,
OUT UINTN Size 
)

Get the offset and size of x-th ELF section.

Parameters
[in]ElfCtELF image context pointer.
[in]IndexELF section index.
[out]OffsetReturn the offset of the specific section.
[out]SizeReturn the size of the specific section.
Return values
EFI_INVALID_PARAMETERImageBase, Offset or Size is NULL.
EFI_INVALID_PARAMETEREiClass doesn't equal to ELFCLASS32 or ELFCLASS64.
EFI_NOT_FOUNDCould not find the section.
EFI_SUCCESSOffset and Size are returned.

Definition at line 446 of file ElfLib.c.

◆ GetElfSegmentInfo()

EFI_STATUS GetElfSegmentInfo ( IN UINT8 *  ImageBase,
IN UINT32  EiClass,
IN UINT32  Index,
OUT SEGMENT_INFO SegInfo 
)

Get a ELF program segment loading info.

Parameters
[in]ImageBaseImage base.
[in]EiClassELF class.
[in]IndexELF segment index.
[out]SegInfoThe pointer to the segment info.
Return values
EFI_INVALID_PARAMETERElfCt or SecPos is NULL.
EFI_NOT_FOUNDCould not find the section.
EFI_SUCCESSSection posistion was filled successfully.

Definition at line 173 of file ElfLib.c.

◆ IsElfFormat()

BOOLEAN IsElfFormat ( IN CONST UINT8 *  ImageBase)

Check if the ELF image is valid.

Parameters
[in]ImageBaseMemory address of an image.
Return values
TRUEif valid.

Definition at line 20 of file ElfLib.c.

◆ LoadElfImage()

EFI_STATUS EFIAPI LoadElfImage ( IN ELF_IMAGE_CONTEXT ElfCt)

Load the ELF image to Context.ImageAddress.

Context should be initialized by ParseElfImage(). Caller should set Context.ImageAddress to a proper value, either pointing to a new allocated memory whose size equal to Context.ImageSize, or pointing to Context.PreferredImageAddress.

Parameters
[in]ElfCtELF image context pointer.
Return values
EFI_INVALID_PARAMETERInput parameters are not valid.
EFI_UNSUPPORTEDUnsupported binary type.
EFI_LOAD_ERRORELF binary loading error.
EFI_SUCCESSELF binary is loaded successfully.

Definition at line 351 of file ElfLib.c.

◆ ParseElfImage()

EFI_STATUS EFIAPI ParseElfImage ( IN VOID *  ImageBase,
OUT ELF_IMAGE_CONTEXT ElfCt 
)

Parse the ELF image info.

On return, all fields in ElfCt are updated except ImageAddress.

Parameters
[in]ImageBaseMemory address of an image.
[out]ElfCtThe EFL image context pointer.
Return values
EFI_INVALID_PARAMETERInput parameters are not valid.
EFI_UNSUPPORTEDUnsupported binary type.
EFI_LOAD_ERRORELF binary loading error.
EFI_SUCCESSELF binary is loaded successfully.

Definition at line 229 of file ElfLib.c.