xref: /cloud-hypervisor/hypervisor/src/lib.rs (revision 8c92d1dbdc7617b88d34687115e0e69bd78b332c)
1 // Copyright © 2019 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
4 //
5 // Copyright © 2020, Microsoft Corporation
6 //
7 // Copyright 2018-2019 CrowdStrike, Inc.
8 //
9 //
10 
11 //! A generic abstraction around hypervisor functionality
12 //!
13 //! This crate offers a trait abstraction for underlying hypervisors
14 //!
15 //! # Platform support
16 //!
17 //! - x86_64
18 //! - arm64
19 //!
20 
21 #[macro_use]
22 extern crate anyhow;
23 #[cfg(target_arch = "x86_64")]
24 #[macro_use]
25 extern crate log;
26 extern crate serde;
27 extern crate serde_derive;
28 extern crate serde_json;
29 extern crate thiserror;
30 
31 /// KVM implementation module
32 pub mod kvm;
33 
34 /// Hypevisor related module
35 pub mod hypervisor;
36 
37 /// Vm related module
38 pub mod vm;
39 
40 /// Architecture specific definitions
41 pub mod arch;
42 
43 /// CPU related module
44 mod cpu;
45 
46 /// Device related module
47 mod device;
48 
49 pub use crate::hypervisor::{Hypervisor, HypervisorError};
50 pub use cpu::{HypervisorCpuError, Vcpu, VmExit};
51 pub use device::{Device, HypervisorDeviceError};
52 pub use kvm::*;
53 pub use vm::{DataMatch, HypervisorVmError, Vm};
54 
55 use std::sync::Arc;
56 
57 pub fn new() -> std::result::Result<Arc<dyn Hypervisor>, HypervisorError> {
58     #[cfg(feature = "kvm")]
59     let hv = kvm::KvmHypervisor::new()?;
60 
61     Ok(Arc::new(hv))
62 }
63