From 7a73d4e3022cb0480f528d137d8c9612a77f35c4 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Wed, 31 May 2023 21:17:53 +0800 Subject: [PATCH] Fix issue #123 --- os/src/mm/address.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/os/src/mm/address.rs b/os/src/mm/address.rs index cf147a080..df3e130fa 100644 --- a/os/src/mm/address.rs +++ b/os/src/mm/address.rs @@ -101,7 +101,11 @@ impl VirtAddr { VirtPageNum(self.0 / PAGE_SIZE) } pub fn ceil(&self) -> VirtPageNum { - VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) + if self.0 == 0 { + VirtPageNum(0) + } else { + VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) + } } pub fn page_offset(&self) -> usize { self.0 & (PAGE_SIZE - 1) @@ -126,7 +130,11 @@ impl PhysAddr { PhysPageNum(self.0 / PAGE_SIZE) } pub fn ceil(&self) -> PhysPageNum { - PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) + if self.0 == 0 { + PhysPageNum(0) + } else { + PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE) + } } pub fn page_offset(&self) -> usize { self.0 & (PAGE_SIZE - 1)