Changeset 368ee04 in mainline for uspace/lib/c/generic/elf/elf_mod.c


Ignore:
Timestamp:
2017-04-05T18:10:39Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
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.
Message:

Merge from lp:~jakub/helenos/vfs-2.5-cherrypick

This merge cherry-picks some of the changesets from Jiri Zarevucky's:

lp:~zarevucky-jiri/helenos/vfs-2.5

and then continues independently, yet sometime in a similar vein.

Roughly speaking, Jiri's branch is merged entirely up to its revision
1926 and then cherry-picked on and off until its revision 1965. Among
these changes are:

  • relativization of the API,
  • client-side roots,
  • server-side mounts,
  • inbox for passing arbitrary files from parent to child,
  • some streamlining and cleanup.

Additional changes include:

  • addressing issues introduced by the above changes,
  • client-side I/O cursors (file positions),
  • all HelenOS file system APIs begin with the vfs_ prefix and can be used after including vfs/vfs.h,
  • removal of some POSIX-ish headers and definitions,
  • additional cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/elf/elf_mod.c

    r39f892a9 r368ee04  
    4444 */
    4545
     46#include <errno.h>
    4647#include <stdio.h>
     48#include <vfs/vfs.h>
    4749#include <sys/types.h>
    4850#include <align.h>
     
    5052#include <as.h>
    5153#include <elf/elf.h>
    52 #include <unistd.h>
    53 #include <fcntl.h>
    5454#include <smc.h>
    5555#include <loader/pcb.h>
    5656#include <entry_point.h>
     57#include <str_error.h>
     58#include <stdlib.h>
    5759
    5860#include <elf/elf_load.h>
     
    8284 * pointed to by @a info.
    8385 *
    84  * @param file_name Path to the ELF file.
     86 * @param file      ELF file.
    8587 * @param so_bias   Bias to use if the file is a shared object.
    8688 * @param info      Pointer to a structure for storing information
     
    9092 *
    9193 */
    92 int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags,
    93     elf_finfo_t *info)
     94int elf_load_file(int file, size_t so_bias, eld_flags_t flags, elf_finfo_t *info)
    9495{
    9596        elf_ld_t elf;
    9697
    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;
    107105        elf.info = info;
    108106        elf.flags = flags;
     
    110108        rc = elf_load_module(&elf, so_bias);
    111109
    112         close(fd);
    113 
     110        vfs_put(ofile);
     111        return rc;
     112}
     113
     114int 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);
    114120        return rc;
    115121}
     
    129135        elf_header_t header_buf;
    130136        elf_header_t *header = &header_buf;
     137        aoff64_t pos = 0;
    131138        int i, rc;
    132139
    133         rc = read(elf->fd, header, sizeof(elf_header_t));
     140        rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t));
    134141        if (rc != sizeof(elf_header_t)) {
    135142                DPRINTF("Read error.\n");
     
    189196                elf_segment_header_t segment_hdr;
    190197
    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,
    196200                    sizeof(elf_segment_header_t));
    197201                if (rc != sizeof(elf_segment_header_t)) {
     
    211215                elf_section_header_t section_hdr;
    212216
    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, &section_hdr,
     217                pos = header->e_shoff + i * sizeof(elf_section_header_t);
     218                rc = vfs_read(elf->fd, &pos, &section_hdr,
    218219                    sizeof(elf_section_header_t));
    219220                if (rc != sizeof(elf_section_header_t)) {
     
    327328        uintptr_t seg_addr;
    328329        size_t mem_sz;
     330        aoff64_t pos;
    329331        ssize_t rc;
    330332
     
    384386         * Load segment data
    385387         */
    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);
    387390        if (rc < 0) {
    388                 printf("seek error\n");
     391                DPRINTF("read error\n");
    389392                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;
    416393        }
    417394
Note: See TracChangeset for help on using the changeset viewer.