Changes in uspace/srv/loader/elf_load.c [1ea99cc:d88218b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/elf_load.c
r1ea99cc rd88218b 60 60 #define DPRINTF(...) 61 61 62 static c har *error_codes[] = {62 static const 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 int elf_load_file(char *file_name, size_t so_bias, eld_flags_t flags, 105 103 * 104 */ 105 int elf_load_file(const char *file_name, size_t so_bias, 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;121 120 122 121 rc = elf_load(&elf, so_bias); … … 125 124 126 125 return rc; 126 } 127 128 /** Run an ELF executable. 129 * 130 * Transfers control to the entry point of an ELF executable loaded 131 * 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 */ 127 141 } 128 142 … … 139 153 pcb->entry = info->entry; 140 154 pcb->dynamic = info->dynamic; 141 pcb->rtld_runtime = NULL;142 155 } 143 156 … … 269 282 * @return NULL terminated description of error. 270 283 */ 271 c har *elf_error(unsigned int rc)284 const char *elf_error(unsigned int rc) 272 285 { 273 286 assert(rc < sizeof(error_codes) / sizeof(char *)); … … 287 300 case PT_NULL: 288 301 case PT_PHDR: 302 case PT_NOTE: 289 303 break; 290 304 case PT_LOAD: … … 292 306 break; 293 307 case PT_INTERP: 294 /* Assume silently interp == "/ app/dload" */295 elf->info->interp = "/ app/dload";308 /* Assume silently interp == "/rtld.so" */ 309 elf->info->interp = "/rtld.so"; 296 310 break; 297 311 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;307 312 case PT_SHLIB: 308 case PT_NOTE: 309 // case PT_LOPROC: 310 // case PT_HIPROC: 313 case PT_LOPROC: 314 case PT_HIPROC: 311 315 default: 312 316 DPRINTF("Segment p_type %d unknown.\n", entry->p_type); … … 340 344 seg_ptr = (void *) seg_addr; 341 345 342 DPRINTF("Load segment at addr 0x%x, size 0x%x\n",seg_addr,343 entry->p_memsz); 346 DPRINTF("Load segment at addr %p, size 0x%x\n", (void *) seg_addr, 347 entry->p_memsz); 344 348 345 349 if (entry->p_align > 1) { … … 368 372 mem_sz = entry->p_memsz + (entry->p_vaddr - base); 369 373 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)); 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))); 372 377 373 378 /* … … 378 383 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 379 384 if (a == (void *)(-1)) { 380 DPRINTF("memory mapping failed (0x%x, %d)\n", 381 base+bias, mem_sz); 385 DPRINTF("Memory mapping failed.\n"); 382 386 return EE_MEMORY; 383 387 } 384 388 385 DPRINTF("as_area_create( 0x%lx, 0x%x, %d) -> 0x%lx\n",386 base + bias, mem_sz, flags, (uintptr_t)a);389 DPRINTF("as_area_create(%p, %#zx, %d) -> %p\n", 390 (void *) (base + bias), mem_sz, flags, (void *) a); 387 391 388 392 /* … … 421 425 } 422 426 423 /*424 * The caller wants to modify the segments first. He will then425 * 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);430 427 rc = as_area_change_flags(seg_ptr, flags); 431 428 if (rc != 0) { … … 464 461 break; 465 462 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); 466 468 break; 467 469 default:
Note:
See TracChangeset
for help on using the changeset viewer.