use crate::{Pa, Va};
#[derive(thiserror::Error, Debug)]
pub enum VmiError {
#[error(transparent)]
Driver(Box<dyn std::error::Error>),
#[error(transparent)]
Os(Box<dyn std::error::Error>),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Isr(#[from] isr_macros::Error),
#[error("Page not present ({:?}, len: {})", .0[0], .0.len())]
PageFault(PageFaults),
#[error("Invalid address width")]
InvalidAddressWidth,
#[error("The given timeout is invalid.")]
InvalidTimeout,
#[error("Operation not supported.")]
NotSupported,
#[error("Out of bounds")]
OutOfBounds,
#[error("Root not present")]
RootNotPresent,
#[error("Operation timed out.")]
Timeout,
#[error("The view was not found.")]
ViewNotFound,
#[error("{0}")]
Other(&'static str),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PageFault {
pub address: Va,
pub root: Pa,
}
pub type PageFaults = smallvec::SmallVec<[PageFault; 1]>;
impl From<(Va, Pa)> for PageFault {
fn from((address, root): (Va, Pa)) -> Self {
Self { address, root }
}
}
impl VmiError {
pub fn page_fault(pf: impl Into<PageFault>) -> Self {
Self::PageFault(smallvec::smallvec![pf.into()])
}
pub fn page_faults(pfs: impl IntoIterator<Item = PageFault>) -> Self {
Self::PageFault(pfs.into_iter().collect())
}
}