Changeset 1ea99cc in mainline for uspace/srv/loader


Ignore:
Timestamp:
2009-08-20T20:47:35Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b50b5af2
Parents:
24edc18
Message:

Merge changes from original Subversion dynload branch.

Location:
uspace/srv/loader
Files:
3 edited

Legend:

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

    r24edc18 r1ea99cc  
    102102 * @return EOK on success or negative error code.
    103103 */
    104 int elf_load_file(char *file_name, size_t so_bias, elf_info_t *info)
     104int elf_load_file(char *file_name, size_t so_bias, eld_flags_t flags,
     105    elf_info_t *info)
    105106{
    106107        elf_ld_t elf;
     
    117118        elf.fd = fd;
    118119        elf.info = info;
     120        elf.flags = flags;
    119121
    120122        rc = elf_load(&elf, so_bias);
     
    123125
    124126        return rc;
    125 }
    126 
    127 /** Run an ELF executable.
    128  *
    129  * Transfers control to the entry point of an ELF executable loaded
    130  * earlier with elf_load_file(). This function does not return.
    131  *
    132  * @param info  Info structure filled earlier by elf_load_file()
    133  */
    134 void elf_run(elf_info_t *info, pcb_t *pcb)
    135 {
    136         program_run(info->entry, pcb);
    137 
    138         /* not reached */
    139127}
    140128
     
    151139        pcb->entry = info->entry;
    152140        pcb->dynamic = info->dynamic;
     141        pcb->rtld_runtime = NULL;
    153142}
    154143
     
    303292                break;
    304293        case PT_INTERP:
    305                 /* Assume silently interp == "/rtld.so" */
    306                 elf->info->interp = "/rtld.so";
     294                /* Assume silently interp == "/app/dload" */
     295                elf->info->interp = "/app/dload";
    307296                break;
    308297        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;
    309307        case PT_SHLIB:
    310308        case PT_NOTE:
    311         case PT_LOPROC:
    312         case PT_HIPROC:
     309//      case PT_LOPROC:
     310//      case PT_HIPROC:
    313311        default:
    314312                DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
     
    380378            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    381379        if (a == (void *)(-1)) {
    382                 DPRINTF("Memory mapping failed.\n");
     380                DPRINTF("memory mapping failed (0x%x, %d)\n",
     381                        base+bias, mem_sz);
    383382                return EE_MEMORY;
    384383        }
     
    422421        }
    423422
     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);
    424430        rc = as_area_change_flags(seg_ptr, flags);
    425431        if (rc != 0) {
     
    458464                break;
    459465        case SHT_DYNAMIC:
    460                 /* Record pointer to dynamic section into info structure */
    461                 elf->info->dynamic =
    462                     (void *)((uint8_t *)entry->sh_addr + elf->bias);
    463                 DPRINTF("Dynamic section found at 0x%x.\n",
    464                         (uintptr_t)elf->info->dynamic);
    465466                break;
    466467        default:
  • uspace/srv/loader/include/elf_load.h

    r24edc18 r1ea99cc  
    4343#include "elf.h"
    4444
     45typedef enum {
     46        /** Leave all segments in RW access mode. */
     47        ELDF_RW = 1
     48} eld_flags_t;
     49
    4550/**
    4651 * Some data extracted from the headers are stored here
     
    6772        uintptr_t bias;
    6873
     74        /** Flags passed to the ELF loader. */
     75        eld_flags_t flags;
     76
    6977        /** A copy of the ELF file header */
    7078        elf_header_t *header;
     
    7482} elf_ld_t;
    7583
    76 int elf_load_file(char *file_name, size_t so_bias, elf_info_t *info);
    77 void elf_run(elf_info_t *info, pcb_t *pcb);
     84int elf_load_file(char *file_name, size_t so_bias, eld_flags_t flags,
     85    elf_info_t *info);
    7886void elf_create_pcb(elf_info_t *info, pcb_t *pcb);
    7987
  • uspace/srv/loader/main.c

    r24edc18 r1ea99cc  
    6666#define DPRINTF(...)
    6767
     68void program_run(void *entry, pcb_t *pcb);
     69
    6870/** Pathname of the file that will be loaded */
    6971static char *pathname = NULL;
     
    304306        int rc;
    305307       
    306         rc = elf_load_file(pathname, 0, &prog_info);
     308        rc = elf_load_file(pathname, 0, 0, &prog_info);
    307309        if (rc != EE_OK) {
    308310                DPRINTF("Failed to load executable '%s'.\n", pathname);
     
    326328        }
    327329       
    328         rc = elf_load_file(prog_info.interp, 0, &interp_info);
     330        printf("Load ELF interpreter '%s'\n", prog_info.interp);
     331        rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
    329332        if (rc != EE_OK) {
    330333                DPRINTF("Failed to load interpreter '%s.'\n",
     
    334337        }
    335338       
     339        printf("Run interpreter.\n");
     340        printf("entry point: 0x%lx\n", interp_info.entry);
     341        printf("pcb address: 0x%lx\n", &pcb);
     342        printf("prog dynamic: 0x%lx\n", prog_info.dynamic);
     343
    336344        is_dyn_linked = true;
    337345        ipc_answer_0(rid, EOK);
     
    362370               
    363371                ipc_answer_0(rid, EOK);
    364                 elf_run(&interp_info, &pcb);
     372                program_run(interp_info.entry, &pcb);
    365373        } else {
    366374                /* Statically linked program */
    367375                ipc_answer_0(rid, EOK);
    368                 elf_run(&prog_info, &pcb);
     376                program_run(prog_info.entry, &pcb);
    369377        }
    370378       
Note: See TracChangeset for help on using the changeset viewer.