MOS Source Code
Loading...
Searching...
No Matches
elf.c File Reference
#include "mos/tasks/elf.h"
#include "mos/filesystem/vfs.h"
#include "mos/mm/mmap.h"
#include "mos/platform/platform.h"
#include "mos/syslog/printk.h"
#include "mos/tasks/process.h"
#include "mos/tasks/schedule.h"
#include "mos/tasks/task_types.h"
#include "mos/tasks/thread.h"
#include <mos/types.h>
#include <mos_stdlib.h>
#include <mos_string.h>
+ Include dependency graph for elf.c:

Go to the source code of this file.

Functions

 MOS_STATIC_ASSERT (sizeof(elf_header_t)==0x40, "elf_header has wrong size")
 
 MOS_STATIC_ASSERT (sizeof(elf_program_hdr_t)==0x38, "elf_program_header has wrong size")
 
static void add_auxv_entry (auxv_vec_t *var, unsigned long type, unsigned long val)
 
static bool elf_verify_header (const elf_header_t *header)
 
static bool elf_read_file (file_t *file, void *buf, off_t offset, size_t size)
 
static ptr_t elf_determine_loadbias (elf_header_t *elf)
 
static void elf_setup_main_thread (thread_t *thread, elf_startup_info_t *const info, ptr_t *const out_pargv, ptr_t *const out_penvp)
 
static void elf_map_segment (const elf_program_hdr_t *const ph, ptr_t map_bias, mm_context_t *mm, file_t *file)
 
static ptr_t elf_map_interpreter (const char *path, mm_context_t *mm)
 
__nodiscard bool elf_do_fill_process (process_t *proc, file_t *file, elf_header_t elf, elf_startup_info_t *info)
 
bool elf_read_and_verify_executable (file_t *file, elf_header_t *header)
 
bool elf_fill_process (process_t *proc, file_t *file, const char *path, const char *const argv[], const char *const envp[])
 
process_telf_create_process (const char *path, process_t *parent, const char *const argv[], const char *const envp[], const stdio_t *ios)
 

Function Documentation

◆ MOS_STATIC_ASSERT() [1/2]

MOS_STATIC_ASSERT ( sizeof(elf_header_t) = =0x40,
"elf_header has wrong size"  )

◆ MOS_STATIC_ASSERT() [2/2]

MOS_STATIC_ASSERT ( sizeof(elf_program_hdr_t) = =0x38,
"elf_program_header has wrong size"  )

◆ add_auxv_entry()

static void add_auxv_entry ( auxv_vec_t * var,
unsigned long type,
unsigned long val )
static

Definition at line 21 of file elf.c.

Referenced by elf_do_fill_process(), and elf_setup_main_thread().

◆ elf_verify_header()

static bool elf_verify_header ( const elf_header_t * header)
static

Definition at line 30 of file elf.c.

Referenced by elf_read_and_verify_executable().

+ Here is the call graph for this function:

◆ elf_read_file()

static bool elf_read_file ( file_t * file,
void * buf,
off_t offset,
size_t size )
staticnodiscard

Definition at line 56 of file elf.c.

Referenced by elf_do_fill_process(), elf_map_interpreter(), and elf_read_and_verify_executable().

+ Here is the call graph for this function:

◆ elf_determine_loadbias()

static ptr_t elf_determine_loadbias ( elf_header_t * elf)
static

Definition at line 62 of file elf.c.

Referenced by elf_do_fill_process().

◆ elf_setup_main_thread()

static void elf_setup_main_thread ( thread_t * thread,
elf_startup_info_t *const info,
ptr_t *const out_pargv,
ptr_t *const out_penvp )
static

Typical Stack Layout:

 (low address)
 |-> u32 argc
 |-> ptr_t argv[]
 |   |-> NULL
 |-> ptr_t envp[]
 |   |-> NULL
 |-> AuxV
 |   |-> AT_...
 |   |-> AT_NULL
 |-> argv strings, NULL-terminated
 |-> environment strings, NULL-terminated
 |-> u32 zero
 (high address, end of stack)

Definition at line 86 of file elf.c.

Referenced by elf_do_fill_process().

+ Here is the call graph for this function:

◆ elf_map_segment()

static void elf_map_segment ( const elf_program_hdr_t *const ph,
ptr_t map_bias,
mm_context_t * mm,
file_t * file )
static

Definition at line 156 of file elf.c.

Referenced by elf_do_fill_process(), and elf_map_interpreter().

+ Here is the call graph for this function:

◆ elf_map_interpreter()

static ptr_t elf_map_interpreter ( const char * path,
mm_context_t * mm )
static

Definition at line 190 of file elf.c.

Referenced by elf_do_fill_process().

+ Here is the call graph for this function:

◆ elf_do_fill_process()

__nodiscard bool elf_do_fill_process ( process_t * proc,
file_t * file,
elf_header_t elf,
elf_startup_info_t * info )

Definition at line 230 of file elf.c.

Referenced by elf_fill_process(), and process_do_execveat().

+ Here is the call graph for this function:

◆ elf_read_and_verify_executable()

bool elf_read_and_verify_executable ( file_t * file,
elf_header_t * header )

Definition at line 338 of file elf.c.

Referenced by elf_fill_process(), elf_map_interpreter(), and process_do_execveat().

+ Here is the call graph for this function:

◆ elf_fill_process()

bool elf_fill_process ( process_t * proc,
file_t * file,
const char * path,
const char *const argv[],
const char *const envp[] )

Definition at line 353 of file elf.c.

Referenced by elf_create_process().

+ Here is the call graph for this function:

◆ elf_create_process()

process_t * elf_create_process ( const char * path,
process_t * parent,
const char *const argv[],
const char *const envp[],
const stdio_t * ios )

Definition at line 408 of file elf.c.

Referenced by mos_start_kernel(), and MOS_STATIC_ASSERT().

+ Here is the call graph for this function: