elf.h

struct ELF_Header

An executable Linux file header. Visit Wikipedia for more details.

u32 magic

First 4 bytes of a file, identifying a file as ELF object file: 0x7F, ELF (45 4c 46)

u8 bitsize

“bitsize” or “e_ident” identifies if a file is using 32 or 64-bit format. 1: 32-bit, 2: 64-bit.

u8 endian

1 for a little endian file, 2 for a big endian one. Affects the interpretation of multi-byte fields starting with offset 0x10.

u8 ident_abi_version

ELF format version, 1 for the current one.

u8 target_platform

A target operating system ABI ID (TODO: add AstraOS ID)

u8 abi_version

ABI version specifier.

u8 padding[7]

Currently unused, fill with zeros.

u16 obj_type

An object file type: 0x00=ET_NONE, 0x01=ET_REL, 0x02=ET_EXEC, 0x03=ET_DYN, 0x04=ET_CORE, 0xFE00=ET_LOOS, 0xFEFF=ET_HIOS, 0xFF00=ET_LOPROC, 0xFFFF=ET_HIPROC.

u16 machine

Target instruction set architecture (ISA), like RISC-V, MIPS, x86, etc.

u32 version

“e_version”, leave as 1.

u64 entry_addr

A memory address for the entry point from where the process starts executing. 32 or 64-bits long depending on bitsize.

u64 phoff

A start of the program header table. TODO: add details.

u64 shoff

A start of the section header table.

u32 flags

Architecture-dependent, TODO

u16 ehsize

Size of the header. 64 Bytes for 64-bit, 52 Bytes for 32-bit format.

u16 phentsize

The size of a program header table entry.

u16 phnum

The number of entries in the program header table.

u16 shentsize

The size of a section header table entry.

u16 shnum

The number of entries in the section header table.

u16 shtrndx

Index of the section header table entry that contains the section names.

struct ELF_ProgramHeader

A structure definition for an ELF program header. Visit a Wikipedia article for more details.

u32 seg_type

Segment type, header table entry unused, loadable, dynamic linking, etc.

u32 flags

Segment-dependent flags

u64 off

Offset of the segment in the file image

u64 vaddr

Virtual address of the segment in memory.

u64 paddr

Reserved for segment’s physical address on systems where physical address is relevant

u64 filesz

Size in bytes of the segment in the file image, may be 0.

u64 memsz

Size in bytes of the segment in memory. May be 0.

u64 align

0 and 1 specify no alignment. Should be a positive, integral power of 2, with p_vaddr equating p_offset modulus p_align.

u64 create_process_from_file(u64 file_id, u64 *pid_ret)

Creates a process from an elf file by its file_id.

Parameters
  • file_id – a system-wide unique id of a file to load it from the filesystem, used instead of a filename

  • pid_ret – a pointer to an unsigned 64-bit integer that will be updated after the process is created with a process id

Returns

0 on error, 1 on success

Tables

TODO move subtables from both apidoc tables here.

EI_OSABI, e_type, e_machine, p_type