UnnamedOS

Executable and Linking Format. More...

+ Collaboration diagram for ELF:

Data Structures

struct  elf_program_header_entry_t
 program header entries tell us how to load executables More...
 
struct  elf_header_t
 The ELF header at the start of every ELF file. More...
 

Macros

#define MAGIC_0   0x7F
 magic value expected at the beginning of an ELF file
 
#define MAGIC_1   'E'
 magic value expected at the beginning of an ELF file
 
#define MAGIC_2   'L'
 magic value expected at the beginning of an ELF file
 
#define MAGIC_3   'F'
 magic value expected at the beginning of an ELF file
 
#define VERSION   1
 only ELF version 1 is supported (the current version)
 

Typedefs

typedef elf_header_t elf_t
 an ELF file starts with the header
 

Enumerations

enum  elf_class { CLASS_32_BIT = 1, CLASS_64_BIT }
 32 or 64 bit
 
enum  elf_data { DATA_LITTLE_ENDIAN = 1, DATA_BIG_ENDIAN }
 little or big endian
 
enum  elf_type { TYPE_RELOCATABLE = 1, TYPE_EXECUTABLE, TYPE_SHARED, TYPE_CORE }
 object type
 
enum  elf_machine { MACHINE_X86 = 3 }
 targeted ISA, we are only interested in x86
 

Functions

static uint8_t elf_check (elf_t *elf)
 Checks whether a pointer points to a valid ELF file for this OS. More...
 
void * elf_load (elf_t *elf, page_directory_t *page_directory)
 Loads the segments of an ELF file into memory. More...
 
void elf_unload (elf_t *elf, page_directory_t *page_directory)
 Frees the segments of an ELF file in memory. More...
 
task_pid_t elf_create_task (elf_t *elf, size_t kernel_stack_len, size_t user_stack_len)
 Creates a user task running the code of an ELF file. More...
 
void elf_destroy_task (task_pid_t pid)
 Destroys a user task running the code of an ELF file. More...
 

Detailed Description

Executable and Linking Format.

ELF files are used to execute external programs in user space.

See also
https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
http://wiki.osdev.org/ELF
http://lowlevel.eu/wiki/ELF
http://www.linux-kernel.de/appendix/ap05.pdf

Function Documentation

static uint8_t elf_check ( elf_t elf)
static

Checks whether a pointer points to a valid ELF file for this OS.

Parameters
elfthe start address of the ELF file in memory
Returns
whether it is a valid ELF file

Definition at line 56 of file elf.c.

+ Here is the caller graph for this function:

task_pid_t elf_create_task ( elf_t elf,
size_t  kernel_stack_len,
size_t  user_stack_len 
)

Creates a user task running the code of an ELF file.

Parameters
elfthe start address of the ELF file in memory
kernel_stack_lennumber of bytes to allocate for the kernel stack
user_stack_lennumber of bytes to allocate for the user stack
Returns
PID of the created ELF task

Definition at line 148 of file elf.c.

+ Here is the call graph for this function:

void elf_destroy_task ( task_pid_t  pid)

Destroys a user task running the code of an ELF file.

Parameters
pidPID of the ELF task

Definition at line 166 of file elf.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* elf_load ( elf_t elf,
page_directory_t page_directory 
)

Loads the segments of an ELF file into memory.

Parameters
elfthe start address of the ELF file in memory
page_directorya page directory to map the segments into
Returns
the entry point as a virtual address

Definition at line 91 of file elf.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void elf_unload ( elf_t elf,
page_directory_t page_directory 
)

Frees the segments of an ELF file in memory.

Parameters
elfthe start address of the ELF file in memory
page_directorya page directory to unmap the segments from

Definition at line 127 of file elf.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: