Skip to content

Instantly share code, notes, and snippets.

@heatd

heatd/xv6-vm.c Secret

Created November 21, 2023 17:21
Show Gist options
  • Save heatd/b4203342798b32606290cde8d58f49de to your computer and use it in GitHub Desktop.
Save heatd/b4203342798b32606290cde8d58f49de to your computer and use it in GitHub Desktop.
// Free a page table and all the physical memory pages
// in the user part.
void
freevm(pde_t *pgdir)
{
uint i, j;
pte_t *pt;
if(pgdir == 0)
panic("freevm: no pgdir");
deallocuvm(pgdir, KERNBASE, 0);
for(i = 0; i < NPDENTRIES; i++){
if(pgdir[i] & PTE_P){
pt = P2V(PTE_ADDR(pgdir[i]));
if ( /* is under KERNBASE */) {
for (j = 0; j < NPTENTRIES; j++) {
if (pt[j] & PTE_P)
kfree(P2V(PTE_ADDR(pt[j])));
}
}
kfree(pt);
}
}
kfree((char*)pgdir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment