kernel/elf.c
static void *elf_alloc_mb(elf_ctx *ctx, uint64 elf_pa, uint64 elf_va, uint64 size) {
  elf_info *msg = (elf_info *)ctx->info;
  // We assume that size of proram segment is smaller than a page.
  kassert(size < PGSIZE);
  void *pa = alloc_page();
  if (pa == 0) panic("uvmalloc mem alloc falied\n");

  memset((void *)pa, 0, PGSIZE);
  user_vm_map((pagetable_t)msg->p->pagetable, elf_va, PGSIZE, (uint64)pa,
         prot_to_type(PROT_WRITE | PROT_READ | PROT_EXEC, 1));

  return pa;
}
//
// the implementation of allocater. allocates memory space for later segment loading
//
the implementation of allocater. allocates memory space for later segment loading
the implementation of allocater . allocates memory space for later segment loading
static void *elf_alloc_mb(elf_ctx *ctx, uint64 elf_pa, uint64 elf_va, uint64 size) {
  elf_info *msg = (elf_info *)ctx->info;
  kassert(size < PGSIZE);
  void *pa = alloc_page();
  if (pa == 0) panic("uvmalloc mem alloc falied\n");
  memset((void *)pa, 0, PGSIZE);
  user_vm_map((pagetable_t)msg->p->pagetable, elf_va, PGSIZE, (uint64)pa,
         prot_to_type(PROT_WRITE | PROT_READ | PROT_EXEC, 1));
  return pa;
}
static void * elf_alloc_mb ( elf_ctx * ctx , uint64 elf_pa , uint64 elf_va , uint64 size ) { elf_info * msg = ( elf_info * ) ctx -> info ; kassert ( size < PGSIZE ) ; void * pa = alloc_page ( ) ; if ( pa == 0 ) panic ( " \n " ) ; memset ( ( void * ) pa , 0 , PGSIZE ) ; user_vm_map ( ( pagetable_t ) msg -> p -> pagetable , elf_va , PGSIZE , ( uint64 ) pa , prot_to_type ( PROT_WRITE | PROT_READ | PROT_EXEC , 1 ) ) ; return pa ; }
the implementation of allocater.
the implementation of allocater .
// We assume that size of proram segment is smaller than a page.