Skip to content

Commit 950dc6e

Browse files
committed
Fix issue #123
1 parent 080da49 commit 950dc6e

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
@@ -100,7 +100,11 @@ impl VirtAddr {
100100
}
101101
///`VirtAddr`->`VirtPageNum`
102102
pub fn ceil(&self) -> VirtPageNum {
103-
VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
103+
if self.0 == 0 {
104+
VirtPageNum(0)
105+
} else {
106+
VirtPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
107+
}
104108
}
105109
///Get page offset
106110
pub fn page_offset(&self) -> usize {
@@ -129,7 +133,11 @@ impl PhysAddr {
129133
}
130134
///`PhysAddr`->`PhysPageNum`
131135
pub fn ceil(&self) -> PhysPageNum {
132-
PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
136+
if self.0 == 0 {
137+
PhysPageNum(0)
138+
} else {
139+
PhysPageNum((self.0 - 1 + PAGE_SIZE) / PAGE_SIZE)
140+
}
133141
}
134142
///Get page offset
135143
pub fn page_offset(&self) -> usize {

0 commit comments

Comments
 (0)