Skip to content

Commit 8527515

Browse files
committed
Add naive default impl for GuestMemory::find_region()
This function can be default-implemented in terms of `GuestMemory::iter()`. Downstream impls can overwrite this more specialized and efficient versions of course (such as GuestMemoryMmap using a binary search). Signed-off-by: Patrick Roy <[email protected]>
1 parent 6c559cb commit 8527515

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/guest_memory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ pub trait GuestMemory {
408408
fn num_regions(&self) -> usize;
409409

410410
/// Returns the region containing the specified address or `None`.
411-
fn find_region(&self, addr: GuestAddress) -> Option<&Self::R>;
411+
fn find_region(&self, addr: GuestAddress) -> Option<&Self::R> {
412+
self.iter().find(|region| addr >= region.start_addr() && addr <= region.last_addr())
413+
}
412414

413415
/// Gets an iterator over the entries in the collection.
414416
///

0 commit comments

Comments
 (0)