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 vmi_arch_amd64::Amd64;
5use vmi_core::{VcpuId, VmiCore};
6use vmi_driver_xen::VmiXenDriver;
7use xen::XenStore;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let domain_id = 'x: {
11        for name in &["win7", "win10", "win11", "ubuntu22"] {
12            if let Some(domain_id) = XenStore::new()?.domain_id_from_name(name)? {
13                break 'x domain_id;
14            }
15        }
16
17        panic!("Domain not found");
18    };
19
20    // Setup VMI.
21    let driver = VmiXenDriver::<Amd64>::new(domain_id)?;
22    let vmi = VmiCore::new(driver)?;
23
24    // Get the interrupt descriptor table for each vCPU and print it.
25    let _pause_guard = vmi.pause_guard()?;
26    let info = vmi.info()?;
27    for vcpu_id in 0..info.vcpus {
28        let registers = vmi.registers(VcpuId(vcpu_id))?;
29        let idt = Amd64::interrupt_descriptor_table(&vmi, &registers)?;
30
31        println!("IDT[{vcpu_id}]: {idt:#?}");
32    }
33
34    Ok(())
35}