In a typical Virtual Machine Monitor (VMM) there are several components, such
as boot loader, virtual device drivers, virtio backend drivers and vhost
drivers, that need to access the VM physical memory. The vm-memory
crate
provides a set of traits to decouple VM memory consumers from VM memory
providers. Based on these traits, VM memory consumers can access the physical
memory of the VM without knowing the implementation details of the VM memory
provider. Thus VMM components based on these traits can be shared and reused by
multiple virtualization solutions.
The detailed design of the vm-memory
crate can be found here.
Add vm-memory
as a dependency in Cargo.toml
[dependencies]
vm-memory = "*"
Then add extern crate vm-memory;
to your crate root.
GuestMemoryMmap
implementation of the GuestMemory
trait:fn provide_mem_to_virt_dev() {
let gm = GuestMemoryMmap::from_ranges(&[
(GuestAddress(0), 0x1000),
(GuestAddress(0x1000), 0x1000)
]).unwrap();
virt_device_io(&gm);
}
fn virt_device_io<T: GuestMemory>(mem: &T) {
let sample_buf = &[1, 2, 3, 4, 5];
assert_eq!(mem.write(sample_buf, GuestAddress(0xffc)).unwrap(), 5);
let buf = &mut [0u8; 5];
assert_eq!(mem.read(buf, GuestAddress(0xffc)).unwrap(), 5);
assert_eq!(buf, sample_buf);
}
This project is licensed under either of
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。