vm.c
// Load a program segment into pgdir.  addr must be page-aligned
// and the pages from addr to addr+sz must already be mapped.
Load a program segment into pgdir.  addr must be page-aligned
and the pages from addr to addr+sz must already be mapped.
Load a program segment into pgdir . addr must be page - aligned and the pages from addr to addr + sz must already be mapped .
int
loaduvm(pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
{
  uint i, pa, n;
  pte_t *pte;
  if((uint) addr % PGSIZE != 0)
    panic("loaduvm: addr must be page aligned");
  for(i = 0; i < sz; i += PGSIZE){
    if((pte = walkpgdir(pgdir, addr+i, 0)) == 0)
      panic("loaduvm: address should exist");
    pa = PTE_ADDR(*pte);
    if(sz - i < PGSIZE)
      n = sz - i;
    else
      n = PGSIZE;
    if(readi(ip, p2v(pa), offset+i, n) != n)
      return -1;
  }
  return 0;
}
int loaduvm ( pde_t * pgdir , char * addr , struct inode * ip , uint offset , uint sz ) { uint i , pa , n ; pte_t * pte ; if ( ( uint ) addr % PGSIZE != 0 ) panic ( " " ) ; for ( i = 0 ; i < sz ; i += PGSIZE ) { if ( ( pte = walkpgdir ( pgdir , addr + i , 0 ) ) == 0 ) panic ( " " ) ; pa = PTE_ADDR ( * pte ) ; if ( sz - i < PGSIZE ) n = sz - i ; else n = PGSIZE ; if ( readi ( ip , p2v ( pa ) , offset + i , n ) != n ) return -1 ; } return 0 ; }
Load a program segment into pgdir.
Load a program segment into pgdir .