This commit is contained in:
Yifan Wu 2023-05-31 21:17:53 +08:00
parent 45477b345f
commit 90e969c0ae

View file

@ -103,7 +103,11 @@ impl VirtAddr {
VirtPageNum(self.0 / PAGE_SIZE) VirtPageNum(self.0 / PAGE_SIZE)
} }
pub fn ceil(&self) -> VirtPageNum { 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 { pub fn page_offset(&self) -> usize {
self.0 & (PAGE_SIZE - 1) self.0 & (PAGE_SIZE - 1)
@ -128,7 +132,11 @@ impl PhysAddr {
PhysPageNum(self.0 / PAGE_SIZE) PhysPageNum(self.0 / PAGE_SIZE)
} }
pub fn ceil(&self) -> PhysPageNum { 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 { pub fn page_offset(&self) -> usize {
self.0 & (PAGE_SIZE - 1) self.0 & (PAGE_SIZE - 1)