vm_memory/
lib.rs

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#![warn(clippy::doc_markdown)]
19#![warn(missing_docs)]
20#![warn(missing_debug_implementations)]
21#![cfg_attr(docsrs, feature(doc_cfg))]
22
23// We only support 64bit. Fail build when attempting to build other targets
24#[cfg(not(target_pointer_width = "64"))]
25compile_error!("vm-memory only supports 64-bit targets!");
26
27pub mod address;
28pub use address::{Address, AddressValue};
29
30#[cfg(feature = "backend-atomic")]
31pub mod atomic;
32#[cfg(feature = "backend-atomic")]
33pub use atomic::{GuestMemoryAtomic, GuestMemoryLoadGuard};
34
35mod atomic_integer;
36pub use atomic_integer::AtomicInteger;
37
38pub mod bitmap;
39
40pub mod bytes;
41pub use bytes::{AtomicAccess, ByteValued, Bytes};
42
43pub mod endian;
44pub use endian::{Be16, Be32, Be64, BeSize, Le16, Le32, Le64, LeSize};
45
46pub mod guest_memory;
47pub use guest_memory::{
48    Error as GuestMemoryError, FileOffset, GuestAddress, GuestAddressSpace, GuestMemory,
49    GuestUsize, MemoryRegionAddress, Result as GuestMemoryResult,
50};
51
52pub mod region;
53pub use region::{
54    GuestMemoryRegion, GuestMemoryRegionBytes, GuestRegionCollection, GuestRegionCollectionError,
55};
56
57pub mod io;
58pub use io::{ReadVolatile, WriteVolatile};
59
60#[cfg(feature = "backend-mmap")]
61pub mod mmap;
62
63#[cfg(feature = "backend-mmap")]
64pub use mmap::{GuestMemoryMmap, GuestRegionMmap, MmapRegion};
65#[cfg(all(feature = "backend-mmap", feature = "xen", target_family = "unix"))]
66pub use mmap::{MmapRange, MmapXenFlags};
67
68pub mod volatile_memory;
69pub use volatile_memory::{
70    Error as VolatileMemoryError, Result as VolatileMemoryResult, VolatileArrayRef, VolatileMemory,
71    VolatileRef, VolatileSlice,
72};