mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add unsafe next_table methods
This commit is contained in:
@@ -14,6 +14,26 @@ impl Table {
|
|||||||
entry.set_unused();
|
entry.set_unused();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next_table_address(&self, index: usize) -> Option<usize> {
|
||||||
|
let entry_flags = self[index].flags();
|
||||||
|
if entry_flags.contains(PRESENT) && !entry_flags.contains(HUGE_PAGE) {
|
||||||
|
let table_address = self as *const _ as usize;
|
||||||
|
Some((table_address << 9) | (index << 12))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn next_table(&self, index: usize) -> Option<&Table> {
|
||||||
|
self.next_table_address(index)
|
||||||
|
.map(|t| unsafe { &*(t as *const _) })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn next_table_mut(&mut self, index: usize) -> Option<&mut Table> {
|
||||||
|
self.next_table_address(index)
|
||||||
|
.map(|t| unsafe { &mut *(t as *mut _) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<usize> for Table {
|
impl Index<usize> for Table {
|
||||||
|
|||||||
Reference in New Issue
Block a user