diff --git a/CHANGELOG.md b/CHANGELOG.md index 1881e7bb..532e96fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ - \[[#307](https://github.com/rust-vmm/vm-memory/pull/304)\] Move `read_volatile_from`, `read_exact_volatile_from`, `write_volatile_to` and `write_all_volatile_to` functions from the `GuestMemory` trait to the `Bytes` trait. +- \[#324](https:////github.com/rust-vmm/vm-memory/pull/324)\] `GuestMemoryRegion::bitmap()` now returns a `BitmapSlice`. Accessing the full bitmap is now possible only if the type of the memory region is know, for example with `MmapRegion::bitmap()`. + ### Removed - \[[#307](https://github.com/rust-vmm/vm-memory/pull/304)\] Remove deprecated functions `Bytes::read_from`, `Bytes::read_exact_from`, diff --git a/src/bitmap/mod.rs b/src/bitmap/mod.rs index 0eab2851..d2682a13 100644 --- a/src/bitmap/mod.rs +++ b/src/bitmap/mod.rs @@ -293,13 +293,13 @@ pub(crate) mod tests { let slice = region.get_slice(dirty_addr, dirty_len).unwrap(); - assert!(range_is_clean(region.bitmap(), 0, region.len() as usize)); + assert!(range_is_clean(®ion.bitmap(), 0, region.len() as usize)); assert!(range_is_clean(slice.bitmap(), 0, dirty_len)); region.write_obj(val, dirty_addr).unwrap(); assert!(range_is_dirty( - region.bitmap(), + ®ion.bitmap(), dirty_addr.0 as usize, dirty_len )); @@ -312,7 +312,7 @@ pub(crate) mod tests { test_bytes( region, |r: &R, start: usize, len: usize, clean: bool| { - check_range(r.bitmap(), start, len, clean) + check_range(&r.bitmap(), start, len, clean) }, |offset| MemoryRegionAddress(offset as u64), 0x1000, @@ -334,13 +334,13 @@ pub(crate) mod tests { let (region, region_addr) = m.to_region_addr(dirty_addr).unwrap(); let slice = m.get_slice(dirty_addr, dirty_len).unwrap(); - assert!(range_is_clean(region.bitmap(), 0, region.len() as usize)); + assert!(range_is_clean(®ion.bitmap(), 0, region.len() as usize)); assert!(range_is_clean(slice.bitmap(), 0, dirty_len)); m.write_obj(val, dirty_addr).unwrap(); assert!(range_is_dirty( - region.bitmap(), + ®ion.bitmap(), region_addr.0 as usize, dirty_len )); @@ -354,7 +354,7 @@ pub(crate) mod tests { let check_range_closure = |m: &M, start: usize, len: usize, clean: bool| -> bool { let mut check_result = true; m.try_access(len, GuestAddress(start as u64), |_, size, reg_addr, reg| { - if !check_range(reg.bitmap(), reg_addr.0 as usize, size, clean) { + if !check_range(®.bitmap(), reg_addr.0 as usize, size, clean) { check_result = false; } Ok(size) diff --git a/src/guest_memory.rs b/src/guest_memory.rs index 189ea8dd..2944169d 100644 --- a/src/guest_memory.rs +++ b/src/guest_memory.rs @@ -177,7 +177,7 @@ pub trait GuestMemoryRegion: Bytes { } /// Borrow the associated `Bitmap` object. - fn bitmap(&self) -> &Self::B; + fn bitmap(&self) -> BS<'_, Self::B>; /// Returns the given address if it is within this region. fn check_address(&self, addr: MemoryRegionAddress) -> Option { diff --git a/src/mmap/mod.rs b/src/mmap/mod.rs index 9f9f1939..9f579d74 100644 --- a/src/mmap/mod.rs +++ b/src/mmap/mod.rs @@ -327,8 +327,8 @@ impl GuestMemoryRegion for GuestRegionMmap { self.guest_base } - fn bitmap(&self) -> &Self::B { - self.mapping.bitmap() + fn bitmap(&self) -> BS<'_, Self::B> { + self.mapping.bitmap().slice_at(0) } fn get_host_address(&self, addr: MemoryRegionAddress) -> guest_memory::Result<*mut u8> {