Exemplo n.º 1
0
int loader_exec(const char * filename, char ** argv, char ** envp, 
             struct target_pt_regs * regs, struct image_info *infop)
{
    struct linux_binprm bprm;
    int retval;
    int i;

    bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
    for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
            bprm.page[i] = 0;
    retval = open(filename, O_RDONLY);
    if (retval < 0)
        return retval;
    bprm.fd = retval;
    bprm.filename = (char *)filename;
    bprm.argc = count(argv);
    bprm.argv = argv;
    bprm.envc = count(envp);
    bprm.envp = envp;

    retval = prepare_binprm(&bprm);

    infop->host_argv = argv;

    if(retval>=0) {
        if (bprm.buf[0] == 0x7f
                && bprm.buf[1] == 'E'
                && bprm.buf[2] == 'L'
                && bprm.buf[3] == 'F') {
            retval = load_elf_binary(&bprm,regs,infop);
#if defined(TARGET_HAS_BFLT)
        } else if (bprm.buf[0] == 'b'
                && bprm.buf[1] == 'F'
                && bprm.buf[2] == 'L'
                && bprm.buf[3] == 'T') {
            retval = load_flt_binary(&bprm,regs,infop);
#endif
        } else {
            fprintf(stderr, "Unknown binary format\n");
            return -1;
        }
    }
    
    if(retval>=0) {
        /* success.  Initialize important registers */
        do_init_thread(regs, infop);
        return retval;
    }

    /* Something went wrong, return the inode and free the argument pages*/
    for (i=0 ; i<MAX_ARG_PAGES ; i++) {
        free(bprm.page[i]);
    }
    return(retval);
}
Exemplo n.º 2
0
int loader_exec(const char * filename, char ** argv, char ** envp,
             struct target_pt_regs * regs, struct image_info *infop,
             struct linux_binprm *bprm)
{
    int retval;
    int i;

    bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
    memset(bprm->page, 0, sizeof(bprm->page));
    retval = open(filename, O_RDONLY);
    if (retval < 0) {
        return -errno;
    }
    bprm->fd = retval;
    bprm->filename = (char *)filename;
    bprm->argc = count(argv);
    bprm->argv = argv;
    bprm->envc = count(envp);
    bprm->envp = envp;

    retval = prepare_binprm(bprm);

    if(retval>=0) {
        if (bprm->buf[0] == 0x7f
                && bprm->buf[1] == 'E'
                && bprm->buf[2] == 'L'
                && bprm->buf[3] == 'F') {
            retval = load_elf_binary(bprm, regs, infop);
#if defined(TARGET_HAS_BFLT)
        } else if (bprm->buf[0] == 'b'
                && bprm->buf[1] == 'F'
                && bprm->buf[2] == 'L'
                && bprm->buf[3] == 'T') {
            retval = load_flt_binary(bprm,regs,infop);
#endif
        } else {
            return -ENOEXEC;
        }
    }

    if(retval>=0) {
        /* success.  Initialize important registers */
        do_init_thread(regs, infop);
        return retval;
    }

    /* Something went wrong, return the inode and free the argument pages*/
    for (i=0 ; i<MAX_ARG_PAGES ; i++) {
        g_free(bprm->page[i]);
    }
    return(retval);
}
Exemplo n.º 3
0
int load_elf_binary_multi(struct linux_binprm *bprm,
                          struct target_pt_regs *regs,
                          struct image_info *info)
{
    struct elfhdr *elf_ex;
    int retval;

    elf_ex = (struct elfhdr *) bprm->buf;          /* exec-header */
    if (elf_ex->e_ident[EI_CLASS] == ELFCLASS64) {
        retval = load_elf_binary(bprm, regs, info);
    } else {
        retval = load_elf_binary32(bprm, regs, info);
        if (personality(info->personality) == PER_LINUX)
            info->personality = PER_LINUX32;
    }

    return retval;
}
Exemplo n.º 4
0
int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
             struct target_pt_regs * regs, struct image_info *infop,
             struct linux_binprm *bprm)
{
    int retval;

    bprm->fd = fdexec;
    bprm->filename = (char *)filename;
    bprm->argc = count(argv);
    bprm->argv = argv;
    bprm->envc = count(envp);
    bprm->envp = envp;

    retval = prepare_binprm(bprm);

    if(retval>=0) {
        if (bprm->buf[0] == 0x7f
                && bprm->buf[1] == 'E'
                && bprm->buf[2] == 'L'
                && bprm->buf[3] == 'F') {
            retval = load_elf_binary(bprm, infop);
#if defined(TARGET_HAS_BFLT)
        } else if (bprm->buf[0] == 'b'
                && bprm->buf[1] == 'F'
                && bprm->buf[2] == 'L'
                && bprm->buf[3] == 'T') {
            retval = load_flt_binary(bprm, infop);
#endif
        } else {
            return -ENOEXEC;
        }
    }

    if(retval>=0) {
        /* success.  Initialize important registers */
        do_init_thread(regs, infop);
        return retval;
    }

    return(retval);
}
Exemplo n.º 5
0
uint32_t exec_elf(const char* name) {
	fs_node_t* file = finddir(fs_root, name);
	open(file, 1, 0);

	// disable interrupts
	asm volatile("cli");

	// save directory and create one for new task
	page_directory_t* old_dir = current_directory;
	page_directory_t* new_dir = clone_directory(old_dir);

	// switch to new directory (this is where we set up process)
	switch_page_directory(new_dir);

	// load elf and get entry point
	uint32_t entry = load_elf_binary(file);

	// setup stack
	uint32_t stack = (uint32_t) allocate_stack(THREAD_STACK_SIZE);

	// create scheduling structures
	thread_t* new_thread = create_thread((int(*)(void*)) entry, 0,
			(uint32_t*) stack, THREAD_STACK_SIZE);
	task_t* new_task = create_task(new_thread, new_dir);
	schedule_add_task(new_task);

	// switch back to parents directory
	switch_page_directory(old_dir);

	// close executable image
	close(file);

	// reenable interrupts
	asm volatile("sti");

	// like in fork return child pid
	return new_task->pid;
}