Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
elf.h File Reference
#include "libk/symbols.h"
#include <type.h>
#include <vector.h>

Go to the source code of this file.

Data Structures

struct  Elf64_Ehdr
 
struct  Elf64_Phdr
 
struct  Elf64_Shdr
 
struct  Elf64_Sym
 
struct  Elf64_Rel
 
struct  Elf64_Rela
 
struct  Elf64_Dyn
 
struct  vector_uint64_t
 
struct  elf_dynamic_map
 
struct  elf_section_map
 
struct  GnuHashHeader
 
struct  elf_load_mmap_table
 
struct  tcb
 

Macros

#define EI_MAG0   0
 
#define ELFMAG0   0x7f
 
#define EI_MAG1   1
 
#define ELFMAG1   'E'
 
#define EI_MAG2   2
 
#define ELFMAG2   'L'
 
#define EI_MAG3   3
 
#define ELFMAG3   'F'
 
#define ELFMAG   "\177ELF"
 
#define PF_X   0x1
 
#define PF_W   0x2
 
#define PF_R   0x4
 
#define ELF64_R_SYM(i)
 
#define ELF64_R_TYPE(i)
 
#define ELF64_R_INFO(s, t)
 
#define ELF_PTR(type, base, off)
 

Typedefs

typedef struct Elf64_Ehdr Elf64_Ehdr
 
typedef struct Elf64_Phdr Elf64_Phdr
 
typedef struct Elf64_Shdr Elf64_Shdr
 
typedef struct Elf64_Sym Elf64_Sym
 
typedef struct Elf64_Rel Elf64_Rel
 
typedef struct Elf64_Rela Elf64_Rela
 
typedef struct Elf64_Dyn Elf64_Dyn
 
typedef void(* ctor_t) (void)
 

Enumerations

enum  Elf_Ptype : uint32_t {
  PT_NULL = 0 , PT_LOAD = 1 , PT_DYNAMIC = 2 , PT_INTERP = 3 ,
  PT_NOTE = 4 , PT_SHLIB = 5 , PT_PHDR = 6 , PT_TLS = 7 ,
  PT_LOPROC = 0x70000000 , PT_HIPROC = 0x7fffffff
}
 
enum  Elf_Shdr_Flags {
  SHF_WRITE = 0x1 , SHF_ALLOC = 0x2 , SHF_EXECINSTR = 0x4 , SHF_MERGE = 0x10 ,
  SHF_STRINGS = 0x20 , SHF_INFO_LINK = 0x40 , SHF_LINK_ORDER = 0x80 , SHF_OS_NONCONFORMING = 0x100 ,
  SHF_GROUP = 0x200 , SHF_TLS = 0x400 , SHF_COMPRESSED = 0x800 , SHF_MASKOS = 0x0FF00000 ,
  SHF_MASKPROC = 0xF0000000 , SHF_ORDERED = 0x4000000 , SHF_EXCLUDE = 0x8000000
}
 
enum  Elf_Dtag {
  DT_NULL = 0 , DT_NEEDED = 1 , DT_PLTRELSZ = 2 , DT_PLTGOT = 3 ,
  DT_HASH = 4 , DT_STRTAB = 5 , DT_SYMTAB = 6 , DT_RELA = 7 ,
  DT_RELASZ = 8 , DT_RELAENT = 9 , DT_STRSZ = 10 , DT_SYMENT = 11 ,
  DT_INIT = 12 , DT_FINI = 13 , DT_SONAME = 14 , DT_RPATH = 15 ,
  DT_SYMBOLIC = 16 , DT_REL = 17 , DT_RELSZ = 18 , DT_RELENT = 19 ,
  DT_PLTREL = 20 , DT_DEBUG = 21 , DT_TEXTREL = 22 , DT_JMPREL = 23 ,
  DT_BIND_NOW = 24 , DT_INIT_ARRAY = 25 , DT_FINI_ARRAY = 26 , DT_INIT_ARRAYSZ = 27 ,
  DT_FINI_ARRAYSZ = 28 , DT_RUNPATH = 29 , DT_FLAGS = 30 , DT_ENCODING = 32 ,
  DT_PREINIT_ARRAY = 32 , DT_PREINIT_ARRAYSZ = 33 , DT_SYMTAB_SHNDX = 34 , DT_NUM = 35 ,
  DT_LOOS = 0x6000000d , DT_HIOS = 0x6ffff000 , DT_LOPROC = 0x70000000 , DT_HIPROC = 0x7fffffff
}
 
