-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move pagetable walker into vm directory
- Loading branch information
Showing
3 changed files
with
43 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod addr; | ||
pub mod page_flag; | ||
pub mod page_table; | ||
pub mod page_table_walker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use super::addr::VirtAddr; | ||
use super::page_table::{PageTable, PageTableEntry, PageTableLevel}; | ||
|
||
|
||
pub struct PageTableWalkerMut<'a, Extra> { | ||
pub page_table: &'a mut PageTable, | ||
pub va: VirtAddr, | ||
pub level: PageTableLevel, | ||
pub extra: Extra, | ||
} | ||
|
||
pub trait PageTableVisitor { | ||
type Output : core::ops::Try; | ||
fn check_va(&mut self, va: VirtAddr) -> Self::Output; | ||
fn leaf(&mut self, pte: &mut PageTableEntry) -> Self::Output; | ||
fn nonleaf(&mut self, pte: &mut PageTableEntry) -> Self::Output; | ||
} | ||
|
||
impl<Extra: PageTableVisitor> PageTableWalkerMut<'_, Extra> { | ||
pub fn visit_mut(&mut self) -> Extra::Output { | ||
let _ = self.extra.check_va(self.va)?; | ||
let index = self.va.get_index(self.level); | ||
let pte = &mut self.page_table[index]; | ||
|
||
match self.level.next_level() { | ||
None => { | ||
self.extra.leaf(pte) | ||
} | ||
Some(next_level) => { | ||
let _ = self.extra.nonleaf(pte)?; | ||
|
||
let next_table = unsafe { &mut *(pte.addr() as *mut PageTable) }; | ||
self.page_table = next_table; | ||
self.level = next_level; | ||
self.visit_mut() | ||
} | ||
} | ||
} | ||
} |