Ignore:
File:
1 edited

Legend:

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

    r1ea99cc rd88218b  
    6060#define DPRINTF(...)
    6161
    62 static char *error_codes[] = {
     62static const char *error_codes[] = {
    6363        "no error",
    6464        "invalid image",
     
    9595 * pointed to by @a info.
    9696 *
    97  * @param file_name     Path to the ELF file.
    98  * @param so_bias       Bias to use if the file is a shared object.
    99  * @param info          Pointer to a structure for storing information
    100  *                      extracted from the binary.
     97 * @param file_name Path to the ELF file.
     98 * @param so_bias   Bias to use if the file is a shared object.
     99 * @param info      Pointer to a structure for storing information
     100 *                  extracted from the binary.
    101101 *
    102102 * @return EOK on success or negative error code.
    103  */
    104 int elf_load_file(char *file_name, size_t so_bias, eld_flags_t flags,
    105     elf_info_t *info)
     103 *
     104 */
     105int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info)
    106106{
    107107        elf_ld_t elf;
     
    109109        int fd;
    110110        int rc;
    111 
     111       
    112112        fd = open(file_name, O_RDONLY);
    113113        if (fd < 0) {
     
    118118        elf.fd = fd;
    119119        elf.info = info;
    120         elf.flags = flags;
    121120
    122121        rc = elf_load(&elf, so_bias);
     
    125124
    126125        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 */
     136void elf_run(elf_info_t *info, pcb_t *pcb)
     137{
     138        program_run(info->entry, pcb);
     139
     140        /* not reached */
    127141}
    128142
     
    139153        pcb->entry = info->entry;
    140154        pcb->dynamic = info->dynamic;
    141         pcb->rtld_runtime = NULL;
    142155}
    143156
     
    269282 * @return NULL terminated description of error.
    270283 */
    271 char *elf_error(unsigned int rc)
     284const char *elf_error(unsigned int rc)
    272285{
    273286        assert(rc < sizeof(error_codes) / sizeof(char *));
     
    287300        case PT_NULL:
    288301        case PT_PHDR:
     302        case PT_NOTE:
    289303                break;
    290304        case PT_LOAD:
     
    292306                break;
    293307        case PT_INTERP:
    294                 /* Assume silently interp == "/app/dload" */
    295                 elf->info->interp = "/app/dload";
     308                /* Assume silently interp == "/rtld.so" */
     309                elf->info->interp = "/rtld.so";
    296310                break;
    297311        case PT_DYNAMIC:
    298                 /* Record pointer to dynamic section into info structure */
    299                 elf->info->dynamic =
    300                     (void *)((uint8_t *)entry->p_vaddr + elf->bias);
    301                 DPRINTF("dynamic section found at 0x%x\n",
    302                         (uintptr_t)elf->info->dynamic);
    303                 break;
    304         case 0x70000000:
    305                 /* FIXME: MIPS reginfo */
    306                 break;
    307312        case PT_SHLIB:
    308         case PT_NOTE:
    309 //      case PT_LOPROC:
    310 //      case PT_HIPROC:
     313        case PT_LOPROC:
     314        case PT_HIPROC:
    311315        default:
    312316                DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
     
    340344        seg_ptr = (void *) seg_addr;
    341345
    342         DPRINTF("Load segment at addr 0x%x, size 0x%x\n", seg_addr,
    343                 entry->p_memsz);       
     346        DPRINTF("Load segment at addr %p, size 0x%x\n", (void *) seg_addr,
     347                entry->p_memsz);
    344348
    345349        if (entry->p_align > 1) {
     
    368372        mem_sz = entry->p_memsz + (entry->p_vaddr - base);
    369373
    370         DPRINTF("Map to seg_addr=0x%x-0x%x.\n", seg_addr,
    371         entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));
     374        DPRINTF("Map to seg_addr=%p-%p.\n", (void *) seg_addr,
     375            (void *) (entry->p_vaddr + bias +
     376            ALIGN_UP(entry->p_memsz, PAGE_SIZE)));
    372377
    373378        /*
     
    378383            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    379384        if (a == (void *)(-1)) {
    380                 DPRINTF("memory mapping failed (0x%x, %d)\n",
    381                         base+bias, mem_sz);
     385                DPRINTF("Memory mapping failed.\n");
    382386                return EE_MEMORY;
    383387        }
    384388
    385         DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
    386                 base + bias, mem_sz, flags, (uintptr_t)a);
     389        DPRINTF("as_area_create(%p, %#zx, %d) -> %p\n",
     390            (void *) (base + bias), mem_sz, flags, (void *) a);
    387391
    388392        /*
     
    421425        }
    422426
    423         /*
    424          * The caller wants to modify the segments first. He will then
    425          * need to set the right access mode and ensure SMC coherence.
    426          */
    427         if ((elf->flags & ELDF_RW) != 0) return EE_OK;
    428 
    429 //      printf("set area flags to %d\n", flags);
    430427        rc = as_area_change_flags(seg_ptr, flags);
    431428        if (rc != 0) {
     
    464461                break;
    465462        case SHT_DYNAMIC:
     463                /* Record pointer to dynamic section into info structure */
     464                elf->info->dynamic =
     465                    (void *)((uint8_t *)entry->sh_addr + elf->bias);
     466                DPRINTF("Dynamic section found at %p.\n",
     467                    (void *) elf->info->dynamic);
    466468                break;
    467469        default:
Note: See TracChangeset for help on using the changeset viewer.