vmi_core/
error.rs

1use crate::AddressContext;
2
3/// An error that can occur when working with the VMI.
4#[derive(thiserror::Error, Debug)]
5pub enum VmiError {
6    /// An error occurred in the VMI driver.
7    #[error(transparent)]
8    Driver(Box<dyn std::error::Error + Send + Sync>),
9
10    /// An OS-specific error occurred.
11    #[error(transparent)]
12    Os(Box<dyn std::error::Error + Send + Sync>),
13
14    /// An I/O error occurred.
15    #[error(transparent)]
16    Io(#[from] std::io::Error),
17
18    /// An error occurred while parsing symbols.
19    #[error(transparent)]
20    Isr(#[from] isr_macros::Error),
21
22    /// A translation error occurred.
23    #[error("Translation error ({:?}, len: {})", .0[0], .0.len())]
24    Translation(PageFaults),
25
26    /// The given address has invalid width.
27    #[error("Invalid address width")]
28    InvalidAddressWidth,
29
30    /// The given timeout is invalid.
31    #[error("The given timeout is invalid.")]
32    InvalidTimeout,
33
34    /// Operation not supported.
35    #[error("Operation not supported.")]
36    NotSupported,
37
38    /// Out of bounds.
39    #[error("Out of bounds")]
40    OutOfBounds,
41
42    /// Root not present.
43    #[error("Root not present")]
44    RootNotPresent,
45
46    /// Timeout.
47    #[error("Operation timed out.")]
48    Timeout,
49
50    /// The view was not found.
51    #[error("The view was not found.")]
52    ViewNotFound,
53
54    /// Other error.
55    #[error("{0}")]
56    Other(&'static str),
57}
58
59/// A collection of page faults.
60pub type PageFaults = smallvec::SmallVec<[AddressContext; 1]>;
61
62impl VmiError {
63    /// Creates a new page fault error.
64    pub fn page_fault(pf: impl Into<AddressContext>) -> Self {
65        Self::Translation(smallvec::smallvec![pf.into()])
66    }
67
68    /// Creates a new page fault error with multiple page faults.
69    pub fn page_faults(pfs: impl IntoIterator<Item = AddressContext>) -> Self {
70        Self::Translation(pfs.into_iter().collect())
71    }
72}