Changes in uspace/srv/loader/elf_load.c [d88218b:1ea99cc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/elf_load.c
rd88218b r1ea99cc 60 60 #define DPRINTF(...) 61 61 62 static c onst char *error_codes[] = {62 static char *error_codes[] = { 63 63 "no error", 64 64 "invalid image", … … 95 95 * pointed to by @a info. 96 96 * 97 * @param file_name 98 * @param so_bias 99 * @param info 100 * 97 * @param file_name Path to the ELF file. 98 * @param so_bias Bias to use if the file is a shared object. 99 * @param info Pointer to a structure for storing information 100 * extracted from the binary. 101 101 * 102 102 * @return EOK on success or negative error code. 103 * 104 */ 105 int elf_load_file(const char *file_name, size_t so_bias,elf_info_t *info)103 */ 104 int elf_load_file(char *file_name, size_t so_bias, eld_flags_t flags, 105 elf_info_t *info) 106 106 { 107 107 elf_ld_t elf; … … 109 109 int fd; 110 110 int rc; 111 111 112 112 fd = open(file_name, O_RDONLY); 113 113 if (fd < 0) { … … 118 118 elf.fd = fd; 119 119 elf.info = info; 120 elf.flags = flags; 120 121 121 122 rc = elf_load(&elf, so_bias); … … 124 125 125 126 return rc; 126 }127 128 /** Run an ELF executable.129 *130 * Transfers control to the entry point of an ELF executable loaded131 * earlier with elf_load_file(). This function does not return.132 *133 * @param info Info structure filled earlier by elf_load_file()134 *135 */136 void elf_run(elf_info_t *info, pcb_t *pcb)137 {138 program_run(info->entry, pcb);139 140 /* not reached */141 127 } 142 128 … … 153 139 pcb->entry = info->entry; 154 140 pcb->dynamic = info->dynamic; 141 pcb->rtld_runtime = NULL; 155 142 } 156 143 … … 282 269 * @return NULL terminated description of error. 283 270 */ 284 c onst char *elf_error(unsigned int rc)271 char *elf_error(unsigned int rc) 285 272 { 286 273 assert(rc < sizeof(error_codes) / sizeof(char *)); … … 300 287 case PT_NULL: 301 288 case PT_PHDR: 302 case PT_NOTE:303 289 break; 304 290 case PT_LOAD: … … 306 292 break; 307 293 case PT_INTERP: 308 /* Assume silently interp == "/ rtld.so" */309 elf->info->interp = "/ rtld.so";294 /* Assume silently interp == "/app/dload" */ 295 elf->info->interp = "/app/dload"; 310 296 break; 311 297 case PT_DYNAMIC: 298 /* Record pointer to dynamic section into info structure */ 299 elf->info->dynamic = 300 (void *)((uint8_t *)entry->p_vaddr + elf->bias); 301 DPRINTF("dynamic section found at 0x%x\n", 302 (uintptr_t)elf->info->dynamic); 303 break; 304 case 0x70000000: 305 /* FIXME: MIPS reginfo */ 306 break; 312 307 case PT_SHLIB: 313 case PT_LOPROC: 314 case PT_HIPROC: 308 case PT_NOTE: 309 // case PT_LOPROC: 310 // case PT_HIPROC: 315 311 default: 316 312 DPRINTF("Segment p_type %d unknown.\n", entry->p_type); … … 344 340 seg_ptr = (void *) seg_addr; 345 341 346 DPRINTF("Load segment at addr %p, size 0x%x\n", (void *)seg_addr,347 entry->p_memsz); 342 DPRINTF("Load segment at addr 0x%x, size 0x%x\n", seg_addr, 343 entry->p_memsz); 348 344 349 345 if (entry->p_align > 1) { … … 372 368 mem_sz = entry->p_memsz + (entry->p_vaddr - base); 373 369 374 DPRINTF("Map to seg_addr=%p-%p.\n", (void *) seg_addr, 375 (void *) (entry->p_vaddr + bias + 376 ALIGN_UP(entry->p_memsz, PAGE_SIZE))); 370 DPRINTF("Map to seg_addr=0x%x-0x%x.\n", seg_addr, 371 entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE)); 377 372 378 373 /* … … 383 378 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 384 379 if (a == (void *)(-1)) { 385 DPRINTF("Memory mapping failed.\n"); 380 DPRINTF("memory mapping failed (0x%x, %d)\n", 381 base+bias, mem_sz); 386 382 return EE_MEMORY; 387 383 } 388 384 389 DPRINTF("as_area_create( %p, %#zx, %d) -> %p\n",390 (void *) (base + bias), mem_sz, flags, (void *)a);385 DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n", 386 base + bias, mem_sz, flags, (uintptr_t)a); 391 387 392 388 /* … … 425 421 } 426 422 423 /* 424 * The caller wants to modify the segments first. He will then 425 * need to set the right access mode and ensure SMC coherence. 426 */ 427 if ((elf->flags & ELDF_RW) != 0) return EE_OK; 428 429 // printf("set area flags to %d\n", flags); 427 430 rc = as_area_change_flags(seg_ptr, flags); 428 431 if (rc != 0) { … … 461 464 break; 462 465 case SHT_DYNAMIC: 463 /* Record pointer to dynamic section into info structure */464 elf->info->dynamic =465 (void *)((uint8_t *)entry->sh_addr + elf->bias);466 DPRINTF("Dynamic section found at %p.\n",467 (void *) elf->info->dynamic);468 466 break; 469 467 default:
Note:
See TracChangeset
for help on using the changeset viewer.