vm_memory: A crate to hold vm-specific memory objects

Move GuestAddress and GuestMemory to a new crate for VM memory. This
will make separating sys_util and crosvm independent making it easier
to use sys_util functions outside of crosvm.

Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Dylan Reid 2020-07-20 20:21:11 -07:00 committed by Commit Bot
parent bedfa1edc8
commit ec058d6c46
96 changed files with 250 additions and 131 deletions

22
Cargo.lock generated
View file

@ -17,6 +17,7 @@ dependencies = [
"sync 0.1.0",
"sys_util 0.1.0",
"vm_control 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -40,6 +41,7 @@ dependencies = [
"sync 0.1.0",
"sys_util 0.1.0",
"vm_control 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -104,6 +106,7 @@ dependencies = [
"pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
"sys_util 0.1.0",
"syscall_defines 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -142,6 +145,7 @@ dependencies = [
"sys_util 0.1.0",
"vhost 0.1.0",
"vm_control 0.1.0",
"vm_memory 0.1.0",
"x86_64 0.1.0",
]
@ -207,6 +211,7 @@ dependencies = [
"vhost 0.1.0",
"virtio_sys 0.1.0",
"vm_control 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -346,6 +351,7 @@ dependencies = [
"data_model 0.1.0",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"sys_util 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -361,6 +367,7 @@ dependencies = [
"msg_socket 0.1.0",
"sync 0.1.0",
"sys_util 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -385,6 +392,7 @@ version = "0.1.0"
dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"sys_util 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -397,6 +405,7 @@ dependencies = [
"msg_socket 0.1.0",
"sync 0.1.0",
"sys_util 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -772,6 +781,7 @@ dependencies = [
"net_util 0.1.0",
"sys_util 0.1.0",
"virtio_sys 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
@ -792,6 +802,17 @@ dependencies = [
"resources 0.1.0",
"sync 0.1.0",
"sys_util 0.1.0",
"vm_memory 0.1.0",
]
[[package]]
name = "vm_memory"
version = "0.1.0"
dependencies = [
"data_model 0.1.0",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"sys_util 0.1.0",
"syscall_defines 0.1.0",
]
[[package]]
@ -823,6 +844,7 @@ dependencies = [
"sync 0.1.0",
"sys_util 0.1.0",
"vm_control 0.1.0",
"vm_memory 0.1.0",
]
[metadata]

View file

@ -26,6 +26,7 @@ exclude = [
"sys_util",
"syscall_defines",
"tempfile",
"vm_memory",
"hypervisor"
]
@ -77,6 +78,7 @@ sys_util = "*"
vhost = { path = "vhost" }
vm_control = { path = "vm_control" }
acpi_tables = { path = "acpi_tables" }
vm_memory = { path = "vm_memory" }
[target.'cfg(target_arch = "x86_64")'.dependencies]
x86_64 = { path = "x86_64" }

View file

@ -18,3 +18,4 @@ resources = { path = "../resources" }
sync = { path = "../sync" }
sys_util = { path = "../sys_util" }
vm_control = { path = "../vm_control" }
vm_memory = { path = "../vm_memory" }

View file

@ -12,7 +12,7 @@ use arch::fdt::{
};
use arch::SERIAL_ADDR;
use devices::{PciAddress, PciInterruptPin};
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
// This is the start of DRAM in the physical address space.
use crate::AARCH64_PHYS_MEM_START;

View file

@ -20,8 +20,9 @@ use minijail::Minijail;
use remain::sorted;
use resources::SystemAllocator;
use sync::Mutex;
use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError};
use sys_util::EventFd;
use vm_control::VmIrqRequestSocket;
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
use kvm::*;
use kvm_sys::kvm_device_attr;

View file

@ -15,3 +15,4 @@ resources = { path = "../resources" }
sync = { path = "../sync" }
sys_util = { path = "../sys_util" }
vm_control = { path = "../vm_control" }
vm_memory = { path = "../vm_memory" }

View file

