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

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 bool elf_verify_header (const elf_header_t *header)
static bool elf_read_file (FsBaseFile *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 *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, MMContext *mm, FsBaseFile *file)
static ptr_t elf_map_interpreter (const char *path, MMContext *mm)
__nodiscard bool elf_do_fill_process (Process *proc, FsBaseFile *file, elf_header_t header, elf_startup_info_t *info)
bool elf_read_and_verify_executable (FsBaseFile *file, elf_header_t *header)
static bool elf_fill_process (Process *proc, FsBaseFile *file, mos::string_view path, const mos::vector< mos::string > &argv, const mos::vector< mos::string > &envp)
Procesself_create_process (mos::string_view path, Process *parent, const mos::vector< mos::string > &argv, const mos::vector< mos::string > &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"  )

◆ elf_verify_header()

bool elf_verify_header ( const elf_header_t * header)
static

Definition at line 23 of file elf.cpp.

Referenced by elf_read_and_verify_executable().

Here is the call graph for this function:

◆ elf_read_file()

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

Definition at line 49 of file elf.cpp.

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()

ptr_t elf_determine_loadbias ( elf_header_t * elf)
static

Definition at line 55 of file elf.cpp.

Referenced by elf_do_fill_process().

◆ elf_setup_main_thread()

void elf_setup_main_thread ( Thread * 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 79 of file elf.cpp.

Referenced by elf_do_fill_process().

Here is the call graph for this function:

◆ elf_map_segment()

void elf_map_segment ( const elf_program_hdr_t *const ph,
ptr_t map_bias,
MMContext * mm,
FsBaseFile * file )
static

Definition at line 149 of file elf.cpp.

Referenced by elf_do_fill_process(), and elf_map_interpreter().

Here is the call graph for this function:

◆ elf_map_interpreter()

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

Definition at line 192 of file elf.cpp.

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 * proc,
FsBaseFile * file,
elf_header_t header,
elf_startup_info_t * info )
nodiscard

Definition at line 232 of file elf.cpp.

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 ( FsBaseFile * file,
elf_header_t * header )
nodiscard

Definition at line 347 of file elf.cpp.

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 * proc,
FsBaseFile * file,
mos::string_view path,
const mos::vector< mos::string > & argv,
const mos::vector< mos::string > & envp )
staticnodiscard

Definition at line 362 of file elf.cpp.

Referenced by elf_create_process().

Here is the call graph for this function:

◆ elf_create_process()

Process * elf_create_process ( mos::string_view path,
Process * parent,
const mos::vector< mos::string > & argv,
const mos::vector< mos::string > & envp,
const stdio_t * ios )

Definition at line 384 of file elf.cpp.

Referenced by mos_start_kernel(), and MOS_STATIC_ASSERT().

Here is the call graph for this function: