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