Skip to main content

basic/
basic.rs

1//! This example demonstrates how to connect to a running Xen domain and
2//! print the interrupt descriptor table (IDT) for each vCPU.
3
4use anyhow::{Context as _, Error};
5use vmi_arch_amd64::Amd64;
6use vmi_core::{VcpuId, VmiCore};
7use vmi_driver_xen::VmiXenDriver;
8
9fn main() -> Result<(), Error> {
10    // Setup VMI.
11    let driver = VmiXenDriver::<Amd64>::try_from_env()?
12        .context("invalid VMI_XEN_DOMAIN environment variable")?;
13    let vmi = VmiCore::new(driver)?;
14
15    // Get the interrupt descriptor table for each vCPU and print it.
16    let _pause_guard = vmi.pause_guard()?;
17    let info = vmi.info()?;
18    for vcpu_id in 0..info.vcpus {
19        let registers = vmi.registers(VcpuId(vcpu_id))?;
20        let idt = Amd64::interrupt_descriptor_table(&vmi, &registers)?;
21
22        println!("IDT[{vcpu_id}]: {idt:#?}");
23    }
24
25    Ok(())
26}