enum  Elf_Shtag {
  SHT_NULL = 0 , SHT_PROGBITS = 1 , SHT_SYMTAB = 2 , SHT_STRTAB = 3 ,
  SHT_RELA = 4 , SHT_HASH = 5 , SHT_DYNAMIC = 6 , SHT_NOTE = 7 ,
  SHT_NOBITS = 8 , SHT_REL = 9 , SHT_SHLIB = 10 , SHT_DYNSYM = 11 ,
  SHT_INIT_ARRAY = 14 , SHT_FINI_ARRAY = 15 , SHT_PREINIT_ARRAY = 16 , SHT_GROUP = 17 ,
  SHT_SYMTAB_SHNDX = 18 , SHT_RELR = 19 , SHT_GNU_ATTRIBUTES = 0x6ffffff5 , SHT_GNU_HASH = 0x6ffffff6 ,
  SHT_GNU_LIBLIST = 0x6ffffff7 , SHT_CHECKSUM = 0x6ffffff8 , SHT_LOSUNW = 0x6ffffffa , SHT_SUNW_move = 0x6ffffffa ,
  SHT_SUNW_COMDAT = 0x6ffffffb , SHT_SUNW_syminfo = 0x6ffffffc , SHT_GNU_verdef = 0x6ffffffd , SHT_GNU_verneed = 0x6ffffffe ,
  SHT_GNU_versym = 0x6fffffff , SHT_LOPROC = 0x70000000 , SHT_HIPROC = 0x7fffffff , SHT_LOUSER = 0x80000000 ,
  SHT_HIUSER = 0x8fffffff
}
 
enum  Elf4_E_Type {
  ET_NONE = 0 , ET_REL = 1 , ET_EXEC = 2 , ET_DYN = 3 ,
  ET_CORE = 4
}
 
enum  Elf64_RelType {
  R_X86_64_NONE = 0 , R_X86_64_64 = 1 , R_X86_64_PC32 = 2 , R_X86_64_GOT32 = 3 ,
  R_X86_64_PLT32 = 4 , R_X86_64_COPY = 5 , R_X86_64_GLOB_DAT = 6 , R_X86_64_JUMP_SLOT = 7 ,
  R_X86_64_RELATIVE = 8 , R_X86_64_GOTPCREL = 9 , R_X86_64_32 = 10 , R_X86_64_32S = 11 ,
  R_X86_64_16 = 12 , R_X86_64_PC16 = 13 , R_X86_64_8 = 14 , R_X86_64_PC8 = 15 ,
  R_X86_64_DTPMOD64 = 16 , R_X86_64_DTPOFF64 = 17 , R_X86_64_TPOFF64 = 18 , R_X86_64_TLSGD = 19 ,
  R_X86_64_TLSLD = 20 , R_X86_64_DTPOFF32 = 21 , R_X86_64_GOTTPOFF = 22 , R_X86_64_TPOFF32 = 23 ,
  R_X86_64_PC64 = 24 , R_X86_64_GOTOFF64 = 25 , R_X86_64_GOTPC32 = 26 , R_X86_64_GOT64 = 27 ,
  R_X86_64_GOTPCREL64 = 28 , R_X86_64_GOTPC64 = 29 , R_X86_64_GOTPLT64 = 30 , R_X86_64_PLTOFF64 = 31 ,
  R_X86_64_SIZE32 = 32 , R_X86_64_SIZE64 = 33 , R_X86_64_GOTPC32_TLSDESC = 34 , R_X86_64_TLSDESC_CALL = 35 ,
  R_X86_64_TLSDESC = 36 , R_X86_64_IRELATIVE = 37 , R_X86_64_RELATIVE64 = 38
}
 

Functions

Elf64_Dynelf_get_phdr_dynamic (uint8_t *data)
 
uintptr_t elf_find_base_addr (uint8_t *data)
 
uint8_telf_dyn_find (Elf64_Dyn *dyn, uint8_t *data, uint64_t tag)
 
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)
 
 __attribute__ ((deprecated("This function is deprecated and may be " "removed in future versions."))) void elf_mmap_got(volatile uintptr_t *page
 
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)
 
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)
 
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)
 
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)
 
uintptr_t elf_find_symbol (const char *name, GnuHashHeader *gnuhash, uintptr_t base, elf_section_map *map, uint8_t *data)
 
uintptr_t elf_count_load_size (uint8_t *data)
 
void elf_call_init_array_with_table (elf_section_map *map, struct elf_load_mmap_table *table, int table_count)
 
