Пример #1
0
/* Parse CL options and register DR event handlers and annotation handlers */
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    context_lock = dr_mutex_create();
    write_lock = dr_mutex_create();

# ifdef WINDOWS
    dr_enable_console_printing();
# endif

    client_id = id;

    /* XXX: should use droption */
    if (argc > 1 && strcmp(argv[1], "full-decode") == 0) {
        PRINTF("Init annotation test client with full decoding");
        dr_register_bb_event(empty_bb_event);
    } else if (argc > 1 && strlen(argv[1]) >= 8 && strncmp(argv[1], "truncate", 8) == 0) {
        bb_truncation_length = (argv[1][9] - '0'); /* format is "truncate@n" (0<n<10) */
        ASSERT(bb_truncation_length < 10 && bb_truncation_length > 0);
        PRINTF("Init annotation test client with bb truncation");
        dr_register_bb_event(bb_event_truncate);
    } else {
        PRINTF("Init annotation test client with fast decoding");
    }

    context_list = dr_global_alloc(sizeof(context_list_t));
    memset(context_list, 0, sizeof(context_list_t));

#if !(defined (WINDOWS) && defined (X64))
    mem_defines = dr_global_alloc(sizeof(mem_defines_t));
    memset(mem_defines, 0, sizeof(mem_defines_t));
#endif

    dr_register_exit_event(event_exit);

    register_call("test_annotation_init_mode", (void *) init_mode, 1);
    register_call("test_annotation_init_context", (void *) init_context, 3);
    register_call("test_annotation_get_mode", (void *) get_mode, 1);
    register_call("test_annotation_set_mode", (void *) set_mode, 2);
#if !(defined (WINDOWS) && defined (X64))
    register_call("test_annotation_rotate_valgrind_handler",
                  (void *) rotate_valgrind_handler, 1);
