From c16b3059cf333efc5dcc1f6e97490a480c3d4d17 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 31 Dec 2015 02:28:03 +0100 Subject: [PATCH] Add ActivePageTable::with draft --- src/memory/paging/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 1439f35f..2a197cc3 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -78,6 +78,22 @@ impl ActivePageTable { unsafe fn new() -> ActivePageTable { ActivePageTable { mapper: Mapper::new() } } + + pub fn with(&mut self, table: &mut InactivePageTable, f: F) + where F: FnOnce(&mut Mapper) + { + use x86::tlb; + let flush_tlb = || unsafe { tlb::flush_all() }; + + // overwrite recursive mapping + self.p4_mut()[511].set(table.p4_frame.clone(), PRESENT | WRITABLE); + flush_tlb(); + + // execute f in the new context + f(self); + + // TODO restore recursive mapping to original p4 table + } } pub struct InactivePageTable {