/* --- Needed so we can add stuff to the string table. --- */
struct _DebugInfo* di;
/* --- a hash table of g_abbv (i.e. parsed abbreviations) --- */
- VgHashTable ht_abbvs;
+ VgHashTable *ht_abbvs;
/* True if this came from .debug_types; otherwise it came from
.debug_info. */
/* Signatured type hash; computed once and then shared by all
CUs. */
- VgHashTable signature_types;
+ VgHashTable *signature_types;
/* True if this came from alternate .debug_info; otherwise
it came from normal .debug_info or .debug_types. */
D3SignatureType;
/* Record a signatured type in the hash table. */
-static void record_signatured_type ( VgHashTable tab,
+static void record_signatured_type ( VgHashTable *tab,
ULong type_signature,
UWord die )
{
/* Given a type signature hash table and a type signature, return the
cooked DIE offset of the type. If the type cannot be found, call
BARF. */
-static UWord lookup_signatured_type ( VgHashTable tab,
+static UWord lookup_signatured_type ( const VgHashTable *tab,
ULong type_signature,
void (*barf)( const HChar* ) __attribute__((noreturn)) )
{
Bool td3 = di->trace_symtab;
XArray* /* of TempVar* */ dioff_lookup_tab;
Int pass;
- VgHashTable signature_types = NULL;
+ VgHashTable *signature_types = NULL;
/* Display/trace various information, if requested. */
if (TD3) {
/* hash table of pool elements, used to dedup.
If NULL, it means the DedupPoolAlloc is frozen. */
- VgHashTable ht_elements;
+ VgHashTable *ht_elements;
/* Hash table nodes of pool_elements are allocated with a pool, to
decrease memory overhead during insertion in the DedupPoolAlloc. */
Note for ARM: addr in GS_Address is the value without the thumb bit set.
*/
-static VgHashTable gs_addresses = NULL;
+static VgHashTable *gs_addresses = NULL;
// Transform addr in the form stored in the list of addresses.
// For the ARM architecture, we store it with the thumb bit set to 0.
#define N_HASH_PRIMES 20
-static SizeT primes[N_HASH_PRIMES] = {
+static const SizeT primes[N_HASH_PRIMES] = {
769UL, 1543UL, 3079UL, 6151UL,
12289UL, 24593UL, 49157UL, 98317UL,
196613UL, 393241UL, 786433UL, 1572869UL,
/*--- Functions ---*/
/*--------------------------------------------------------------------*/
-VgHashTable VG_(HT_construct) ( const HChar* name )
+VgHashTable *VG_(HT_construct) ( const HChar* name )
{
/* Initialises to zero, ie. all entries NULL */
SizeT n_chains = primes[0];
SizeT sz = n_chains * sizeof(VgHashNode*);
- VgHashTable table = VG_(calloc)("hashtable.Hc.1",
+ VgHashTable *table = VG_(calloc)("hashtable.Hc.1",
1, sizeof(struct _VgHashTable));
table->chains = VG_(calloc)("hashtable.Hc.2", 1, sz);
table->n_chains = n_chains;
return table;
}
-Int VG_(HT_count_nodes) ( VgHashTable table )
+Int VG_(HT_count_nodes) ( const VgHashTable *table )
{
return table->n_elements;
}
-static void resize ( VgHashTable table )
+static void resize ( VgHashTable *table )
{
Int i;
SizeT sz;
/* Puts a new, heap allocated VgHashNode, into the VgHashTable. Prepends
the node to the appropriate chain. No duplicate key detection is done. */
-void VG_(HT_add_node) ( VgHashTable table, void* vnode )
+void VG_(HT_add_node) ( VgHashTable *table, void* vnode )
{
VgHashNode* node = (VgHashNode*)vnode;
UWord chain = CHAIN_NO(node->key, table);
}
/* Looks up a VgHashNode by key in the table. Returns NULL if not found. */
-void* VG_(HT_lookup) ( VgHashTable table, UWord key )
+void* VG_(HT_lookup) ( const VgHashTable *table, UWord key )
{
VgHashNode* curr = table->chains[ CHAIN_NO(key, table) ];
/* Looks up a VgHashNode by node in the table. Returns NULL if not found.
GEN!!! marks the lines that differs from VG_(HT_lookup). */
-void* VG_(HT_gen_lookup) ( VgHashTable table, void* node, HT_Cmp_t cmp )
+void* VG_(HT_gen_lookup) ( const VgHashTable *table, const void* node,
+ HT_Cmp_t cmp )
{
- VgHashNode* hnode = (VgHashNode*) node; // GEN!!!
+ const VgHashNode* hnode = node; // GEN!!!
VgHashNode* curr = table->chains[ CHAIN_NO(hnode->key, table) ]; // GEN!!!
while (curr) {
}
/* Removes a VgHashNode from the table. Returns NULL if not found. */
-void* VG_(HT_remove) ( VgHashTable table, UWord key )
+void* VG_(HT_remove) ( VgHashTable *table, UWord key )
{
UWord chain = CHAIN_NO(key, table);
VgHashNode* curr = table->chains[chain];
/* Removes a VgHashNode by node from the table. Returns NULL if not found.
GEN!!! marks the lines that differs from VG_(HT_remove). */
-void* VG_(HT_gen_remove) ( VgHashTable table, void* node, HT_Cmp_t cmp )
+void* VG_(HT_gen_remove) ( VgHashTable *table, const void* node, HT_Cmp_t cmp )
{
- VgHashNode* hnode = (VgHashNode*) node; // GEN!!!
+ const VgHashNode* hnode = node; // GEN!!!
UWord chain = CHAIN_NO(hnode->key, table); // GEN!!!
VgHashNode* curr = table->chains[chain];
VgHashNode** prev_next_ptr = &(table->chains[chain]);
return NULL;
}
-void VG_(HT_print_stats) ( VgHashTable table, HT_Cmp_t cmp )
+void VG_(HT_print_stats) ( const VgHashTable *table, HT_Cmp_t cmp )
{
#define MAXOCCUR 20
UInt elt_occurences[MAXOCCUR+1];
elements into it, then returns both the array and the size of it. The
array must be freed with VG_(free).
*/
-VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_elems )
+VgHashNode** VG_(HT_to_array) (const VgHashTable *table, /*OUT*/ UInt* n_elems)
{
UInt i, j;
VgHashNode** arr;
return arr;
}
-void VG_(HT_ResetIter)(VgHashTable table)
+void VG_(HT_ResetIter)(VgHashTable *table)
{
vg_assert(table);
table->iterNode = NULL;
table->iterOK = True;
}
-void* VG_(HT_Next)(VgHashTable table)
+void* VG_(HT_Next)(VgHashTable *table)
{
Int i;
vg_assert(table);
return NULL;
}
-void VG_(HT_destruct)(VgHashTable table, void(*freenode_fn)(void*))
+void VG_(HT_destruct)(VgHashTable *table, void(*freenode_fn)(void*))
{
UInt i;
VgHashNode *node, *node_next;
static SizeT s_cmalloc_n_frees = 0;
static SizeT s_cmalloc_bs_mallocd = 0;
/* Record malloc'd blocks. */
-static VgHashTable s_malloc_list = NULL;
+static VgHashTable *s_malloc_list = NULL;
/* Function definitions. */
/* A hash table of MallocMetas, used to track malloc'd blocks
(obviously). */
-static VgHashTable hg_mallocmeta_table = NULL;
+static VgHashTable *hg_mallocmeta_table = NULL;
/* MallocMeta are small elements. We use a pool to avoid
the overhead of malloc for each MallocMeta. */
}
VgHashNode;
-typedef struct _VgHashTable * VgHashTable;
+typedef struct _VgHashTable VgHashTable;
/* Make a new table. Allocates the memory with VG_(calloc)(), so can
be freed with VG_(free)(). The table starts small but will
periodically be expanded. This is transparent to the users of this
module. The function never returns NULL. */
-extern VgHashTable VG_(HT_construct) ( const HChar* name );
+extern VgHashTable *VG_(HT_construct) ( const HChar* name );
/* Count the number of nodes in a table. */
-extern Int VG_(HT_count_nodes) ( VgHashTable table );
+extern Int VG_(HT_count_nodes) ( const VgHashTable *table );
/* Add a node to the table. Duplicate keys are permitted. */
-extern void VG_(HT_add_node) ( VgHashTable t, void* node );
+extern void VG_(HT_add_node) ( VgHashTable *t, void* node );
/* Looks up a VgHashNode by key in the table.
* Returns NULL if not found. If entries
* with duplicate keys are present, the most recently-added of the dups will
* be returned, but it's probably better to avoid dups altogether. */
-extern void* VG_(HT_lookup) ( VgHashTable table, UWord key );
+extern void* VG_(HT_lookup) ( const VgHashTable *table, UWord key );
/* Removes a VgHashNode by key from the table. Returns NULL if not found. */
-extern void* VG_(HT_remove) ( VgHashTable table, UWord key );
+extern void* VG_(HT_remove) ( VgHashTable *table, UWord key );
typedef Word (*HT_Cmp_t) ( const void* node1, const void* node2 );
between components, either the node memory should be fully initialised
(e.g. allocated using VG_(calloc)) or each component should be compared
individually. */
-extern void* VG_(HT_gen_lookup) ( VgHashTable table, void* node, HT_Cmp_t cmp );
-extern void* VG_(HT_gen_remove) ( VgHashTable table, void* node, HT_Cmp_t cmp );
+extern void* VG_(HT_gen_lookup) ( const VgHashTable *table, const void* node,
+ HT_Cmp_t cmp );
+extern void* VG_(HT_gen_remove) ( VgHashTable *table, const void* node,
+ HT_Cmp_t cmp );
/* Output detailed usage/collision statistics.
cmp will be used to verify if 2 elements with the same key are equal.
Use NULL cmp if the hash table elements are only to be compared by key. */
-extern void VG_(HT_print_stats) ( VgHashTable table, HT_Cmp_t cmp );
+extern void VG_(HT_print_stats) ( const VgHashTable *table, HT_Cmp_t cmp );
/* Allocates a suitably-sized array, copies pointers to all the hashtable
elements into it, then returns both the array and the size of it. The
array must be freed with VG_(free). If the hashtable is empty, the
function returns NULL and assigns *nelems = 0. */
-extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_elems );
+extern VgHashNode** VG_(HT_to_array) ( const VgHashTable *table,
+ /*OUT*/ UInt* n_elems );
/* Reset the table's iterator to point to the first element. */
-extern void VG_(HT_ResetIter) ( VgHashTable table );
+extern void VG_(HT_ResetIter) ( VgHashTable *table );
/* Return the element pointed to by the iterator and move on to the
next one. Returns NULL if the last one has been passed, or if
Since resizing only happens as a result of calling HT_add_node,
disallowing HT_add_node during iteration should give the required
assurance. */
-extern void* VG_(HT_Next) ( VgHashTable table );
+extern void* VG_(HT_Next) ( VgHashTable *table );
/* Destroy a table and deallocates the memory used by the nodes using
freenode_fn.*/
-extern void VG_(HT_destruct) ( VgHashTable t, void(*freenode_fn)(void*) );
+extern void VG_(HT_destruct) ( VgHashTable *table, void(*freenode_fn)(void*) );
#endif // __PUB_TOOL_HASHTABLE_H
}
HP_Chunk;
-static VgHashTable malloc_list = NULL; // HP_Chunks
+static VgHashTable *malloc_list = NULL; // HP_Chunks
static void update_alloc_stats(SSizeT szB_delta)
{
Addr pool; // pool identifier
SizeT rzB; // pool red-zone size
Bool is_zeroed; // allocations from this pool are zeroed
- VgHashTable chunks; // chunks associated with this pool
+ VgHashTable *chunks; // chunks associated with this pool
}
MC_Mempool;
void* MC_(new_block) ( ThreadId tid,
Addr p, SizeT size, SizeT align,
Bool is_zeroed, MC_AllocKind kind,
- VgHashTable table);
+ VgHashTable *table);
void MC_(handle_free) ( ThreadId tid,
Addr p, UInt rzB, MC_AllocKind kind );
VgHashTable, because VgHashTable allows duplicate keys without complaint.
This can occur if a user marks a malloc() block as also a custom block with
MALLOCLIKE_BLOCK. */
-extern VgHashTable MC_(malloc_list);
+extern VgHashTable *MC_(malloc_list);
/* For tracking memory pools. */
-extern VgHashTable MC_(mempool_list);
+extern VgHashTable *MC_(mempool_list);
/* Shadow memory functions */
Bool MC_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr );
SizeT MC_(Malloc_Redzone_SzB) = -10000000; // If used before set, should BOMB
/* Record malloc'd blocks. */
-VgHashTable MC_(malloc_list) = NULL;
+VgHashTable *MC_(malloc_list) = NULL;
/* Memory pools: a hash table of MC_Mempools. Search key is
MC_Mempool::pool. */
-VgHashTable MC_(mempool_list) = NULL;
+VgHashTable *MC_(mempool_list) = NULL;
/* Pool allocator for MC_Chunk. */
PoolAlloc *MC_(chunk_poolalloc) = NULL;
}
// True if mc is in the given block list.
-static Bool in_block_list (VgHashTable block_list, MC_Chunk* mc)
+static Bool in_block_list (const VgHashTable *block_list, MC_Chunk* mc)
{
MC_Chunk* found_mc = VG_(HT_lookup) ( block_list, (UWord)mc->data );
if (found_mc) {
/* Allocate memory and note change in memory available */
void* MC_(new_block) ( ThreadId tid,
Addr p, SizeT szB, SizeT alignB,
- Bool is_zeroed, MC_AllocKind kind, VgHashTable table)
+ Bool is_zeroed, MC_AllocKind kind, VgHashTable *table)
{
MC_Chunk* mc;