#endif

    register_call("test_annotation_eight_args", (void *) test_eight_args_v1, 8);
    register_call("test_annotation_eight_args", (void *) test_eight_args_v2, 8);
    /* Test removing the last handler */
    dr_annotation_unregister_call("test_annotation_eight_args", test_eight_args_v1);

    register_call("test_annotation_nine_args", (void *) test_nine_args_v1, 9);
    register_call("test_annotation_nine_args", (void *) test_nine_args_v2, 9);
    /* Test removing the first handler */
    dr_annotation_unregister_call("test_annotation_nine_args", test_nine_args_v2);

    /* Test multiple handlers */
    register_call("test_annotation_ten_args", (void *) test_ten_args_v1, 10);
    register_call("test_annotation_ten_args", (void *) test_ten_args_v2, 10);

    dr_annotation_register_return("test_annotation_get_client_version", (void *) "2.2.8");
}
Пример #2
0
DR_EXPORT void dr_init(client_id_t id) {
  dr_fprintf(STDERR, "info: starting dtrace, &dr_init=%p..\n", &dr_init);

  trace_file = dr_open_file(TRACE_FILE_NAME,
                            DR_FILE_ALLOW_LARGE | DR_FILE_WRITE_OVERWRITE);
  if(trace_file == INVALID_FILE) {
    dr_fprintf(STDERR, "fatal: dr_open_file() failed\n");
    dr_exit_process(1);
  }
  trace_file_lock = dr_mutex_create();

  trace_buffer = tb_create(-1);
  trace_buffer_lock = dr_mutex_create();

  hashtable_init_ex(&tags,
                    16,
                    HASH_INTPTR,
                    false,
                    false,
                    &tag_info_free_raw,
                    NULL,
                    NULL);
  tags_lock = dr_mutex_create();

  dr_register_exit_event(&dr_exit);
  dr_register_thread_init_event(&handle_thread_init);
  dr_register_thread_exit_event(&handle_thread_exit);
  dr_register_bb_event(&handle_bb);
  dr_register_trace_event(&handle_trace);
  dr_register_delete_event(&handle_delete);
  dr_register_signal_event(&handle_signal);
  dr_register_restore_state_event(&handle_restore_state);
}
Пример #3
0
void
symcache_init(const char *symcache_dir_in,
              size_t modsize_cache_threshold)
{
    initialized = true;

    op_modsize_cache_threshold = modsize_cache_threshold;

    hashtable_init_ex(&symcache_table, SYMCACHE_MASTER_TABLE_HASH_BITS,
                      IF_WINDOWS_ELSE(HASH_STRING_NOCASE, HASH_STRING),
                      true/*strdup*/, false/*!synch*/,
                      symcache_free_entry, NULL, NULL);
    symcache_lock = dr_mutex_create();

    dr_snprintf(symcache_dir, BUFFER_SIZE_ELEMENTS(symcache_dir), 
                "%s", symcache_dir_in);
    NULL_TERMINATE_BUFFER(symcache_dir);
    if (!dr_directory_exists(symcache_dir)) {
        if (!dr_create_dir(symcache_dir)) {
            /* check again in case of a race (i#616) */
            if (!dr_directory_exists(symcache_dir)) {
                NOTIFY_ERROR("Unable to create symcache dir %s"NL, symcache_dir);
                ASSERT(false, "unable to create symcache dir");
                dr_abort();
            }
        }
    }
}
Пример #4
0
DR_EXPORT void
dr_init(client_id_t id)
{
    dr_register_exit_event(exit_event);
    dr_register_bb_event(bb_event);
    count_mutex = dr_mutex_create();
}
Пример #5
0
DR_EXPORT void
dr_init(client_id_t id)
{
    drmgr_priority_t priority = {sizeof(priority), "drmgr-test", NULL, NULL, 0};
    drmgr_priority_t priority4 = {sizeof(priority), "drmgr-test4", NULL, NULL, 0};
    drmgr_priority_t sys_pri_A = {sizeof(priority), "drmgr-test-A",
                                  NULL, NULL, 10};
    drmgr_priority_t sys_pri_B = {sizeof(priority), "drmgr-test-B",
                                  "drmgr-test-A", NULL, 5};
    bool ok;

    drmgr_init();
    dr_register_exit_event(event_exit);
    drmgr_register_thread_init_event(event_thread_init);
    drmgr_register_thread_exit_event(event_thread_exit);

    ok = drmgr_register_bb_instrumentation_event(event_bb_analysis,
                                                 event_bb_insert,
                                                 &priority);
    CHECK(ok, "drmgr register bb failed");

    /* check register/unregister instrumentation_ex */
    ok = drmgr_register_bb_instrumentation_ex_event(event_bb4_app2app,
                                                    event_bb4_analysis,
                                                    event_bb4_insert2,
                                                    event_bb4_instru2instru,
                                                    NULL);
    CHECK(ok, "drmgr_register_bb_instrumentation_ex_event failed");
    ok = drmgr_unregister_bb_instrumentation_ex_event(event_bb4_app2app,
                                                      event_bb4_analysis,
                                                      event_bb4_insert2,
                                                      event_bb4_instru2instru);
    CHECK(ok, "drmgr_unregister_bb_instrumentation_ex_event failed");

    /* test data passing among all 4 phases */
    ok = drmgr_register_bb_instrumentation_ex_event(event_bb4_app2app,
                                                    event_bb4_analysis,
                                                    event_bb4_insert,
                                                    event_bb4_instru2instru,
                                                    &priority4);

    tls_idx = drmgr_register_tls_field();
    CHECK(tls_idx != -1, "drmgr_register_tls_field failed");
    cls_idx = drmgr_register_cls_field(event_thread_context_init,
                                       event_thread_context_exit);
    CHECK(cls_idx != -1, "drmgr_register_tls_field failed");

    dr_register_filter_syscall_event(event_filter_syscall);
    ok = drmgr_register_pre_syscall_event_ex(event_pre_sys_A, &sys_pri_A) &&
        drmgr_register_pre_syscall_event_ex(event_pre_sys_B, &sys_pri_B);
    CHECK(ok, "drmgr register sys failed");
    ok = drmgr_register_post_syscall_event_ex(event_post_sys_A, &sys_pri_A) &&
        drmgr_register_post_syscall_event_ex(event_post_sys_B, &sys_pri_B);
    CHECK(ok, "drmgr register sys failed");

    syslock = dr_mutex_create();

    ok = drmgr_register_bb_app2app_event(one_time_bb_event, NULL);
    CHECK(ok, "drmgr app2app registration failed");
}
Пример #6
0
void
hashtable_init_ex(hashtable_t *table, uint num_bits, hash_type_t hashtype, bool str_dup,
                  bool synch, void (*free_payload_func)(void*),
                  uint (*hash_key_func)(void*), bool (*cmp_key_func)(void*, void*))
{
    hash_entry_t **alloc = (hash_entry_t **)
        hash_alloc((size_t)HASHTABLE_SIZE(num_bits) * sizeof(hash_entry_t*));
    memset(alloc, 0, (size_t)HASHTABLE_SIZE(num_bits) * sizeof(hash_entry_t*));
    table->table = alloc;
    table->hashtype = hashtype;
    table->str_dup = str_dup;
    ASSERT(!str_dup || hashtype == HASH_STRING || hashtype == HASH_STRING_NOCASE,
           "hashtable_init_ex internal error: invalid hashtable type");
    table->lock = dr_mutex_create();
    table->table_bits = num_bits;
    table->synch = synch;
    table->free_payload_func = free_payload_func;
    table->hash_key_func = hash_key_func;
    table->cmp_key_func = cmp_key_func;
    ASSERT(table->hashtype != HASH_CUSTOM ||
           (table->hash_key_func != NULL && table->cmp_key_func != NULL),
           "hashtable_init_ex missing cmp/hash key func");
    table->entries = 0;
    table->config.size = sizeof(table->config);
    table->config.resizable = true;
    table->config.resize_threshold = 75;
}
Пример #7
0
/* callbacks for the entire process */
void memdump_init(client_id_t id, const char * name, const char * arguments)
{

	char logfilename[MAX_STRING_LENGTH];
	file_t in_file;

	drmgr_init();
	drutil_init();
	drwrap_init();
	tls_index = drmgr_register_tls_field();
	DR_ASSERT(parse_commandline_args(arguments) == true);

	filter_head = md_initialize();
	done_head = md_initialize();
	app_pc_head = md_initialize();
	
	in_file = dr_open_file(client_arg->filter_filename, DR_FILE_READ);
	md_read_from_file(filter_head, in_file, false);
	dr_close_file(in_file);
	
	in_file = dr_open_file(client_arg->app_pc_filename, DR_FILE_READ);
	md_read_from_file(app_pc_head, in_file, false);
	dr_close_file(in_file);


	if (log_mode){
		populate_conv_filename(logfilename, logdir, name, NULL);
		logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE);
	}
	strncpy(ins_pass_name, name, MAX_STRING_LENGTH);
	mutex = dr_mutex_create();

}
Пример #8
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    /* We need 2 reg slots beyond drreg's eflags slots => 3 slots */
    drreg_options_t ops = { sizeof(ops), 3, false };
    dr_set_client_name("DynamoRIO Sample Client 'memtrace'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS || !drutil_init())
        DR_ASSERT(false);

    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_thread_init_event(event_thread_init) ||
        !drmgr_register_thread_exit_event(event_thread_exit) ||
        !drmgr_register_bb_app2app_event(event_bb_app2app, NULL) ||
        !drmgr_register_bb_instrumentation_event(NULL /*analysis_func*/,
                                                 event_app_instruction, NULL))
        DR_ASSERT(false);

    client_id = id;
    mutex = dr_mutex_create();

    tls_idx = drmgr_register_tls_field();
    DR_ASSERT(tls_idx != -1);
    /* The TLS field provided by DR cannot be directly accessed from the code cache.
     * For better performance, we allocate raw TLS so that we can directly
     * access and update it with a single instruction.
     */
    if (!dr_raw_tls_calloc(&tls_seg, &tls_offs, MEMTRACE_TLS_COUNT, 0))
        DR_ASSERT(false);

    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'memtrace' initializing\n");
}
Пример #9
0
DR_EXPORT void dr_init(client_id_t id)
{
  /* Register Events */
  dr_register_exit_event(event_exit);
  dr_register_bb_event(event_basic_block);

  /* Initalize lock */
  as_built_lock = dr_mutex_create();
}
Пример #10
0
int
main(int argc, char *argv[])
{
#ifdef STANDALONE_DECODER
    void *dcontext = GLOBAL_DCONTEXT;
#else
    void *dcontext = dr_standalone_init();

    /* simple test of deadlock_avoidance, etc. being disabled in standalone */
    void *x = dr_mutex_create();
    dr_mutex_lock(x);
    dr_mutex_unlock(x);
    dr_mutex_destroy(x);
#endif

    test_all_opcodes_0(dcontext);
#ifndef STANDALONE_DECODER /* speed up compilation */
    test_all_opcodes_1(dcontext);
    test_all_opcodes_2(dcontext);
    test_all_opcodes_2_mm(dcontext);
    test_all_opcodes_3(dcontext);
    test_all_opcodes_3_avx(dcontext);
    test_all_opcodes_4(dcontext);
#endif

    test_disp_control(dcontext);

    test_indirect_cti(dcontext);

    test_cti_prefixes(dcontext);

#ifndef X64
    test_modrm16(dcontext);
#endif

    test_size_changes(dcontext);

    test_nop_xchg(dcontext);

#ifdef X64
    test_x86_mode(dcontext);

    test_x64_abs_addr(dcontext);

    test_x64_inc(dcontext);
#endif

    test_regs(dcontext);

    test_instr_opnds(dcontext);

    test_strict_invalid(dcontext);

    print("all done\n");
    return 0;
}
Пример #11
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    dr_set_client_name("DynamoRIO Sample Client 'div'", "http://dynamorio.org/issues");
    if (!drmgr_init())
        DR_ASSERT(false);
    dr_register_exit_event(exit_event);
    if (!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
        DR_ASSERT(false);
    count_mutex = dr_mutex_create();
}
Пример #12
0
DR_EXPORT
bool
drmgr_init(void)
{
    static bool initialized;
    if (initialized)
        return true;
    initialized = true;
    exit_lock = dr_mutex_create();
    note_lock = dr_mutex_create();

    bb_cb_lock = dr_rwlock_create();
    thread_event_lock = dr_rwlock_create();
    tls_lock = dr_mutex_create();
    cls_event_lock = dr_rwlock_create();
    presys_event_lock = dr_rwlock_create();

    dr_register_thread_init_event(drmgr_thread_init_event);
    dr_register_thread_exit_event(drmgr_thread_exit_event);
    dr_register_pre_syscall_event(drmgr_presyscall_event);

    return true;
}
Пример #13
0
DR_EXPORT void 
dr_init(client_id_t id)
{
    num_bb = 0;
    ave_size = 0.;
    max_size = 0;
    stats_mutex = dr_mutex_create();
    dr_register_bb_event(event_basic_block);
    dr_register_exit_event(event_exit);
#ifdef SHOW_RESULTS
    if (dr_is_notify_on())
	dr_fprintf(STDERR, "Client bbsize is running\n");
#endif
}
Пример #14
0
bool
drvector_init(drvector_t *vec, uint initial_capacity, bool synch,
              void (*free_data_func)(void*))
{
    if (vec == NULL)
        return false;
    vec->array = dr_global_alloc(initial_capacity * sizeof(void*));
    vec->entries = 0;
    vec->capacity = initial_capacity;
    vec->synch = synch;
    vec->lock = dr_mutex_create();
    vec->free_data_func = free_data_func;
    return true;
}
Пример #15
0
DR_EXPORT void
dr_init(client_id_t id)
{
    htable_mutex = dr_mutex_create();

    /* global HASH_BITS-bit addressed hash table */
    htable = htable_create(NULL/*global*/);

    dr_register_exit_event(event_exit);
    dr_register_bb_event(event_basic_block);
    dr_register_delete_event(event_fragment_deleted);
    dr_register_end_trace_event(query_end_trace);

    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, LOG_ALL, 1, "Client 'inline' initializing\n");
    num_complete_inlines = 0;
}
Пример #16
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    /* We need 2 reg slots beyond drreg's eflags slots => 3 slots */
    drreg_options_t ops = {sizeof(ops), 3, false};
    /* Specify priority relative to other instrumentation operations: */
    drmgr_priority_t priority = {
        sizeof(priority), /* size of struct */
        "memtrace",       /* name of our operation */
        NULL,             /* optional name of operation we should precede */
        NULL,             /* optional name of operation we should follow */
        0};               /* numeric priority */
    dr_set_client_name("DynamoRIO Sample Client 'memtrace'",
                       "http://dynamorio.org/issues");
    page_size = dr_page_size();
    drmgr_init();
    drutil_init();
    client_id = id;
    mutex = dr_mutex_create();
    dr_register_exit_event(event_exit);
    if (!drmgr_register_thread_init_event(event_thread_init) ||
        !drmgr_register_thread_exit_event(event_thread_exit) ||
        !drmgr_register_bb_app2app_event(event_bb_app2app, &priority) ||
        !drmgr_register_bb_instrumentation_event(NULL, event_bb_insert, &priority) ||
        drreg_init(&ops) != DRREG_SUCCESS) {
        /* something is wrong: can't continue */
        DR_ASSERT(false);
        return;
    }
    tls_index = drmgr_register_tls_field();
    DR_ASSERT(tls_index != -1);

    code_cache_init();
    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, DR_LOG_ALL, 1, "Client 'memtrace' initializing\n");
