kernel/exec.c
static int
loadseg(pagetable_t pagetable, uint64 va, struct dirent *ep, uint offset, uint sz)
{
  uint i, n;
  uint64 pa;
  if((va % PGSIZE) != 0)
    panic("loadseg: va must be page aligned");

  for(i = 0; i < sz; i += PGSIZE){
    pa = walkaddr(pagetable, va + i);
    if(pa == NULL)
      panic("loadseg: address should exist");
    if(sz - i < PGSIZE)
      n = sz - i;
    else
      n = PGSIZE;
    if(eread(ep, 0, (uint64)pa, offset+i, n) != n)
      return -1;
  }

  return 0;
}
// Load a program segment into pagetable at virtual address va.
// va must be page-aligned
// and the pages from va to va+sz must already be mapped.
// Returns 0 on success, -1 on failure.
Load a program segment into pagetable at virtual address va.
va must be page-aligned
and the pages from va to va+sz must already be mapped.
Returns 0 on success, -1 on failure.
Load a program segment into pagetable at virtual address va . va must be page - aligned and the pages from va to va + sz must already be mapped . Returns 0 on success - 1 on failure .
static int
loadseg(pagetable_t pagetable, uint64 va, struct dirent *ep, uint offset, uint sz)
{
  uint i, n;
  uint64 pa;
  if((va % PGSIZE) != 0)
    panic("loadseg: va must be page aligned");
  for(i = 0; i < sz; i += PGSIZE){
    pa = walkaddr(pagetable, va + i);
    if(pa == NULL)
      panic("loadseg: address should exist");
    if(sz - i < PGSIZE)
      n = sz - i;
    else
      n = PGSIZE;
    if(eread(ep, 0, (uint64)pa, offset+i, n) != n)
      return -1;
  }
  return 0;
}
static int loadseg ( pagetable_t pagetable , uint64 va , struct dirent * ep , uint offset , uint sz ) { uint i , n ; uint64 pa ; if ( ( va % PGSIZE ) != 0 ) panic ( " " ) ; for ( i = 0 ; i < sz ; i += PGSIZE ) { pa = walkaddr ( pagetable , va + i ) ; if ( pa == NULL ) panic ( " " ) ; if ( sz - i < PGSIZE ) n = sz - i ; else n = PGSIZE ; if ( eread ( ep , 0 , ( uint64 ) pa , offset + i , n ) != n ) return -1 ; } return 0 ; }
Load a program segment into pagetable at virtual address va.
va must be page-aligned
and the pages from va to va+sz must already be mapped.
Load a program segment into pagetable at virtual address va . va must be page - aligned and the pages from va to va + sz must already be mapped .