Skip to content

Commit

Permalink
Merge pull request #66 from franzscherr/master
Browse files Browse the repository at this point in the history
x86_64: free PageTable pages if unmapping
  • Loading branch information
dgruss committed Dec 3, 2015
2 parents 1420ce8 + 5db674c commit b4a63f3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions arch/x86/64/source/ArchMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool ArchMemory::checkAndRemove(pointer map_ptr, uint64 index)
((uint64*) map)[index] = 0;
for (uint64 i = 0; i < PAGE_DIR_ENTRIES; i++)
{
if (map[index].present != 0)
if (map[i].present != 0)
return false;
}
return true;
Expand All @@ -43,13 +43,23 @@ bool ArchMemory::unmapPage(uint64 virtual_page)
ArchMemoryMapping m = resolveMapping(page_map_level_4_, virtual_page);

assert(m.page_ppn != 0 && m.page_size == PAGE_SIZE);
PageManager::instance()->freePPN(m.pt_ppn, PAGE_SIZE);
bool empty = checkAndRemove<PageTableEntry>(getIdentAddressOfPPN(m.pt_ppn), m.pti);
if (empty)
empty = checkAndRemove<PageDirPageEntry>(getIdentAddressOfPPN(m.pd_ppn), m.pdi);
if (empty)
if (empty)
{
PageManager::instance()->freePPN(m.pt_ppn, PAGE_SIZE);
empty = checkAndRemove<PageDirPageTableEntry>(getIdentAddressOfPPN(m.pd_ppn), m.pdi);
}
if (empty)
{
PageManager::instance()->freePPN(m.pd_ppn, PAGE_SIZE);
empty = checkAndRemove<PageDirPointerTablePageDirEntry>(getIdentAddressOfPPN(m.pdpt_ppn), m.pdpti);
if (empty)
}
if (empty)
{
PageManager::instance()->freePPN(m.pdpt_ppn, PAGE_SIZE);
empty = checkAndRemove<PageMapLevel4Entry>(getIdentAddressOfPPN(m.pml4_ppn), m.pml4i);
}
return true;
}

Expand Down

0 comments on commit b4a63f3

Please sign in to comment.