FreeNOS
Public Member Functions | Static Public Member Functions
ELF Class Reference

Executable and Linkable Format (ELF). More...

#include <ELF.h>

Inheritance diagram for ELF:
ExecutableFormat

Public Member Functions

 ELF (const u8 *image, const Size size)
 Class constructor. More...
 
virtual ~ELF ()
 Class destructor. More...
 
virtual Result regions (Region *regions, Size *count) const
 Reads out segments from the ELF program table. More...
 
virtual Result entry (Address *entry) const
 Lookup the program entry point. More...
 
- Public Member Functions inherited from ExecutableFormat
 ExecutableFormat (const u8 *image, const Size size)
 Class constructor. More...
 
virtual ~ExecutableFormat ()
 Class destructor. More...
 

Static Public Member Functions

static Result detect (const u8 *image, const Size size, ExecutableFormat **fmt)
 Read ELF header from memory. More...
 
- Static Public Member Functions inherited from ExecutableFormat
static Result find (const u8 *image, const Size size, ExecutableFormat **fmt)
 Find a ExecutableFormat which can handle the given format. More...
 

Additional Inherited Members

- Public Types inherited from ExecutableFormat
enum  Result { Success, NotFound, InvalidFormat, OutOfMemory }
 Result code. More...
 
typedef struct ExecutableFormat::Region Region
 Memory region. More...
 
- Protected Attributes inherited from ExecutableFormat
const u8m_image
 Input image raw data. More...
 
const Size m_size
 Input image size in bytes. More...
 

Detailed Description

Executable and Linkable Format (ELF).

Definition at line 37 of file ELF.h.

Constructor & Destructor Documentation

◆ ELF()

ELF::ELF ( const u8 image,
const Size  size 
)

Class constructor.

Parameters
imagePointer to raw input image data
sizeNumber of bytes of input image data

Definition at line 21 of file ELF.cpp.

Referenced by detect().

◆ ~ELF()

ELF::~ELF ( )
virtual

Class destructor.

Definition at line 26 of file ELF.cpp.

Member Function Documentation

◆ detect()

ELF::Result ELF::detect ( const u8 image,
const Size  size,
ExecutableFormat **  fmt 
)
static

Read ELF header from memory.

Parameters
imagePointer to raw input image data
sizeNumber of bytes of input image data
fmtOutputs a pointer to an ELF instance
Returns
Result code

Definition at line 30 of file ELF.cpp.

References ELF(), ELF_CLASS_32, ELF_INDEX_CLASS, ELF_INDEX_MAGIC0, ELF_INDEX_MAGIC1, ELF_INDEX_MAGIC2, ELF_INDEX_MAGIC3, ELF_MAGIC0, ELF_MAGIC1, ELF_MAGIC2, ELF_MAGIC3, ELF_TYPE_EXEC, ELF_VERSION_CURRENT, header, ExecutableFormat::InvalidFormat, and ExecutableFormat::Success.

Referenced by ExecutableFormat::find().

◆ entry()

ELF::Result ELF::entry ( Address entry) const
virtual

Lookup the program entry point.

Parameters
entryProgram entry point on output.
Returns
Result code.

Implements ExecutableFormat.

Definition at line 87 of file ELF.cpp.

References header, ExecutableFormat::m_image, and ExecutableFormat::Success.

◆ regions()

ELF::Result ELF::regions ( ELF::Region regions,
Size count 
) const
virtual

Reads out segments from the ELF program table.

Parameters
regionsMemory regions to fill.
countMaximum number of memory regions on input. Actual number of memory regions on output.
Returns
Result code.
Todo:
Rework executables to avoid giving all mapped regions read, write and execute permissions.

Implements ExecutableFormat.

Definition at line 52 of file ELF.cpp.

References ELF_SEGMENT_LOAD, Memory::Executable, ELFSegment::fileSize, header, ExecutableFormat::InvalidFormat, ExecutableFormat::m_image, ELFSegment::memorySize, ELFSegment::offset, Memory::Readable, ExecutableFormat::Success, type, Memory::User, ELFSegment::virtualAddress, and Memory::Writable.


The documentation for this class was generated from the following files: