static void event_module_load(void *drcontext, const module_data_t *data, bool loaded) { module_entry_t *entry = NULL; module_data_t *mod; int i; /* Some apps repeatedly unload and reload the same module, * so we will try to re-use the old one. */ ASSERT(data != NULL, "data must not be NULL"); drvector_lock(&module_table.vector); /* Assuming most recently loaded entries are most likely to be unloaded, * we iterate the module table in a backward way for better performance. */ for (i = module_table.vector.entries-1; i >= 0; i--) { entry = drvector_get_entry(&module_table.vector, i); mod = entry->data; if (entry->unload && /* If the same module is re-loaded at the same address, * we will try to use the existing entry. */ mod->start == data->start && mod->end == data->end && mod->entry_point == data->entry_point && #ifdef WINDOWS mod->checksum == data->checksum && mod->timestamp == data->timestamp && #endif /* If a module w/ no name (there are some) is loaded, we will * keep making new entries. */ dr_module_preferred_name(data) != NULL && dr_module_preferred_name(mod) != NULL && strcmp(dr_module_preferred_name(data), dr_module_preferred_name(mod)) == 0) { entry->unload = false; break; } entry = NULL; } if (entry == NULL) { entry = dr_global_alloc(sizeof(*entry)); entry->id = module_table.vector.entries; entry->unload = false; entry->data = dr_copy_module_data(data); drvector_append(&module_table.vector, entry); } drvector_unlock(&module_table.vector); global_module_cache_add(module_table.cache, entry); }
static void event_module_load(void *drcontext, const module_data_t *info, bool loaded) { int i; dr_mutex_lock(mod_lock); for (i = 0; i < num_mods; i++) { /* check if it is the same as any unloaded module */ if (!mod_array[i].loaded && module_data_same(mod_array[i].info, info)) { mod_array[i].loaded = true; break; } } if (i == num_mods) { /* new module */ mod_array[i].base = info->start; mod_array[i].end = info->end; mod_array[i].loaded = true; mod_array[i].info = dr_copy_module_data(info); num_mods++; } DR_ASSERT(num_mods < UNKNOW_MODULE_IDX); dr_mutex_unlock(mod_lock); }