Changeset e796dc8 in mainline


Ignore:
Timestamp:
2017-03-07T18:01:55Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bb9ec2d
Parents:
48178b56
git-author:
Jiri Zarevucky <zarevucky.jiri@…> (2017-03-07 18:01:55)
git-committer:
Jakub Jermar <jakub@…> (2017-03-07 18:01:55)
Message:

Cherry-pick changes from lp:~zarevucky-jiri/helenos/vfs-2.5/ revision 1940

Original commit message:

1940: Jiri Zarevucky 2013-08-06 Make elf loader more generic.

File:
1 edited

Legend:

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

    r48178b56 re796dc8  
    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)
     94static int elf_load_file2(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, 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        close(ofile);
     111        return rc;
     112}
     113
     114int elf_load_file(const char *path, size_t so_bias, eld_flags_t flags, elf_finfo_t *info)
     115{
     116        int file = vfs_lookup(path);
     117        int rc = elf_load_file2(file, so_bias, flags, info);
     118        close(file);
    114119        return rc;
    115120}
Note: See TracChangeset for help on using the changeset viewer.