#ifdef SHOW_RESULTS
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called at init. */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client memtrace is running\n");
    }
#endif
}
Пример #17
0
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
    /* We need no drreg slots ourselves, but we initialize drreg as we call
     * drreg_restore_app_values(), required since drx_insert_counter_update()
     * uses drreg when drmgr is used.
     */
    drreg_options_t ops = {sizeof(ops)};
    dr_set_client_name("DynamoRIO Sample Client 'modxfer'",
                       "http://dynamorio.org/issues");
    if (!drmgr_init() || drreg_init(&ops) != DRREG_SUCCESS)
        DR_ASSERT(false);
    drx_init();
    /* register events */
    dr_register_exit_event(event_exit);
    if (!drmgr_register_bb_instrumentation_event(event_analyze_bb,
                                                 event_insert_instrumentation, NULL))
        DR_ASSERT(false);
    drmgr_register_module_load_event(event_module_load);
    drmgr_register_module_unload_event(event_module_unload);

    mod_lock = dr_mutex_create();

    logfile = log_file_open(id, NULL /* drcontext */,
                            NULL/* path */, "modxfer",
#ifndef WINDOWS
                            DR_FILE_CLOSE_ON_FORK |
#endif
                            DR_FILE_ALLOW_LARGE);

    DR_ASSERT(logfile != INVALID_FILE);
    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, LOG_ALL, 1, "Client 'modxfer' initializing\n");
