Example #1
0
File: pager.c Project: gapry/aos-1
/*
 * This function loads the entire elf file into the phsical frames and
 * maps fpages corresponding to virtual address in elf file to the process
 */
int load_code_segment_virtual(char *elfFile,L4_ThreadId_t new_tid) {
  uint32_t min[2];
  uint32_t max[2];
  elf_getMemoryBounds(elfFile, 0, (uint64_t*)min, (uint64_t*)max);
  //Now we need to reserve memory between min and max
  L4_Word_t lower_address = ((L4_Word_t) min[1] / PAGESIZE) * PAGESIZE; 
  L4_Word_t upper_address = ((L4_Word_t) max[1] / PAGESIZE) * PAGESIZE;
 
  while(lower_address <= upper_address) {
    L4_Word_t frame = frame_alloc();
    if(!frame) {
      //Oops out of frames
      unmap_process(new_tid);
      return -1;
    } else {
      L4_Fpage_t targetpage = L4_FpageLog2(lower_address,12);
      lower_address += PAGESIZE;
      //Now map fpage
      L4_Set_Rights(&targetpage,L4_FullyAccessible);
      L4_PhysDesc_t phys = L4_PhysDesc(frame, L4_DefaultMemory);
      //Map the frame to root task but enter entries in pagetable with tid since we will update the mappings once elf loading is done
      if (L4_MapFpage(L4_Myself(), targetpage, phys) ) {
	page_table[(frame-new_low)/PAGESIZE].tid = new_tid;
	page_table[(frame-new_low)/PAGESIZE].pinned = 1;
	page_table[(frame-new_low)/PAGESIZE].pageNo = targetpage;
      } else {
	unmap_process(new_tid);
      }
    }
  }
  //Now we have mapped the pages, now load elf_file should work with the virtual addresses
  if(elf_loadFile(elfFile,0) == 1) {
      //Elffile was successfully loaded
      //Map the fpages which were previously mapped to Myself to the tid
    for(int i=0;i<numPTE;i++) {
      if(L4_ThreadNo(new_tid) == L4_ThreadNo(page_table[i].tid)) {
	//Now remap the pages which were mapped to root task to the new tid
	L4_UnmapFpage(L4_Myself(),page_table[i].pageNo);
	L4_PhysDesc_t phys = L4_PhysDesc(new_low + i * PAGESIZE, L4_DefaultMemory);
	if(!L4_MapFpage(new_tid, page_table[i].pageNo, phys)) {
	  unmap_process(new_tid);
	  return -1;
	}
      }
    }
  } else {
    unmap_process(new_tid);
  }
  //Remove later
  L4_CacheFlushAll();
  return 0;
}
Example #2
0
static void
load_image(void** entry)
{
	char* start = mod_dite_start;
	char* end = mod_dite_end;

	if(start == end) {
		printf("elf-loader: error, dite image is empty!\n");
		abort();
	}
	/*  awiggins (2004-12-21): Should probably add an alignment check? */
        /** awiggins (2005-05-29): Probably should add checks to see 
         *  the correct kind of elf file is being loaded for the platform,
         *  or does the elf library do that somewhere?.
         */
	if(!elf32_checkFile((struct Elf32_Header*)start)) {
                *entry =
			(void*)(uintptr_t)elf32_getEntryPoint((struct Elf32_Header*)start);
	} else if(!elf64_checkFile((struct Elf64_Header*)start)) {
		*entry =
                        (void*)(uintptr_t)elf64_getEntryPoint((struct Elf64_Header*)start);
	} else {
		printf("elf-loader: error, dite image not a valid elf file!\n");
		abort();
	}
#ifdef __PPC64__
	if (arch_claim_memory((struct Elf32_Header*)start)) {
		printf("could not claim memory for elf file!\n");
		abort();
	}
#endif
	if(!elf_loadFile(start, 1)) {
		printf("elf-loader: error, unable to load dite image!\n");
		abort();
	}
}