LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
elf.h File Reference

(775762e fatcreate: fix GCC detection)

#include "stdint.h"
#include "vm.h"
#include "allocator.h"
+ Include dependency graph for elf.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  elf_file_header
 Header of ELF images. More...
 
struct  elf_program_header
 Program headers in ELF images, required for preparing a program for execution. More...
 
struct  elf_section_header
 Section headers in ELF images, required to read additional information from file. More...
 
struct  elf_symbol
 Symbols in ELF images, there may be many. More...
 

Macros

#define ELF_MAGIC   0x464c457f
 

Typedefs

typedef struct elf_file_header elf_file_header_t
 
typedef struct elf_program_header elf_program_header_t
 
typedef struct elf_section_header elf_section_header_t
 
typedef struct elf_symbol elf_symbol_t
 

Functions

struct elf_file_header __attribute__ ((packed))
 
ptr_t load_elf (ptr_t elf, struct vm_table *context, ptr_t *data_start, ptr_t *data_end)
 
elf_section_header_telf_section_by_name (const char *name, const void *elf)
 
void * elf_load_symbols (ptr_t elf, allocator_t *alloc)
 
bool elf_symbolize (void *symbols, ptr_t addr, size_t *symbol_length, char *symbol)
 

Variables

uint32_t ident_magic
 
uint8_t ident_arch
 
uint8_t ident_byteOrder
 
uint8_t ident_version
 
uint8_t ident_abi
 
uint8_t ident_abi_version
 
uint8_t _ident_padding [7]
 
uint16_t type
 
uint16_t machine
 
uint32_t version
 
ptr_t entrypoint
 
ptr_t programHeaderOffset
 
ptr_t sectionHeaderOffset
 
uint32_t flags
 
uint16_t headerSize
 
uint16_t programHeaderEntrySize
 
uint16_t programHeaderCount
 
uint16_t sectionHeaderEntrySize
 
uint16_t sectionHeaderCount
 
uint16_t sectionHeaderSectionNameIndex
 
uint64_t offset
 
uint64_t vaddr
 
uint64_t paddr
 
uint64_t fileLength
 
uint64_t memLength
 
uint64_t align
 
uint32_t name
 
ptr_t addr
 
uint64_t size
 
uint32_t link
 
uint32_t info
 
uint64_t addralign
 
uint64_t entrySize
 
uint8_t other
 
uint16_t sectionHeader
 

Data Structure Documentation

◆ elf_file_header

struct elf_file_header

Header of ELF images.

Definition at line 11 of file elf.h.

+ Collaboration diagram for elf_file_header:
Data Fields
uint8_t _ident_padding[7]
ptr_t entrypoint
uint32_t flags
uint16_t headerSize
uint8_t ident_abi
uint8_t ident_abi_version
uint8_t ident_arch
uint8_t ident_byteOrder
uint32_t ident_magic
uint8_t ident_version
uint16_t machine
uint16_t programHeaderCount
uint16_t programHeaderEntrySize
ptr_t programHeaderOffset
uint16_t sectionHeaderCount
uint16_t sectionHeaderEntrySize
ptr_t sectionHeaderOffset
uint16_t sectionHeaderSectionNameIndex
uint16_t type
uint32_t version

◆ elf_program_header

struct elf_program_header

Program headers in ELF images, required for preparing a program for execution.

Definition at line 44 of file elf.h.

+ Collaboration diagram for elf_program_header:
Data Fields
uint64_t align
uint64_t fileLength
uint32_t flags
uint64_t memLength
uint64_t offset
uint64_t paddr
uint32_t type
uint64_t vaddr

◆ elf_section_header

struct elf_section_header

Section headers in ELF images, required to read additional information from file.

Definition at line 59 of file elf.h.

+ Collaboration diagram for elf_section_header:
Data Fields
ptr_t addr
uint64_t addralign
uint64_t entrySize
uint64_t flags
uint32_t info
uint32_t link
uint32_t name
uint64_t offset
uint64_t size
uint32_t type

◆ elf_symbol

struct elf_symbol

Symbols in ELF images, there may be many.

Definition at line 74 of file elf.h.

+ Collaboration diagram for elf_symbol:
Data Fields
uint64_t addr
uint8_t info
uint32_t name
uint8_t other
uint16_t sectionHeader
uint64_t size

Macro Definition Documentation

◆ ELF_MAGIC

#define ELF_MAGIC   0x464c457f

Definition at line 8 of file elf.h.

Typedef Documentation

◆ elf_file_header_t

Definition at line 41 of file elf.h.

◆ elf_program_header_t

Definition at line 56 of file elf.h.

◆ elf_section_header_t

Definition at line 71 of file elf.h.

◆ elf_symbol_t

typedef struct elf_symbol elf_symbol_t

Definition at line 82 of file elf.h.

Function Documentation

◆ __attribute__()

struct elf_file_header __attribute__ ( (packed)  )

Definition at line 28 of file hpet.c.

◆ elf_load_symbols()

void * elf_load_symbols ( ptr_t  elf,
allocator_t alloc 
)

Load symbols of the provided ELF file.

Parameters
elfELF file already loaded into memory
allocAllocator to use for dynamically allocating memory
Returns
Pointer to a opaque data structure containing the symbols, use elf_symbolize to retrieve the symbol for a given address

Definition at line 101 of file elf.c.

References elf_symbol::addr, Symbol::address, allocator::alloc, alloc, elf_section_by_name(), elf_section_header::entrySize, header, logw, memcpy(), Symbol::name, elf_symbol::name, SymbolData::numSymbols, elf_section_header::offset, and elf_section_header::size.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ elf_section_by_name()

