Skip to main content

Crate kernel_elf_parser

Crate kernel_elf_parser 

Source
Expand description

§kernel-elf-parser

Crates.io Docs.rs CI

A lightweight ELF parser written in Rust, providing assistance for loading applications into the kernel.

It reads the data of the ELF file, and generates Sections, Relocations, Segments and so on.

It also generate a layout of the user stack according to the given user parameters and environment variables,which will be used for loading a given application into the physical memory of the kernel.

§Examples

use std::collections::BTreeMap;
use kernel_elf_parser::{AuxEntry, AuxType};
let args: Vec<String> = vec!["arg1".to_string(), "arg2".to_string(), "arg3".to_string()];
let envs: Vec<String> = vec!["LOG=file".to_string()];
let mut auxv = [
    AuxEntry::new(AuxType::PHDR, 0x1000),
    AuxEntry::new(AuxType::PHENT, 1024),
    AuxEntry::new(AuxType::PHNUM, 10),
    AuxEntry::new(AuxType::PAGESZ, 0x1000),
    AuxEntry::new(AuxType::ENTRY, 0x1000),
];
// The highest address of the user stack.
let ustack_end = 0x4000_0000;

let stack_data = kernel_elf_parser::app_stack_region(&args, &envs, &auxv, ustack_end);

// args length
assert_eq!(stack_data[0..8], [3, 0, 0, 0, 0, 0, 0, 0]);

Structs§

AuxEntry
Represents an entry in the auxiliary vector.
ELFHeaders
ELFHeadersBuilder
ELFParser
A wrapper for the ELF file data with some useful methods.

Enums§

AuxType
Represents the type of an auxiliary vector entry.

Functions§

app_stack_region
Generate initial stack frame for user stack