Changeset a33f0a6 in mainline for uspace/lib/c/generic/elf/elf_load.c
- Timestamp:
- 2011-08-03T17:34:57Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1940326
- Parents:
- 52a79081 (diff), 3fab770 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/elf/elf_load.c
r52a79081 ra33f0a6 2 2 * Copyright (c) 2006 Sergey Bondari 3 3 * Copyright (c) 2006 Jakub Jermar 4 * Copyright (c) 20 08Jiri Svoboda4 * Copyright (c) 2011 Jiri Svoboda 5 5 * All rights reserved. 6 6 * … … 29 29 */ 30 30 31 /** @addtogroup generic 31 /** @addtogroup generic 32 32 * @{ 33 33 */ … … 49 49 #include <assert.h> 50 50 #include <as.h> 51 #include <elf/elf.h> 51 52 #include <unistd.h> 52 53 #include <fcntl.h> 53 54 #include <smc.h> 54 55 #include <loader/pcb.h> 55 56 #include "elf.h" 57 #include "elf_load.h" 58 #include "arch.h" 56 #include <entry_point.h> 57 58 #include <elf/elf_load.h> 59 59 60 60 #define DPRINTF(...) … … 74 74 static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry); 75 75 76 /** Read until the buffer is read in its entirety. */77 static int my_read(int fd, void *buf, size_t len)78 {79 int cnt = 0;80 do {81 buf += cnt;82 len -= cnt;83 cnt = read(fd, buf, len);84 } while ((cnt > 0) && ((len - cnt) > 0));85 86 return cnt;87 }88 89 76 /** Load ELF binary from a file. 90 77 * … … 103 90 * 104 91 */ 105 int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info) 92 int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags, 93 elf_info_t *info) 106 94 { 107 95 elf_ld_t elf; … … 118 106 elf.fd = fd; 119 107 elf.info = info; 108 elf.flags = flags; 120 109 121 110 rc = elf_load(&elf, so_bias); … … 124 113 125 114 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 115 } 142 116 … … 153 127 pcb->entry = info->entry; 154 128 pcb->dynamic = info->dynamic; 129 pcb->rtld_runtime = NULL; 155 130 } 156 131 … … 172 147 int i, rc; 173 148 174 rc = my_read(elf->fd, header, sizeof(elf_header_t));175 if (rc < 0) {149 rc = read_all(elf->fd, header, sizeof(elf_header_t)); 150 if (rc != sizeof(elf_header_t)) { 176 151 DPRINTF("Read error.\n"); 177 152 return EE_INVALID; … … 234 209 + i * sizeof(elf_segment_header_t), SEEK_SET); 235 210 236 rc = my_read(elf->fd, &segment_hdr,211 rc = read_all(elf->fd, &segment_hdr, 237 212 sizeof(elf_segment_header_t)); 238 if (rc < 0) {213 if (rc != sizeof(elf_segment_header_t)) { 239 214 DPRINTF("Read error.\n"); 240 215 return EE_INVALID; … … 256 231 + i * sizeof(elf_section_header_t), SEEK_SET); 257 232 258 rc = my_read(elf->fd, §ion_hdr,233 rc = read_all(elf->fd, §ion_hdr, 259 234 sizeof(elf_section_header_t)); 260 if (rc < 0) {235 if (rc != sizeof(elf_section_header_t)) { 261 236 DPRINTF("Read error.\n"); 262 237 return EE_INVALID; … … 306 281 break; 307 282 case PT_INTERP: 308 /* Assume silently interp == "/ rtld.so" */309 elf->info->interp = "/ rtld.so";283 /* Assume silently interp == "/app/dload" */ 284 elf->info->interp = "/app/dload"; 310 285 break; 311 286 case PT_DYNAMIC: 287 /* Record pointer to dynamic section into info structure */ 288 elf->info->dynamic = 289 (void *)((uint8_t *)entry->p_vaddr + elf->bias); 290 DPRINTF("dynamic section found at 0x%x\n", 291 (uintptr_t)elf->info->dynamic); 292 break; 293 case 0x70000000: 294 /* FIXME: MIPS reginfo */ 295 break; 312 296 case PT_SHLIB: 313 case PT_LOPROC:314 case PT_HIPROC:297 // case PT_LOPROC: 298 // case PT_HIPROC: 315 299 default: 316 300 DPRINTF("Segment p_type %d unknown.\n", entry->p_type); … … 337 321 uintptr_t seg_addr; 338 322 size_t mem_sz; 339 int rc;323 ssize_t rc; 340 324 341 325 bias = elf->bias; … … 383 367 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 384 368 if (a == (void *)(-1)) { 385 DPRINTF("Memory mapping failed.\n"); 369 DPRINTF("memory mapping failed (0x%x, %d)\n", 370 base+bias, mem_sz); 386 371 return EE_MEMORY; 387 372 } … … 414 399 if (now > left) now = left; 415 400 416 rc = my_read(elf->fd, dp, now);417 418 if (rc < 0) {401 rc = read_all(elf->fd, dp, now); 402 403 if (rc != (ssize_t) now) { 419 404 DPRINTF("Read error.\n"); 420 405 return EE_INVALID; … … 425 410 } 426 411 412 /* 413 * The caller wants to modify the segments first. He will then 414 * need to set the right access mode and ensure SMC coherence. 415 */ 416 if ((elf->flags & ELDF_RW) != 0) return EE_OK; 417 418 // printf("set area flags to %d\n", flags); 427 419 rc = as_area_change_flags(seg_ptr, flags); 428 420 if (rc != 0) {
Note:
See TracChangeset
for help on using the changeset viewer.