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"); }
DR_EXPORT void dr_init(client_id_t id) { /* register events */ dr_register_thread_init_event(event_thread_init); dr_register_thread_exit_event(event_thread_exit); dr_register_exit_event(event_exit); dr_register_bb_event(event_basic_block); /* The TLS field provided by DR cannot be directly accessed from 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, 1, 0)) DR_ASSERT(false); }