Changeset eb522e8 in mainline for uspace/srv/loader/elf_load.c


Ignore:
Timestamp:
2011-06-01T08:43:42Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8d6c1f1
Parents:
9e2e715 (diff), e51a514 (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:

Huuuuuge merge from development - all the work actually :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loader/elf_load.c

    r9e2e715 reb522e8  
    22 * Copyright (c) 2006 Sergey Bondari
    33 * Copyright (c) 2006 Jakub Jermar
    4  * Copyright (c) 2008 Jiri Svoboda
     4 * Copyright (c) 2011 Jiri Svoboda
    55 * All rights reserved.
    66 *
     
    5353#include <smc.h>
    5454#include <loader/pcb.h>
     55#include <entry_point.h>
    5556
    5657#include "elf.h"
    5758#include "elf_load.h"
    58 #include "arch.h"
    5959
    6060#define DPRINTF(...)
     
    103103 *
    104104 */
    105 int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info)
     105int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags,
     106    elf_info_t *info)
    106107{
    107108        elf_ld_t elf;
     
    109110        int fd;
    110111        int rc;
    111 
     112       
    112113        fd = open(file_name, O_RDONLY);
    113114        if (fd < 0) {
     
    118119        elf.fd = fd;
    119120        elf.info = info;
     121        elf.flags = flags;
    120122
    121123        rc = elf_load(&elf, so_bias);
     
    124126
    125127        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 */
    141128}
    142129
     
    153140        pcb->entry = info->entry;
    154141        pcb->dynamic = info->dynamic;
     142        pcb->rtld_runtime = NULL;
    155143}
    156144
     
    300288        case PT_NULL:
    301289        case PT_PHDR:
     290        case PT_NOTE:
    302291                break;
    303292        case PT_LOAD:
     
    305294                break;
    306295        case PT_INTERP:
    307                 /* Assume silently interp == "/rtld.so" */
    308                 elf->info->interp = "/rtld.so";
     296                /* Assume silently interp == "/app/dload" */
     297                elf->info->interp = "/app/dload";
    309298                break;
    310299        case PT_DYNAMIC:
     300                /* Record pointer to dynamic section into info structure */
     301                elf->info->dynamic =
     302                    (void *)((uint8_t *)entry->p_vaddr + elf->bias);
     303                DPRINTF("dynamic section found at 0x%x\n",
     304                        (uintptr_t)elf->info->dynamic);
     305                break;
     306        case 0x70000000:
     307                /* FIXME: MIPS reginfo */
     308                break;
    311309        case PT_SHLIB:
    312         case PT_NOTE:
    313         case PT_LOPROC:
    314         case PT_HIPROC:
     310//      case PT_LOPROC:
     311//      case PT_HIPROC:
    315312        default:
    316313                DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
     
    344341        seg_ptr = (void *) seg_addr;
    345342
    346         DPRINTF("Load segment at addr %p, size 0x%x\n", seg_addr,
     343        DPRINTF("Load segment at addr %p, size 0x%x\n", (void *) seg_addr,
    347344                entry->p_memsz);
    348345
     
    372369        mem_sz = entry->p_memsz + (entry->p_vaddr - base);
    373370
    374         DPRINTF("Map to seg_addr=%p-%p.\n", seg_addr,
    375         entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));
     371        DPRINTF("Map to seg_addr=%p-%p.\n", (void *) seg_addr,
     372            (void *) (entry->p_vaddr + bias +
     373            ALIGN_UP(entry->p_memsz, PAGE_SIZE)));
    376374
    377375        /*
     
    382380            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    383381        if (a == (void *)(-1)) {
    384                 DPRINTF("Memory mapping failed.\n");
     382                DPRINTF("memory mapping failed (0x%x, %d)\n",
     383                        base+bias, mem_sz);
    385384                return EE_MEMORY;
    386385        }
    387386
    388         DPRINTF("as_area_create(%p, 0x%x, %d) -> 0x%lx\n",
    389                 base + bias, mem_sz, flags, (uintptr_t)a);
     387        DPRINTF("as_area_create(%p, %#zx, %d) -> %p\n",
     388            (void *) (base + bias), mem_sz, flags, (void *) a);
    390389
    391390        /*
     
    424423        }
    425424
     425        /*
     426         * The caller wants to modify the segments first. He will then
     427         * need to set the right access mode and ensure SMC coherence.
     428         */
     429        if ((elf->flags & ELDF_RW) != 0) return EE_OK;
     430
     431//      printf("set area flags to %d\n", flags);
    426432        rc = as_area_change_flags(seg_ptr, flags);
    427433        if (rc != 0) {
     
    464470                    (void *)((uint8_t *)entry->sh_addr + elf->bias);
    465471                DPRINTF("Dynamic section found at %p.\n",
    466                         (uintptr_t)elf->info->dynamic);
     472                    (void *) elf->info->dynamic);
    467473                break;
    468474        default:
Note: See TracChangeset for help on using the changeset viewer.