MentOS  0.8.0
The Mentoring Operating System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions
elf.c File Reference

Function for multiboot support. More...

Macros

#define __DEBUG_HEADER__   "[ELF ]"
 Change header.
 
#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Set log level.
 

Functions

static elf_section_header_telf_get_section_header_table (elf_header_t *header)
 Returns the pointer to where the section headers reside. More...
 
static elf_program_header_telf_get_program_header_table (elf_header_t *header)
 Returns the pointer to where the program headers reside. More...
 
static elf_section_header_telf_get_section_header (elf_header_t *header, unsigned idx)
 Returns a pointer to the desired section header. More...
 
static elf_program_header_telf_get_program_header (elf_header_t *header, unsigned idx)
 Returns a pointer to the desired program header. More...
 
static const char * elf_get_section_header_string_table (elf_header_t *header)
 Returns a pointer to the section header string table. More...
 
static const char * elf_get_symbol_string_table (elf_header_t *header, elf_section_header_t *section_header)
 Returns a pointer to the section header symbol table. More...
 
static const char * elf_get_section_header_name (elf_header_t *header, elf_section_header_t *section_header)
 Returns the name of the given section header. More...
 
static const char * elf_get_symbol_name (elf_header_t *header, elf_section_header_t *section_header, elf_symbol_t *symbol)
 Returns a pointer to the section header string table. More...
 
static elf_section_header_telf_find_section_header (elf_header_t *header, const char *name)
 Finds the section header with the given name. More...
 
static elf_symbol_telf_find_symbol (elf_header_t *header, const char *name)
 Finds the symbol with the given name. More...
 
static void elf_dump_section_headers (elf_header_t *header)
 Dumps the information about the sections. More...
 
static void elf_dump_symbol_table (elf_header_t *header)
 Dumps the information about the symbols. More...
 
static int elf_load_exec (elf_header_t *header, task_struct *task)
 Loads an ELF executable. More...
 
int elf_load_file (task_struct *task, vfs_file_t *file, uint32_t *entry)
 Loads an ELF file into the memory of task. More...
 
int elf_check_file_type (vfs_file_t *file, Elf_Type type)
 Checks if the file is a valid ELF. More...
 
int elf_check_file_header (elf_header_t *header)
 Checks the correctness of the ELF header. More...
 
int elf_check_magic_number (elf_header_t *header)
 Checks the correctness of the ELF header magic number. More...
 
const char * elf_type_to_string (int type)
 Transforms the passed ELF type to string. More...
 
const char * elf_section_header_type_to_string (int type)
 Transforms the passed ELF section header type to string. More...
 
const char * elf_symbol_type_to_string (int type)
 Transforms the passed ELF symbol type to string. More...
 
const char * elf_symbol_bind_to_string (int bind)
 Transforms the passed ELF symbol bind to string. More...
 

Detailed Description

Function for multiboot support.

Function Documentation

◆ elf_check_file_header()

int elf_check_file_header ( elf_header_t hdr)

Checks the correctness of the ELF header.

Parameters
hdrThe header to check.
Returns
0 if fails, 1 if succeed.

◆ elf_check_file_type()

int elf_check_file_type ( vfs_file_t file,
Elf_Type  type 
)

Checks if the file is a valid ELF.

Parameters
fileThe file to check.
typeThe type of ELF file we expect.
Returns
0 if fails, 1 if succeed.

◆ elf_check_magic_number()

int elf_check_magic_number ( elf_header_t hdr)

Checks the correctness of the ELF header magic number.

Parameters
hdrThe header to check.
Returns
0 if fails, 1 if succeed.

◆ elf_dump_section_headers()

static void elf_dump_section_headers ( elf_header_t header)
inlinestatic

Dumps the information about the sections.

Parameters
headera pointer to the ELF header.

◆ elf_dump_symbol_table()

static void elf_dump_symbol_table ( elf_header_t header)
inlinestatic

Dumps the information about the symbols.

Parameters
headera pointer to the ELF header.

◆ elf_find_section_header()

static elf_section_header_t* elf_find_section_header ( elf_header_t header,
const char *  name 
)
inlinestatic

Finds the section header with the given name.

Parameters
headera pointer to the ELF header.
namethe name of the section we are looking for.
Returns
a pointer to the section header.

◆ elf_find_symbol()

