kernel/vm.c
int
copyout(pagetable_t pagetable, uint64 dstva, char *src, uint64 len)
{
  uint64 n, va0, pa0;

  while(len > 0){
    va0 = PGROUNDDOWN(dstva);
    pa0 = walkaddr(pagetable, va0);
    if(pa0 == NULL)
      return -1;
    n = PGSIZE - (dstva - va0);
    if(n > len)
      n = len;
    memmove((void *)(pa0 + (dstva - va0)), src, n);

    len -= n;
    src += n;
    dstva = va0 + PGSIZE;
  }
  return 0;
}
// Copy from kernel to user.
// Copy len bytes from src to virtual address dstva in a given page table.
// Return 0 on success, -1 on error.
Copy from kernel to user.
Copy len bytes from src to virtual address dstva in a given page table.
Return 0 on success, -1 on error.
Copy from kernel to user . Copy len bytes from src to virtual address dstva in a given page table . Return 0 on success - 1 on error .
int
copyout(pagetable_t pagetable, uint64 dstva, char *src, uint64 len)
{
  uint64 n, va0, pa0;
  while(len > 0){
    va0 = PGROUNDDOWN(dstva);
    pa0 = walkaddr(pagetable, va0);
    if(pa0 == NULL)
      return -1;
    n = PGSIZE - (dstva - va0);
    if(n > len)
      n = len;
    memmove((void *)(pa0 + (dstva - va0)), src, n);
    len -= n;
    src += n;
    dstva = va0 + PGSIZE;
  }
  return 0;
}
int copyout ( pagetable_t pagetable , uint64 dstva , char * src , uint64 len ) { uint64 n , va0 , pa0 ; while ( len > 0 ) { va0 = PGROUNDDOWN ( dstva ) ; pa0 = walkaddr ( pagetable , va0 ) ; if ( pa0 == NULL ) return -1 ; n = PGSIZE - ( dstva - va0 ) ; if ( n > len ) n = len ; memmove ( ( void * ) ( pa0 + ( dstva - va0 ) ) , src , n ) ; len -= n ; src += n ; dstva = va0 + PGSIZE ; } return 0 ; }
Copy from kernel to user.
Copy from kernel to user .