vm.c
// Allocate page tables and physical memory to grow process from oldsz to
// newsz, which need not be page aligned.  Returns new size or 0 on error.
Allocate page tables and physical memory to grow process from oldsz to
newsz, which need not be page aligned.  Returns new size or 0 on error.
Allocate page tables and physical memory to grow process from oldsz to newsz which need not be page aligned . Returns new size or 0 on error .
int allocuvm(pde_t *pgdir, uint oldsz, uint newsz){
  char *mem;
  uint a;
  if(newsz >= KERNBASE)
    return 0;
  if(newsz < oldsz)
    return oldsz;
  if (!isNONEpolicy()){
     if (PGROUNDUP(newsz)/PGSIZE > MAX_TOTAL_PAGES && proc->pid > 2) {
		    cprintf("proc is too big\n", PGROUNDUP(newsz)/PGSIZE);
		    return 0;
		  }
	}
  a = PGROUNDUP(oldsz);
  int i = 0; 
  for(; a < newsz; a += PGSIZE){
    mem = kalloc();
    i++;
    if(mem == 0){
      cprintf("allocuvm out of memory\n");
      deallocuvm(pgdir, newsz, oldsz);
      return 0;
    }
    memset(mem, 0, PGSIZE);
    mappages(pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U);
    if (!isNONEpolicy() && proc->pid > 2){
      if (PGROUNDUP(oldsz)/PGSIZE + i > MAX_PYSC_PAGES)
        swap(pgdir, a);
      else 
        addToRamCtrlr(pgdir, a);
	  }
  }
  return newsz;
}
int allocuvm ( pde_t * pgdir , uint oldsz , uint newsz ) { char * mem ; uint a ; if ( newsz >= KERNBASE ) return 0 ; if ( newsz < oldsz ) return oldsz ; if ( ! isNONEpolicy ( ) ) { if ( PGROUNDUP ( newsz ) / PGSIZE > MAX_TOTAL_PAGES && proc -> pid > 2 ) { cprintf ( " \n " , PGROUNDUP ( newsz ) / PGSIZE ) ; return 0 ; } } a = PGROUNDUP ( oldsz ) ; int i = 0 ; for ( ; a < newsz ; a += PGSIZE ) { mem = kalloc ( ) ; i ++ ; if ( mem == 0 ) { cprintf ( " \n " ) ; deallocuvm ( pgdir , newsz , oldsz ) ; return 0 ; } memset ( mem , 0 , PGSIZE ) ; mappages ( pgdir , ( char * ) a , PGSIZE , v2p ( mem ) , PTE_W | PTE_U ) ; if ( ! isNONEpolicy ( ) && proc -> pid > 2 ) { if ( PGROUNDUP ( oldsz ) / PGSIZE + i > MAX_PYSC_PAGES ) swap ( pgdir , a ) ; else addToRamCtrlr ( pgdir , a ) ; } } return newsz ; }
Allocate page tables and physical memory to grow process from oldsz to
newsz, which need not be page aligned.
Allocate page tables and physical memory to grow process from oldsz to newsz which need not be page aligned .
//debugging //there's room