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