Skip to content

Commit c62e8d7

Browse files
committed
get rid of unsafe in PageTable::iter
1 parent ce296f3 commit c62e8d7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/structures/paging/page_table.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ impl PageTable {
208208
/// Returns an iterator over the entries of the page table.
209209
#[inline]
210210
pub fn iter(&self) -> impl Iterator<Item = &PageTableEntry> {
211+
(0..512).map(move |i| &self.entries[i])
212+
}
213+
214+
/// Returns an iterator that allows modifying the entries of the page table.
215+
#[inline]
216+
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut PageTableEntry> {
211217
// Note that we intentionally don't just return `self.entries.iter()`:
212218
// Some users may choose to create a reference to a page table at
213219
// `0xffff_ffff_ffff_f000`. This causes problems because calculating
@@ -222,14 +228,6 @@ impl PageTable {
222228
// calculate the end pointer. This doesn't make creating page tables at
223229
// that address sound, but it avoids some easy to trigger
224230
// miscompilations.
225-
let ptr = self.entries.as_ptr();
226-
(0..512).map(move |i| unsafe { &*ptr.add(i) })
227-
}
228-
229-
/// Returns an iterator that allows modifying the entries of the page table.
230-
#[inline]
231-
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut PageTableEntry> {
232-
// See `Self::iter`.
233231
let ptr = self.entries.as_mut_ptr();
234232
(0..512).map(move |i| unsafe { &mut *ptr.add(i) })
235233
}

0 commit comments

Comments
 (0)