Skip to main content

openvmm_hypervisors/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Hypervisor backend implementations for OpenVMM.
5//!
6//! Each submodule provides a [`HypervisorProbe`](hypervisor_resources::HypervisorProbe)
7//! implementation for the corresponding hypervisor backend.
8//!
9//! Probes are registered here via `register_hypervisor_probes!`. Resource
10//! resolvers are registered separately in `openvmm_resources`.
11
12#![forbid(unsafe_code)]
13
14pub mod hvf;
15pub mod kvm;
16pub mod mshv;
17pub mod whp;
18
19// Register probes for auto-detection (checked in this order).
20hypervisor_resources::register_hypervisor_probes! {
21    #[cfg(all(target_os = "linux", feature = "virt_mshv", guest_is_native))]
22    mshv::MshvProbe,
23
24    #[cfg(all(target_os = "linux", feature = "virt_kvm", guest_is_native))]
25    kvm::KvmProbe,
26
27    #[cfg(all(target_os = "windows", feature = "virt_whp", guest_is_native))]
28    whp::WhpProbe,
29
30    #[cfg(all(target_os = "macos", guest_arch = "aarch64", guest_is_native, feature = "virt_hvf"))]
31    hvf::HvfProbe,
32}
33
34#[expect(clippy::allow_attributes, reason = "lots of conditions")]
35#[allow(dead_code)]
36pub(crate) fn parse_bool_param(key: &str, val: &str) -> anyhow::Result<bool> {
37    match val {
38        "true" | "1" | "yes" => Ok(true),
39        "false" | "0" | "no" => Ok(false),
40        _ => anyhow::bail!("invalid boolean value for {key}: {val}"),
41    }
42}