summary refs log tree commit diff
path: root/sys_util/src/guest_memory.rs
diff options
context:
space:
mode:
authorStephen Barber <smbarber@chromium.org>2017-06-21 14:46:00 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-07-07 13:15:46 -0700
commitf98d8f3ba6d0d158accb65f4a2ff726da1c65486 (patch)
treeeeb3fa734e15987861b18c442913a98924061f41 /sys_util/src/guest_memory.rs
parente4c8c1463e222e23b428e81181b52b0037fdf9a2 (diff)
downloadcrosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.tar
crosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.tar.gz
crosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.tar.bz2
crosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.tar.lz
crosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.tar.xz
crosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.tar.zst
crosvm-f98d8f3ba6d0d158accb65f4a2ff726da1c65486.zip
sys_util: add with_regions_mut and make do_in_region pub
Add a new method to GuestMemory that allows running a FnMut over all
regions. This will allow the virtio module to generate a vhost memory
table.

Also make do_in_region public, so that VHOST_NET can find the host
userspace address of vrings (necessary for VHOST ioctls).

BUG=none
TEST=cargo build

Change-Id: I43611dcc56146ed4d160f0e189b9328ca0e6d87d
Reviewed-on: https://chromium-review.googlesource.com/543909
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'sys_util/src/guest_memory.rs')
-rw-r--r--sys_util/src/guest_memory.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/sys_util/src/guest_memory.rs b/sys_util/src/guest_memory.rs
index e9a33f6..dd553c0 100644
--- a/sys_util/src/guest_memory.rs
+++ b/sys_util/src/guest_memory.rs
@@ -117,6 +117,18 @@ impl GuestMemory {
         Ok(())
     }
 
+    /// Perform the specified action on each region's addresses mutably.
+    pub fn with_regions_mut<F, E>(&self, mut cb: F) -> result::Result<(), E>
+        where F: FnMut(usize, GuestAddress, usize, usize) -> result::Result<(), E>
+    {
+        for (index, region) in self.regions.iter().enumerate() {
+            cb(index,
+               region.guest_base,
+               region.mapping.size(),
+               region.mapping.as_ptr() as usize)?;
+        }
+        Ok(())
+    }
     /// Writes a slice to guest memory at the specified guest address.
     /// Returns the number of bytes written.  The number of bytes written can
     /// be less than the length of the slice if there isn't enough room in the
@@ -272,7 +284,7 @@ impl GuestMemory {
         })
     }
 
-    fn do_in_region<F, T>(&self, guest_addr: GuestAddress, cb: F) -> Result<T>
+    pub fn do_in_region<F, T>(&self, guest_addr: GuestAddress, cb: F) -> Result<T>
         where F: FnOnce(&MemoryMapping, usize) -> Result<T>
     {
         for region in self.regions.iter() {