vm.c
// Return the address of the PTE in page table pgdir
// that corresponds to virtual address (in u.m) va.  If alloc!=0,
// create any required page table pages.
Return the address of the PTE in page table pgdir
that corresponds to virtual address (in u.m) va.  If alloc!=0,
create any required page table pages.
Return the address of the PTE in page table pgdir that corresponds to virtual address ( in u . m ) va . If alloc! = 0 create any required page table pages .
static pte_t * walkpgdir(pde_t *pgdir, const void *va, int alloc){
  pde_t *pde;
  pte_t *pgtab;
  pde = &pgdir[PDX(va)]; 
  if(*pde & PTE_P){      
    pgtab = (pte_t*)p2v(PTE_ADDR(*pde)); 
  } else {
    if(!alloc || (pgtab = (pte_t*)kalloc()) == 0) 
      return 0; 
    memset(pgtab, 0, PGSIZE);
    *pde = v2p(pgtab) | PTE_P | PTE_W | PTE_U; 
  }
  return &pgtab[PTX(va)]; 
}
static pte_t * walkpgdir ( pde_t * pgdir , const void * va , int alloc ) { pde_t * pde ; pte_t * pgtab ; pde = & pgdir [ PDX ( va ) ] ; if ( * pde & PTE_P ) { pgtab = ( pte_t * ) p2v ( PTE_ADDR ( * pde ) ) ; } else { if ( ! alloc || ( pgtab = ( pte_t * ) kalloc ( ) ) == 0 ) return 0 ; memset ( pgtab , 0 , PGSIZE ) ; * pde = v2p ( pgtab ) | PTE_P | PTE_W | PTE_U ; } return & pgtab [ PTX ( va ) ] ; }
Return the address of the PTE in page table pgdir
that corresponds to virtual address (in u.m) va.
Return the address of the PTE in page table pgdir that corresponds to virtual address ( in u . m ) va .
//PDE index in page directory (0 to 1023 + FLAGS) //Present bit is on in PDE //pgtab = virtual address to beginning of page table //if alloc != 0, try to create new page table //page table (PDE) doesn't exist or kalloc failed // Make sure all those PTE_P bits are zero. // The permissions here are overly generous, but they can // be further restricted by the permissions in the page table  // entries, if necessary. //link PDE to the new page table //return PTE in page table which corresponse to va address