hv1_emulator/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Hyper-V hypervisor interface emulator.
5//!
6//! This crate implements support for emulating the hypervisor's synthetic
7//! interrupt controller, synthetic MSRs, and synthetic cpuid leaves, as defined
8//! in the [Hypervisor Top Level Functional Specification][].
9//!
10//! See also the peer crate `hv1_hypercall` for emulating HV#1 hypercalls.
11//!
12//! [Hypervisor Top Level Functional Specification]:
13//!     <https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/tlfs>
14
15#![forbid(unsafe_code)]
16
17pub mod cpuid;
18pub mod hv;
19pub mod hypercall;
20pub mod message_queues;
21mod pages;
22pub mod synic;
23pub mod x86;
24
25/// Trait for requesting an interrupt.
26pub trait RequestInterrupt {
27    /// Requests an interrupt with the specified vector.
28    ///
29    /// If `auto_eoi` is true, then the APIC should not set ISR when the
30    /// interrupt is delivered.
31    fn request_interrupt(&mut self, vector: u32, auto_eoi: bool);
32}
33
34impl<T: FnMut(u32, bool)> RequestInterrupt for T {
35    fn request_interrupt(&mut self, vector: u32, auto_eoi: bool) {
36        self(vector, auto_eoi)
37    }
38}
39
40/// A trait for managing the vtl protections on pages.
41pub trait VtlProtectAccess {
42    /// Check if the given GPN has the specified VTL permissions, optionally
43    /// modify them, then lock them.
44    fn check_modify_and_lock_overlay_page(
45        &mut self,
46        gpn: u64,
47        check_perms: hvdef::HvMapGpaFlags,
48        new_perms: Option<hvdef::HvMapGpaFlags>,
49    ) -> Result<guestmem::LockedPages, hvdef::HvError>;
50
51    /// Unlocks an overlay page by its GPN, restoring its previous permissions.
52    fn unlock_overlay_page(&mut self, gpn: u64) -> Result<(), hvdef::HvError>;
53}