#ifdef SHOW_RESULTS
    /* also give notification to stderr */
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called at init. */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client modxfer is running\n");
    }
#endif
}
Пример #18
0
DR_EXPORT void 
dr_init(client_id_t id)
{
    num_bb = 0;
    ave_size = 0.;
    max_size = 0;
    stats_mutex = dr_mutex_create();
    dr_register_bb_event(event_basic_block);
    dr_register_exit_event(event_exit);
#ifdef SHOW_RESULTS
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called in dr_init(). */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client bbsize is running\n");
    }
#endif
}
Пример #19
0
DR_EXPORT void 
dr_init(client_id_t id)
{
    dr_printf("dr_init()\n");
    my_bbcount = 0;
    stats_mutex = dr_mutex_create();
    dr_register_exit_event(event_exit);
    dr_register_bb_event(event_basic_block);

#ifdef SHOW_RESULTS
    dr_log(NULL, LOG_ALL, 1, "Client 'inspar' initializing\n");
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client inspar is running\n");
    }
#endif
}
Пример #20
0
void instrace_init(client_id_t id, const char * name, const char * arguments)
{

	file_t in_file;
	file_t out_file;
	int i;
	char logfilename[MAX_STRING_LENGTH];

    drmgr_init();
    drutil_init();
    client_id = id;

	DR_ASSERT(parse_commandline_args(arguments)==true);

	head = md_initialize();
	instrace_head = md_initialize();

	if(client_arg->filter_mode != FILTER_NONE){
		in_file = dr_open_file(client_arg->filter_filename,DR_FILE_READ);
		DR_ASSERT(in_file != INVALID_FILE);
		md_read_from_file(head,in_file,false);
		dr_close_file(in_file);
	}

	mutex = dr_mutex_create();
    tls_index = drmgr_register_tls_field();
    DR_ASSERT(tls_index != -1);
    code_cache_init();

	if (log_mode){
		populate_conv_filename(logfilename, logdir, name, NULL);
		logfile = dr_open_file(logfilename, DR_FILE_WRITE_OVERWRITE);
	}
	strncpy(ins_pass_name, name, MAX_STRING_LENGTH);

	for(i=OP_FIRST;i<=OP_LAST; i++){
		opcodes_visited[i] = false;
	}

	
	

}
Пример #21
0
DR_EXPORT void 
dr_init(client_id_t id)
{
    /* make it easy to tell, by looking at log file, which client executed */
    dr_log(NULL, LOG_ALL, 1, "Client 'wrap' initializing\n");
    /* also give notification to stderr */
#ifdef SHOW_RESULTS
    if (dr_is_notify_on()) {
# ifdef WINDOWS
        /* ask for best-effort printing to cmd window.  must be called in dr_init(). */
        dr_enable_console_printing();
# endif
        dr_fprintf(STDERR, "Client wrap is running\n");
    }
#endif
    drwrap_init();
    dr_register_exit_event(event_exit);
    dr_register_module_load_event(module_load_event);
    max_lock = dr_mutex_create();
}
Пример #22
0
DR_EXPORT void
dr_init(client_id_t id)
{

printf("Started dr_init\n");

    dr_register_exit_event(exit_event);
    dr_register_bb_event(bb_event);
    dr_register_thread_init_event(writeLog); 
    count_mutex = dr_mutex_create();
    client_id = id;
#ifdef SHOW_SYMBOLS
    if (drsym_init(0) != DRSYM_SUCCESS) {
        dr_log(NULL, LOG_ALL, 1, "WARNING: unable to initialize symbol translation\n");
    }
#endif

htinit();

}
Пример #23
0
void
umbra_client_init()
{
    umbra_client_t *client;

    client_proc_data.lock = dr_mutex_create();
    client = &proc_info.client;
    memset(client, 0, sizeof(umbra_client_t));
    client->thread_init = umbra_client_thread_init;
    client->thread_exit = umbra_client_thread_exit;
    client->client_exit        = umbra_client_exit;
    client->bb_is_interested   = bb_is_interested;
    client->ref_is_interested  = ref_is_interested;
    client->app_unit_bits[0]  = 0;   
    client->shd_unit_bits[0]  = 0;   /* byte-2-byte mapping */
    client->orig_addr      = false;
    client->num_steal_regs = 1;
    client->instrument_update   = instrument_update;
    client->shadow_memory_module_destroy = NULL; /* Do nothing on removal */
    client->shadow_memory_module_create  = NULL;
}
Пример #24
0
DR_EXPORT void dr_init( client_id_t id ) {
  dr_printf( "In dr_init()\n" );

  // Initialize extensions.
  drsym_error_t rc = drsym_init( 0 );
  if( DRSYM_SUCCESS != rc ) {
    dr_printf( "drsym_init() failed: %i\n", rc );
    exit( 1 );
  }

  bool wrapInit = drwrap_init();
  if( !wrapInit ) {
    dr_printf( "drwrap_init() failed\n" );
    exit( 1 );
  }

  // Set up output.
  char fileName[256];
  unsigned int pid = (unsigned int)dr_get_process_id();
  dr_snprintf( fileName, sizeof( fileName ), "objcount-%u.out", pid );
  fileName[sizeof( fileName ) - 1] = 0;
  outFile = dr_open_file( fileName, DR_FILE_WRITE_OVERWRITE );
  outMutex = dr_mutex_create();

  // Set up hashtable.
  hashtable_init_ex( &wraps,      // table
                     16,          // num_bits
                     HASH_INTPTR, // hashtype
                     false,       // str_dup
                     false,       // synch
                     &free_wrap,  // free_payload_func
                     NULL,        // hash_key_func
                     NULL );      // cmp_key_func

  // Register for events.
  dr_register_module_load_event( onLoad );
  dr_register_exit_event( onExit );
}
Пример #25
0
DR_EXPORT void
dr_init(client_id_t id)
{
    dr_set_client_name("DynamoRIO Sample Client 'MF_moduledb'",
                       "http://dynamorio.org/issues");
    VDISPLAY_FUNC(NAME" initializing.");

    /* register the events we wish to handle */
    dr_register_security_event(event_security_violation);
    dr_register_nudge_event(event_nudge, id);
    dr_register_exit_event(event_exit);

    /* read the client options */
    table_def_file_name = dr_get_options(id);
    if (table_def_file_name == NULL ||
        table_def_file_name[0] == '\0') {
        DISPLAY_FUNC(NAME" requires the table name as parameter\n");
        dr_abort();
    }

    /* initialize structures */
    table_lock = dr_mutex_create();
    read_table();
}
Пример #26
0
static void
unload_module(HANDLE proc, DWORD64 base);