@ -27,8 +27,9 @@ use kvm::{IoeventAddress, Kvm, Vcpu, Vm};
use minijail::Minijail;
use resources::SystemAllocator;
use sync::Mutex;
use sys_util::{syslog, EventFd, GuestAddress, GuestMemory, GuestMemoryError};
use sys_util::{syslog, EventFd};
use vm_control::VmIrqRequestSocket;
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
pub use serial::{
add_serial_devices, get_serial_cmdline, set_default_serial_parameters, GetSerialCmdlineError,

View file

@ -10,7 +10,8 @@ use crate::Pstore;
use kvm::Vm;
use resources::SystemAllocator;
use resources::{Alloc, MmioType};
use sys_util::{GuestAddress, MemoryMapping};
use sys_util::MemoryMapping;
use vm_memory::GuestAddress;
/// Error for pstore.
#[derive(Debug)]

View file

@ -11,6 +11,7 @@ paste = "*"
pin-utils = "0.1.0-alpha.4"
sys_util = { path = "../sys_util" }
syscall_defines = { path = "../syscall_defines" }
vm_memory = { path = "../vm_memory" }
[dependencies.futures]
version = "*"

View file

@ -192,7 +192,7 @@ mod tests {
#[test]
fn read_to_mem() {
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
use crate::uring_mem::VecIoWrapper;

View file

@ -52,6 +52,7 @@ vfio_sys = { path = "../vfio_sys" }
vhost = { path = "../vhost" }
virtio_sys = { path = "../virtio_sys" }
vm_control = { path = "../vm_control" }
vm_memory = { path = "../vm_memory" }
[dev-dependencies]
tempfile = { path = "../tempfile" }

View file

@ -360,7 +360,7 @@ mod tests {
fn new() -> Ioapic {
let kvm = kvm::Kvm::new().unwrap();
let gm = sys_util::GuestMemory::new(&vec![(sys_util::GuestAddress(0), 0x1000)]).unwrap();
let gm = vm_memory::GuestMemory::new(&vec![(vm_memory::GuestAddress(0), 0x1000)]).unwrap();
let mut vm = Vm::new(&kvm, gm).unwrap();
vm.enable_split_irqchip().unwrap();
let (_, device_socket) = msg_socket::pair::<VmIrqResponse, VmIrqRequest>().unwrap();

View file

@ -156,7 +156,7 @@ mod tests {
use hypervisor::kvm::{Kvm, KvmVm};
use hypervisor::{MPState, Vm};
use sys_util::GuestMemory;
use vm_memory::GuestMemory;
use crate::irqchip::{IrqChip, KvmKernelIrqChip};

View file

@ -641,7 +641,8 @@ mod tests {
use super::*;
use hypervisor::kvm::Kvm;
use sys_util::{EventReadResult, GuestMemory};
use sys_util::EventReadResult;
use vm_memory::GuestMemory;
use hypervisor::{IoapicRedirectionTableEntry, PitRWMode, TriggerMode, Vm, VmX86_64};
use vm_control::{VmIrqRequest, VmIrqResponse};

View file

@ -14,7 +14,8 @@ use audio_streams::{
};
use libcras::{CrasClient, CrasClientType, CrasSocketType};
use resources::{Alloc, MmioType, SystemAllocator};
use sys_util::{error, EventFd, GuestMemory};
use sys_util::{error, EventFd};
use vm_memory::GuestMemory;
use crate::pci::ac97_bus_master::Ac97BusMaster;
use crate::pci::ac97_mixer::Ac97Mixer;
@ -336,7 +337,7 @@ impl PciDevice for Ac97Dev {
mod tests {
use super::*;
use audio_streams::shm_streams::MockShmStreamSource;
use sys_util::GuestAddress;
use vm_memory::GuestAddress;
#[test]
fn create() {

View file

@ -17,9 +17,8 @@ use audio_streams::{
BoxError, DummyStreamControl, SampleFormat, StreamControl, StreamDirection, StreamEffect,
};
use sync::{Condvar, Mutex};
use sys_util::{
self, error, set_rt_prio_limit, set_rt_round_robin, warn, EventFd, GuestAddress, GuestMemory,
};
use sys_util::{self, error, set_rt_prio_limit, set_rt_round_robin, warn, EventFd};
use vm_memory::{GuestAddress, GuestMemory};
use crate::pci::ac97_mixer::Ac97Mixer;
use crate::pci::ac97_regs::*;
@ -95,7 +94,7 @@ impl Ac97BusMasterRegs {
#[derive(Debug)]
enum GuestMemoryError {
// Failure getting the address of the audio buffer.
ReadingGuestBufferAddress(sys_util::GuestMemoryError),
ReadingGuestBufferAddress(vm_memory::GuestMemoryError),
}
impl std::error::Error for GuestMemoryError {}

View file

@ -18,7 +18,8 @@ use crate::utils::EventLoop;
use std::fmt::{self, Display};
use std::sync::Arc;
use sync::Mutex;
use sys_util::{error, warn, Error as SysError, EventFd, GuestAddress, GuestMemory};
use sys_util::{error, warn, Error as SysError, EventFd};
use vm_memory::{GuestAddress, GuestMemory};
#[derive(Debug)]
pub enum Error {

View file

@ -20,7 +20,8 @@ use std::mem::size_of;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use sync::Mutex;
use sys_util::{error, GuestAddress, GuestMemory, GuestMemoryError};
use sys_util::error;
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
#[derive(Debug)]
pub enum Error {

View file

@ -6,7 +6,7 @@ use data_model::DataInit;
use std::fmt::{self, Display};
use std::mem::size_of;
use std::sync::atomic::{fence, Ordering};
use sys_util::{GuestAddress, GuestMemory, GuestMemoryError};
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
use super::xhci_abi::*;

View file

@ -10,7 +10,8 @@ use super::xhci_abi::{
use super::xhci_regs::*;
use crate::register_space::Register;
use std::fmt::{self, Display};
use sys_util::{Error as SysError, EventFd, GuestAddress, GuestMemory};
use sys_util::{Error as SysError, EventFd};
use vm_memory::{GuestAddress, GuestMemory};
#[derive(Debug)]
pub enum Error {

View file

@ -7,7 +7,7 @@ use super::xhci_abi::{
};
use std::fmt::{self, Display};
use std::mem::size_of;
use sys_util::{GuestAddress, GuestMemory, GuestMemoryError};
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
#[derive(Debug)]
pub enum Error {

View file

@ -9,7 +9,8 @@ use std::fmt::{self, Display};
use std::sync::{Arc, MutexGuard};
use sync::Mutex;
use sys_util::{error, Error as SysError, EventFd, GuestAddress, GuestMemory, WatchingEvents};
use sys_util::{error, Error as SysError, EventFd, WatchingEvents};
use vm_memory::{GuestAddress, GuestMemory};
use super::ring_buffer::RingBuffer;

View file

@ -7,7 +7,7 @@ use super::xhci_abi::{
};
use bit_field::Error as BitFieldError;
use std::fmt::{self, Display};
use sys_util::{GuestAddress, GuestMemory, GuestMemoryError};
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
#[derive(Debug)]
pub enum Error {

View file

@ -8,7 +8,8 @@ use crate::usb::xhci::ring_buffer_controller::{
use crate::utils::EventLoop;
use std::sync::Arc;
use sync::Mutex;
use sys_util::{error, EventFd, GuestMemory};
use sys_util::{error, EventFd};
use vm_memory::GuestMemory;
use super::interrupter::Interrupter;
use super::usb_hub::UsbPort;

View file

@ -16,7 +16,8 @@ use std::fmt::{self, Display};
use std::sync::Arc;
use std::thread;
use sync::Mutex;
use sys_util::{error, EventFd, GuestAddress, GuestMemory};
use sys_util::{error, EventFd};
use vm_memory::{GuestAddress, GuestMemory};
#[derive(Debug)]
pub enum Error {

View file

@ -6,7 +6,7 @@ use bit_field::Error as BitFieldError;
use bit_field::*;
use data_model::DataInit;
use std::fmt::{self, Display};
use sys_util::GuestAddress;
use vm_memory::GuestAddress;
#[derive(Debug)]
pub enum Error {

View file

@ -17,7 +17,8 @@ use std::mem;
use std::os::unix::io::RawFd;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use sys_util::{error, EventFd, GuestMemory};
use sys_util::{error, EventFd};
use vm_memory::GuestMemory;
const XHCI_BAR0_SIZE: u64 = 0x10000;

View file

@ -16,8 +16,9 @@ use std::fmt::{self, Display};
use std::mem;
use std::sync::{Arc, Weak};
use sync::Mutex;
use sys_util::{error, Error as SysError, EventFd, GuestMemory};
use sys_util::{error, Error as SysError, EventFd};
use usb_util::{TransferStatus, UsbRequestSetup};
use vm_memory::GuestMemory;
#[derive(Debug)]
pub enum Error {

View file

@ -18,9 +18,9 @@ use sync::Mutex;
use kvm::Vm;
use sys_util::{
ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val, warn, Error,
EventFd, GuestMemory,
ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val, warn, Error, EventFd,
};
use vm_memory::GuestMemory;
use vfio_sys::*;

View file

@ -10,12 +10,11 @@ use std::thread;
use data_model::{DataInit, Le16, Le32, Le64};
use msg_socket::{MsgReceiver, MsgSender};
use sys_util::{
self, error, info, warn, EventFd, GuestAddress, GuestMemory, PollContext, PollToken,
};
use sys_util::{self, error, info, warn, EventFd, PollContext, PollToken};
use vm_control::{
BalloonControlCommand, BalloonControlResponseSocket, BalloonControlResult, BalloonStats,
};
use vm_memory::{GuestAddress, GuestMemory};
use super::{
copy_config, Interrupt, Queue, Reader, VirtioDevice, TYPE_BALLOON, VIRTIO_F_VERSION_1,

View file

@ -19,9 +19,10 @@ use msg_socket::{MsgReceiver, MsgSender};
use sync::Mutex;
use sys_util::Error as SysError;
use sys_util::Result as SysResult;
use sys_util::{error, info, iov_max, warn, EventFd, GuestMemory, PollContext, PollToken, TimerFd};
use sys_util::{error, info, iov_max, warn, EventFd, PollContext, PollToken, TimerFd};
use virtio_sys::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use vm_control::{DiskControlCommand, DiskControlResponseSocket, DiskControlResult};
use vm_memory::GuestMemory;
use super::{
copy_config, DescriptorChain, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer,
@ -818,8 +819,8 @@ impl VirtioDevice for Block {
mod tests {
use std::fs::{File, OpenOptions};
use std::mem::size_of_val;
use sys_util::GuestAddress;
use tempfile::TempDir;
use vm_memory::GuestAddress;
use crate::virtio::descriptor_utils::{create_descriptor_chain, DescriptorType};

View file

@ -8,7 +8,8 @@ use std::sync::mpsc::{channel, Receiver, TryRecvError};
use std::thread;
use data_model::{DataInit, Le16, Le32};
use sys_util::{error, EventFd, GuestMemory, PollContext, PollToken};
use sys_util::{error, EventFd, PollContext, PollToken};
use vm_memory::GuestMemory;
use super::{
copy_config, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_CONSOLE, VIRTIO_F_VERSION_1,

View file

@ -14,14 +14,15 @@ use std::ptr::copy_nonoverlapping;
use std::result;
use data_model::{DataInit, Le16, Le32, Le64, VolatileMemoryError, VolatileSlice};
use sys_util::{FileReadWriteAtVolatile, FileReadWriteVolatile, GuestAddress, GuestMemory};
use sys_util::{FileReadWriteAtVolatile, FileReadWriteVolatile};
use vm_memory::{GuestAddress, GuestMemory};
use super::DescriptorChain;
#[derive(Debug)]
pub enum Error {
DescriptorChainOverflow,
GuestMemoryError(sys_util::GuestMemoryError),
GuestMemoryError(vm_memory::GuestMemoryError),
InvalidChain,
IoError(io::Error),
SplitOutOfBounds(usize),

View file

@ -11,7 +11,8 @@ use std::sync::Arc;
use std::thread;
use data_model::{DataInit, Le32};
use sys_util::{error, warn, Error as SysError, EventFd, GuestMemory};
use sys_util::{error, warn, Error as SysError, EventFd};
use vm_memory::GuestMemory;
use crate::virtio::{
copy_config, DescriptorError, Interrupt, Queue, VirtioDevice, TYPE_FS, VIRTIO_F_VERSION_1,

View file

@ -4,7 +4,8 @@
use std::sync::Arc;
use sys_util::{error, EventFd, GuestMemory, PollContext, PollToken};
use sys_util::{error, EventFd, PollContext, PollToken};
use vm_memory::GuestMemory;
use crate::virtio::fs::filesystem::FileSystem;
use crate::virtio::fs::server::Server;

View file

@ -22,7 +22,8 @@ use std::time::Duration;
use data_model::*;
use sys_util::{debug, error, warn, EventFd, GuestAddress, GuestMemory, PollContext, PollToken};
use sys_util::{debug, error, warn, EventFd, PollContext, PollToken};
use vm_memory::{GuestAddress, GuestMemory};
use gpu_buffer::Format;
pub use gpu_display::EventDevice;

View file

@ -17,8 +17,9 @@ use data_model::*;
use gpu_display::*;
use gpu_renderer::RendererFlags;
use resources::Alloc;
use sys_util::{error, GuestAddress, GuestMemory};
use sys_util::error;
use vm_control::VmMemoryControlRequestSocket;
use vm_memory::{GuestAddress, GuestMemory};
use super::protocol::GpuResponse;
pub use super::virtio_backend::{VirtioBackend, VirtioResource};

View file

@ -17,7 +17,8 @@ use libc::EINVAL;
use data_model::*;
use msg_socket::{MsgReceiver, MsgSender};
use resources::Alloc;
use sys_util::{error, warn, Error, GuestAddress, GuestMemory};
use sys_util::{error, warn, Error};
use vm_memory::{GuestAddress, GuestMemory};
use gpu_display::*;
use gpu_renderer::{

View file

@ -10,7 +10,8 @@ use std::rc::Rc;
use super::protocol::GpuResponse;
use data_model::*;
use gpu_display::*;
use sys_util::{error, GuestMemory};
use sys_util::error;
use vm_memory::GuestMemory;
pub trait VirtioResource {
fn width(&self) -> u32;

View file

@ -20,8 +20,9 @@ use std::usize;
use gpu_display::*;
use gpu_renderer::RendererFlags;
use resources::Alloc;
use sys_util::{error, GuestAddress, GuestMemory};
use sys_util::error;
use vm_control::VmMemoryControlRequestSocket;
use vm_memory::{GuestAddress, GuestMemory};
use super::protocol::GpuResponse;
pub use super::virtio_backend::{VirtioBackend, VirtioResource};

View file

@ -13,7 +13,8 @@ use self::constants::*;
use std::os::unix::io::{AsRawFd, RawFd};
use data_model::{DataInit, Le16, Le32};
use sys_util::{error, warn, EventFd, GuestMemory, PollContext, PollToken};
use sys_util::{error, warn, EventFd, PollContext, PollToken};
use vm_memory::GuestMemory;
use self::event_source::{EvdevEventSource, EventSource, SocketEventSource};
use super::{

View file

@ -15,12 +15,13 @@ use std::thread;
use data_model::{DataInit, Le16, Le64};
use net_util::{Error as TapError, MacAddress, TapT};
use sys_util::Error as SysError;
use sys_util::{error, warn, EventFd, GuestMemory, PollContext, PollToken, WatchingEvents};
use sys_util::{error, warn, EventFd, PollContext, PollToken, WatchingEvents};
use virtio_sys::virtio_net::{
virtio_net_hdr_v1, VIRTIO_NET_CTRL_GUEST_OFFLOADS, VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
VIRTIO_NET_CTRL_MQ, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, VIRTIO_NET_ERR, VIRTIO_NET_OK,
};
use virtio_sys::{vhost, virtio_net};
use vm_memory::GuestMemory;
use super::{
copy_config, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_NET,

View file

@ -10,8 +10,9 @@ use std::path::{Path, PathBuf};
use std::result;
use std::thread;
use sys_util::{error, warn, Error as SysError, EventFd, GuestMemory, PollContext, PollToken};
use sys_util::{error, warn, Error as SysError, EventFd, PollContext, PollToken};
use virtio_sys::vhost::VIRTIO_F_VERSION_1;
use vm_memory::GuestMemory;
use super::{
copy_config, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_9P,

View file

@ -8,8 +8,9 @@ use std::io;
use std::os::unix::io::{AsRawFd, RawFd};
use std::thread;
use sys_util::{error, EventFd, GuestAddress, GuestMemory, PollContext, PollToken};
use sys_util::{error, EventFd, PollContext, PollToken};
use sys_util::{Error as SysError, Result as SysResult};
use vm_memory::{GuestAddress, GuestMemory};
use data_model::{DataInit, Le32, Le64};

View file

@ -8,8 +8,9 @@ use std::os::unix::io::AsRawFd;
use std::sync::atomic::{fence, Ordering};
use cros_async::{AsyncError, U64Source};
use sys_util::{error, GuestAddress, GuestMemory};
use sys_util::error;
use virtio_sys::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use vm_memory::{GuestAddress, GuestMemory};
use super::{Interrupt, VIRTIO_MSI_NO_VECTOR};

View file

@ -8,7 +8,8 @@ use std::io;
use std::os::unix::io::{AsRawFd, RawFd};
use std::thread;
use sys_util::{error, warn, EventFd, GuestMemory, PollContext, PollToken};
use sys_util::{error, warn, EventFd, PollContext, PollToken};
use vm_memory::GuestMemory;
use super::{Interrupt, Queue, VirtioDevice, Writer, TYPE_RNG};

View file

@ -11,7 +11,8 @@ use std::os::unix::io::RawFd;
use std::path::PathBuf;
use std::thread;
use sys_util::{error, EventFd, GuestMemory, PollContext, PollToken};
use sys_util::{error, EventFd, PollContext, PollToken};
use vm_memory::GuestMemory;
use super::{
DescriptorChain, DescriptorError, Interrupt, Queue, Reader, VirtioDevice, Writer, TYPE_TPM,

View file

@ -9,9 +9,10 @@ use std::thread;
use net_util::{MacAddress, TapT};
use sys_util::{error, warn, EventFd, GuestMemory};
use sys_util::{error, warn, EventFd};
use vhost::NetT as VhostNetT;
use virtio_sys::virtio_net;
use vm_memory::GuestMemory;
use super::control_socket::*;
use super::worker::Worker;
@ -350,8 +351,8 @@ pub mod tests {
use std::result;
use std::sync::atomic::AtomicUsize;
use std::sync::Arc;
use sys_util::{GuestAddress, GuestMemory, GuestMemoryError};
use vhost::net::fakes::FakeNet;
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
fn create_guest_memory() -> result::Result<GuestMemory, GuestMemoryError> {
let start_addr1 = GuestAddress(0x0);

View file

@ -7,9 +7,10 @@ use std::thread;
use data_model::{DataInit, Le64};
use sys_util::{error, warn, EventFd, GuestMemory};
use sys_util::{error, warn, EventFd};
use vhost::Vhost;
use vhost::Vsock as VhostVsockHandle;
use vm_memory::GuestMemory;
use super::worker::Worker;
use super::{Error, Result};

View file

@ -12,7 +12,8 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::thread;
use data_model::{DataInit, Le32};
use sys_util::{error, Error as SysError, EventFd, GuestMemory};
use sys_util::{error, Error as SysError, EventFd};
use vm_memory::GuestMemory;
use crate::virtio::resource_bridge::ResourceRequestSocket;
use crate::virtio::virtio_device::VirtioDevice;

View file

@ -6,7 +6,8 @@
use std::collections::{BTreeMap, VecDeque};
use sys_util::{error, EventFd, GuestMemory, PollContext};
use sys_util::{error, EventFd, PollContext};
use vm_memory::GuestMemory;
use crate::virtio::queue::{DescriptorChain, Queue};
use crate::virtio::resource_bridge::ResourceRequestSocket;

View file

@ -4,7 +4,8 @@
use std::os::unix::io::RawFd;
use sys_util::{EventFd, GuestMemory};
use sys_util::EventFd;
use vm_memory::GuestMemory;
use super::*;
use crate::pci::{MsixStatus, PciAddress, PciBarConfiguration, PciCapability};

View file

@ -4,7 +4,8 @@
use std::convert::TryInto;
use sys_util::{warn, GuestAddress};
use sys_util::warn;
use vm_memory::GuestAddress;
use super::*;
@ -243,7 +244,8 @@ mod tests {
use super::*;
use std::os::unix::io::RawFd;
use sys_util::{EventFd, GuestMemory};
use sys_util::EventFd;
use vm_memory::GuestMemory;
struct DummyDevice(u32);
const QUEUE_SIZE: u16 = 256;

View file

@ -11,7 +11,8 @@ use data_model::{DataInit, Le32};
use kvm::Datamatch;
use libc::ERANGE;
use resources::{Alloc, MmioType, SystemAllocator};
use sys_util::{warn, EventFd, GuestMemory, Result};
use sys_util::{warn, EventFd, Result};
use vm_memory::GuestMemory;
use super::*;
use crate::pci::{

View file

@ -59,9 +59,10 @@ use resources::GpuMemoryDesc;
#[cfg(feature = "wl-dmabuf")]
use sys_util::ioctl_iow_nr;
use sys_util::{
error, pipe, round_up_to_page_size, warn, Error, EventFd, FileFlags, GuestMemory,
GuestMemoryError, PollContext, PollToken, Result, ScmSocket, SharedMemory,
error, pipe, round_up_to_page_size, warn, Error, EventFd, FileFlags, PollContext, PollToken,
Result, ScmSocket, SharedMemory,
};
use vm_memory::{GuestMemory, GuestMemoryError};
#[cfg(feature = "wl-dmabuf")]
use sys_util::ioctl_with_ref;

View file

@ -13,7 +13,8 @@ use std::sync::Arc;
use cros_fuzz::fuzz_target;
use devices::virtio::{Block, Interrupt, Queue, VirtioDevice};
use sys_util::{EventFd, GuestAddress, GuestMemory, SharedMemory};
use sys_util::{EventFd, SharedMemory};
use vm_memory::{GuestAddress, GuestMemory};
const MEM_SIZE: u64 = 256 * 1024 * 1024;
const DESC_SIZE: u64 = 16; // Bytes in one virtio descriptor.

View file

@ -9,7 +9,7 @@ use std::convert::TryInto;
use cros_fuzz::fuzz_target;
use devices::virtio::fs::fuzzing::fuzz_server;
use devices::virtio::{create_descriptor_chain, DescriptorType, Reader, Writer};
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
const MEM_SIZE: u64 = 256 * 1024 * 1024;
const BUFFER_ADDR: GuestAddress = GuestAddress(0x100);

View file

@ -10,7 +10,7 @@ use cros_fuzz::fuzz_target;
use cros_fuzz::rand::FuzzRng;
use devices::virtio::{DescriptorChain, Queue};
use rand::{Rng, RngCore};
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
const MAX_QUEUE_SIZE: u16 = 256;
const MEM_SIZE: u64 = 1024 * 1024;

View file

@ -5,7 +5,8 @@
#![no_main]
use cros_fuzz::fuzz_target;
use sys_util::{GuestAddress, GuestMemory, SharedMemory};
use sys_util::SharedMemory;
use vm_memory::{GuestAddress, GuestMemory};
use std::fs::File;
use std::io::Write;

View file

@ -12,3 +12,4 @@ gfxstream = []
data_model = { path = "../data_model" }
libc = "*"
sys_util = { path = "../sys_util" }
vm_memory = { path = "../vm_memory" }

View file

@ -24,7 +24,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use libc::close;
use data_model::VolatileSlice;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
use crate::generated::p_defines::{
PIPE_BIND_RENDER_TARGET, PIPE_BIND_SAMPLER_VIEW, PIPE_TEXTURE_1D, PIPE_TEXTURE_2D,

View file

@ -14,3 +14,4 @@ libc = "*"
msg_socket = { path = "../msg_socket" }
sync = { path = "../sync" }
sys_util = { path = "../sys_util" }
vm_memory = { path = "../vm_memory" }

View file

@ -177,7 +177,7 @@ mod tests {
IoapicRedirectionTableEntry, IoapicState, IrqRoute, IrqSource, IrqSourceChip, LapicState,
PicInitState, PicState, PitChannelState, PitRWMode, PitRWState, PitState, TriggerMode, Vm,
};
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[test]
fn set_gsi_routing() {

View file

@ -33,9 +33,9 @@ use sync::Mutex;
use sys_util::{
block_signal, errno_result, error, ioctl, ioctl_with_mut_ref, ioctl_with_ref, ioctl_with_val,
pagesize, signal, unblock_signal, AsRawDescriptor, Error, EventFd, FromRawDescriptor,
GuestAddress, GuestMemory, MappedRegion, MemoryMapping, MmapError, RawDescriptor, Result,
SafeDescriptor,
MappedRegion, MemoryMapping, MmapError, RawDescriptor, Result, SafeDescriptor,
};
use vm_memory::{GuestAddress, GuestMemory};
use crate::{
ClockState, Datamatch, DeviceKind, Hypervisor, HypervisorCap, IoEventAddress, IrqRoute,
@ -1097,7 +1097,8 @@ mod tests {
use super::*;
use std::os::unix::io::FromRawFd;
use std::thread;
use sys_util::{pagesize, GuestAddress, MemoryMapping, MemoryMappingArena};
use sys_util::{pagesize, MemoryMapping, MemoryMappingArena};
use vm_memory::GuestAddress;
#[test]
fn dirty_log_size() {

View file

@ -12,8 +12,9 @@ use data_model::vec_with_array_field;
use kvm_sys::*;
use sys_util::{
errno_result, error, ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr,
ioctl_with_ref, ioctl_with_val, Error, GuestAddress, MappedRegion, Result,
ioctl_with_ref, ioctl_with_val, Error, MappedRegion, Result,
};
use vm_memory::GuestAddress;
use super::{Kvm, KvmVcpu, KvmVm};
use crate::{
@ -1136,7 +1137,7 @@ mod tests {
PicInitState, PicState, PitChannelState, PitRWMode, PitRWState, PitState, TriggerMode, Vm,
};
use libc::EINVAL;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[test]
fn get_supported_cpuid() {

View file

@ -14,7 +14,8 @@ use std::ops::{Deref, DerefMut};
use std::os::raw::c_int;
use msg_socket::MsgOnSocket;
use sys_util::{EventFd, GuestAddress, GuestMemory, MappedRegion, Result, SafeDescriptor};
use sys_util::{EventFd, MappedRegion, Result, SafeDescriptor};
use vm_memory::{GuestAddress, GuestMemory};
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
pub use crate::aarch64::*;

View file

@ -3,7 +3,8 @@
// found in the LICENSE file.
use bit_field::*;
use sys_util::{error, GuestAddress, Result};
use sys_util::{error, Result};
use vm_memory::GuestAddress;
use crate::{Hypervisor, IrqRoute, IrqSource, IrqSourceChip, Vcpu, Vm};

View file

@ -6,3 +6,4 @@ edition = "2018"
[dependencies]
libc = "*"
sys_util = { path = "../sys_util" }
vm_memory = { path = "../vm_memory" }

View file

@ -8,7 +8,7 @@ use std::io::{Read, Seek, SeekFrom};
use std::mem;
use std::os::unix::io::AsRawFd;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[allow(dead_code)]
#[allow(non_camel_case_types)]
@ -179,7 +179,8 @@ mod test {
use super::*;
use std::fs::File;
use std::io::Write;
use sys_util::{GuestAddress, GuestMemory, SharedMemory};
use sys_util::SharedMemory;
use vm_memory::{GuestAddress, GuestMemory};
const MEM_SIZE: u64 = 0x8000;

View file

@ -11,3 +11,4 @@ libc = "*"
msg_socket = { path = "../msg_socket" }
sys_util = { path = "../sys_util" }
sync = { path = "../sync" }
vm_memory = { path = "../vm_memory" }

View file

@ -29,9 +29,10 @@ use msg_socket::MsgOnSocket;
#[allow(unused_imports)]
use sys_util::{
block_signal, ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref,
ioctl_with_val, pagesize, signal, unblock_signal, warn, Error, EventFd, GuestAddress,
GuestMemory, IoctlNr, MappedRegion, MemoryMapping, MmapError, Result, SIGRTMIN,
ioctl_with_val, pagesize, signal, unblock_signal, warn, Error, EventFd, IoctlNr, MappedRegion,
MemoryMapping, MmapError, Result, SIGRTMIN,
};
use vm_memory::{GuestAddress, GuestMemory};
pub use crate::cap::*;

View file

@ -6,7 +6,8 @@
use kvm::*;
use kvm_sys::kvm_regs;
use sys_util::{GuestAddress, GuestMemory, MemoryMapping, SharedMemory};
use sys_util::{MemoryMapping, SharedMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[test]
fn test_run() {

View file

@ -6,7 +6,8 @@
use kvm::*;
use kvm_sys::kvm_regs;
use sys_util::{GuestAddress, GuestMemory, MemoryMapping, SharedMemory};
use sys_util::{MemoryMapping, SharedMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[test]
fn test_run() {

View file

@ -6,7 +6,7 @@
use kvm::*;
use kvm_sys::kvm_regs;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[test]
fn test_run() {

View file

@ -49,9 +49,9 @@ use sys_util::net::{UnixSeqpacket, UnixSeqpacketListener, UnlinkUnixSeqpacketLis
use sys_util::{
self, block_signal, clear_signal, drop_capabilities, error, flock, get_blocked_signals,
get_group_id, get_user_id, getegid, geteuid, info, register_rt_signal_handler,
set_cpu_affinity, validate_raw_fd, warn, EventFd, ExternalMapping, FlockOperation,
GuestAddress, GuestMemory, Killable, MemoryMappingArena, PollContext, PollToken, Protection,
ScopedEvent, SignalFd, Terminal, TimerFd, WatchingEvents, SIGRTMIN,
set_cpu_affinity, validate_raw_fd, warn, EventFd, ExternalMapping, FlockOperation, Killable,
MemoryMappingArena, PollContext, PollToken, Protection, ScopedEvent, SignalFd, Terminal,
TimerFd, WatchingEvents, SIGRTMIN,
};
use vm_control::{
BalloonControlCommand, BalloonControlRequestSocket, BalloonControlResponseSocket,
@ -61,6 +61,7 @@ use vm_control::{
VmMemoryRequest, VmMemoryResponse, VmMsyncRequest, VmMsyncRequestSocket, VmMsyncResponse,
VmMsyncResponseSocket, VmRunMode,
};
use vm_memory::{GuestAddress, GuestMemory};
use crate::{Config, DiskOption, Executable, SharedDir, SharedDirKind, TouchDeviceOption};
use arch::{

View file

@ -31,10 +31,10 @@ use minijail::{self, Minijail};
use net_util::{Error as TapError, Tap, TapT};
use sys_util::{
block_signal, clear_signal, drop_capabilities, error, getegid, geteuid, info, pipe,
register_rt_signal_handler, validate_raw_fd, warn, Error as SysError, EventFd, GuestMemory,
Killable, MmapError, PollContext, PollToken, Result as SysResult, SignalFd, SignalFdError,
SIGRTMIN,
register_rt_signal_handler, validate_raw_fd, warn, Error as SysError, EventFd, Killable,
MmapError, PollContext, PollToken, Result as SysResult, SignalFd, SignalFdError, SIGRTMIN,
};
use vm_memory::GuestMemory;
use self::process::*;
use self::vcpu::*;

View file

@ -26,9 +26,10 @@ use minijail::Minijail;
use protos::plugin::*;
use sync::Mutex;
use sys_util::{
error, Error as SysError, EventFd, GuestAddress, Killable, MemoryMapping, Result as SysResult,
ScmSocket, SharedMemory, SIGRTMIN,
error, Error as SysError, EventFd, Killable, MemoryMapping, Result as SysResult, ScmSocket,
SharedMemory, SIGRTMIN,
};
use vm_memory::GuestAddress;
use super::*;

View file

@ -20,8 +20,6 @@ mod external_mapping;
mod file_flags;
pub mod file_traits;
mod fork;
mod guest_address;
pub mod guest_memory;
mod mmap;
pub mod net;
mod passwd;
@ -48,8 +46,6 @@ pub use crate::eventfd::*;
pub use crate::external_mapping::*;
pub use crate::file_flags::*;
pub use crate::fork::*;
pub use crate::guest_address::*;
pub use crate::guest_memory::*;
pub use crate::ioctl::*;
pub use crate::mmap::*;
pub use crate::passwd::*;
@ -72,7 +68,6 @@ pub use crate::file_traits::{
AsRawFds, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile, FileSetLen,
FileSync,
};
pub use crate::guest_memory::Error as GuestMemoryError;
pub use crate::mmap::Error as MmapError;
pub use crate::seek_hole::SeekHole;
pub use crate::signalfd::Error as SignalFdError;

View file

@ -10,3 +10,4 @@ libc = "*"
net_util = { path = "../net_util" }
sys_util = { path = "../sys_util" }
virtio_sys = { path = "../virtio_sys" }
vm_memory = { path = "../vm_memory" }

View file

@ -18,7 +18,8 @@ use std::ptr::null;
use assertions::const_assert;
use sys_util::{ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref};
use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError, LayoutAllocation};
use sys_util::{EventFd, LayoutAllocation};
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
#[derive(Debug)]
pub enum Error {
@ -342,7 +343,7 @@ mod tests {
use crate::net::fakes::FakeNet;
use net_util::fakes::FakeTap;
use std::result;
use sys_util::{GuestAddress, GuestMemory, GuestMemoryError};
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
fn create_guest_memory() -> result::Result<GuestMemory, GuestMemoryError> {
let start_addr1 = GuestAddress(0x0);

View file

@ -8,7 +8,8 @@ use std::marker::PhantomData;
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, RawFd};
use sys_util::{ioctl_with_ref, GuestMemory};
use sys_util::ioctl_with_ref;
use vm_memory::GuestMemory;
use super::{ioctl_result, Error, Result, Vhost};

View file

@ -6,8 +6,9 @@ use std::fs::{File, OpenOptions};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, RawFd};
use sys_util::{ioctl_with_ref, GuestMemory};
use sys_util::ioctl_with_ref;
use virtio_sys::{VHOST_VSOCK_SET_GUEST_CID, VHOST_VSOCK_SET_RUNNING};
use vm_memory::GuestMemory;
use super::{ioctl_result, Error, Result, Vhost};

View file

@ -12,3 +12,4 @@ msg_socket = { path = "../msg_socket" }
resources = { path = "../resources" }
sync = { path = "../sync" }
sys_util = { path = "../sys_util" }
vm_memory = { path = "../vm_memory" }

View file

@ -24,9 +24,10 @@ use msg_socket::{MsgError, MsgOnSocket, MsgReceiver, MsgResult, MsgSender, MsgSo
use resources::{Alloc, GpuMemoryDesc, MmioType, SystemAllocator};
use sync::Mutex;
use sys_util::{
error, Error as SysError, EventFd, ExternalMapping, GuestAddress, MappedRegion, MemoryMapping,
MmapError, Result,
error, Error as SysError, EventFd, ExternalMapping, MappedRegion, MemoryMapping, MmapError,
Result,
};
use vm_memory::GuestAddress;
/// A file descriptor either borrowed or owned by this.
#[derive(Debug)]

14
vm_memory/Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
name = "vm_memory"
version = "0.1.0"
authors = ["The Chromium OS Authors"]
edition = "2018"
include = ["src/**/*", "Cargo.toml"]
[dependencies]
data_model = { path = "../data_model" } # provided by ebuild
libc = "*"
sys_util = { path = "../sys_util" } # provided by ebuild
syscall_defines = { path = "../syscall_defines" } # provided by ebuild
[workspace]

View file

@ -18,7 +18,7 @@ impl GuestAddress {
/// # Examples
///
/// ```
/// # use sys_util::GuestAddress;
/// # use vm_memory::GuestAddress;
/// let base = GuestAddress(0x100);
/// let addr = GuestAddress(0x150);
/// assert_eq!(addr.offset_from(base), 0x50u64);

View file

@ -13,24 +13,24 @@ use std::result;
use std::sync::Arc;
use crate::guest_address::GuestAddress;
use crate::mmap::{self, MappedRegion, MemoryMapping};
use crate::shm::{MemfdSeals, SharedMemory};
use crate::{errno, pagesize};
use data_model::volatile_memory::*;
use data_model::DataInit;
use sys_util::{pagesize, Error as SysError};
use sys_util::{MappedRegion, MemoryMapping, MmapError};
use sys_util::{MemfdSeals, SharedMemory};
#[derive(Debug)]
pub enum Error {
DescriptorChainOverflow,
InvalidGuestAddress(GuestAddress),
MemoryAccess(GuestAddress, mmap::Error),
MemoryMappingFailed(mmap::Error),
MemoryAccess(GuestAddress, MmapError),
MemoryMappingFailed(MmapError),
MemoryRegionOverlap,
MemoryRegionTooLarge(u64),
MemoryNotAligned,
MemoryCreationFailed(errno::Error),
MemorySetSizeFailed(errno::Error),
MemoryAddSealsFailed(errno::Error),
MemoryCreationFailed(SysError),
MemorySetSizeFailed(SysError),
MemoryAddSealsFailed(SysError),
ShortWrite { expected: usize, completed: usize },
ShortRead { expected: usize, completed: usize },
SplitOutOfBounds(usize),
@ -198,7 +198,8 @@ impl GuestMemory {
/// # Examples
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # fn test_end_addr() -> Result<(), ()> {
/// let start_addr = GuestAddress(0x1000);
/// let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?;
@ -292,7 +293,8 @@ impl GuestMemory {
/// * Write a slice at guestaddress 0x200.
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # fn test_write_u64() -> Result<(), ()> {
/// # let start_addr = GuestAddress(0x1000);
/// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?;
@ -319,7 +321,7 @@ impl GuestMemory {
/// # Examples
///
/// ```
/// use sys_util::{guest_memory, GuestAddress, GuestMemory};
/// use vm_memory::{guest_memory, GuestAddress, GuestMemory};
///
/// fn test_write_all() -> guest_memory::Result<()> {
/// let ranges = &[(GuestAddress(0x1000), 0x400)];
@ -349,7 +351,8 @@ impl GuestMemory {
/// * Read a slice of length 16 at guestaddress 0x200.
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # fn test_write_u64() -> Result<(), ()> {
/// # let start_addr = GuestAddress(0x1000);
/// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?;
@ -376,7 +379,7 @@ impl GuestMemory {
/// # Examples
///
/// ```
/// use sys_util::{guest_memory, GuestAddress, GuestMemory, MemoryMapping};
/// use vm_memory::{guest_memory, GuestAddress, GuestMemory};
///
/// fn test_read_exact() -> guest_memory::Result<()> {
/// let ranges = &[(GuestAddress(0x1000), 0x400)];
@ -407,7 +410,8 @@ impl GuestMemory {
/// * Read a u64 from two areas of guest memory backed by separate mappings.
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # fn test_read_u64() -> Result<u64, ()> {
/// # let start_addr1 = GuestAddress(0x0);
/// # let start_addr2 = GuestAddress(0x400);
@ -433,7 +437,8 @@ impl GuestMemory {
/// * Write a u64 at guest address 0x1100.
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # fn test_write_u64() -> Result<(), ()> {
/// # let start_addr = GuestAddress(0x1000);
/// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)]).map_err(|_| ())?;
@ -456,7 +461,8 @@ impl GuestMemory {
/// * Write `99` to 30 bytes starting at guest address 0x1010.
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, GuestMemoryError, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
/// # fn test_volatile_slice() -> Result<(), GuestMemoryError> {
/// # let start_addr = GuestAddress(0x1000);
/// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)])?;
@ -487,7 +493,8 @@ impl GuestMemory {
/// * Get a &u64 at offset 0x1010.
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, GuestMemoryError, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
/// # fn test_ref_u64() -> Result<(), GuestMemoryError> {
/// # let start_addr = GuestAddress(0x1000);
/// # let mut gm = GuestMemory::new(&vec![(start_addr, 0x400)])?;
@ -516,7 +523,8 @@ impl GuestMemory {
/// * Read bytes from /dev/urandom
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # use std::fs::File;
/// # use std::path::Path;
/// # fn test_read_random() -> Result<u32, ()> {
@ -555,7 +563,8 @@ impl GuestMemory {
/// * Write 128 bytes to /dev/null
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory, MemoryMapping};
/// # use sys_util::MemoryMapping;
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # use std::fs::File;
/// # use std::path::Path;
/// # fn test_write_null() -> Result<(), ()> {
@ -591,7 +600,7 @@ impl GuestMemory {
/// # Examples
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory};
/// # use vm_memory::{GuestAddress, GuestMemory};
/// # fn test_host_addr() -> Result<(), ()> {
/// let start_addr = GuestAddress(0x1000);
/// let mut gm = GuestMemory::new(&vec![(start_addr, 0x500)]).map_err(|_| ())?;
@ -637,7 +646,7 @@ impl GuestMemory {
/// # Examples
///
/// ```
/// # use sys_util::{GuestAddress, GuestMemory};
/// # use vm_memory::{GuestAddress, GuestMemory};
/// let addr_a = GuestAddress(0x1000);
/// let addr_b = GuestAddress(0x8000);
/// let mut gm = GuestMemory::new(&vec![
@ -659,7 +668,7 @@ impl GuestMemory {
#[cfg(test)]
mod tests {
use super::*;
use crate::kernel_has_memfd;
use sys_util::kernel_has_memfd;
#[test]
fn test_alignment() {

11
vm_memory/src/lib.rs Normal file
View file

@ -0,0 +1,11 @@
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
mod guest_address;
pub mod guest_memory;
pub use guest_address::*;
pub use guest_memory::Error as GuestMemoryError;
pub use guest_memory::*;

View file

@ -21,3 +21,4 @@ sync = { path = "../sync" }
sys_util = { path = "../sys_util" }
acpi_tables = {path = "../acpi_tables" }
vm_control = { path = "../vm_control" }
vm_memory = { path = "../vm_memory" }

View file

@ -3,7 +3,7 @@
// found in the LICENSE file.
use acpi_tables::{rsdp::RSDP, sdt::SDT};
use data_model::DataInit;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
pub struct ACPIDevResource {
pub amls: Vec<u8>,

View file

@ -9,7 +9,7 @@ use std::fmt::{self, Display};
use std::io::{Read, Seek, SeekFrom};
use std::os::unix::io::AsRawFd;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
use crate::bootparam::boot_params;

View file

@ -7,7 +7,7 @@ use arch::fdt::{begin_node, end_node, finish_fdt, start_fdt, Error};
use data_model::DataInit;
use std::fs::File;
use std::mem;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
use crate::bootparam::setup_data;
use crate::{SETUP_DTB, X86_64_FDT_MAX_SIZE};

View file

@ -70,8 +70,9 @@ use minijail::Minijail;
use remain::sorted;
use resources::SystemAllocator;
use sync::Mutex;
use sys_util::{Clock, EventFd, GuestAddress, GuestMemory, GuestMemoryError};
use sys_util::{Clock, EventFd};
use vm_control::VmIrqRequestSocket;
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
#[sorted]
#[derive(Debug)]

View file

@ -11,7 +11,7 @@ use std::slice;
use libc::c_char;
use devices::{PciAddress, PciInterruptPin};
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
use crate::mpspec::*;

View file

@ -12,7 +12,8 @@ use kvm_sys::kvm_msr_entry;
use kvm_sys::kvm_msrs;
use kvm_sys::kvm_regs;
use kvm_sys::kvm_sregs;
use sys_util::{self, warn, GuestAddress, GuestMemory, LayoutAllocation};
use sys_util::{self, warn, LayoutAllocation};
use vm_memory::{GuestAddress, GuestMemory};
use crate::gdt;
@ -413,7 +414,7 @@ pub fn setup_sregs(mem: &GuestMemory, vcpu: &kvm::Vcpu) -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
fn create_guest_mem() -> GuestMemory {
GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap()

View file

@ -8,7 +8,7 @@ use std::result;
use std::slice;
use data_model::DataInit;
use sys_util::{GuestAddress, GuestMemory};
use vm_memory::{GuestAddress, GuestMemory};
#[derive(Debug)]
pub enum Error {