Fix deallocation issues by ignoring deallocation on temporary page
This commit is contained in:
@@ -175,7 +175,7 @@ fn parse_sdt(sdt: &'static Sdt, active_table: &mut ActivePageTable) {
|
||||
}
|
||||
|
||||
// Unmap trampoline
|
||||
let (result, _frame) = active_table.unmap_return(trampoline_page);
|
||||
let (result, _frame) = active_table.unmap_return(trampoline_page, false);
|
||||
result.flush(active_table);
|
||||
*/
|
||||
} else if let Some(dmar) = Dmar::new(sdt) {
|
||||
|
||||
@@ -94,7 +94,7 @@ impl Grant {
|
||||
let start_page = Page::containing_address(self.start);
|
||||
let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size - 1));
|
||||
for page in Page::range_inclusive(start_page, end_page) {
|
||||
let (result, _frame) = active_table.unmap_return(page);
|
||||
let (result, _frame) = active_table.unmap_return(page, false);
|
||||
flush_all.consume(result);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ impl Grant {
|
||||
let start_page = Page::containing_address(self.start);
|
||||
let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size - 1));
|
||||
for page in Page::range_inclusive(start_page, end_page) {
|
||||
let (result, _frame) = mapper.unmap_return(page);
|
||||
let (result, _frame) = mapper.unmap_return(page, false);
|
||||
// This is not the active table, so the flush can be ignored
|
||||
unsafe { result.ignore(); }
|
||||
}
|
||||
@@ -240,7 +240,7 @@ impl Memory {
|
||||
let mut flush_all = MapperFlushAll::new();
|
||||
|
||||
for page in self.pages() {
|
||||
let (result, frame) = active_table.unmap_return(page);
|
||||
let (result, frame) = active_table.unmap_return(page, false);
|
||||
flush_all.consume(result);
|
||||
|
||||
active_table.with(new_table, temporary_page, |mapper| {
|
||||
|
||||
@@ -133,7 +133,7 @@ impl Mapper {
|
||||
self.map_to(page, frame, flags)
|
||||
}
|
||||
|
||||
fn unmap_inner(&mut self, page: &Page) -> Frame {
|
||||
fn unmap_inner(&mut self, page: &Page, keep_parents: bool) -> Frame {
|
||||
let frame;
|
||||
|
||||
let p4 = self.p4_mut();
|
||||
@@ -147,39 +147,39 @@ impl Mapper {
|
||||
frame = p1[page.p1_index()].pointed_frame().expect("unmap_inner: frame not found");
|
||||
p1[page.p1_index()].set_unused();
|
||||
|
||||
if ! p1.is_unused() {
|
||||
if keep_parents || ! p1.is_unused() {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let p1_frame = p2[page.p2_index()].pointed_frame().expect("unmap_inner: p1 frame not found");
|
||||
println!("Free p1 {:?}", p1_frame);
|
||||
//println!("Free p1 {:?}", p1_frame);
|
||||
p2[page.p2_index()].set_unused();
|
||||
deallocate_frames(p1_frame, 1);
|
||||
}
|
||||
|
||||
if ! p2.is_unused() {
|
||||
if keep_parents || ! p2.is_unused() {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let p2_frame = p3[page.p3_index()].pointed_frame().expect("unmap_inner: p2 frame not found");
|
||||
println!("Free p2 {:?}", p2_frame);
|
||||
//println!("Free p2 {:?}", p2_frame);
|
||||
p3[page.p3_index()].set_unused();
|
||||
deallocate_frames(p2_frame, 1);
|
||||
}
|
||||
|
||||
if ! p3.is_unused() {
|
||||
if keep_parents || ! p3.is_unused() {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let p3_frame = p4[page.p4_index()].pointed_frame().expect("unmap_inner: p3 frame not found");
|
||||
println!("Free p3 {:?}", p3_frame);
|
||||
p4[page.p2_index()].set_unused();
|
||||
//println!("Free p3 {:?}", p3_frame);
|
||||
p4[page.p4_index()].set_unused();
|
||||
deallocate_frames(p3_frame, 1);
|
||||
}
|
||||
|
||||
@@ -188,14 +188,14 @@ impl Mapper {
|
||||
|
||||
/// Unmap a page
|
||||
pub fn unmap(&mut self, page: Page) -> MapperFlush {
|
||||
let frame = self.unmap_inner(&page);
|
||||
let frame = self.unmap_inner(&page, false);
|
||||
deallocate_frames(frame, 1);
|
||||
MapperFlush::new(page)
|
||||
}
|
||||
|
||||
/// Unmap a page, return frame without free
|
||||
pub fn unmap_return(&mut self, page: Page) -> (MapperFlush, Frame) {
|
||||
let frame = self.unmap_inner(&page);
|
||||
pub fn unmap_return(&mut self, page: Page, keep_parents: bool) -> (MapperFlush, Frame) {
|
||||
let frame = self.unmap_inner(&page, keep_parents);
|
||||
(MapperFlush::new(page), frame)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ impl TemporaryPage {
|
||||
|
||||
/// Unmaps the temporary page in the active table.
|
||||
pub fn unmap(&mut self, active_table: &mut ActivePageTable) {
|
||||
let (result, _frame) = active_table.unmap_return(self.page);
|
||||
let (result, _frame) = active_table.unmap_return(self.page, true);
|
||||
result.flush(active_table);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user