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("The given timeout is invalid.")]
32 InvalidTimeout,
33
34 #[error("Operation not supported.")]
36 NotSupported,
37
38 #[error("Out of bounds")]
40 OutOfBounds,
41
42 #[error("Root not present")]
44 RootNotPresent,
45
46 #[error("Operation timed out.")]
48 Timeout,
49
50 #[error("The view was 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 page_fault(pf: impl Into<AddressContext>) -> Self {
65 Self::Translation(smallvec::smallvec![pf.into()])
66 }
67
68 pub fn page_faults(pfs: impl IntoIterator<Item = AddressContext>) -> Self {
70 Self::Translation(pfs.into_iter().collect())
71 }
72}