From f98d8f3ba6d0d158accb65f4a2ff726da1c65486 Mon Sep 17 00:00:00 2001 From: Stephen Barber Date: Wed, 21 Jun 2017 14:46:00 -0700 Subject: 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 Tested-by: Zach Reizner Reviewed-by: Dylan Reid --- sys_util/src/guest_memory.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sys_util/src/guest_memory.rs') 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(&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(&self, guest_addr: GuestAddress, cb: F) -> Result + pub fn do_in_region(&self, guest_addr: GuestAddress, cb: F) -> Result where F: FnOnce(&MemoryMapping, usize) -> Result { for region in self.regions.iter() { -- cgit 1.4.1