1#![warn(rust_2018_idioms)]
2#![allow(clippy::useless_conversion)]
3
4use std::path::PathBuf;
5
6use thiserror::Error;
7
8#[macro_use]
9extern crate log;
10
11mod arch;
12pub mod consts;
13mod fdt;
14mod gdb;
15
16#[cfg_attr(target_os = "linux", path = "linux/mod.rs")]
17#[cfg_attr(target_os = "macos", path = "macos/mod.rs")]
18pub mod os;
19
20mod hypercall;
21mod isolation;
22pub mod mem;
23pub(crate) mod paging;
24pub mod params;
25mod parking;
26mod serial;
27pub mod stats;
28mod vcpu;
29pub mod vm;
30
31pub use arch::*;
32
33#[derive(Debug, Error)]
34pub enum HypervisorError {
35 #[cfg(target_os = "linux")]
36 #[error("The KVM backend reported an error: {0}")]
37 BackendError(#[from] kvm_ioctls::Error),
38
39 #[cfg(target_os = "macos")]
40 #[error("The xhypervisor backend reported an error: {0}")]
41 BackendError(#[from] xhypervisor::Error),
42
43 #[error("IO Error: {0}")]
44 IOError(#[from] std::io::Error),
45
46 #[error("Invalid kernel path ({0})")]
47 InvalidKernelPath(PathBuf),
48
49 #[error(transparent)]
50 HermitImageError(#[from] crate::isolation::filemap::HermitImageError),
51
52 #[error("Unable to find Hermit image config in archive")]
53 HermitImageConfigNotFound,
54
55 #[error("Unable to parse Hermit image config: {0}")]
56 HermitImageConfigParseError(#[from] toml::de::Error),
57
58 #[error("Insufficient guest memory size: got = {got}, wanted = {wanted}")]
59 InsufficientGuestMemorySize {
60 got: byte_unit::Byte,
61 wanted: byte_unit::Byte,
62 },
63
64 #[error("Insufficient guest CPU count: got = {got}, wanted = {wanted}")]
65 InsufficientGuestCPUs { got: u32, wanted: u32 },
66
67 #[error("Kernel Loading Error: {0}")]
68 LoadedKernelError(#[from] vm::LoadKernelError),
69
70 #[error("Kernel doesn't support the necessary features: {0}")]
71 FeatureMismatch(&'static str),
72}
73
74impl HypervisorError {
75 fn backend_invalid_value() -> Self {
77 Self::BackendError({
78 #[cfg(target_os = "linux")]
79 {
80 kvm_ioctls::Error::new(libc::EINVAL)
81 }
82 #[cfg(target_os = "macos")]
83 {
84 xhypervisor::Error::BadArg
85 }
86 })
87 }
88}
89
90pub type HypervisorResult<T> = Result<T, HypervisorError>;
91
92pub mod net;
93mod pci;
94mod virtio;