Changeset 368ee04 in mainline for uspace/lib/c/generic/elf/elf_mod.c
- Timestamp:
- 2017-04-05T18:10:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (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 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/elf/elf_mod.c
r39f892a9 r368ee04 44 44 */ 45 45 46 #include <errno.h> 46 47 #include <stdio.h> 48 #include <vfs/vfs.h> 47 49 #include <sys/types.h> 48 50 #include <align.h> … … 50 52 #include <as.h> 51 53 #include <elf/elf.h> 52 #include <unistd.h>53 #include <fcntl.h>54 54 #include <smc.h> 55 55 #include <loader/pcb.h> 56 56 #include <entry_point.h> 57 #include <str_error.h> 58 #include <stdlib.h> 57 59 58 60 #include <elf/elf_load.h> … … 82 84 * pointed to by @a info. 83 85 * 84 * @param file _name Path to theELF file.86 * @param file ELF file. 85 87 * @param so_bias Bias to use if the file is a shared object. 86 88 * @param info Pointer to a structure for storing information … … 90 92 * 91 93 */ 92 int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags, 93 elf_finfo_t *info) 94 int elf_load_file(int file, size_t so_bias, eld_flags_t flags, elf_finfo_t *info) 94 95 { 95 96 elf_ld_t elf; 96 97 97 int fd; 98 int rc; 99 100 fd = open(file_name, O_RDONLY); 101 if (fd < 0) { 102 DPRINTF("failed opening file\n"); 103 return -1; 104 } 105 106 elf.fd = fd; 98 int ofile = vfs_clone(file, -1, true); 99 int rc = vfs_open(ofile, MODE_READ); 100 if (rc != EOK) { 101 return rc; 102 } 103 104 elf.fd = ofile; 107 105 elf.info = info; 108 106 elf.flags = flags; … … 110 108 rc = elf_load_module(&elf, so_bias); 111 109 112 close(fd); 113 110 vfs_put(ofile); 111 return rc; 112 } 113 114 int elf_load_file_name(const char *path, size_t so_bias, eld_flags_t flags, 115 elf_finfo_t *info) 116 { 117 int file = vfs_lookup(path, 0); 118 int rc = elf_load_file(file, so_bias, flags, info); 119 vfs_put(file); 114 120 return rc; 115 121 } … … 129 135 elf_header_t header_buf; 130 136 elf_header_t *header = &header_buf; 137 aoff64_t pos = 0; 131 138 int i, rc; 132 139 133 rc = read(elf->fd, header, sizeof(elf_header_t));140 rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t)); 134 141 if (rc != sizeof(elf_header_t)) { 135 142 DPRINTF("Read error.\n"); … … 189 196 elf_segment_header_t segment_hdr; 190 197 191 /* Seek to start of segment header */ 192 lseek(elf->fd, header->e_phoff 193 + i * sizeof(elf_segment_header_t), SEEK_SET); 194 195 rc = read(elf->fd, &segment_hdr, 198 pos = header->e_phoff + i * sizeof(elf_segment_header_t); 199 rc = vfs_read(elf->fd, &pos, &segment_hdr, 196 200 sizeof(elf_segment_header_t)); 197 201 if (rc != sizeof(elf_segment_header_t)) { … … 211 215 elf_section_header_t section_hdr; 212 216 213 /* Seek to start of section header */ 214 lseek(elf->fd, header->e_shoff 215 + i * sizeof(elf_section_header_t), SEEK_SET); 216 217 rc = read(elf->fd, §ion_hdr, 217 pos = header->e_shoff + i * sizeof(elf_section_header_t); 218 rc = vfs_read(elf->fd, &pos, §ion_hdr, 218 219 sizeof(elf_section_header_t)); 219 220 if (rc != sizeof(elf_section_header_t)) { … … 327 328 uintptr_t seg_addr; 328 329 size_t mem_sz; 330 aoff64_t pos; 329 331 ssize_t rc; 330 332 … … 384 386 * Load segment data 385 387 */ 386 rc = lseek(elf->fd, entry->p_offset, SEEK_SET); 388 pos = entry->p_offset; 389 rc = vfs_read(elf->fd, &pos, seg_ptr, entry->p_filesz); 387 390 if (rc < 0) { 388 printf("seekerror\n");391 DPRINTF("read error\n"); 389 392 return EE_INVALID; 390 }391 392 /* rc = read(fd, (void *)(entry->p_vaddr + bias), entry->p_filesz);393 if (rc < 0) { printf("read error\n"); return EE_INVALID; }*/394 395 /* Long reads are not possible yet. Load segment piecewise. */396 397 unsigned left, now;398 uint8_t *dp;399 400 left = entry->p_filesz;401 dp = seg_ptr;402 403 while (left > 0) {404 now = 16384;405 if (now > left) now = left;406 407 rc = read(elf->fd, dp, now);408 409 if (rc != (ssize_t) now) {410 DPRINTF("Read error.\n");411 return EE_INVALID;412 }413 414 left -= now;415 dp += now;416 393 } 417 394
Note:
See TracChangeset
for help on using the changeset viewer.