kernel/vm.c
pagetable_t
proc_kpagetable()
{
  pagetable_t kpt = (pagetable_t) kalloc();
  if (kpt == NULL)
    return NULL;
  memmove(kpt, kernel_pagetable, PGSIZE);

  // remap stack and trampoline, because they share the same page table of level 1 and 0
  char *pstack = kalloc();
  if(pstack == NULL)
    goto fail;
  if (mappages(kpt, VKSTACK, PGSIZE, (uint64)pstack, PTE_R | PTE_W) != 0)
    goto fail;
  
  return kpt;

fail:
  kvmfree(kpt, 1);
  return NULL;
}
// initialize kernel pagetable for each process.
initialize kernel pagetable for each process.
initialize kernel pagetable for each process .
pagetable_t
proc_kpagetable()
{
  pagetable_t kpt = (pagetable_t) kalloc();
  if (kpt == NULL)
    return NULL;
  memmove(kpt, kernel_pagetable, PGSIZE);
  char *pstack = kalloc();
  if(pstack == NULL)
    goto fail;
  if (mappages(kpt, VKSTACK, PGSIZE, (uint64)pstack, PTE_R | PTE_W) != 0)
    goto fail;
  return kpt;
fail:
  kvmfree(kpt, 1);
  return NULL;
}
pagetable_t proc_kpagetable ( ) { pagetable_t kpt = ( pagetable_t ) kalloc ( ) ; if ( kpt == NULL ) return NULL ; memmove ( kpt , kernel_pagetable , PGSIZE ) ; char * pstack = kalloc ( ) ; if ( pstack == NULL ) goto fail ; if ( mappages ( kpt , VKSTACK , PGSIZE , ( uint64 ) pstack , PTE_R | PTE_W ) != 0 ) goto fail ; return kpt ; fail : kvmfree ( kpt , 1 ) ; return NULL ; }
initialize kernel pagetable for each process.
initialize kernel pagetable for each process .
// remap stack and trampoline, because they share the same page table of level 1 and 0