Ejemplo n.º 1
0
Archivo: elf.c Proyecto: ahixon/papaya
int elf_load (addrspace_t dest_as, char *elf_file) {

    int num_headers;
    int err;
    int i;

    /* Ensure that the ELF file looks sane. */
    if (elf_checkFile(elf_file)){
        return seL4_InvalidArgument;
    }

    num_headers = elf_getNumProgramHeaders(elf_file);
    for (i = 0; i < num_headers; i++) {
        char *source_addr;
        unsigned long flags, file_size, segment_size, vaddr;

        /* Skip non-loadable segments (such as debugging data). */
        if (elf_getProgramHeaderType(elf_file, i) != PT_LOAD)
            continue;

        /* Fetch information about this segment. */
        source_addr = elf_file + elf_getProgramHeaderOffset(elf_file, i);
        file_size = elf_getProgramHeaderFileSize(elf_file, i);
        segment_size = elf_getProgramHeaderMemorySize(elf_file, i);
        vaddr = elf_getProgramHeaderVaddr(elf_file, i);
        flags = elf_getProgramHeaderFlags(elf_file, i);

        /* Copy it across into the vspace. */
        err = load_segment_directly_into_vspace(dest_as, source_addr,
            segment_size, file_size, vaddr,
            get_sel4_rights_from_elf(flags) & seL4_AllRights);

        if (err != 0) {
            return 1;
        }
    }

    return 0;
}
Ejemplo n.º 2
0
Archivo: elf.c Proyecto: 8l/sel4-riscv
int elf_load(seL4_RISCV_PageDirectory dest_as, char *elf_file) {

    int num_headers;
    int err;
    int i;

    /* Ensure that the ELF file looks sane. */
    if (elf_checkFile(elf_file)){
        return seL4_InvalidArgument;
    }

    num_headers = elf_getNumProgramHeaders(elf_file);
    for (i = 0; i < num_headers; i++) {
        char *source_addr;
        unsigned long flags, file_size, segment_size, vaddr;

        /* Skip non-loadable segments (such as debugging data). */
        if (elf_getProgramHeaderType(elf_file, i) != PT_LOAD)
            continue;

        /* Fetch information about this segment. */
        source_addr = elf_file + elf_getProgramHeaderOffset(elf_file, i);
        file_size = elf_getProgramHeaderFileSize(elf_file, i);
        segment_size = elf_getProgramHeaderMemorySize(elf_file, i);
        vaddr = elf_getProgramHeaderVaddr(elf_file, i);
        flags = elf_getProgramHeaderFlags(elf_file, i);

        /* Copy it across into the vspace. */
        dprintf(1, " * Loading segment %08x-->%08x\n", (int)vaddr, (int)(vaddr + segment_size));
        err = load_segment_into_vspace(dest_as, source_addr, segment_size, file_size, vaddr,
                                       get_sel4_rights_from_elf(flags) & seL4_AllRights);
        conditional_panic(err != 0, "Elf loading failed!\n");
    }

    return 0;
}
Ejemplo n.º 3
0
Archivo: elf.c Proyecto: KGG814/AOS
void elf_load(int pid, seL4_CPtr reply_cap, void *_args, int err) {
    if (TMP_DEBUG) printf("elf_load\n");

    elf_load_args *args = (elf_load_args *) _args;
    if (err) {
        eprintf("Error caught in elf_load\n");
        args->cb(pid, reply_cap, args->cb_args, err);
        free(args);
        return;  
    }

    char *elf_file = args->elf_file;
    int curr_header = args->curr_header;
    //addr_space *as = proc_table[pid];
    /* Ensure that the ELF file looks sane. */
    if (elf_checkFile(elf_file)){
        eprintf("Error caught in elf_load\n");
        args->cb(pid, reply_cap, args->cb_args, -1);
        free(args);
        return;
    }

    int num_headers = elf_getNumProgramHeaders(elf_file);
    if (curr_header < num_headers) {
        char *source_addr;
        unsigned long flags, file_size, segment_size, vaddr;

        /* Skip non-loadable segments (such as debugging data). */
        if (elf_getProgramHeaderType(elf_file, curr_header) != PT_LOAD) {
            args->curr_header++;
            elf_load(pid, reply_cap, args, 0);
        } else {
            /* Fetch information about this segment. */
            source_addr = elf_file + elf_getProgramHeaderOffset(elf_file, curr_header);
            file_size = elf_getProgramHeaderFileSize(elf_file, curr_header);
            segment_size = elf_getProgramHeaderMemorySize(elf_file, curr_header);
            vaddr = elf_getProgramHeaderVaddr(elf_file, curr_header);
            flags = elf_getProgramHeaderFlags(elf_file, curr_header);

            /* Copy it across into the vspace. */
            dprintf(1, " * Loading segment %08x-->%08x\n", (int)vaddr, (int)(vaddr + segment_size));
            // Set up load segment arguments
            args->curr_header++;
            load_segment_args *segment_args = malloc(sizeof(load_segment_args));
            
            if (segment_args == NULL) {
                eprintf("Error caught in elf_load\n");
                args->cb(pid, reply_cap, args->cb_args, -1);
                free(args);
                return;
            }

            segment_args->src = source_addr;
            segment_args->dst = vaddr;
            segment_args->pos = 0;
            segment_args->segment_size = segment_size;
            segment_args->file_size = file_size;
            segment_args->permissions = get_sel4_rights_from_elf(flags) & seL4_AllRights;
            segment_args->cb = elf_load;
            segment_args->cb_args = args;

            load_segment_into_vspace(pid, reply_cap, segment_args, 0);
        }
  
        //conditional_panic(err != 0, "Elf loading failed!\n");
    } else {
        // Do callback
        printf("Doing callback with pid :%d\n", pid);
        args->cb(pid, reply_cap, args->cb_args, 0);
        free(args);
    }

    if (TMP_DEBUG) printf("elf_load end\n");
}