Skip to main content

load_image

Function load_image 

Source
pub fn load_image(
    world_id: u64,
    caps: &HwCaps,
    image_bytes: &[u8],
    load_base_gpa: u64,
) -> Result<LoadedImage, VmError>
Expand description

Loads an ELF64 guest image into a world’s guest memory.

The image is parsed and validated by Image::parse; every PT_LOAD segment is then mapped through map_memory with its ELF permissions and default write-back memory type. The file-backed prefix of each segment is copied page by page into the pinned frames (GPA -> HPA -> HHDM) and the remaining bytes (BSS) are zeroed. Nothing is executed: the policy layer decides the initial registers.

load_base_gpa is the guest-physical address of the image base (Image::base_vaddr) and must be 4 KiB aligned; the image virtual addresses are relocated by the same delta. Loading is not atomic: if a later segment cannot be mapped, the segments already mapped stay in place and the world must be destroyed (the world memory layer has no unmap primitive yet). A malformed image is rejected before any mapping.