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;
  if(pgdir == 0)
    panic("freevm: no pgdir");
  deallocuvm(pgdir, KERNBASE, 0);
  int j = 0;
  for(i = 0; i < NPDENTRIES; i++){
    if(pgdir[i] & PTE_P){ 
      char * v = p2v(PTE_ADDR(pgdir[i]));
      kfree(v); 
      j++;
    }
  }
  kfree((char*)pgdir); 
}
void freevm ( pde_t * pgdir ) { uint i ; if ( pgdir == 0 ) panic ( " " ) ; deallocuvm ( pgdir , KERNBASE , 0 ) ; int j = 0 ; for ( i = 0 ; i < NPDENTRIES ; i ++ ) { if ( pgdir [ i ] & PTE_P ) { char * v = p2v ( PTE_ADDR ( pgdir [ i ] ) ) ; kfree ( v ) ; j ++ ; } } 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 .
//PDE exists //free page table //free page directory