Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
elf.c File Reference
#include "hal/cpu/paging.h"
#include "libk/math.h"
#include "libk/serial.h"
#include "libk/symbols.h"
#include "memory/memory_utils.h"
#include "memory/phys_base_allocator.h"
#include "memory/vm_manager.h"
#include <libk/executable/elf.h>
#include <str.h>
#include <type.h>
#include <vector.h>

Go to the source code of this file.

Functions

void module_loader (uintptr_t addr, uintptr_t stack)
 
uintptr_t elf_find_base_addr (uint8_t *data)
 
static uint64_t vaddr_to_file_offset (Elf64_Ehdr *ehdr, Elf64_Phdr *phdr, uint64_t vaddr)
 
Elf64_Dynelf_get_phdr_dynamic (uint8_t *data)
 
void elf_dyn_map_all (Elf64_Dyn *dyn, uint8_t *data, elf_dynamic_map *map)
 
void elf_section_map_all (uint8_t *data, elf_section_map *map)
 
uint64_t elf_pflags_to_page_flags (uint64_t p_flags)
 
void elf_mmap_got (volatile uintptr_t *page, elf_section_map *map, uintptr_t base)
 
uintptr_t elf_get_entry (uint8_t *data, uintptr_t base)
 
size_t elf_load (volatile uintptr_t *page, uint8_t *data, uintptr_t temporary_base, uintptr_t base, struct elf_load_mmap_table *table)
 
static uintptr_t elf_resolve_external_symbol (symbols_ptr_vector_t *external_syms, const char *name)
 
static uint64_telf_roffset_to_kernel_ptr (uintptr_t r_offset, struct elf_load_mmap_table *table, int table_count, uintptr_t fallback_base)
 
static void elf_relocate_rel (Elf64_Rela *rel, uintptr_t kernel_base, uintptr_t user_base, uint64_t rela_count, uint8_t *strtab, Elf64_Sym *symbols, GnuHashHeader *gnu_hash, symbols_ptr_vector_t *external_syms, struct elf_load_mmap_table *table, int table_count)
 
void elf_relocate_dyn (elf_dynamic_map *map, uintptr_t kernel_base, uintptr_t user_base, GnuHashHeader *gnu_hash, symbols_ptr_vector_t *external_syms, struct elf_load_mmap_table *table, int table_count)
 
static uint32_t elf_gnu_hash (const char *s)
 
static int elf_gnu_maybe_present (GnuHashHeader *gh, uint32_t hash)
 
Elf64_Symelf_gnu_lookup (const char *name, GnuHashHeader *gh, Elf64_Sym *symtab, const char *strtab)
 
void elf_gnu_hash_parse (GnuHashHeader *gnu_hash, Elf64_Shdr *gnu_hash_sym, uint8_t *data)
 
uintptr_t elf_count_load_size (uint8_t *data)
 
void elf_get_symbol (const char *sym_name, uintptr_t base, elf_section_map *map, uint8_t *data, symbols_ptr_vector_t *syms, boolean_t skip_empty_val)
 
void elf_call_init_array (elf_section_map *map, uintptr_t base)
 
void elf_call_init_array_with_table (elf_section_map *map, struct elf_load_mmap_table *table, int table_count)
 
uintptr_t elf_find_symbol (const char *name, GnuHashHeader *gnuhash, uintptr_t base, elf_section_map *map, uint8_t *data)
 

Variables

boolean_t elf_has_running = 0
 
uintptr_t rip_before_run_elf = 0
 

Function Documentation

◆ elf_call_init_array()

void elf_call_init_array ( elf_section_map * map,
uintptr_t base )

Definition at line 680 of file elf.c.

References base, count, LOG2_DEBUG, LOG2_INFO, map, Elf64_Shdr::sh_addr, and Elf64_Shdr::sh_size.

Referenced by proccess_elf().

◆ elf_call_init_array_with_table()

void elf_call_init_array_with_table ( elf_section_map * map,
struct elf_load_mmap_table * table,
int table_count )

Definition at line 699 of file elf.c.