uint64_t elf_pflags_to_page_flags (uint64_t p_flags)
 

Variables

elf_section_mapmap
 
elf_section_map uintptr_t base
 

Macro Definition Documentation

◆ EI_MAG0

#define EI_MAG0   0

Definition at line 8 of file elf.h.

◆ EI_MAG1

#define EI_MAG1   1

Definition at line 11 of file elf.h.

◆ EI_MAG2

#define EI_MAG2   2

Definition at line 14 of file elf.h.

◆ EI_MAG3

#define EI_MAG3   3

Definition at line 17 of file elf.h.

◆ ELF64_R_INFO

#define ELF64_R_INFO ( s,
t )
Value:
(((Elf64_Xword)(s) << 32) + (Elf64_Xword)(t))

Definition at line 345 of file elf.h.

◆ ELF64_R_SYM

#define ELF64_R_SYM ( i)
Value:
((i) >> 32)

Definition at line 343 of file elf.h.

Referenced by elf_relocate_rel().

◆ ELF64_R_TYPE

#define ELF64_R_TYPE ( i)
Value:
((i) & 0xffffffffL)

Definition at line 344 of file elf.h.

Referenced by elf_relocate_rel().

◆ ELF_PTR

#define ELF_PTR ( type,
base,
off )
Value:
((type*)ASSUME_ALIGNED(PTR_ADD((base), (off)), alignof(type)))
elf_section_map uintptr_t base
Definition elf.h:296
#define PTR_ADD(ptr, off)
#define ASSUME_ALIGNED(ptr, align)
uint8_t type
Definition vnode.h:2

Definition at line 346 of file elf.h.

Referenced by elf_count_load_size(), elf_dyn_map_all(), elf_load(), and execve().

◆ ELFMAG

#define ELFMAG   "\177ELF"

Definition at line 20 of file elf.h.

◆ ELFMAG0

#define ELFMAG0   0x7f

Definition at line 9 of file elf.h.

Referenced by execve().

◆ ELFMAG1

#define ELFMAG1   'E'

Definition at line 12 of file elf.h.

Referenced by execve().

◆ ELFMAG2

#define ELFMAG2   'L'

Definition at line 15 of file elf.h.

Referenced by execve().

◆ ELFMAG3

#define ELFMAG3   'F'

Definition at line 18 of file elf.h.

Referenced by execve().

◆ PF_R

#define PF_R   0x4

Definition at line 260 of file elf.h.

Referenced by elf_pflags_to_page_flags().

◆ PF_W

#define PF_W   0x2

Definition at line 259 of file elf.h.

Referenced by elf_pflags_to_page_flags().

◆ PF_X

#define PF_X   0x1

Definition at line 258 of file elf.h.

Referenced by elf_pflags_to_page_flags().

Typedef Documentation

◆ ctor_t

typedef void(* ctor_t) (void)

Definition at line 337 of file elf.h.

◆ Elf64_Dyn

typedef struct Elf64_Dyn Elf64_Dyn

◆ Elf64_Ehdr

typedef struct Elf64_Ehdr Elf64_Ehdr

◆ Elf64_Phdr

typedef struct Elf64_Phdr Elf64_Phdr

◆ Elf64_Rel

typedef struct Elf64_Rel Elf64_Rel

◆ Elf64_Rela

typedef struct Elf64_Rela Elf64_Rela

◆ Elf64_Shdr

typedef struct Elf64_Shdr Elf64_Shdr

◆ Elf64_Sym

typedef struct Elf64_Sym Elf64_Sym

Enumeration Type Documentation

◆ Elf4_E_Type

Enumerator
ET_NONE 
ET_REL 
ET_EXEC 
ET_DYN 
ET_CORE 

Definition at line 204 of file elf.h.

◆ Elf64_RelType

