vm.c
// Free a page table and all the physical memory pages
// in the user part.
Free a page table and all the physical memory pages
in the user part.
Free a page table and all the physical memory pages in the user part .
void
freevm(pde_t *pgdir)
{
  uint i, blockno;
  if(pgdir == 0)
    panic("freevm: no pgdir");
  deallocuvm(pgdir, KERNBASE, PGSIZE);
  for(i = 0; i < NPDENTRIES; i++){
    if(pgdir[i] & PTE_P){
      char * v = P2V(PTE_ADDR(pgdir[i]));
      kfree(v);
    }
    else if((pgdir[i] & PTE_SWAPPED)) {
        blockno = pgdir[i]>>12;
        bfree_page(blockno);
        char * v = P2V(PTE_ADDR(pgdir[i]));
        kfree(v);
    }
  }
  kfree((char*)pgdir);
}
void freevm ( pde_t * pgdir ) { uint i , blockno ; if ( pgdir == 0 ) panic ( " " ) ; deallocuvm ( pgdir , KERNBASE , PGSIZE ) ; for ( i = 0 ; i < NPDENTRIES ; i ++ ) { if ( pgdir [ i ] & PTE_P ) { char * v = P2V ( PTE_ADDR ( pgdir [ i ] ) ) ; kfree ( v ) ; } else if ( ( pgdir [ i ] & PTE_SWAPPED ) ) { blockno = pgdir [ i ] >> 12 ; bfree_page ( blockno ) ; char * v = P2V ( PTE_ADDR ( pgdir [ i ] ) ) ; kfree ( v ) ; } } kfree ( ( char * ) pgdir ) ; }
Free a page table and all the physical memory pages
in the user part.
Free a page table and all the physical memory pages in the user part .