References count, elf_roffset_to_kernel_ptr(), map, serial2_printf(), and table.

◆ elf_count_load_size()

◆ elf_dyn_map_all()

◆ elf_find_base_addr()

◆ elf_find_symbol()

uintptr_t elf_find_symbol ( const char * name,
GnuHashHeader * gnuhash,
uintptr_t base,
elf_section_map * map,
uint8_t * data )

◆ elf_get_entry()

uintptr_t elf_get_entry ( uint8_t * data,
uintptr_t base )

Definition at line 255 of file elf.c.

References ASSUME_ALIGNED, base, data, and Elf64_Ehdr::e_entry.

◆ elf_get_phdr_dynamic()

Elf64_Dyn * elf_get_phdr_dynamic ( uint8_t * data)

◆ elf_get_symbol()

void elf_get_symbol ( const char * sym_name,
uintptr_t base,
elf_section_map * map,
uint8_t * data,
symbols_ptr_vector_t * syms,
boolean_t skip_empty_val )

◆ elf_gnu_hash()

static uint32_t elf_gnu_hash ( const char * s)
static

Definition at line 563 of file elf.c.

References h.

Referenced by elf_gnu_lookup().

◆ elf_gnu_hash_parse()

◆ elf_gnu_lookup()

Elf64_Sym * elf_gnu_lookup ( const char * name,
GnuHashHeader * gh,
Elf64_Sym * symtab,
const char * strtab )

◆ elf_gnu_maybe_present()

static int elf_gnu_maybe_present ( GnuHashHeader * gh,
uint32_t hash )
static

Definition at line 571 of file elf.c.

References GnuHashHeader::bloom, GnuHashHeader::bloom_shift, GnuHashHeader::bloom_size, and hash.

Referenced by elf_gnu_lookup().

◆ elf_load()

◆ elf_mmap_got()

void elf_mmap_got ( volatile uintptr_t * page,
elf_section_map * map,
uintptr_t base )

◆ elf_pflags_to_page_flags()

uint64_t elf_pflags_to_page_flags ( uint64_t p_flags)

Definition at line 216 of file elf.c.

References flags, PAGE_NO_EXECUTE, PAGE_PRESENT, PAGE_USER, PAGE_WRITABLE, PF_R, PF_W, and PF_X.

Referenced by elf_load().

◆ elf_relocate_dyn()

void elf_relocate_dyn ( elf_dynamic_map * map,
uintptr_t kernel_base,
uintptr_t user_base,
GnuHashHeader * gnu_hash,
symbols_ptr_vector_t * external_syms,
struct elf_load_mmap_table * table,
int table_count )

Definition at line 534 of file elf.c.

References count, elf_relocate_rel(), LOG2_INFO, map, serial2_printf(), and table.

Referenced by execve(), and proccess_elf().

◆ elf_relocate_rel()

◆ elf_resolve_external_symbol()

static uintptr_t elf_resolve_external_symbol ( symbols_ptr_vector_t * external_syms,
const char * name )
static

◆ elf_roffset_to_kernel_ptr()

static uint64_t * elf_roffset_to_kernel_ptr ( uintptr_t r_offset,
struct elf_load_mmap_table * table,
int table_count,
uintptr_t fallback_base )
static

Definition at line 349 of file elf.c.

References BLOCK_SIZE, and table.

Referenced by elf_call_init_array_with_table(), and elf_relocate_rel().

◆ elf_section_map_all()

◆ module_loader()

void module_loader ( uintptr_t addr,
uintptr_t stack )
extern

References addr, and stack.

◆ vaddr_to_file_offset()

static uint64_t vaddr_to_file_offset ( Elf64_Ehdr * ehdr,
Elf64_Phdr * phdr,
uint64_t vaddr )
static

Variable Documentation

◆ elf_has_running

boolean_t elf_has_running = 0

Definition at line 14 of file elf.c.

Referenced by virtio_irq().

◆ rip_before_run_elf

uintptr_t rip_before_run_elf = 0

Definition at line 15 of file elf.c.

Referenced by virtio_irq().