Add unsafe map_to function and make translate unsafe, too

These functions are unsafe because it's possible to get aliased &mut references.
This commit is contained in:
Philipp Oppermann
2015-12-09 00:51:34 +01:00
parent e84344f59a
commit 46b93e0650
2 changed files with 33 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
use memory::paging::entry::*;
use memory::paging::ENTRY_COUNT;
use memory::FrameAllocator;
use core::ops::{Index, IndexMut};
use core::marker::PhantomData;
@@ -40,6 +41,22 @@ impl<L> Table<L> where L: HierachicalLevel
self.next_table_address(index)
.map(|t| unsafe { &mut *(t as *mut _) })
}
pub fn next_table_create<A>(&mut self,
index: usize,
allocator: &mut A)
-> &mut Table<L::NextLevel>
where A: FrameAllocator
{
if self.next_table(index).is_none() {
assert!(!self.entries[index].flags().contains(HUGE_PAGE),
"mapping code does not support huge pages");
let frame = allocator.allocate_frame().expect("no frames available");
self.entries[index].set(frame, PRESENT | WRITABLE);
self.next_table_mut(index).unwrap().zero();
}
self.next_table_mut(index).unwrap()
}
}
impl<L> Index<usize> for Table<L> where L: TableLevel