static elf_symbol_t* elf_find_symbol ( elf_header_t header,
const char *  name 
)
inlinestatic

Finds the symbol with the given name.

Parameters
headera pointer to the ELF header.
namethe name of the symbol we are looking for.
Returns
a pointer to the symbol.

◆ elf_get_program_header()

static elf_program_header_t* elf_get_program_header ( elf_header_t header,
unsigned  idx 
)
inlinestatic

Returns a pointer to the desired program header.

Parameters
headera pointer to the ELF header.
idxthe index of the program header.
Returns
a pointer to the desired section header.

◆ elf_get_program_header_table()

static elf_program_header_t* elf_get_program_header_table ( elf_header_t header)
inlinestatic

Returns the pointer to where the program headers reside.

Parameters
headera pointer to the ELF header.
Returns
a pointer to the program headers table.

◆ elf_get_section_header()

static elf_section_header_t* elf_get_section_header ( elf_header_t header,
unsigned  idx 
)
inlinestatic

Returns a pointer to the desired section header.

Parameters
headera pointer to the ELF header.
idxThe index of the section header.
Returns
a pointer to the desired section header.

◆ elf_get_section_header_name()

static const char* elf_get_section_header_name ( elf_header_t header,
elf_section_header_t section_header 
)
inlinestatic

Returns the name of the given section header.

Parameters
headera pointer to the ELF header.
section_headera pointer to the section header.
Returns
a pointer to the name, or NULL on failure.

◆ elf_get_section_header_string_table()

static const char* elf_get_section_header_string_table ( elf_header_t header)
inlinestatic

Returns a pointer to the section header string table.

Parameters
headera pointer to the ELF header.
Returns
a pointer to the section header string table, or NULL on failure.

◆ elf_get_section_header_table()

static elf_section_header_t* elf_get_section_header_table ( elf_header_t header)
inlinestatic

Returns the pointer to where the section headers reside.

Parameters
headera pointer to the ELF header.
Returns
a pointer to the section headers table.

◆ elf_get_symbol_name()

static const char* elf_get_symbol_name ( elf_header_t header,
elf_section_header_t section_header,
elf_symbol_t symbol 
)
inlinestatic

Returns a pointer to the section header string table.

Parameters
headera pointer to the ELF header.
section_headera pointer to the section header.
symbola pointer to the symbol we want to get the name for.
Returns
a pointer to the section header string table, or NULL on failure.

◆ elf_get_symbol_string_table()

static const char* elf_get_symbol_string_table ( elf_header_t header,
elf_section_header_t section_header 
)
inlinestatic

Returns a pointer to the section header symbol table.

Parameters
headera pointer to the ELF header.
section_headera pointer to the ELF section header.
Returns
a pointer to the section header symbol table, or NULL on failure.

◆ elf_load_exec()

static int elf_load_exec ( elf_header_t header,
task_struct task 
)
inlinestatic

Loads an ELF executable.

Parameters
headerThe header of the ELF file.
taskThe task for which we load the ELF.
Returns
The ELF entry.

◆ elf_load_file()

int elf_load_file ( task_struct task,
vfs_file_t file,
uint32_t entry 
)

Loads an ELF file into the memory of task.

Parameters
taskThe task for which we load the ELF.
fileThe ELF file.
entryThe ELF binary entry.
Returns
0 if fails, 1 if succeed.

◆ elf_section_header_type_to_string()

const char* elf_section_header_type_to_string ( int  type)

Transforms the passed ELF section header type to string.

Parameters
typeThe integer representing the ELF section header type.
Returns
The string representing the ELF section header type.

◆ elf_symbol_bind_to_string()

const char* elf_symbol_bind_to_string ( int  bind)

Transforms the passed ELF symbol bind to string.

Parameters
bindThe integer representing the ELF symbol bind.
Returns
The string representing the ELF symbol bind.

◆ elf_symbol_type_to_string()

const char* elf_symbol_type_to_string ( int  type)

Transforms the passed ELF symbol type to string.

Parameters
typeThe integer representing the ELF symbol type.
Returns
The string representing the ELF symbol type.

◆ elf_type_to_string()

const char* elf_type_to_string ( int  type)

Transforms the passed ELF type to string.

Parameters
typeThe integer representing the ELF type.
Returns
The string representing the ELF type.