Skip to content

Commit

Permalink
Fix issue #123
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfcyx committed May 31, 2023
1 parent 173f401 commit 7a73d4e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions os/src/mm/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 7a73d4e

Please sign in to comment.