Auto deallocate frame

master
WangRunji 7 years ago
parent f3d62a5b8f
commit 7b57e64ff6

@ -94,7 +94,7 @@ impl Mapper {
self.map_to(page, frame, flags)
}
pub fn unmap(&mut self, page: Page)
pub fn unmap(&mut self, page: Page) -> Frame
{
use x86_64::instructions::tlb;
use x86_64::VirtualAddress;
@ -110,5 +110,6 @@ impl Mapper {
p1[page.p1_index()].set_unused();
tlb::flush(VirtualAddress(page.start_address()));
// TODO free p(1,2,3) table if empty
frame
}
}

@ -185,6 +185,7 @@ impl InactivePageTable {
impl Drop for InactivePageTable {
fn drop(&mut self) {
warn!("PageTable dropped: {:?}", self);
info!("PageTable dropping: {:?}", self);
dealloc_frame(self.p4_frame.clone());
}
}

@ -25,7 +25,7 @@ impl TemporaryPage {
}
/// Unmaps the temporary page in the active table.
pub fn unmap(&self, active_table: &mut ActivePageTable) {
pub fn unmap(&self, active_table: &mut ActivePageTable) -> Frame {
active_table.unmap(self.page)
}

@ -67,7 +67,7 @@ impl MemoryArea {
Some(phys_start) => {
for page in Page::range_of(self.start_addr, self.end_addr) {
let frame = Frame::of_addr(phys_start.get() + page.start_address() - self.start_addr);
pt.map_to(page, frame.clone(), self.flags.0);
pt.map_to(page, frame, self.flags.0);
}
}
None => {
@ -79,7 +79,10 @@ impl MemoryArea {
}
fn unmap(&self, pt: &mut Mapper) {
for page in Page::range_of(self.start_addr, self.end_addr) {
pt.unmap(page);
let frame = pt.unmap(page);
if self.phys_start_addr.is_none() {
dealloc_frame(frame);
}
}
}
}

@ -22,8 +22,14 @@ lazy_static! {
static STACK_ALLOCATOR: Mutex<Option<StackAllocator>> = Mutex::new(None);
pub fn alloc_frame() -> Frame {
FRAME_ALLOCATOR.lock()
.allocate_frame().expect("no more frame")
let frame = FRAME_ALLOCATOR.lock().allocate_frame().expect("no more frame");
trace!("alloc: {:?}", frame);
frame
}
pub fn dealloc_frame(frame: Frame) {
trace!("dealloc: {:?}", frame);
FRAME_ALLOCATOR.lock().deallocate_frame(frame);
}
fn alloc_stack(size_in_pages: usize) -> Stack {

Loading…
Cancel
Save