Skip to main content

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