void drsyscall_os_exit(void) { hashtable_delete(&systable); hashtable_delete(&secondary_systable); hashtable_delete(&name2num_table); }
int main(void) { struct hashmap aa; struct hashmap *a= &aa; hashtable_initialize(a, 200, default_hash, 4); uint8_t key[4] = {1,2,3,4}; int i; for (i= 0; i < 10; i++) { key[0] = i; hashtable_add(a,key,(void*)5); } hashtable_iter(a,iter); printf("deleting\n"); for (i= 0; i < 5; i++) { key[0] = i; hashtable_delete(a,key); } hashtable_iter(a,iter); return 0; }
bool drstrace_unit_test_syscall_exit() { if (drsym_exit() != DRSYM_SUCCESS) return false; hashtable_delete(&nconsts_table); return true; }
void replace_exit(void) { #ifdef USE_DRSYMS if (options.replace_libc) { hashtable_delete(&replace_name_table); } #endif }
static void exit_event(void) { if (outf != STDERR) dr_close_file(outf); if (drsys_exit() != DRMF_SUCCESS) ASSERT(false, "drsys failed to exit"); drsym_exit(); drx_exit(); drmgr_exit(); hashtable_delete(&nconsts_table); }
/* caller must hold symcache_lock, even at exit time */ static void symcache_free_entry(void *v) { mod_cache_t *modcache = (mod_cache_t *) v; ASSERT(dr_mutex_self_owns(symcache_lock), "missing symcache lock"); if (modcache != NULL) { hashtable_delete(&modcache->table); if (modcache->modname != NULL) { global_free((void *)modcache->modname, strlen(modcache->modname) + 1, HEAPSTAT_HASHTABLE); } global_free(modcache, sizeof(*modcache), HEAPSTAT_HASHTABLE); } }
static void onExit() { dr_printf( "In onExit()\n" ); // Clean up hashtable. hashtable_delete( &wraps ); // Clean up output. dr_mutex_destroy( outMutex ); dr_close_file( outFile ); // Clean up extensions. drwrap_exit(); drsym_exit(); }
static void symcache_free_entry(void *v) { /* caller holds symcache_lock, or exit time */ mod_cache_t *modcache = (mod_cache_t *) v; if (modcache != NULL) { hashtable_delete(&modcache->table); if (modcache->modname != NULL) { global_free((void *)modcache->modname, strlen(modcache->modname) + 1, HEAPSTAT_HASHTABLE); } global_free(modcache, sizeof(*modcache), HEAPSTAT_HASHTABLE); } }
static void symcache_free_list(void *v) { offset_list_t *olist = (offset_list_t *) v; offset_entry_t *tmp, *e = olist->list; if (olist->table != NULL) { hashtable_delete(olist->table); global_free(olist->table, sizeof(*olist->table), HEAPSTAT_HASHTABLE); } while (e != NULL) { tmp = e; e = e->next; global_free(tmp, sizeof(*tmp), HEAPSTAT_HASHTABLE); } global_free(olist, sizeof(*olist), HEAPSTAT_HASHTABLE); }
int hashtable_insert(hashtable *hash, char *key, void *data) { ENTRY e, *ep; int retval; hashtable_delete(hash, key); /* CRITICAL SECTION */ pthread_mutex_lock(&hash_mutex); retval = 1; e.key = strdup(key); if (!e.key) { lerror("calloc"); pthread_mutex_unlock(&hash_mutex); return -1; } e.data = strdup(data); if (!e.data) { lerror("calloc"); free(e.key); pthread_mutex_unlock(&hash_mutex); return -1; } if (!hash || hsearch_r(e, ENTER, &ep, hash) < 1) { free(e.key); free(e.data); lerror("hsearch_r"); retval = -1; } if (ep) { if (!ep->data) { ep->data = e.data; } } pthread_mutex_unlock(&hash_mutex); /* CRITICAL SECTION */ return retval; }
void symcache_exit(void) { uint i; ASSERT(initialized, "symcache was not initialized"); dr_mutex_lock(symcache_lock); for (i = 0; i < HASHTABLE_SIZE(symcache_table.table_bits); i++) { hash_entry_t *he; for (he = symcache_table.table[i]; he != NULL; he = he->next) { mod_cache_t *modcache = (mod_cache_t *) he->payload; symcache_write_symfile(modcache->modname, modcache); } } hashtable_delete(&symcache_table); dr_mutex_unlock(symcache_lock); dr_mutex_destroy(symcache_lock); }
DR_EXPORT drmf_status_t drfuzz_exit(void) { int count = dr_atomic_add32_return_sum(&drfuzz_init_count, -1); if (count > 0) return DRMF_SUCCESS; if (count < 0) return DRMF_ERROR; global_free(callbacks, sizeof(drfuzz_callbacks_t), HEAPSTAT_MISC); drmgr_exit(); drwrap_exit(); hashtable_delete(&fuzz_target_htable); return DRMF_SUCCESS; }
void dllhashtable_delete(struct DLLHASHTABLE* dllhashtable_ptr, void* key) { struct DLL* dll_ptr; struct HASHTABLE* hashtable_ptr; struct HASHITEM* hashitem_ptr; struct DLLHASHTABLE_HASHTABLEVALUE* hashtablevalue_ptr; struct DLLHASHTABLE_DLLITEM* dllitem_ptr; dll_ptr = dllhashtable_ptr->dll_ptr; hashtable_ptr = dllhashtable_ptr->hashtable_ptr; hashitem_ptr = hashtable_search(hashtable_ptr, key); hashtablevalue_ptr = hashitem_ptr->value; dllitem_ptr = hashtablevalue_ptr->dllitem_ptr; dll_delete(dll_ptr, (struct DLLITEM*)dllitem_ptr); hashtable_delete(hashtable_ptr, key); }
/* * Unlinks an item from the hash table. */ static void _item_unlink(struct item *it) { ASSERT(it->magic == ITEM_MAGIC); log_verb("unlink it %p of id %"PRIu8" at offset %"PRIu32, it, it->id, it->offset); if (it->is_linked) { it->is_linked = 0; hashtable_delete(item_key(it), it->klen, hash_table); } DECR(slab_metrics, item_linked_curr); INCR(slab_metrics, item_unlink); DECR_N(slab_metrics, item_keyval_byte, it->klen + it->vlen); DECR_N(slab_metrics, item_val_byte, it->vlen); PERSLAB_DECR_N(it->id, item_keyval_byte, it->klen + it->vlen); PERSLAB_DECR_N(it->id, item_val_byte, it->vlen); }
static void event_exit(void) { #ifdef SHOW_RESULTS /* Display the results! */ char msg[512]; int len = dr_snprintf(msg, sizeof(msg)/sizeof(msg[0]), "Inlining results:\n" " Number of traces: %d\n" " Number of complete inlines: %d\n", num_traces, num_complete_inlines); DR_ASSERT(len > 0); msg[sizeof(msg)/sizeof(msg[0])-1] = '\0'; DISPLAY_STRING(msg); #endif hashtable_delete(&head_table); if (!drmgr_unregister_bb_instrumentation_event(event_analyze_bb)) DR_ASSERT(false); drmgr_exit(); }
void dr_exit() { dr_fprintf(STDERR, "info: stopping dtrace..\n"); tb_delete(trace_buffer); dr_mutex_destroy(trace_buffer_lock); dr_close_file(trace_file); dr_mutex_destroy(trace_file_lock); hashtable_delete(&tags); dr_mutex_destroy(tags_lock); dr_unregister_exit_event(&dr_exit); dr_unregister_thread_init_event(&handle_thread_init); dr_unregister_thread_exit_event(&handle_thread_exit); dr_unregister_bb_event(&handle_bb); dr_unregister_trace_event(&handle_trace); dr_unregister_delete_event(&handle_delete); dr_unregister_signal_event(&handle_signal); dr_unregister_restore_state_event(&handle_restore_state); }
static int cpool_del(chunk_t *ch) { if (ch == NULL || ch->ref_cnt != 0) return EBUSY; if (ch != ch->next) { ch->prev->next = ch->next; ch->next->prev = ch->prev; if (ch == ch->cpool->head) ch->cpool->head = ch->next; } else ch->cpool->head = NULL; int err; for(unsigned i = 0; i < ch->len; ++i) { err = hashtable_delete(ch->cpool->ht, ch->idx + i); if (err && err != ENODATA) return err; } ch->cpool->nr_pages -= ch->len; err = ch_destruct(ch); if (err) return err; return 0; }
/* * Evict a slab by evicting all the items within it. This means that the * items that are carved out of the slab must either be deleted from their * a) hash + lru Q, or b) free Q. The candidate slab itself must also be * delinked from its respective slab pool so that it is available for reuse. * * Eviction complexity is O(#items/slab). */ static void _slab_evict_one(struct slab *slab) { struct slabclass *p; struct item *it; uint32_t i; p = &slabclass[slab->id]; INCR(slab_metrics, slab_evict); /* candidate slab is also the current slab */ if (p->next_item_in_slab != NULL && slab == item_to_slab(p->next_item_in_slab)) { p->nfree_item = 0; p->next_item_in_slab = NULL; } /* delete slab items either from hash or free Q */ for (i = 0; i < p->nitem; i++) { it = _slab_to_item(slab, i, p->size); if (it->is_linked) { it->is_linked = 0; hashtable_delete(item_key(it), it->klen, hash_table); } else if (it->in_freeq) { ASSERT(slab == item_to_slab(it)); ASSERT(!SLIST_EMPTY(&p->free_itemq)); ASSERT(p->nfree_itemq > 0); it->in_freeq = 0; p->nfree_itemq--; SLIST_REMOVE(&p->free_itemq, it, item, i_sle); } } /* unlink the slab from its class */ _slab_lruq_remove(slab); }
int httpd_cgi_conf_compile(int fd, char *raw, char *cgi) { char *nval, *old_www, *new_url; int i; lprintf("[ghost/notice] compiling config options ...\n"); if (!alt_cfg) { lprintf("[ghost/notice] no alternative config hashtable, aborted!\n"); httpd_header(fd, 302, "/config.html"); return 0; } old_www = strdup(hashtable_lookup(cfg, "http-admin-url")); if (!old_www) { lerror("calloc"); httpd_header(fd, 302, "/config.html"); return 0; } for (i = 0; cfg_truthtable[i].tag != NULL; i++) { if (cfg_truthtable[i].tag_mode == STATIC) { continue; } nval = hashtable_lookup(alt_cfg, cfg_truthtable[i].tag); if (nval) { lprintf("[ghost/notice]\t* %s -> %s\n", cfg_truthtable[i].tag, nval); hashtable_insert(cfg, cfg_truthtable[i].tag, nval); hashtable_delete(alt_cfg, cfg_truthtable[i].tag); } } if (!cfg_validate_all(cfg, GLITCH_MODE)) { httpd_www_gerror(fd, "Validation Failed!", raw, \ "Unable to validate new configuration layout. Please refer to the <A HREF=\"/log.html\">log</A> for more details!"); free(old_www); return 0; } proxy_build_limits(); lprintf("[ghost/notice] new config options are now in place!\n"); if (!strcmp(hashtable_lookup(cfg, "http-analyzer"), "off")) { httpd_header(fd, 200, NULL); httpd_msg_page(fd, "HTTP-ANALYZER", -1, NULL, "You have choosen to deactivate the HTTP-ANALYZER option. <BR> \n \ Therefor the Web Interface is no longer accessable. <BR> \n \ You can manually reactivate it by restarting the program!"); free(old_www); return 1; }
void GUIID_Table_Destory() { hashtable_delete(g_guid_table); }
void symcache_module_load(void *drcontext, const module_data_t *mod, bool loaded) { /* look for cache file for this module. * fill in hashtable: key is string, value is list of offsets */ mod_cache_t *modcache; const char *modname = dr_module_preferred_name(mod); file_t f; if (modname == NULL) return; /* don't support caching */ /* if smaller than threshold, not worth caching */ if (mod->end - mod->start < op_modsize_cache_threshold) { LOG(1, "%s: module %s too small to cache\n", __FUNCTION__, modname); return; } ASSERT(initialized, "symcache was not initialized"); /* support initializing prior to module events => called twice */ dr_mutex_lock(symcache_lock); modcache = (mod_cache_t *) hashtable_lookup(&symcache_table, (void *)mod->full_path); dr_mutex_unlock(symcache_lock); if (modcache != NULL) return; modcache = (mod_cache_t *) global_alloc(sizeof(*modcache), HEAPSTAT_HASHTABLE); memset(modcache, 0, sizeof(*modcache)); hashtable_init_ex(&modcache->table, SYMCACHE_MODULE_TABLE_HASH_BITS, HASH_STRING, true/*strdup*/, true/*synch*/, symcache_free_list, NULL, NULL); /* store consistency fields */ f = dr_open_file(mod->full_path, DR_FILE_READ); if (f != INVALID_FILE) { bool ok = dr_file_size(f, &modcache->module_file_size); if (!ok) WARN("WARNING: unable to determine size of %s\n", mod->full_path); dr_close_file(f); } else WARN("WARNING: unable to open %s\n", mod->full_path); #ifdef WINDOWS modcache->file_version = mod->file_version; modcache->product_version = mod->product_version; modcache->checksum = mod->checksum; modcache->timestamp = mod->timestamp; modcache->module_internal_size = mod->module_internal_size; #endif modcache->modname = drmem_strdup(modname, HEAPSTAT_HASHTABLE); modcache->from_file = symcache_read_symfile(mod, modname, modcache); dr_mutex_lock(symcache_lock); if (!hashtable_add(&symcache_table, (void *)mod->full_path, (void *)modcache)) { /* this should be really rare to have dup paths (xref i#729) -- and * actually we now have a lookup up above so we should only get here * on a race while we let go of the lock */ WARN("WARNING: duplicate module paths: only caching symbols from first\n"); hashtable_delete(&modcache->table); global_free(modcache, sizeof(*modcache), HEAPSTAT_HASHTABLE); } dr_mutex_unlock(symcache_lock); }
int main(int argc, char **argv) { int *vals = (int *)GC_MALLOC(SIZE * sizeof(int)); int i; for(i=0;i<SIZE; i++) vals[i] = i; hashtable_t *tab = hashtable_create(1000001); clock_t start, diff; int msec; start = clock(); for(i=0; i<SIZE; i++) hashtable_put(tab, (void *)(vals[i]), (void *)(i*i)); diff = clock() - start; msec = diff * 1000 / CLOCKS_PER_SEC; printf("Put took %d seconds %d milliseconds\n", msec/1000, msec%1000); start = clock(); for(i=0; i<SIZE; i++) { hashtable_entry_t *b = hashtable_get(tab, (void *)(vals[i])); assert((int)(b->ptr) == i); assert((int)(b->value) == i*i); } assert(tab->count == SIZE); diff = clock() - start; msec = diff * 1000 / CLOCKS_PER_SEC; printf("Get took %d seconds %d milliseconds\n", msec/1000, msec%1000); start = clock(); hashtable_remove(tab, (void *)(vals[SIZE/2])); assert(tab->count == SIZE-1); diff = clock() - start; msec = diff * 1000 / CLOCKS_PER_SEC; printf("Remove took %d seconds %d milliseconds\n", msec/1000, msec%1000); assert(hashtable_get(tab, (void *)(vals[SIZE/2])) == NULL); hashtable_remove(tab, (void *)(vals[0])); hashtable_delete(tab); tab = hashtable_create(1000001); for(i=0; i<SIZE; i++) hashtable_put(tab, (void *)vals[i], (void *)(i*i)); hashtable_entry_t *entries = hashtable_entries(tab); while(entries) { assert((int)(entries->value) == (int)(entries->ptr) * (int)(entries->ptr)); entries = entries->next; } hashtable_delete(tab); //free(vals); }