MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / load_kernel

Method load_kernel

vmm/src/vm.rs:1514–1545  ·  view source on GitHub ↗
(
        mut kernel: File,
        memory_manager: Arc<Mutex<MemoryManager>>,
    )

Source from the content-addressed store, hash-verified

1512 #[allow(clippy::needless_pass_by_value)]
1513 #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
1514 fn load_kernel(
1515 mut kernel: File,
1516 memory_manager: Arc<Mutex<MemoryManager>>,
1517 ) -> Result<EntryPoint> {
1518 let guest_memory = memory_manager.lock().as_ref().unwrap().guest_memory();
1519 let mem = guest_memory.memory();
1520 let alignment = 0x20_0000;
1521 // round up
1522 let aligned_kernel_addr = arch::layout::KERNEL_START.0.div_ceil(alignment) * alignment;
1523 let entry_addr = {
1524 match linux_loader::loader::pe::PE::load(
1525 mem.deref(),
1526 Some(GuestAddress(aligned_kernel_addr)),
1527 &mut kernel,
1528 None,
1529 ) {
1530 Ok(entry_addr) => entry_addr.kernel_load,
1531 // Try to load the binary as kernel PE file at first.
1532 // If failed, retry to load it as UEFI binary.
1533 // As the UEFI binary is formatless, it must be the last option to try.
1534 Err(linux_loader::loader::Error::Pe(InvalidImageMagicNumber)) => {
1535 Self::load_firmware(&kernel, memory_manager)?;
1536 arch::layout::UEFI_START
1537 }
1538 Err(e) => {
1539 return Err(Error::KernelLoad(e));
1540 }
1541 }
1542 };
1543
1544 Ok(EntryPoint { entry_addr })
1545 }
1546
1547 #[cfg(all(feature = "kvm", feature = "sev_snp"))]
1548 fn reserve_bootloader_regions(memory_manager: &Arc<Mutex<MemoryManager>>) -> Result<()> {

Callers

nothing calls this directly

Calls 3

memoryMethod · 0.80
guest_memoryMethod · 0.45
derefMethod · 0.45

Tested by

no test coverage detected