From ffefbd92833a6a980bfc08cf582c76ed28852d7d Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Wed, 11 Sep 2019 15:32:54 -0400 Subject: [PATCH] added remove_memory_region() as complement of add_memory_region() --- rust/src/kvm/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rust/src/kvm/mod.rs b/rust/src/kvm/mod.rs index fa63f10..62a1853 100644 --- a/rust/src/kvm/mod.rs +++ b/rust/src/kvm/mod.rs @@ -56,8 +56,14 @@ impl Kvm { }) } - pub fn add_memory_region(&self, slot: usize, guest_address: u64, host_address: u64, size: usize) -> Result<()> { - let region = ioctl::KvmUserspaceMemoryRegion::new(slot as u32, guest_address, host_address, size as u64); + pub fn add_memory_region(&self, slot: u32, guest_address: u64, host_address: u64, size: usize) -> Result<()> { + let region = ioctl::KvmUserspaceMemoryRegion::new(slot, guest_address, host_address, size as u64); + ioctl::kvm_set_user_memory_region(&self.vmfd, ®ion)?; + Ok(()) + } + + pub fn remove_memory_region(&self, slot: u32) -> Result<()> { + let region = ioctl::KvmUserspaceMemoryRegion::new(slot, 0, 0, 0); ioctl::kvm_set_user_memory_region(&self.vmfd, ®ion)?; Ok(()) }