From 4160cb6d7ea894e17c7bb7b33a5f43f0f789f585 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 18 Apr 2017 12:00:17 +0200 Subject: [PATCH] Begin creating an ActivePageTable::with function --- src/memory/paging/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 2aa7e85..25e1e77 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -157,6 +157,23 @@ impl ActivePageTable { // TODO free p(1,2,3) table if empty //allocator.deallocate_frame(frame); } + + pub fn with(&mut self, + table: &mut InactivePageTable, + f: F) + where F: FnOnce(&mut ActivePageTable) + { + use x86_64::instructions::tlb; + + // overwrite recursive mapping + self.p4_mut()[511].set(table.p4_frame.clone(), PRESENT | WRITABLE); + tlb::flush_all(); + + // execute f in the new context + f(self); + + // TODO restore recursive mapping to original p4 table + } } pub struct InactivePageTable {