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(transparent)]
24 IsrCache(#[from] isr_cache::Error),
25
26 #[error("translation error ({:?})", .0)]
28 Translation(AddressContext),
29
30 #[error("invalid address width")]
32 InvalidAddressWidth,
33
34 #[error("invalid timeout")]
36 InvalidTimeout,
37
38 #[error("operation not supported")]
40 NotSupported,
41
42 #[error("out of bounds")]
44 OutOfBounds,
45
46 #[error("translation root not present")]
48 RootNotPresent,
49
50 #[error("operation timed out")]
52 Timeout,
53
54 #[error("view not found")]
56 ViewNotFound,
57
58 #[error("{0}")]
60 Other(&'static str),
61}
62
63impl VmiError {
64 pub fn driver<E>(err: E) -> Self
66 where
67 E: std::error::Error + Send + Sync + 'static,
68 {
69 Self::Driver(Box::new(err))
70 }
71
72 pub fn os<E>(err: E) -> Self
74 where
75 E: std::error::Error + Send + Sync + 'static,
76 {
77 Self::Os(Box::new(err))
78 }
79
80 pub fn translation(pf: impl Into<AddressContext>) -> Self {
82 Self::Translation(pf.into())
83 }
84}