underhill_core/
wrapped_partition.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use async_trait::async_trait;
5use hvdef::Vtl;
6use inspect::InspectMut;
7use memory_range::MemoryRange;
8use std::sync::Arc;
9use virt::PageVisibility;
10use virt_mshv_vtl::UhPartition;
11use vmcore::save_restore::NoSavedState;
12use vmcore::save_restore::RestoreError;
13use vmcore::save_restore::SaveError;
14use vmcore::save_restore::SaveRestore;
15use vmm_core::partition_unit::VmPartition;
16
17/// Wraps `Arc<UhPartition>` and implements [`VmPartition`].
18#[derive(InspectMut)]
19#[inspect(transparent)]
20pub struct WrappedPartition(pub Arc<UhPartition>);
21
22#[async_trait]
23impl VmPartition for WrappedPartition {
24    fn reset(&mut self) -> anyhow::Result<()> {
25        anyhow::bail!("reset not supported")
26    }
27
28    fn scrub_vtl(&mut self, _vtl: Vtl) -> anyhow::Result<()> {
29        unreachable!()
30    }
31
32    fn accept_initial_pages(
33        &mut self,
34        _pages: Vec<(MemoryRange, PageVisibility)>,
35    ) -> anyhow::Result<()> {
36        unreachable!()
37    }
38}
39
40impl SaveRestore for WrappedPartition {
41    type SavedState = NoSavedState;
42
43    fn save(&mut self) -> Result<Self::SavedState, SaveError> {
44        Ok(NoSavedState)
45    }
46
47    fn restore(&mut self, NoSavedState: Self::SavedState) -> Result<(), RestoreError> {
48        Ok(())
49    }
50}