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_auto_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
27#[macro_use]
28pub mod address;
29pub use address::{Address, AddressValue};
30
31#[cfg(feature = "backend-atomic")]
32pub mod atomic;
33#[cfg(feature = "backend-atomic")]
34pub use atomic::{GuestMemoryAtomic, GuestMemoryLoadGuard};
35
36mod atomic_integer;
37pub use atomic_integer::AtomicInteger;
38
39pub mod bitmap;
40
41pub mod bytes;
42pub use bytes::{AtomicAccess, ByteValued, Bytes};
43
44pub mod endian;
45pub use endian::{Be16, Be32, Be64, BeSize, Le16, Le32, Le64, LeSize};
46
47pub mod guest_memory;
48pub use guest_memory::{
49    Error as GuestMemoryError, FileOffset, GuestAddress, GuestAddressSpace, GuestMemory,
50    GuestMemoryRegion, GuestUsize, MemoryRegionAddress, Result as GuestMemoryResult,
51};
52
53pub mod io;
54pub use io::{ReadVolatile, WriteVolatile};
55
56#[cfg(all(feature = "backend-mmap", not(feature = "xen"), unix))]
57mod mmap_unix;
58
59#[cfg(all(feature = "backend-mmap", feature = "xen", unix))]
60mod mmap_xen;
61
62#[cfg(all(feature = "backend-mmap", windows))]
63mod mmap_windows;
64
65#[cfg(feature = "backend-mmap")]
66pub mod mmap;
67
68#[cfg(feature = "backend-mmap")]
69pub use mmap::{Error, GuestMemoryMmap, GuestRegionMmap, MmapRegion};
70#[cfg(all(feature = "backend-mmap", feature = "xen", unix))]
71pub use mmap::{MmapRange, MmapXenFlags};
72
73pub mod volatile_memory;
74pub use volatile_memory::{
75    Error as VolatileMemoryError, Result as VolatileMemoryResult, VolatileArrayRef, VolatileMemory,
76    VolatileRef, VolatileSlice,
77};