From b6d38e5a0d6958198be5cc307e614cee2c1b2622 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Wed, 24 Feb 2021 03:49:33 +0800 Subject: [PATCH] Fix overflow bug when ceiling va --- os/src/mm/address.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/os/src/mm/address.rs b/os/src/mm/address.rs index 5a3d6161..c059c3a5 100644 --- a/os/src/mm/address.rs +++ b/os/src/mm/address.rs @@ -69,7 +69,7 @@ impl From for usize { impl VirtAddr { pub fn floor(&self) -> VirtPageNum { VirtPageNum(self.0 / PAGE_SIZE) } - pub fn ceil(&self) -> VirtPageNum { VirtPageNum((self.0 + PAGE_SIZE - 1) / PAGE_SIZE) } + pub fn ceil(&self) -> VirtPageNum { VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) } pub fn page_offset(&self) -> usize { self.0 & (PAGE_SIZE - 1) } pub fn aligned(&self) -> bool { self.page_offset() == 0 } } @@ -84,7 +84,7 @@ impl From for VirtAddr { } impl PhysAddr { pub fn floor(&self) -> PhysPageNum { PhysPageNum(self.0 / PAGE_SIZE) } - pub fn ceil(&self) -> PhysPageNum { PhysPageNum((self.0 + PAGE_SIZE - 1) / PAGE_SIZE) } + pub fn ceil(&self) -> PhysPageNum { PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) } pub fn page_offset(&self) -> usize { self.0 & (PAGE_SIZE - 1) } pub fn aligned(&self) -> bool { self.page_offset() == 0 } }