static char * read_module_list(char *buf, void ***tables, uint *num_mods) { char path[MAXIMUM_PATH]; uint i; uint version; PRINT(3, "Reading module table...\n"); /* versione number */ PRINT(4, "Reading version number"); if (dr_sscanf(buf, "DRCOV VERSION: %u\n", &version) != 1 && version != DRCOV_VERSION) { WARN(2, "Failed to read version number"); return NULL; } buf = move_to_next_line(buf); /* module table header */ PRINT(4, "Reading Module Table Header\n"); if (dr_sscanf(buf, "Module Table: %d\n", num_mods) != 1) { WARN(2, "Failed to read module table"); return NULL; } buf = move_to_next_line(buf); /* module lists */ PRINT(4, "Reading Module Lists\n"); *tables = calloc(*num_mods, sizeof(*tables)); for (i = 0; i < *num_mods; i++) { uint mod_id; uint64 mod_size; void *bb_table; /* assuming the string is something like: "0, 2207744, /bin/ls" */ /* XXX: i#1143: we do not use dr_sscanf since it does not support %[] */ if (sscanf(buf, " %u, %"INT64_FORMAT"u, %[^\n\r]", &mod_id, &mod_size, path) != 3) ASSERT(false, "Failed to read module table"); buf = move_to_next_line(buf); PRINT(5, "Module: %u, "PFX", %s\n", mod_id, (ptr_uint_t)mod_size, path); bb_table = hashtable_lookup(&module_htable, path); if (bb_table == NULL) { if (mod_size >= UINT_MAX) ASSERT(false, "module size is too large"); if (strstr(path, "<unknown>") != NULL || (mod_filter != NULL && strstr(path, mod_filter) == NULL)) bb_table = BB_TABLE_IGNORE; else bb_table = bb_table_create((uint)mod_size); PRINT(4, "Create bb table "PFX" for module %s\n", (ptr_uint_t)bb_table, path); num_module_htable_entries++; if (!hashtable_add(&module_htable, path, bb_table)) ASSERT(false, "Failed to add new module"); } (*tables)[i] = bb_table; } return buf; }
static per_thread_t * thread_data_create(void *drcontext) { per_thread_t *data; if (drcontext == NULL) { ASSERT(!drcov_per_thread, "drcov_per_thread should not be set"); data = dr_global_alloc(sizeof(*data)); } else { ASSERT(drcov_per_thread, "drcov_per_thread should be set"); data = dr_thread_alloc(drcontext, sizeof(*data)); } /* XXX: can we assume bb create event is serialized, * if so, no lock is required for bb_table operation. */ data->bb_table = bb_table_create(drcontext == NULL ? true : false); log_file_create(drcontext, data); return data; }