elf_section_header_t * elf_section_by_name ( const char *  name,
const void *  elf 
)

Return section header of ELF file by name

Parameters
nameName of the section to return
elfLoaded ELF image in memory
Returns
Pointer to elf_section_header_t if found, NULL otherwise

Definition at line 71 of file elf.c.

References name, elf_section_header::name, elf_section_header::offset, elf_file_header::sectionHeaderCount, elf_file_header::sectionHeaderEntrySize, elf_file_header::sectionHeaderOffset, elf_file_header::sectionHeaderSectionNameIndex, and strcmp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ elf_symbolize()

bool elf_symbolize ( void *  symbols,
ptr_t  addr,
size_t symbol_length,
char *  symbol 
)

Get the symbol name (and offset) for a given address from the data loaded with elf_load_symbols.

Parameters
symbolsOpaque data structure returned by elf_load_symbols
addrAddress to symbolize
symbol_lengthInput for size of the buffer where to write symbol, output actual size of either the data written into the buffer or the size needed for the buffer
symbolOutput buffer where to write the symbol
Returns
true if a symbol was found and the output buffer had enough space, false if no symbol was found or output buffer was too small. Output buffer to small can be recognized by symbol_length being set to a non-zero value.

Definition at line 133 of file elf.c.

References addr, Symbol::address, ksnprintf(), Symbol::name, SymbolData::numSymbols, strlen(), strncpy(), SymbolData::symbolNames, and SymbolData::symbols.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_elf()

ptr_t load_elf ( ptr_t  elf,
struct vm_table context,
ptr_t data_start,
ptr_t data_end 
)

Parse ELF file, map program segments to context and return proper location for stack.

Parameters
[in]elfMemory chunk where the ELF file is loaded.
[in]contextVM context for mapping of program segments.
[out]data_startStart of the data section
[out]data_endEnd of the data section
Returns
Entrypoint of the image

Definition at line 7 of file elf.c.

References ALLOCATOR_REGION_DIRECT_MAPPING, data_end, ELF_MAGIC, fileLength, elf_program_header::fileLength, header, logf, memcpy(), elf_program_header::memLength, memset(), mm_alloc_pages(), offset, elf_program_header::offset, elf_program_header::type, elf_program_header::vaddr, and vm_context_map().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ _ident_padding

uint8_t _ident_padding[7]

Definition at line 8 of file elf.h.

◆ addr

uint64_t addr

Definition at line 3 of file elf.h.

◆ addralign

uint64_t addralign

Definition at line 8 of file elf.h.

◆ align

uint64_t align

Definition at line 9 of file elf.h.

◆ entrypoint

ptr_t entrypoint

Definition at line 15 of file elf.h.

◆ entrySize

uint64_t entrySize

Definition at line 9 of file elf.h.

◆ fileLength

uint64_t fileLength

Definition at line 6 of file elf.h.

◆ flags

uint64_t flags

Definition at line 19 of file elf.h.

◆ headerSize

uint16_t headerSize

Definition at line 20 of file elf.h.

◆ ident_abi

uint8_t ident_abi

Definition at line 5 of file elf.h.

◆ ident_abi_version

uint8_t ident_abi_version

Definition at line 6 of file elf.h.

◆ ident_arch

uint8_t ident_arch

Definition at line 1 of file elf.h.

◆ ident_byteOrder

uint8_t ident_byteOrder

Definition at line 2 of file elf.h.

◆ ident_magic

uint32_t ident_magic

Definition at line 0 of file elf.h.

◆ ident_version

uint8_t ident_version

Definition at line 3 of file elf.h.

◆ info

uint8_t info

Definition at line 7 of file elf.h.

◆ link

uint32_t link

Definition at line 6 of file elf.h.

◆ machine

uint16_t machine

Definition at line 11 of file elf.h.

◆ memLength

uint64_t memLength

Definition at line 7 of file elf.h.

◆ name

uint32_t name

Definition at line 0 of file elf.h.

◆ offset

uint64_t offset

Definition at line 3 of file elf.h.

◆ other

uint8_t other

Definition at line 2 of file elf.h.

◆ paddr

uint64_t paddr

Definition at line 5 of file elf.h.

◆ programHeaderCount

uint16_t programHeaderCount

Definition at line 23 of file elf.h.

◆ programHeaderEntrySize

uint16_t programHeaderEntrySize

Definition at line 22 of file elf.h.

◆ programHeaderOffset

ptr_t programHeaderOffset

Definition at line 16 of file elf.h.

◆ sectionHeader

uint16_t sectionHeader

Definition at line 3 of file elf.h.

◆ sectionHeaderCount

uint16_t sectionHeaderCount

Definition at line 26 of file elf.h.

◆ sectionHeaderEntrySize

uint16_t sectionHeaderEntrySize

Definition at line 25 of file elf.h.

◆ sectionHeaderOffset

ptr_t sectionHeaderOffset

Definition at line 17 of file elf.h.

◆ sectionHeaderSectionNameIndex

uint16_t sectionHeaderSectionNameIndex

Definition at line 27 of file elf.h.

◆ size

uint64_t size

Definition at line 5 of file elf.h.

◆ type

uint32_t type

Definition at line 10 of file elf.h.

◆ vaddr

uint64_t vaddr

Definition at line 4 of file elf.h.

◆ version

uint32_t version

Definition at line 13 of file elf.h.