1use crate::AddressContext;
2
3#[derive(thiserror::Error, Debug)]
5pub enum VmiError {
6 #[error(transparent)]
8 Driver(Box<dyn std::error::Error + Send + Sync>),
9
10 #[error(transparent)]
12 Os(Box<dyn std::error::Error + Send + Sync>),
13
14 #[error(transparent)]
16 Io(#[from] std::io::Error),
17
18 #[error(transparent)]
20 Isr(#[from] isr_macros::Error),
21
22 #[error("translation error ({:?}, len: {})", .0[0], .0.len())]
24 Translation(PageFaults),
25
26 #[error("invalid address width")]
28 InvalidAddressWidth,
29
30 #[error("invalid timeout")]
32 InvalidTimeout,
33
34 #[error("operation not supported")]
36 NotSupported,
37
38 #[error("out of bounds")]
40 OutOfBounds,
41
42 #[error("translation root not present")]
44 RootNotPresent,
45
46 #[error("operation timed out")]
48 Timeout,
49
50 #[error("view not found")]
52 ViewNotFound,
53
54 #[error("{0}")]
56 Other(&'static str),
57}
58
59pub type PageFaults = smallvec::SmallVec<[AddressContext; 1]>;
61
62impl VmiError {
63 pub fn driver<E>(err: E) -> Self
65 where
66 E: std::error::Error + Send + Sync + 'static,
67 {
68 Self::Driver(Box::new(err))
69 }
70
71 pub fn os<E>(err: E) -> Self
73 where
74 E: std::error::Error + Send + Sync + 'static,
75 {
76 Self::Os(Box::new(err))
77 }
78
79 pub fn page_fault(pf: impl Into<AddressContext>) -> Self {
81 Self::Translation(smallvec::smallvec![pf.into()])
82 }
83
84 pub fn page_faults(pfs: impl IntoIterator<Item = AddressContext>) -> Self {
86 Self::Translation(pfs.into_iter().collect())
87 }
88}