1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![deny(missing_docs)]
use vm_memory::GuestUsize;
mod address_space;
pub use self::address_space::{AddressSpace, AddressSpaceBase};
mod layout;
pub use layout::{AddressSpaceLayout, USABLE_END};
mod memory;
pub use memory::{GuestMemoryHybrid, GuestMemoryManager, GuestRegionHybrid, GuestRegionRaw};
mod numa;
pub use self::numa::{NumaIdTable, NumaNode, NumaNodeInfo, MPOL_MF_MOVE, MPOL_PREFERRED};
mod region;
pub use region::{AddressSpaceRegion, AddressSpaceRegionType};
#[derive(Debug, thiserror::Error)]
pub enum AddressSpaceError {
#[error("invalid address space region type")]
InvalidRegionType,
#[error("invalid address space region (0x{0:x}, 0x{1:x})")]
InvalidAddressRange(u64, GuestUsize),
#[error("invalid memory source type {0}")]
InvalidMemorySourceType(String),
#[error("can not create memfd to map anonymous memory")]
CreateMemFd(#[source] nix::Error),
#[error("can not open memory file")]
OpenFile(#[source] std::io::Error),
#[error("can not create directory")]
CreateDir(#[source] std::io::Error),
#[error("can not set size for memory file")]
SetFileSize(#[source] std::io::Error),
#[error("can not unlink memory file")]
UnlinkFile(#[source] nix::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_code() {
let e = AddressSpaceError::InvalidRegionType;
assert_eq!(format!("{e}"), "invalid address space region type");
assert_eq!(format!("{e:?}"), "InvalidRegionType");
assert_eq!(
format!(
"{}",
AddressSpaceError::InvalidMemorySourceType("test".to_string())
),
"invalid memory source type test"
);
}
}