#elf-file #elf #kernel #starry #no-std

no-std kernel-elf-parser

An lightweight ELF parser that parses ELF files and converts them into information needed for kernel building

1 unstable release

0.1.0 Sep 26, 2024

#1622 in Parser implementations

Download history 132/week @ 2024-09-23 24/week @ 2024-09-30 28/week @ 2024-10-07 16/week @ 2024-10-14 32/week @ 2024-10-21 21/week @ 2024-11-11 149/week @ 2024-11-18 36/week @ 2024-11-25 14/week @ 2024-12-02 28/week @ 2024-12-09

228 downloads per month

GPL-3.0-or-later OR Apache-2…

38KB
605 lines

elf-parser

A lightweight parser written in Rust that reads the data of the ELF file and generates the layout of the corresponding user stack and other data structures according to the given user parameters and environment variables.

Examples

let args: Vec<String> = vec![1, 2, 3];
let envs: Vec<String> = vec!["LOG=file"];
let auxv: BTreeMap<u8, usize> = BTreeMap::new();

// The top of the user stack
let stack_top = uspace.end() - stack_size;

let (stack_data, stack_bottom) = elf_parser::get_app_stack_region(
    args,
    &envs,
    auxv,
    stack_top,
    stack_size,
);

uspace.map_alloc(stack_top, stack_size, MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER)?;

unsafe {
    core::ptr::copy_nonoverlapping(
        stack_data.as_ptr(),
        phys_to_virt(stack_top).as_mut_ptr(),
        stack_data.len(),
    );
}

// The stack_bottom is the real stack pointer after inserting some auxiliary data on the user stack.
ucontext.sp = stack_bottom;

Dependencies

~1MB
~17K SLoC