1 // Portions Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 //
3 // Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE-BSD-3-Clause file.
6 //
7 // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
8 
9 //! Traits for allocating, handling and interacting with the VM's physical memory.
10 //!
11 //! For a typical hypervisor, there are several components, such as boot loader, virtual device
12 //! drivers, virtio backend drivers and vhost drivers etc, that need to access VM's physical memory.
13 //! This crate aims to provide a set of stable traits to decouple VM memory consumers from VM
14 //! memory providers. Based on these traits, VM memory consumers could access VM's physical memory
15 //! without knowing the implementation details of the VM memory provider. Thus hypervisor
16 //! components, such as boot loader, virtual device drivers, virtio backend drivers and vhost
17 //! drivers etc, could be shared and reused by multiple hypervisors.
18 
19 #![deny(clippy::doc_markdown)]
20 #![deny(missing_docs)]
21 
22 #[macro_use]
23 pub mod address;
24 pub use address::{Address, AddressValue};
25 
26 #[cfg(feature = "backend-atomic")]
27 pub mod atomic;
28 #[cfg(feature = "backend-atomic")]
29 pub use atomic::{GuestMemoryAtomic, GuestMemoryLoadGuard};
30 
31 mod atomic_integer;
32 pub use atomic_integer::AtomicInteger;
33 
34 pub mod bitmap;
35 
36 pub mod bytes;
37 pub use bytes::{AtomicAccess, ByteValued, Bytes};
38 
39 pub mod endian;
40 pub use endian::{Be16, Be32, Be64, BeSize, Le16, Le32, Le64, LeSize};
41 
42 pub mod guest_memory;
43 pub use guest_memory::{
44     Error as GuestMemoryError, FileOffset, GuestAddress, GuestAddressSpace, GuestMemory,
45     GuestMemoryRegion, GuestUsize, MemoryRegionAddress, Result as GuestMemoryResult,
46 };
47 
48 #[cfg(all(feature = "backend-mmap", not(feature = "xen"), unix))]
49 mod mmap_unix;
50 
51 #[cfg(all(feature = "backend-mmap", feature = "xen", unix))]
52 mod mmap_xen;
53 
54 #[cfg(all(feature = "backend-mmap", windows))]
55 mod mmap_windows;
56 
57 #[cfg(feature = "backend-mmap")]
58 pub mod mmap;
59 #[cfg(feature = "backend-mmap")]
60 pub use mmap::{Error, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
61 #[cfg(all(feature = "backend-mmap", feature = "xen", unix))]
62 pub use mmap::{MmapRange, MmapXenFlags};
63 
64 pub mod volatile_memory;
65 pub use volatile_memory::{
66     Error as VolatileMemoryError, Result as VolatileMemoryResult, VolatileArrayRef, VolatileMemory,
67     VolatileRef, VolatileSlice,
68 };
69