Expand description
os_image_lens is a dependency-free, no_std-first crate that parses ELF64
images and produces a deterministic load plan suitable for bootloaders and kernels.
The core goal is to make a very common OS-development task boring and correct:
- Validate an ELF64 image from a byte slice.
- Enumerate
PT_LOADsegments. - Compute file ranges to copy and the in-memory ranges to zero.
- Derive a stable “what to map/copy/zero” plan without allocation.
This crate is intentionally strict and small:
- Rust edition: 2024
- External dependencies: none
- Unsafe in this crate: none
§What this crate is
- A pure parser and planner for ELF64 binaries (typically kernel images).
- A way to keep bootloader and kernel loader code short, explicit, and testable.
- A crate that works in
no_stdenvironments by default.
§What this crate is not
- It is not an ELF relocator or dynamic loader.
- It is not a filesystem, block device, or network fetcher.
- It does not allocate; if you want owned collections, build them outside this crate.
§Minimal example
use os_image_lens::{Elf64, LoadSegmentKind};
let elf = Elf64::parse(bytes)?;
for seg in elf.load_segments() {
let seg = seg?;
match seg.kind() {
LoadSegmentKind::CopyFromFile { file_range } => {
let _to_copy = &bytes[file_range.start..file_range.end];
}
LoadSegmentKind::ZeroFill => {
// memsz > filesz: you must zero the tail in memory.
}
}
}Structs§
- Elf64
- A parsed ELF64 image.
- Elf64
Header - Parsed, validated ELF64 file header.
- ElfProgram
Header - A parsed ELF64 program header entry.
- Error
- A compact, allocation-free error used by all fallible APIs in this crate.
- Load
Segment - A fully validated load segment derived from an ELF
PT_LOADprogram header. - Segment
Permissions - Permissions for a memory segment derived from ELF
p_flags.
Enums§
- ElfData
Encoding - ELF data encoding (endianness) as reported by
e_ident[EI_DATA]. - ElfMachine
- ELF machine type (
e_machine). - ElfOs
Abi - ELF OS ABI byte (
e_ident[EI_OSABI]). - ElfType
- ELF file type (
e_type). - Error
Kind - Machine-matchable categories of parsing/planning errors.
- Load
Segment Kind - A single copy/zero step a loader must perform for a
PT_LOADsegment.