Docs.rs
  • linux-loader-0.11.0
    • linux-loader 0.11.0
    • Docs.rs crate page
    • Apache-2.0 AND BSD-3-Clause
    • Links
    • Homepage
    • Repository
    • crates.io
    • Source
    • Owners
    • andreeaflorescu
    • sameo
    • github:rust-vmm:gatekeepers
    • JonathanWoollett-Light
    • aghecenco
    • lauralt
    • jiangliu
    • roypat
    • Dependencies
      • vm-memory ^0.14.0 normal
      • criterion ^0.5.1 dev
      • vm-memory ^0.14.0 dev
    • Versions
    • 100% of the crate is documented
  • Go to latest version
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate linux_loader

linux_loader0.11.0

  • All Items
  • Modules

Crates

  • linux_loader
?
Change settings

Crate linux_loader

source ·
Expand description

A Linux kernel image loading crate.

This crate offers support for loading raw ELF (vmlinux), compressed big zImage (bzImage) and PE (Image) kernel images. ELF support includes the Linux and PVH boot protocols. Support for any other kernel image format can be added by implementing the KernelLoader and BootConfigurator.

§Platform support

  • x86_64
  • ARM64

§Example - load an ELF kernel and configure boot params with the PVH protocol

This example shows how to prepare a VM for booting with an ELF kernel, following the PVH boot protocol.


fn build_boot_params() -> (hvm_start_info, Vec<hvm_memmap_table_entry>) {
    let mut start_info = hvm_start_info::default();
    let memmap_entry = hvm_memmap_table_entry {
        addr: 0x7000,
        size: 0,
        type_: E820_RAM,
        reserved: 0,
    };
    start_info.magic = XEN_HVM_START_MAGIC_VALUE;
    start_info.version = 1;
    start_info.nr_modules = 0;
    start_info.memmap_entries = 0;
    (start_info, vec![memmap_entry])
}

fn main() {
    let guest_mem = GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), MEM_SIZE)]).unwrap();

    let mut elf_pvh_image = Vec::new();
    let path = concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/src/loader/x86_64/elf/test_elfnote.bin"
    );
    let mut file = File::open(path).unwrap();
    file.read_to_end(&mut elf_pvh_image).unwrap();

    // Load the kernel image.
    let loader_result =
        Elf::load(&guest_mem, None, &mut Cursor::new(&elf_pvh_image), None).unwrap();

    // Build boot parameters.
    let (mut start_info, memmap_entries) = build_boot_params();
    // Address in guest memory where the `start_info` struct will be written.
    let start_info_addr = GuestAddress(0x6000);
    // Address in guest memory where the memory map will be written.
    let memmap_addr = GuestAddress(0x7000);
    start_info.memmap_paddr = memmap_addr.raw_value();

    // Write boot parameters in guest memory.
    let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
    boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
    PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap();
}

Modules§

  • cmdline
    Helper for creating valid kernel command line strings.
  • configuratorelf or pe or bzimage
    Traits and structs for configuring and loading boot parameters.
  • elfx86 or x86-64
  • loader
    Traits and structs for loading kernels into guest memory.
  • start_infox86 or x86-64

Results

struct
linux_loader::configurator::BootParams
Boot parameters to be written in guest memory.
method
linux_loader::configurator::BootParams::clone
trait method
linux_loader::configurator::BootConfigurator::write_bootparams
Writes the boot parameters (configured elsewhere) into …
method
linux_loader::configurator::linux::LinuxBootConfigurator::write_bootparams
Writes the boot parameters (configured elsewhere) into …
method
linux_loader::configurator::pvh::PvhBootConfigurator::write_bootparams
Writes the boot parameters (configured elsewhere) into …
method
linux_loader::configurator::BootParams::add_module
Adds a boot module at the specified address (if specified …
method
linux_loader::configurator::BootParams::add_section
Adds a boot section at the specified address (if specified …
method
linux_loader::configurator::BootParams::set_modules
Sets or overwrites the boot modules and associated memory …
method
linux_loader::configurator::BootParams::set_sections
Sets or overwrites the boot sections and associated memory …
method
linux_loader::configurator::BootParams::clone
method
linux_loader::configurator::BootParams::new
Creates a new BootParams struct with the specified header.