MentOS  0.8.0
The Mentoring Operating System
Classes | Macros | Typedefs | Enumerations | Functions
elf.h File Reference

Function for managing the Executable and Linkable Format (ELF). More...

Go to the source code of this file.

Classes

struct  elf_header
 The elf starting section. More...
 
struct  elf_program_header
 The elf program header, holding program layout information. More...
 
struct  elf_section_header
 A section header with all kinds of useful information. More...
 
struct  elf_symbol
 A symbol itself. More...
 
struct  elf_rel_t
 Holds information about relocation object (that do not need an addend). More...
 
struct  elf_rela_t
 Holds information about relocation object (that need an addend). More...
 

Macros

#define PT_NULL   0
 Unused.
 
#define PT_LOAD   1
 Specifies a loadable segment, described by p_filesz and p_memsz. The bytes from the file are mapped to the beginning of the memory segment. If the segment's memory size (p_memsz) is larger than the file size (p_filesz), the extra bytes are defined to hold the value 0 and to follow the segment's initialized area. The file size can not be larger than the memory size. Loadable segment entries in the program header table appear in ascending order, sorted on the p_vaddr member.
 
#define PT_DYNAMIC   2
 Specifies dynamic linking information.
 
#define PT_INTERP   3
 Specifies the location and size of a null-terminated path name to invoke as an interpreter. This segment type is mandatory for dynamic executable files and can occur in shared objects. It cannot occur more than once in a file. This type, if present, it must precede any loadable segment entry.
 
#define PT_NOTE   4
 Specifies the location and size of auxiliary information.
 
#define PT_SHLIB   5
 Reserved but has unspecified semantics.
 
#define PT_PHDR   6
 Specifies the location and size of the program header table itself, both in the file and in the memory image of the program. This segment type cannot occur more than once in a file. Moreover, it can occur only if the program header table is part of the memory image of the program. This type, if present, must precede any loadable segment entry.
 
#define PT_EH_FRAME   0x6474E550
 Section for supporting exception handling routines. More...
 
#define PT_GNU_STACK   0x6474E551
 Is a program header which tells the system how to control the stack when the ELF is loaded into memory.
 
#define PT_GNU_RELRO   0x6474E552
 This segment indicates the memory region which should be made Read-Only after relocation is done. This segment usually appears in a dynamic link library and it contains .ctors, .dtors, .dynamic, .got s ections. See paragraph below.
 
#define PT_LOPROC   0x70000000
 TODO: Document.
 
#define PT_HIPROC   0x7FFFFFFF
 TODO: Document.
 
#define EI_NIDENT   16
 Elf header ident size.
 
#define ELFMAG0   0x7F
 e_ident[EI_MAG0]
 
#define ELFMAG1   'E'
 e_ident[EI_MAG1]
 
#define ELFMAG2   'L'
 e_ident[EI_MAG2]
 
#define ELFMAG3   'F'
 e_ident[EI_MAG3]
 
#define ELFDATA2LSB   1
 Little Endian.
 
#define ELFCLASS32   1
 32-bit Architecture
 
#define EM_386   3
 x86 Machine Type.
 
#define EV_CURRENT   1
 ELF Current Version.
 
#define ELF32_ST_BIND(INFO)   ((INFO) >> 4)
 Provide access to teh symbol biding.
 
#define ELF32_ST_TYPE(INFO)   ((INFO)&0x0F)
 Provide access to teh symbol type.
 

Typedefs

typedef struct elf_header elf_header_t
 The elf starting section.
 
typedef struct elf_program_header elf_program_header_t
 The elf program header, holding program layout information.
 
typedef struct elf_section_header elf_section_header_t
 A section header with all kinds of useful information.
 
typedef struct elf_symbol elf_symbol_t
 A symbol itself.
 
typedef struct elf_rel_t elf_rel_t
 Holds information about relocation object (that do not need an addend).
 