Enumerator
R_X86_64_NONE 
R_X86_64_64 
R_X86_64_PC32 
R_X86_64_GOT32 
R_X86_64_PLT32 
R_X86_64_COPY 
R_X86_64_GLOB_DAT 
R_X86_64_JUMP_SLOT 
R_X86_64_RELATIVE 
R_X86_64_GOTPCREL 
R_X86_64_32 
R_X86_64_32S 
R_X86_64_16 
R_X86_64_PC16 
R_X86_64_8 
R_X86_64_PC8 
R_X86_64_DTPMOD64 
R_X86_64_DTPOFF64 
R_X86_64_TPOFF64 
R_X86_64_TLSGD 
R_X86_64_TLSLD 
R_X86_64_DTPOFF32 
R_X86_64_GOTTPOFF 
R_X86_64_TPOFF32 
R_X86_64_PC64 
R_X86_64_GOTOFF64 
R_X86_64_GOTPC32 
R_X86_64_GOT64 
R_X86_64_GOTPCREL64 
R_X86_64_GOTPC64 
R_X86_64_GOTPLT64 
R_X86_64_PLTOFF64 
R_X86_64_SIZE32 
R_X86_64_SIZE64 
R_X86_64_GOTPC32_TLSDESC 
R_X86_64_TLSDESC_CALL 
R_X86_64_TLSDESC 
R_X86_64_IRELATIVE 
R_X86_64_RELATIVE64 

Definition at line 212 of file elf.h.

◆ Elf_Dtag

enum Elf_Dtag
Enumerator
DT_NULL 
DT_NEEDED 
DT_PLTRELSZ 
DT_PLTGOT 
DT_HASH 
DT_STRTAB 
DT_SYMTAB 
DT_RELA 
DT_RELASZ 
DT_RELAENT 
DT_STRSZ 
DT_SYMENT 
DT_INIT 
DT_FINI 
DT_SONAME 
DT_RPATH 
DT_SYMBOLIC 
DT_REL 
DT_RELSZ 
DT_RELENT 
DT_PLTREL 
DT_DEBUG 
DT_TEXTREL 
DT_JMPREL 
DT_BIND_NOW 
DT_INIT_ARRAY 
DT_FINI_ARRAY 
DT_INIT_ARRAYSZ 
DT_FINI_ARRAYSZ 
DT_RUNPATH 
DT_FLAGS 
DT_ENCODING 
DT_PREINIT_ARRAY 
DT_PREINIT_ARRAYSZ 
DT_SYMTAB_SHNDX 
DT_NUM 
DT_LOOS 
DT_HIOS 
DT_LOPROC 
DT_HIPROC 

Definition at line 114 of file elf.h.

◆ Elf_Ptype

Enumerator
PT_NULL 
PT_LOAD 
PT_DYNAMIC 
PT_INTERP 
PT_NOTE 
PT_SHLIB 
PT_PHDR 
PT_TLS 
PT_LOPROC 
PT_HIPROC 

Definition at line 83 of file elf.h.

◆ Elf_Shdr_Flags

Enumerator
SHF_WRITE 
SHF_ALLOC 
SHF_EXECINSTR 
SHF_MERGE 
SHF_STRINGS 
SHF_INFO_LINK 
SHF_LINK_ORDER 
SHF_OS_NONCONFORMING 
SHF_GROUP 
SHF_TLS 
SHF_COMPRESSED 
SHF_MASKOS 
SHF_MASKPROC 
SHF_ORDERED 
SHF_EXCLUDE 

Definition at line 96 of file elf.h.

◆ Elf_Shtag

enum Elf_Shtag
Enumerator
SHT_NULL 
SHT_PROGBITS 
SHT_SYMTAB 
SHT_STRTAB 
SHT_RELA 
SHT_HASH 
SHT_DYNAMIC 
SHT_NOTE 
SHT_NOBITS 
SHT_REL 
SHT_SHLIB 
SHT_DYNSYM 
SHT_INIT_ARRAY 
SHT_FINI_ARRAY 
SHT_PREINIT_ARRAY 
SHT_GROUP 
SHT_SYMTAB_SHNDX 
SHT_RELR 
SHT_GNU_ATTRIBUTES 
SHT_GNU_HASH 
SHT_GNU_LIBLIST 
SHT_CHECKSUM 
SHT_LOSUNW 
SHT_SUNW_move 
SHT_SUNW_COMDAT 
SHT_SUNW_syminfo 
SHT_GNU_verdef 
SHT_GNU_verneed 
SHT_GNU_versym 
SHT_LOPROC 
SHT_HIPROC 
SHT_LOUSER 
SHT_HIUSER 

Definition at line 157 of file elf.h.

Function Documentation

◆ __attribute__()

__attribute__ ( (deprecated("This function is deprecated and may be " "removed in future versions.")) ) volatile

References DEPRECATED.

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

uint8_t * elf_dyn_find ( Elf64_Dyn * dyn,
uint8_t * data,
uint64_t tag )

References data, and map.

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

◆ elf_gnu_lookup()

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

◆ elf_load()

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

Variable Documentation

◆ base

◆ map