static void
modtable_entry_free(void *p)
{
    unload_module(GetCurrentProcess(), (DWORD64)p);
}

DR_EXPORT
drsym_error_t
drsym_init(IF_WINDOWS_ELSE(const wchar_t *, int) shmid_in)
{
    shmid = shmid_in;

    symbol_lock = dr_mutex_create();

    if (IS_SIDELINE) {
        /* FIXME NYI: establish connection with sideline server via
         * shared memory specified by shmid
         */
    } else {
        hashtable_init_ex(&modtable, MODTABLE_HASH_BITS, HASH_STRING_NOCASE,
                          true/*strdup*/, false/*!synch: using symbol_lock*/,
                          modtable_entry_free, NULL, NULL);
        
        SymSetOptions(SYMOPT_LOAD_LINES | SymGetOptions());
        if (!SymInitialize(GetCurrentProcess(), NULL, FALSE)) {
            NOTIFY("SymInitialize error %d\n", GetLastError());
            return DRSYM_ERROR;
        }
Пример #27
0
void
init_IPC(int idx, const char *path, bool standalone)
{
    DR_ASSERT(idx < MAX_IPC_CHANNELS);

    int path_len, pad_len, shmem_len, fullfifo_len, emptyfifo_len;
    ipc_channel_t *channel = &IPC[idx];

    channel->standalone = standalone;

    /* Initialize channel state */
    ticket_node_t *node = dr_global_alloc(sizeof(ticket_node_t));
    if (node == NULL)
        DR_ABORT_MSG("Failed to allocate ticket node\n");
    node->next = NULL;
    node->dr_event = NULL;
    node->waiting = false;
    node->thread_id = 0;
    channel->ticket_queue.head = node;
    channel->ticket_queue.tail = node;
    channel->ticket_queue.locked = false;
    channel->queue_lock = dr_mutex_create();

    channel->shared_mem = NULL;
    channel->full_fifo = -1;
    channel->empty_fifo = -1;
    channel->shmem_buf_idx = 0;

    for(uint i=0; i<sizeof(channel->empty_buf_idx)/sizeof(channel->empty_buf_idx[0]); ++i)
        channel->empty_buf_idx[i] = true;

    channel->last_active_tid = 0;
    channel->initialized     = false;

    if (standalone)
    {
        /* mimic shared memory writes */
        channel->shared_mem = dr_raw_mem_alloc(sizeof(Sigil2DBISharedData),
                                               DR_MEMPROT_READ | DR_MEMPROT_WRITE,
                                               NULL);
        if (channel->shared_mem == NULL)
            DR_ABORT_MSG("Failed to allocate pseudo shared memory buffer\n");
        for (int i=0; i<SIGIL2_IPC_BUFFERS; ++i)
            channel->shared_mem->eventBuffers[i].used = 0;
    }
    else
    {
        /* Connect to Sigil2 */
        path_len = strlen(path);
        pad_len = 4; /* extra space for '/', 2x'-', '\0' */
        shmem_len     = (path_len + pad_len +
                         sizeof(SIGIL2_IPC_SHMEM_BASENAME) +
                         sizeof(STRINGIFY(MAX_IPC_CHANNELS)));
        fullfifo_len  = (path_len + pad_len +
                         sizeof(SIGIL2_IPC_FULLFIFO_BASENAME) +
                         sizeof(STRINGIFY(MAX_IPC_CHANNELS)));
        emptyfifo_len = (path_len + pad_len +
                         sizeof(SIGIL2_IPC_EMPTYFIFO_BASENAME) +
                         sizeof(STRINGIFY(MAX_IPC_CHANNELS)));

        /* set up names of IPC files */
        char shmem_name[shmem_len];
        sprintf(shmem_name, "%s/%s-%d", path, SIGIL2_IPC_SHMEM_BASENAME, idx);

        char fullfifo_name[fullfifo_len];
        sprintf(fullfifo_name, "%s/%s-%d", path, SIGIL2_IPC_FULLFIFO_BASENAME, idx);

        char emptyfifo_name[emptyfifo_len];
        sprintf(emptyfifo_name, "%s/%s-%d", path, SIGIL2_IPC_EMPTYFIFO_BASENAME, idx);


        /* initialize read/write pipes */
        channel->empty_fifo = open_sigil2_fifo(emptyfifo_name, DR_FILE_READ);
        channel->full_fifo = open_sigil2_fifo(fullfifo_name, DR_FILE_WRITE_ONLY);

        /* no need to timeout on file because shared memory MUST be initialized
         * by Sigil2 before the fifos are created */
        file_t map_file = dr_open_file(shmem_name, DR_FILE_READ|DR_FILE_WRITE_APPEND);
        if(map_file == INVALID_FILE)
            DR_ABORT_MSG("error opening shared memory file");

        size_t mapped_size = sizeof(Sigil2DBISharedData);
        channel->shared_mem = dr_map_file(map_file, &mapped_size,
                                          0, 0, /* assume this is not honored */
                                          DR_MEMPROT_READ|DR_MEMPROT_WRITE, 0);

        if(mapped_size != sizeof(Sigil2DBISharedData) || channel->shared_mem == NULL)
            DR_ABORT_MSG("error mapping shared memory");

        dr_close_file(map_file);
    }

    channel->initialized = true;
}
Пример #28
0
DR_EXPORT
drmf_status_t
drsymcache_init(client_id_t client_id,
                const char *symcache_dir_in,
                size_t modsize_cache_threshold)
{
#ifdef WINDOWS
    module_data_t *mod;
#endif
    drmf_status_t res;
    drmgr_priority_t pri_mod_load_cache =
        {sizeof(pri_mod_load_cache), DRMGR_PRIORITY_NAME_DRSYMCACHE, NULL, NULL,
         DRMGR_PRIORITY_MODLOAD_DRSYMCACHE_READ};
    drmgr_priority_t pri_mod_unload_cache =
        {sizeof(pri_mod_unload_cache), DRMGR_PRIORITY_NAME_DRSYMCACHE, NULL, NULL,
         DRMGR_PRIORITY_MODUNLOAD_DRSYMCACHE};
    drmgr_priority_t pri_mod_save_cache =
        {sizeof(pri_mod_save_cache), DRMGR_PRIORITY_NAME_DRSYMCACHE_SAVE, NULL, NULL,
         DRMGR_PRIORITY_MODLOAD_DRSYMCACHE_SAVE};

    /* handle multiple sets of init/exit calls */
    int count = dr_atomic_add32_return_sum(&symcache_init_count, 1);
    if (count > 1)
        return DRMF_WARNING_ALREADY_INITIALIZED;

    res = drmf_check_version(client_id);
    if (res != DRMF_SUCCESS)
        return res;

    drmgr_init();
    drmgr_register_module_load_event_ex(symcache_module_load, &pri_mod_load_cache);
    drmgr_register_module_unload_event_ex(symcache_module_unload, &pri_mod_unload_cache);
    drmgr_register_module_load_event_ex(symcache_module_load_save, &pri_mod_save_cache);

    initialized = true;

    op_modsize_cache_threshold = modsize_cache_threshold;

    hashtable_init_ex(&symcache_table, SYMCACHE_MASTER_TABLE_HASH_BITS,
                      IF_WINDOWS_ELSE(HASH_STRING_NOCASE, HASH_STRING),
                      true/*strdup*/, false/*!synch*/,
                      symcache_free_entry, NULL, NULL);
    symcache_lock = dr_mutex_create();

    dr_snprintf(symcache_dir, BUFFER_SIZE_ELEMENTS(symcache_dir),
                "%s", symcache_dir_in);
    NULL_TERMINATE_BUFFER(symcache_dir);
    if (!dr_directory_exists(symcache_dir)) {
        if (!dr_create_dir(symcache_dir)) {
            /* check again in case of a race (i#616) */
            if (!dr_directory_exists(symcache_dir)) {
                NOTIFY_ERROR("Unable to create symcache dir %s"NL, symcache_dir);
                ASSERT(false, "unable to create symcache dir");
                dr_abort();
            }
        }
    }

#ifdef WINDOWS
    /* It's common for tools to query ntdll in their init routines so we add it
     * early here
     */
    mod = dr_lookup_module_by_name("ntdll.dll");
    if (mod != NULL) {
        symcache_module_load(dr_get_current_drcontext(), mod, true);
        dr_free_module_data(mod);
    }
#endif

    return DRMF_SUCCESS;
}