|
|
@ -47,23 +47,21 @@ impl PageTable for ActivePageTable {
|
|
|
|
fn map(&mut self, addr: usize, target: usize) -> &mut Entry {
|
|
|
|
fn map(&mut self, addr: usize, target: usize) -> &mut Entry {
|
|
|
|
let flags = EF::PRESENT | EF::WRITABLE | EF::NO_EXECUTE;
|
|
|
|
let flags = EF::PRESENT | EF::WRITABLE | EF::NO_EXECUTE;
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
if let Ok(flush) = self.0.map_to(
|
|
|
|
self.0
|
|
|
|
Page::of_addr(addr),
|
|
|
|
.map_to(
|
|
|
|
Frame::of_addr(target),
|
|
|
|
Page::of_addr(addr),
|
|
|
|
flags,
|
|
|
|
Frame::of_addr(target),
|
|
|
|
&mut FrameAllocatorForX86,
|
|
|
|
flags,
|
|
|
|
) {
|
|
|
|
&mut FrameAllocatorForX86,
|
|
|
|
flush.flush();
|
|
|
|
)
|
|
|
|
}
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsafe { &mut *(get_entry_ptr(addr, 1)) }
|
|
|
|
unsafe { &mut *(get_entry_ptr(addr, 1)) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn unmap(&mut self, addr: usize) {
|
|
|
|
fn unmap(&mut self, addr: usize) {
|
|
|
|
// unmap and flush if it is mapped
|
|
|
|
self.0.unmap(Page::of_addr(addr)).unwrap().1.flush();
|
|
|
|
if let Ok((_, flush)) = self.0.unmap(Page::of_addr(addr)) {
|
|
|
|
|
|
|
|
flush.flush();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_entry(&mut self, addr: usize) -> Option<&mut Entry> {
|
|
|
|
fn get_entry(&mut self, addr: usize) -> Option<&mut Entry> {
|
|
|
@ -238,6 +236,9 @@ impl InactivePageTable for InactivePageTable0 {
|
|
|
|
|
|
|
|
|
|
|
|
fn edit<T>(&mut self, f: impl FnOnce(&mut Self::Active) -> T) -> T {
|
|
|
|
fn edit<T>(&mut self, f: impl FnOnce(&mut Self::Active) -> T) -> T {
|
|
|
|
let target = Cr3::read().0.start_address().as_u64() as usize;
|
|
|
|
let target = Cr3::read().0.start_address().as_u64() as usize;
|
|
|
|
|
|
|
|
if self.p4_frame == Cr3::read().0 {
|
|
|
|
|
|
|
|
return f(&mut active_table());
|
|
|
|
|
|
|
|
}
|
|
|
|
active_table().with_temporary_map(target, |active_table, p4_table: &mut x86PageTable| {
|
|
|
|
active_table().with_temporary_map(target, |active_table, p4_table: &mut x86PageTable| {
|
|
|
|
let backup = p4_table[0o777].clone();
|
|
|
|
let backup = p4_table[0o777].clone();
|
|
|
|
|
|
|
|
|
|
|
|