xref: /cloud-hypervisor/hypervisor/src/lib.rs (revision cc57467d10a6ed036be81c38b6b0b8a0ddfa26ed)
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 extern crate serde;
22 extern crate serde_derive;
23 extern crate serde_json;
24 extern crate thiserror;
25 #[macro_use]
26 extern crate anyhow;
27 
28 /// KVM implementation module
29 pub mod kvm;
30 
31 /// Hypevisor related module
32 pub mod hypervisor;
33 
34 /// Vm related module
35 pub mod vm;
36 
37 /// Architecture specific definitions
38 pub mod arch;
39 
40 /// CPU related module
41 mod cpu;
42 
43 pub use crate::hypervisor::{Hypervisor, HypervisorError};
44 pub use cpu::{HypervisorCpuError, Vcpu, VmExit};
45 pub use kvm::*;
46 pub use vm::{DataMatch, HypervisorVmError, Vm};
47 
48 use std::sync::Arc;
49 pub fn new() -> std::result::Result<Arc<dyn Hypervisor>, HypervisorError> {
50     #[cfg(feature = "kvm")]
51     let hv = kvm::KvmHypervisor::new()?;
52 
53     Ok(Arc::new(hv))
54 }
55