From 6753251af3fbbb2a4037b0151f5a1f4520661efd Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 31 Aug 2022 16:14:27 -0600 Subject: [PATCH] Do not allow mmap with page_count 0 --- src/context/memory.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/context/memory.rs b/src/context/memory.rs index 3ee6d31..b0462c2 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -208,6 +208,9 @@ impl AddrSpace { } pub fn mmap(&mut self, page: Option, page_count: usize, flags: MapFlags, map: impl FnOnce(Page, PageFlags, &mut PageMapper, &mut dyn Flusher) -> Result) -> Result { // Finally, the end of all "T0DO: Abstract with other grant creation"! + if page_count == 0 { + return Err(Error::new(EINVAL)); + } let region = match page { Some(page) => self.grants.find_free_at(self.mmap_min, page.start_address(), page_count * PAGE_SIZE, flags)?, @@ -872,7 +875,7 @@ impl Borrow for Grant { impl Drop for Grant { fn drop(&mut self) { - assert!(!self.mapped, "Grant dropped while still mapped"); + assert!(!self.mapped, "Grant dropped while still mapped: {:#x?}", self); } }