typedef struct elf_rela_t elf_rela_t
 Holds information about relocation object (that need an addend).
 
typedef enum Elf_Type Elf_Type
 Type of ELF files.
 
typedef enum ShT_Types ShT_Types
 Defines a number of different types of sections, which correspond to values stored in the field sh_type in the section header.
 

Enumerations

enum  Elf_Ident {
  EI_MAG0 = 0 , EI_MAG1 = 1 , EI_MAG2 = 2 , EI_MAG3 = 3 ,
  EI_CLASS = 4 , EI_DATA = 5 , EI_VERSION = 6 , EI_OSABI = 7 ,
  EI_ABIVERSION = 8 , EI_PAD = 9
}
 Fields index of ELF_IDENT. More...
 
enum  Elf_Type { ET_NONE = 0 , ET_REL = 1 , ET_EXEC = 2 }
 Type of ELF files. More...
 
enum  ShT_Types {
  SHT_NULL = 0 , SHT_PROGBITS = 1 , SHT_SYMTAB = 2 , SHT_STRTAB = 3 ,
  SHT_RELA = 4 , SHT_NOBITS = 8 , SHT_REL = 9
}
 Defines a number of different types of sections, which correspond to values stored in the field sh_type in the section header. More...
 
enum  ShT_Attributes { SHF_WRITE = 0x01 , SHF_ALLOC = 0x02 }
 ShT_Attributes corresponds to the field sh_flags, but are bit flags rather than stand-alone values. More...
 
enum  StT_Bindings { STB_LOCAL = 0 , STB_GLOBAL = 1 , STB_WEAK = 2 }
 Provides possible symbol bindings. More...
 
enum  StT_Types { STT_NOTYPE = 0 , STT_OBJECT = 1 , STT_FUNC = 2 }
 Provides a number of possible symbol types. More...
 

Functions

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 *hdr)
 Checks the correctness of the ELF header. More...
 
int elf_check_magic_number (elf_header_t *hdr)
 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 managing the Executable and Linkable Format (ELF).

Enumeration Type Documentation

◆ Elf_Ident

enum Elf_Ident

Fields index of ELF_IDENT.

Enumerator
EI_MAG0 

0x7F

EI_MAG1 

'E'

EI_MAG2 

'L'

EI_MAG3 

'F'

EI_CLASS 

Architecture (32/64)

EI_DATA 

Set to either 1 or 2 to signify little or big endianness.

EI_VERSION 

ELF Version.

EI_OSABI 

OS Specific.

EI_ABIVERSION 

OS Specific.

EI_PAD 

Padding.

◆ Elf_Type

enum Elf_Type

Type of ELF files.

Enumerator
ET_NONE 

Unkown Type.

ET_REL 

Relocatable File.

ET_EXEC 

Executable File.

◆ ShT_Attributes

ShT_Attributes corresponds to the field sh_flags, but are bit flags rather than stand-alone values.

Enumerator
SHF_WRITE 

Writable section.

SHF_ALLOC 

Exists in memory.

◆ ShT_Types

enum ShT_Types

Defines a number of different types of sections, which correspond to values stored in the field sh_type in the section header.

Enumerator
SHT_NULL 

Null section.

SHT_PROGBITS 

Program information.

SHT_SYMTAB 

Symbol table.

SHT_STRTAB 

String table.

SHT_RELA 

Relocation (w/ addend)

SHT_NOBITS 

Not present in file.

SHT_REL 

Relocation (no addend)

◆ StT_Bindings

Provides possible symbol bindings.

Enumerator
STB_LOCAL 

Local scope.

STB_GLOBAL 

Global scope.

STB_WEAK 

Weak, (ie. attribute((weak)))

◆ StT_Types

enum StT_Types

Provides a number of possible symbol types.

Enumerator
STT_NOTYPE 

No type.

STT_OBJECT 

Variables, arrays, etc.

STT_FUNC 

Methods or functions.

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_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.