Ignore:
File:
1 edited

Legend:

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

    rd88218b r1ea99cc  
    6060#define DPRINTF(...)
    6161
    62 static const char *error_codes[] = {
     62static 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  */
    105 int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info)
     103 */
     104int elf_load_file(char *file_name, size_t so_bias, eld_flags_t flags,
     105    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;
    120121
    121122        rc = elf_load(&elf, so_bias);
     
    124125
    125126        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 */
    141127}
    142128
     
    153139        pcb->entry = info->entry;
    154140        pcb->dynamic = info->dynamic;
     141        pcb->rtld_runtime = NULL;
    155142}
    156143
     
    282269 * @return NULL terminated description of error.
    283270 */
    284 const char *elf_error(unsigned int rc)
     271char *elf_error(unsigned int rc)
    285272{
    286273        assert(rc < sizeof(error_codes) / sizeof(char *));
     
    300287        case PT_NULL:
    301288        case PT_PHDR:
    302         case PT_NOTE:
    303289                break;
    304290        case PT_LOAD:
     
    306292                break;
    307293        case PT_INTERP:
    308                 /* Assume silently interp == "/rtld.so" */
    309                 elf->info->interp = "/rtld.so";
     294                /* Assume silently interp == "/app/dload" */
     295                elf->info->interp = "/app/dload";
    310296                break;
    311297        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;
    312307        case PT_SHLIB:
    313         case PT_LOPROC:
    314         case PT_HIPROC:
     308        case PT_NOTE:
     309//      case PT_LOPROC:
     310//      case PT_HIPROC:
    315311        default:
    316312                DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
     
    344340        seg_ptr = (void *) seg_addr;
    345341
    346         DPRINTF("Load segment at addr %p, size 0x%x\n", (void *) seg_addr,
    347                 entry->p_memsz);
     342        DPRINTF("Load segment at addr 0x%x, size 0x%x\n", seg_addr,
     343                entry->p_memsz);       
    348344
    349345        if (entry->p_align > 1) {
     
    372368        mem_sz = entry->p_memsz + (entry->p_vaddr - base);
    373369
    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)));
     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));
    377372
    378373        /*
     
    383378            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    384379        if (a == (void *)(-1)) {
    385                 DPRINTF("Memory mapping failed.\n");
     380                DPRINTF("memory mapping failed (0x%x, %d)\n",
     381                        base+bias, mem_sz);
    386382                return EE_MEMORY;
    387383        }
    388384
    389         DPRINTF("as_area_create(%p, %#zx, %d) -> %p\n",
    390             (void *) (base + bias), mem_sz, flags, (void *) a);
     385        DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
     386                base + bias, mem_sz, flags, (uintptr_t)a);
    391387
    392388        /*
     
    425421        }
    426422
     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);
    427430        rc = as_area_change_flags(seg_ptr, flags);
    428431        if (rc != 0) {
     
    461464                break;
    462465        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);
    468466                break;
    469467        default:
Note: See TracChangeset for help on using the changeset viewer.