Skip to content

Commit c462545

Browse files
committed
Fix issue #123
1 parent 8e66303 commit c462545

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

os/src/mm/address.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ impl VirtAddr {
107107
}
108108
///`VirtAddr`->`VirtPageNum`
109109
pub fn ceil(&self) -> VirtPageNum {
110-
VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
110+
if self.0 == 0 {
111+
VirtPageNum(0)
112+
} else {
113+
VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
114+
}
111115
}
112116
///Get page offset
113117
pub fn page_offset(&self) -> usize {
@@ -136,7 +140,11 @@ impl PhysAddr {
136140
}
137141
///`PhysAddr`->`PhysPageNum`
138142
pub fn ceil(&self) -> PhysPageNum {
139-
PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
143+
if self.0 == 0 {
144+
PhysPageNum(0)
145+
} else {
146+
PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
147+
}
140148
}
141149
///Get page offset
142150
pub fn page_offset(&self) -> usize {

0 commit comments

Comments
 (0)