コード例 #1
0
ファイル: tracer.c プロジェクト: dakov/ITS-dynamic-analysis
void handleSyscall(struct user_regs_struct regs) {

    long syscall = regs.orig_rax;

    push_syscall(syscall);
    // report only after exitting the call
    if (top_syscall()->status == 2) {
	// parameters, cf.:
	// http://www.x86-64.org/documentation/abi.pdf Section A.2.1


	switch (syscall) {

	    case __NR_munlockall: init_munlockall(regs);
		break;

	    case __NR_brk: init_brk(regs);
		break;

	    case __NR_munlock: init_munlock(regs);
		break;

	    case __NR_mlock: init_mlock(regs);
		break;

	    case __NR_munmap: init_munmap(regs);
		break;

	    case __NR_mlockall:init_mlockall(regs);
		break;

	    case __NR_mmap: init_mmap(regs);
		break;

	    case __NR_mprotect: init_mprotect(regs);
		break;

	    case __NR_msync: init_msync(regs);
		break;
	}

	pop_syscall();
    }

}
コード例 #2
0
ファイル: shim_exec.c プロジェクト: rkumar2468/graphene
int shim_do_execve_rtld (struct shim_handle * hdl, const char ** argv,
                         const char ** envp)
{
    BEGIN_PROFILE_INTERVAL();

    struct shim_thread * cur_thread = get_cur_thread();
    int ret;

    if ((ret = close_cloexec_handle(cur_thread->handle_map)) < 0)
        return ret;

    SAVE_PROFILE_INTERVAL(close_CLOEXEC_files_for_exec);

    void * tcb = malloc(sizeof(__libc_tcb_t));
    if (!tcb)
        return -ENOMEM;

    populate_tls(tcb);

    put_handle(cur_thread->exec);
    get_handle(hdl);
    cur_thread->exec = hdl;

    old_stack_top = cur_thread->stack_top;
    old_stack     = cur_thread->stack;
    old_stack_red = cur_thread->stack_red;
    cur_thread->stack_top = NULL;
    cur_thread->stack     = NULL;
    cur_thread->stack_red = NULL;

    initial_envp = NULL;
    new_argc = 0;
    for (const char ** a = argv ; *a ; a++, new_argc++);

    if ((ret = init_stack(argv, envp, &new_argp,
                          REQUIRED_ELF_AUXV, &new_auxp)) < 0)
        return ret;

    SAVE_PROFILE_INTERVAL(alloc_new_stack_for_exec);

    switch_stack(new_argp);
    cur_thread = get_cur_thread();

    UPDATE_PROFILE_INTERVAL();

    DkVirtualMemoryFree(old_stack, old_stack_top - old_stack);
    DkVirtualMemoryFree(old_stack_red, old_stack - old_stack_red);
    int flags = VMA_INTERNAL;
    bkeep_munmap(old_stack, old_stack_top - old_stack, &flags);
    bkeep_munmap(old_stack_red, old_stack - old_stack_red, &flags);

    remove_loaded_libraries();
    clean_link_map_list();
    SAVE_PROFILE_INTERVAL(unmap_loaded_binaries_for_exec);

    init_brk();
    unmap_all_vmas();
    SAVE_PROFILE_INTERVAL(unmap_all_vmas_for_exec);

    if ((ret = load_elf_object(cur_thread->exec, NULL, 0)) < 0)
        shim_terminate();

    load_elf_interp(cur_thread->exec);

    SAVE_PROFILE_INTERVAL(load_new_executable_for_exec);

    debug("execve: start execution\n");
    execute_elf_object(cur_thread->exec, new_argc, new_argp,
                       REQUIRED_ELF_AUXV, new_auxp);

    return 0;
}