/*--------------------------------------------------------------------*/
/*--- An AVL tree based finite map for word keys and word values. ---*/
/*--- Inspired by Haskell's "FiniteMap" library. ---*/
-/*--- hg_wordfm.c ---*/
+/*--- m_wordfm.c ---*/
/*--------------------------------------------------------------------*/
/*
- This file is part of Helgrind, a Valgrind tool for detecting errors
- in threaded programs.
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
Copyright (C) 2007-2008 Julian Seward
jseward@acm.org
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_tool_basics.h"
-#include "pub_tool_libcassert.h"
-#include "pub_tool_libcbase.h"
+#include "pub_core_basics.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_wordfm.h" /* self */
-#ifdef HG_WORDFM_STANDALONE // standalone compilation
-// Standalone mode (for testing).
-// On x86_64 compile like this:
-// gcc -m64 hg_wordfm.c -I../include -I../VEX/pub
-// -DVGA_amd64=1 -DHG_WORDFM_STANDALONE -g -O -Wall
-# include <assert.h>
-# include <string.h>
-# include <stdio.h>
-# include <stdlib.h>
-
-# undef tl_assert
-# define tl_assert assert
-# define vgPlain_memset memset
-
-#endif /* def HG_WORDFM_STANDALONE */
-
-
-#define HG_(str) VGAPPEND(vgHelgrind_,str)
-#include "hg_wordfm.h"
-
//------------------------------------------------------------------//
//--- WordFM ---//
//--- Implementation ---//
sections of the map, or the whole thing. If kCmp is NULL then the
ordering used is unsigned word ordering (UWord) on the key
values. */
-WordFM* HG_(newFM) ( void* (*alloc_nofail)( SizeT ),
+WordFM* VG_(newFM) ( void* (*alloc_nofail)( SizeT ),
void (*dealloc)(void*),
Word (*kCmp)(UWord,UWord) )
{
/* Free up the FM. If kFin is non-NULL, it is applied to keys
before the FM is deleted; ditto with vFin for vals. */
-void HG_(deleteFM) ( WordFM* fm, void(*kFin)(UWord), void(*vFin)(UWord) )
+void VG_(deleteFM) ( WordFM* fm, void(*kFin)(UWord), void(*vFin)(UWord) )
{
void(*dealloc)(void*) = fm->dealloc;
avl_free( fm->root, kFin, vFin, dealloc );
}
/* Add (k,v) to fm. */
-void HG_(addToFM) ( WordFM* fm, UWord k, UWord v )
+void VG_(addToFM) ( WordFM* fm, UWord k, UWord v )
{
MaybeWord oldV;
AvlNode* node;
}
// Delete key from fm, returning associated key and val if found
-Bool HG_(delFromFM) ( WordFM* fm,
+Bool VG_(delFromFM) ( WordFM* fm,
/*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key )
{
AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
}
// Look up in fm, assigning found key & val at spec'd addresses
-Bool HG_(lookupFM) ( WordFM* fm,
+Bool VG_(lookupFM) ( WordFM* fm,
/*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key )
{
AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
}
}
-UWord HG_(sizeFM) ( WordFM* fm )
+UWord VG_(sizeFM) ( WordFM* fm )
{
// Hmm, this is a bad way to do this
return fm->root ? size_avl_nonNull( fm->root ) : 0;
}
// set up FM for iteration
-void HG_(initIterFM) ( WordFM* fm )
+void VG_(initIterFM) ( WordFM* fm )
{
tl_assert(fm);
stackClear(fm);
}
// set up FM for iteration so that the first key subsequently produced
-// by HG_(nextIterFM) is the smallest key in the map >= start_at.
+// by VG_(nextIterFM) is the smallest key in the map >= start_at.
// Naturally ">=" is defined by the comparison function supplied to
-// HG_(newFM), as documented above.
-void HG_(initIterAtFM) ( WordFM* fm, UWord start_at )
+// VG_(newFM), as documented above.
+void VG_(initIterAtFM) ( WordFM* fm, UWord start_at )
{
Int i;
AvlNode *n, *t;
// get next key/val pair. Will tl_assert if fm has been modified
// or looked up in since initIter{,At}FM was called.
-Bool HG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
+Bool VG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
{
Int i = 0;
AvlNode* n = NULL;
}
// clear the I'm iterating flag
-void HG_(doneIterFM) ( WordFM* fm )
+void VG_(doneIterFM) ( WordFM* fm )
{
}
-WordFM* HG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
+WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
{
WordFM* nyu;
WordFM* fm;
};
-WordBag* HG_(newBag) ( void* (*alloc_nofail)( SizeT ),
+WordBag* VG_(newBag) ( void* (*alloc_nofail)( SizeT ),
void (*dealloc)(void*) )
{
WordBag* bag = alloc_nofail(sizeof(WordBag));
- bag->fm = HG_(newFM)( alloc_nofail, dealloc, NULL );
+ bag->fm = VG_(newFM)( alloc_nofail, dealloc, NULL );
return bag;
}
-void HG_(deleteBag) ( WordBag* bag )
+void VG_(deleteBag) ( WordBag* bag )
{
void (*dealloc)(void*) = bag->fm->dealloc;
- HG_(deleteFM)( bag->fm, NULL, NULL );
+ VG_(deleteFM)( bag->fm, NULL, NULL );
VG_(memset)(bag, 0, sizeof(WordBag));
dealloc(bag);
}
-void HG_(addToBag)( WordBag* bag, UWord w )
+void VG_(addToBag)( WordBag* bag, UWord w )
{
UWord key, count;
- if (HG_(lookupFM)(bag->fm, &key, &count, w)) {
+ if (VG_(lookupFM)(bag->fm, &key, &count, w)) {
tl_assert(key == w);
tl_assert(count >= 1);
- HG_(addToFM)(bag->fm, w, count+1);
+ VG_(addToFM)(bag->fm, w, count+1);
} else {
- HG_(addToFM)(bag->fm, w, 1);
+ VG_(addToFM)(bag->fm, w, 1);
}
}
-UWord HG_(elemBag) ( WordBag* bag, UWord w )
+UWord VG_(elemBag) ( WordBag* bag, UWord w )
{
UWord key, count;
- if (HG_(lookupFM)( bag->fm, &key, &count, w)) {
+ if (VG_(lookupFM)( bag->fm, &key, &count, w)) {
tl_assert(key == w);
tl_assert(count >= 1);
return count;
}
}
-UWord HG_(sizeUniqueBag) ( WordBag* bag )
+UWord VG_(sizeUniqueBag) ( WordBag* bag )
{
- return HG_(sizeFM)( bag->fm );
+ return VG_(sizeFM)( bag->fm );
}
static UWord sizeTotalBag_wrk ( AvlNode* nd )
w += sizeTotalBag_wrk(nd->child[1]);
return w;
}
-UWord HG_(sizeTotalBag)( WordBag* bag )
+UWord VG_(sizeTotalBag)( WordBag* bag )
{
if (bag->fm->root)
return sizeTotalBag_wrk(bag->fm->root);
return 0;
}
-Bool HG_(delFromBag)( WordBag* bag, UWord w )
+Bool VG_(delFromBag)( WordBag* bag, UWord w )
{
UWord key, count;
- if (HG_(lookupFM)(bag->fm, &key, &count, w)) {
+ if (VG_(lookupFM)(bag->fm, &key, &count, w)) {
tl_assert(key == w);
tl_assert(count >= 1);
if (count > 1) {
- HG_(addToFM)(bag->fm, w, count-1);
+ VG_(addToFM)(bag->fm, w, count-1);
} else {
tl_assert(count == 1);
- HG_(delFromFM)( bag->fm, NULL, NULL, w );
+ VG_(delFromFM)( bag->fm, NULL, NULL, w );
}
return True;
} else {
}
}
-Bool HG_(isEmptyBag)( WordBag* bag )
+Bool VG_(isEmptyBag)( WordBag* bag )
{
- return HG_(sizeFM)(bag->fm) == 0;
+ return VG_(sizeFM)(bag->fm) == 0;
}
-Bool HG_(isSingletonTotalBag)( WordBag* bag )
+Bool VG_(isSingletonTotalBag)( WordBag* bag )
{
AvlNode* nd;
- if (HG_(sizeFM)(bag->fm) != 1)
+ if (VG_(sizeFM)(bag->fm) != 1)
return False;
nd = bag->fm->root;
tl_assert(nd);
return nd->val == 1;
}
-UWord HG_(anyElementOfBag)( WordBag* bag )
+UWord VG_(anyElementOfBag)( WordBag* bag )
{
/* Return an arbitrarily chosen element in the bag. We might as
well return the one at the root of the underlying AVL tree. */
return nd->key;
}
-void HG_(initIterBag)( WordBag* bag )
+void VG_(initIterBag)( WordBag* bag )
{
- HG_(initIterFM)(bag->fm);
+ VG_(initIterFM)(bag->fm);
}
-Bool HG_(nextIterBag)( WordBag* bag, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount )
+Bool VG_(nextIterBag)( WordBag* bag, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount )
{
- return HG_(nextIterFM)( bag->fm, pVal, pCount );
+ return VG_(nextIterFM)( bag->fm, pVal, pCount );
}
-void HG_(doneIterBag)( WordBag* bag )
+void VG_(doneIterBag)( WordBag* bag )
{
- HG_(doneIterFM)( bag->fm );
+ VG_(doneIterFM)( bag->fm );
}
//------------------------------------------------------------------//
//--- Implementation ---//
//------------------------------------------------------------------//
-
-#ifdef HG_WORDFM_STANDALONE
-
-//------------------------------------------------------------------//
-//--- Simple test driver. ---//
-//------------------------------------------------------------------//
-
-// We create a map with N values {1, 3, 5, ..., (N*2-1)}
-// and do some trivial stuff with it.
-
-
-// Return the number of elements in range [beg, end).
-// Just lookup for each element in range and count.
-int search_all_elements_in_range_1(WordFM *map, long beg, long end)
-{
- long n_found = 0;
- long i;
- for (i = beg; i < end; i++) {
- UWord key, val;
- if (HG_(lookupFM)(map, &key, &val, (Word)i)) {
- n_found++;
- assert(key == -val);
- assert(key == (UWord)i);
- }
- }
- return n_found;
-}
-
-// Return the number of elements in range [beg, end).
-// Start with the largest element 'e' such that 'e <= beg'
-// and iterate until 'e < end'.
-int search_all_elements_in_range_2(WordFM *map, long beg, long end)
-{
- int n_found = 0;
- UWord key, val;
- HG_(initIterAtFM)(map, beg);
- while (HG_(nextIterFM)(map, &key, &val) && (long)key < end) {
- assert(key == -val);
- n_found++;
- }
- HG_(doneIterFM)(map);
- return n_found;
-}
-
-int main(void)
-{
- long i, n = 10;
- UWord key, val;
- long beg, end;
-
- printf("Create the map, n=%ld\n", n);
- WordFM *map = HG_(newFM)(malloc, free, NULL/*unboxed Word cmp*/);
-
- printf("Add keys: ");
- for(i = 0; i < n; i++) {
- long val = i * 2 + 1; // 1, 3, 5, ... (n*2-1)
- printf("%ld ", val);
- HG_(addToFM)(map, val, -val);
- }
- assert(HG_(sizeFM)(map) == (UWord)n);
- printf("\n");
- printf("Iterate elements, size=%d\n", (int)HG_(sizeFM)(map));
- HG_(initIterFM)(map);
-
- while (HG_(nextIterFM(map, &key, &val))) {
- // int j;
- // printf("Stack k=%d\n", (int)key);
- // for(j = map->stackTop-1; j >= 0; j--) {
- // printf("\t[%d]: k=%d s=%d\n", j,
- // (int)map->nodeStack[j]->key, (int)map->numStack[j]);
- // }
- assert(key == -val);
- }
- HG_(doneIterFM)(map);
-
- printf("Test initIterAtFM\n");
- for(beg = 0; beg <= n*2; beg++) {
- HG_(initIterAtFM)(map, (Word)beg);
- int prev = -1;
- printf("StartWith: %ld: ", beg);
- int n_iter = 0;
-
- while(HG_(nextIterFM(map, &key, &val))) {
- printf("%d ", (int)key);
- assert(key == -val);
- if(prev > 0) assert(prev + 2 == (int)key);
- prev = (int)key;
- n_iter++;
- }
- HG_(doneIterFM)(map);
-
- printf("\ntotal: %d\n", n_iter);
- if (beg < 1 ) assert(n_iter == n);
- else if (beg >= n*2) assert(n_iter == 0);
- else assert(n_iter == (n - beg/2));
- }
-
- printf("Compare search_all_elements_in_range_[12]\n");
- for (beg = 0; beg <= n*2; beg++) {
- for (end = 0; end <= n*2; end++) {
- assert( search_all_elements_in_range_1(map, beg, end)
- == search_all_elements_in_range_2(map, beg, end));
- }
- }
-
- printf("Delete the map\n");
- HG_(deleteFM)(map, NULL, NULL);
- printf("Ok!\n");
- return 0;
-}
-
-#endif
-
/*--------------------------------------------------------------------*/
-/*--- end hg_wordfm.c ---*/
+/*--- end m_wordfm.c ---*/
/*--------------------------------------------------------------------*/
#include "pub_tool_xarray.h"
#include "pub_tool_stacktrace.h"
#include "pub_tool_debuginfo.h" /* VG_(get_data_description) */
+#include "pub_tool_wordfm.h"
#include "helgrind.h"
#define HG_(str) VGAPPEND(vgHelgrind_,str)
-#include "hg_wordfm.h"
#include "hg_wordset.h"
/*----------------------------------------------------------------*/
{
Thread* thr;
Word count;
- HG_(initIterBag)( bag );
- while (HG_(nextIterBag)( bag, (Word*)&thr, &count )) {
+ VG_(initIterBag)( bag );
+ while (VG_(nextIterBag)( bag, (Word*)&thr, &count )) {
if (count < 1) return False;
if (!is_sane_Thread(thr)) return False;
}
- HG_(doneIterBag)( bag );
+ VG_(doneIterBag)( bag );
return True;
}
static Bool is_sane_Lock_BASE ( Lock* lock )
/* If heldBy is non-NULL, we require it to contain at least one
thread. */
- if (HG_(isEmptyBag)(lock->heldBy))
+ if (VG_(isEmptyBag)(lock->heldBy))
return False;
/* Lock is either r- or w-held. */
if (lock->heldW) {
/* Held in write-mode */
if ((lock->kind == LK_nonRec || lock->kind == LK_rdwr)
- && !HG_(isSingletonTotalBag)(lock->heldBy))
+ && !VG_(isSingletonTotalBag)(lock->heldBy))
return False;
} else {
/* Held in read-mode */
{
tl_assert(is_sane_LockN(lk));
if (lk->heldBy)
- HG_(deleteBag)( lk->heldBy );
+ VG_(deleteBag)( lk->heldBy );
VG_(memset)(lk, 0xAA, sizeof(*lk));
hg_free(lk);
}
tl_assert(lk->heldBy == NULL); /* can't w-lock recursively */
tl_assert(!lk->heldW);
lk->heldW = True;
- lk->heldBy = HG_(newBag)( hg_zalloc, hg_free );
- HG_(addToBag)( lk->heldBy, (Word)thr );
+ lk->heldBy = VG_(newBag)( hg_zalloc, hg_free );
+ VG_(addToBag)( lk->heldBy, (Word)thr );
break;
case LK_mbRec:
if (lk->heldBy == NULL)
/* 2nd and subsequent locking of a lock by its owner */
tl_assert(lk->heldW);
/* assert: lk is only held by one thread .. */
- tl_assert(HG_(sizeUniqueBag(lk->heldBy)) == 1);
+ tl_assert(VG_(sizeUniqueBag(lk->heldBy)) == 1);
/* assert: .. and that thread is 'thr'. */
- tl_assert(HG_(elemBag)(lk->heldBy, (Word)thr)
- == HG_(sizeTotalBag)(lk->heldBy));
- HG_(addToBag)(lk->heldBy, (Word)thr);
+ tl_assert(VG_(elemBag)(lk->heldBy, (Word)thr)
+ == VG_(sizeTotalBag)(lk->heldBy));
+ VG_(addToBag)(lk->heldBy, (Word)thr);
break;
case LK_rdwr:
tl_assert(lk->heldBy == NULL && !lk->heldW); /* must be unheld */
/* end EXPOSITION only */
if (lk->heldBy) {
- HG_(addToBag)(lk->heldBy, (Word)thr);
+ VG_(addToBag)(lk->heldBy, (Word)thr);
} else {
lk->heldW = False;
- lk->heldBy = HG_(newBag)( hg_zalloc, hg_free );
- HG_(addToBag)( lk->heldBy, (Word)thr );
+ lk->heldBy = VG_(newBag)( hg_zalloc, hg_free );
+ VG_(addToBag)( lk->heldBy, (Word)thr );
}
tl_assert(!lk->heldW);
tl_assert(is_sane_LockN(lk));
tl_assert(lk->heldBy);
stats__lockN_releases++;
/* Remove it from the holder set */
- b = HG_(delFromBag)(lk->heldBy, (Word)thr);
+ b = VG_(delFromBag)(lk->heldBy, (Word)thr);
/* thr must actually have been a holder of lk */
tl_assert(b);
/* normalise */
tl_assert(lk->acquired_at);
- if (HG_(isEmptyBag)(lk->heldBy)) {
- HG_(deleteBag)(lk->heldBy);
+ if (VG_(isEmptyBag)(lk->heldBy)) {
+ VG_(deleteBag)(lk->heldBy);
lk->heldBy = NULL;
lk->heldW = False;
lk->acquired_at = NULL;
return;
}
/* for each thread that holds this lock do ... */
- HG_(initIterBag)( lk->heldBy );
- while (HG_(nextIterBag)( lk->heldBy, (Word*)&thr, NULL )) {
+ VG_(initIterBag)( lk->heldBy );
+ while (VG_(nextIterBag)( lk->heldBy, (Word*)&thr, NULL )) {
tl_assert(is_sane_Thread(thr));
tl_assert(HG_(elemWS)( univ_lsets,
thr->locksetA, (Word)lk ));
= HG_(delFromWS)( univ_lsets, thr->locksetW, (Word)lk );
}
}
- HG_(doneIterBag)( lk->heldBy );
+ VG_(doneIterBag)( lk->heldBy );
}
/* --------- xxxID functions --------- */
Thread* thr;
Word count;
VG_(printf)(" { ");
- HG_(initIterBag)( lk->heldBy );
- while (HG_(nextIterBag)( lk->heldBy, (Word*)&thr, &count ))
+ VG_(initIterBag)( lk->heldBy );
+ while (VG_(nextIterBag)( lk->heldBy, (Word*)&thr, &count ))
VG_(printf)("%lu:%p ", count, thr);
- HG_(doneIterBag)( lk->heldBy );
+ VG_(doneIterBag)( lk->heldBy );
VG_(printf)("}");
}
VG_(printf)("\n");
void* gla;
Lock* lk;
space(d); VG_(printf)("map_locks (%d entries) {\n",
- (Int)HG_(sizeFM)( map_locks ));
- HG_(initIterFM)( map_locks );
- while (HG_(nextIterFM)( map_locks, (Word*)&gla,
+ (Int)VG_(sizeFM)( map_locks ));
+ VG_(initIterFM)( map_locks );
+ while (VG_(nextIterFM)( map_locks, (Word*)&gla,
(Word*)&lk )) {
space(d+3);
VG_(printf)("guest %p -> Lock %p\n", gla, lk);
}
- HG_(doneIterFM)( map_locks );
+ VG_(doneIterFM)( map_locks );
space(d); VG_(printf)("}\n");
}
SegmentID segid;
Segment* seg;
space(d); VG_(printf)("map_segments (%d entries) {\n",
- (Int)HG_(sizeFM)( map_segments ));
- HG_(initIterFM)( map_segments );
- while (HG_(nextIterFM)( map_segments, (Word*)&segid,
+ (Int)VG_(sizeFM)( map_segments ));
+ VG_(initIterFM)( map_segments );
+ while (VG_(nextIterFM)( map_segments, (Word*)&segid,
(Word*)&seg )) {
space(d+3);
VG_(printf)("segid 0x%x -> Segment %p\n", (UInt)segid, seg);
}
- HG_(doneIterFM)( map_segments );
+ VG_(doneIterFM)( map_segments );
space(d); VG_(printf)("}\n");
}
Addr ga;
SecMap* sm;
space(d); VG_(printf)("map_shmem_ShR_and_ShM_only {\n");
- HG_(initIterFM)( map_shmem );
- while (HG_(nextIterFM)( map_shmem, (Word*)&ga,
+ VG_(initIterFM)( map_shmem );
+ while (VG_(nextIterFM)( map_shmem, (Word*)&ga,
(Word*)&sm )) {
pp_SecMap_shared( d+3, sm, ga );
}
- HG_(doneIterFM) ( map_shmem );
+ VG_(doneIterFM) ( map_shmem );
space(d); VG_(printf)("}\n");
}
tl_assert(sizeof(Addr) == sizeof(Word));
tl_assert(map_shmem == NULL);
- map_shmem = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
+ map_shmem = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
tl_assert(map_shmem != NULL);
shmem__invalidate_scache();
tl_assert(sizeof(SegmentID) <= sizeof(Word));
tl_assert(sizeof(Segment*) == sizeof(Word));
tl_assert(map_segments == NULL);
- map_segments = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
+ map_segments = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
tl_assert(map_segments != NULL);
hbefore__invalidate_cache();
tl_assert(sizeof(Addr) == sizeof(Word));
tl_assert(map_locks == NULL);
- map_locks = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
+ map_locks = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxed Word cmp*/);
tl_assert(map_locks != NULL);
__bus_lock_Lock = mk_LockN( LK_nonRec, (Addr)&__bus_lock );
tl_assert(is_sane_LockN(__bus_lock_Lock));
- HG_(addToFM)( map_locks, (Word)&__bus_lock, (Word)__bus_lock_Lock );
+ VG_(addToFM)( map_locks, (Word)&__bus_lock, (Word)__bus_lock_Lock );
tl_assert(univ_tsets == NULL);
univ_tsets = HG_(newWordSetU)( hg_zalloc, hg_free, 8/*cacheSize*/ );
Bool found;
Lock* oldlock = NULL;
tl_assert(is_sane_ThreadId(tid));
- found = HG_(lookupFM)( map_locks,
+ found = VG_(lookupFM)( map_locks,
NULL, (Word*)&oldlock, (Word)ga );
if (!found) {
Lock* lock = mk_LockN(lkk, ga);
lock->appeared_at = VG_(record_ExeContext)( tid, 0 );
tl_assert(is_sane_LockN(lock));
- HG_(addToFM)( map_locks, (Word)ga, (Word)lock );
+ VG_(addToFM)( map_locks, (Word)ga, (Word)lock );
tl_assert(oldlock == NULL);
// mark the relevant secondary map has .mbHasLocks
shmem__set_mbHasLocks( ga, True );
{
Bool found;
Lock* lk = NULL;
- found = HG_(lookupFM)( map_locks, NULL, (Word*)&lk, (Word)ga );
+ found = VG_(lookupFM)( map_locks, NULL, (Word*)&lk, (Word)ga );
tl_assert(found ? lk != NULL : lk == NULL);
if (found) {
// check the relevant secondary map has .mbHasLocks?
{
Addr ga2 = 0;
Lock* lk = NULL;
- HG_(delFromFM)( map_locks,
+ VG_(delFromFM)( map_locks,
(Word*)&ga2, (Word*)&lk, (Word)ga );
/* delFromFM produces the val which is being deleted, if it is
found. So assert it is non-null; that in effect asserts that we
Bool found;
Segment* seg = NULL;
tl_assert( is_sane_SegmentID(segid) );
- found = HG_(lookupFM)( map_segments,
+ found = VG_(lookupFM)( map_segments,
NULL, (Word*)&seg, (Word)segid );
tl_assert(found);
tl_assert(seg != NULL);
Bool found;
Segment* seg = NULL;
tl_assert( is_sane_SegmentID(segid) );
- found = HG_(lookupFM)( map_segments,
+ found = VG_(lookupFM)( map_segments,
NULL, (Word*)&seg, (Word)segid );
if (!found) tl_assert(seg == NULL);
return seg;
static void map_segments_add ( SegmentID segid, Segment* seg )
{
/* This is a bit inefficient. Oh well. */
- tl_assert( !HG_(lookupFM)( map_segments, NULL, NULL, segid ));
- HG_(addToFM)( map_segments, (Word)segid, (Word)seg );
+ tl_assert( !VG_(lookupFM)( map_segments, NULL, NULL, segid ));
+ VG_(addToFM)( map_segments, (Word)segid, (Word)seg );
}
/*--------------- to do with Vector Timestamps ---------------*/
{
SecMap* sm = NULL;
Addr gaKey = shmem__round_to_SecMap_base(ga);
- if (HG_(lookupFM)( map_shmem,
+ if (VG_(lookupFM)( map_shmem,
NULL/*keyP*/, (Word*)&sm, (Word)gaKey )) {
/* Found; address of SecMap is in sm */
tl_assert(sm);
/* create a new one */
sm = shmem__alloc_SecMap();
tl_assert(sm);
- HG_(addToFM)( map_shmem, (Word)gaKey, (Word)sm );
+ VG_(addToFM)( map_shmem, (Word)gaKey, (Word)sm );
}
return sm;
}
{
SecMap* sm;
Addr aKey = shmem__round_to_SecMap_base(a);
- if (HG_(lookupFM)( map_shmem,
+ if (VG_(lookupFM)( map_shmem,
NULL/*keyP*/, (Word*)&sm, (Word)aKey )) {
/* Found */
return sm->mbHasLocks;
SecMap* sm;
Addr aKey = shmem__round_to_SecMap_base(a);
tl_assert(b == False || b == True);
- if (HG_(lookupFM)( map_shmem,
+ if (VG_(lookupFM)( map_shmem,
NULL/*keyP*/, (Word*)&sm, (Word)aKey )) {
/* Found; address of SecMap is in sm */
} else {
/* create a new one */
sm = shmem__alloc_SecMap();
tl_assert(sm);
- HG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
+ VG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
}
sm->mbHasLocks = b;
}
SecMap* sm;
Addr aKey = shmem__round_to_SecMap_base(a);
tl_assert(b == False || b == True);
- if (HG_(lookupFM)( map_shmem,
+ if (VG_(lookupFM)( map_shmem,
NULL/*keyP*/, (Word*)&sm, (Word)aKey )) {
/* Found; address of SecMap is in sm */
} else {
/* create a new one */
sm = shmem__alloc_SecMap();
tl_assert(sm);
- HG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
+ VG_(addToFM)( map_shmem, (Word)aKey, (Word)sm );
}
sm->mbHasShared = b;
}
static Bool thread_is_a_holder_of_Lock ( Thread* thr, Lock* lk )
{
if (lk->heldBy)
- return HG_(elemBag)( lk->heldBy, (Word)thr ) > 0;
+ return VG_(elemBag)( lk->heldBy, (Word)thr ) > 0;
else
return False;
}
// # entries in admin_locks == # entries in map_locks
for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin)
;
- if (i != HG_(sizeFM)(map_locks)) BAD("1");
+ if (i != VG_(sizeFM)(map_locks)) BAD("1");
// for each entry (gla, lk) in map_locks
// gla == lk->guest_addr
- HG_(initIterFM)( map_locks );
- while (HG_(nextIterFM)( map_locks,
+ VG_(initIterFM)( map_locks );
+ while (VG_(nextIterFM)( map_locks,
(Word*)&gla, (Word*)&lk )) {
if (lk->guestaddr != gla) BAD("2");
}
- HG_(doneIterFM)( map_locks );
+ VG_(doneIterFM)( map_locks );
// scan through admin_locks ...
for (lk = admin_locks; lk; lk = lk->admin) {
// lock is sane. Quite comprehensive, also checks that
if (lk->heldBy) {
Thread* thr;
Word count;
- HG_(initIterBag)( lk->heldBy );
- while (HG_(nextIterBag)( lk->heldBy,
+ VG_(initIterBag)( lk->heldBy );
+ while (VG_(nextIterBag)( lk->heldBy,
(Word*)&thr, &count )) {
// is_sane_LockN above ensures these
tl_assert(count >= 1);
&& HG_(elemWS)(univ_lsets, thr->locksetW, (Word)lk))
BAD("8");
}
- HG_(doneIterBag)( lk->heldBy );
+ VG_(doneIterBag)( lk->heldBy );
} else {
/* lock not held by anybody */
if (lk->heldW) BAD("9"); /* should be False if !heldBy */
// # entries in admin_segments == # entries in map_segments
for (i = 0, seg = admin_segments; seg; i++, seg = seg->admin)
;
- if (i != HG_(sizeFM)(map_segments)) BAD("1");
+ if (i != VG_(sizeFM)(map_segments)) BAD("1");
// for seg in Segments {
for (seg = admin_segments; seg; seg = seg->admin) {
if (!is_sane_Segment(seg)) BAD("2");
Word i, j, ws_size, n_valid_tags;
UWord* ws_words;
Addr* valid_tags;
- HG_(initIterFM)( map_shmem );
+ VG_(initIterFM)( map_shmem );
// for sm in SecMaps {
- while (HG_(nextIterFM)( map_shmem,
+ while (VG_(nextIterFM)( map_shmem,
(Word*)&smga, (Word*)&sm )) {
SecMapIter itr;
SVal* w32p = NULL;
// GCing of SecMaps is implemented
//if (allNoAccess && sm->mbHasLocks) BAD("13a");
}
- HG_(doneIterFM)( map_shmem );
+ VG_(doneIterFM)( map_shmem );
// check the cache
valid_tags = hg_zalloc(N_WAY_NENT * sizeof(Addr));
HG_(cardinalityWS)( univ_lsets, lset_old), lk );
if (lk->appeared_at) {
if (ga_to_lastlock == NULL)
- ga_to_lastlock = HG_(newFM)( hg_zalloc, hg_free, NULL );
- HG_(addToFM)( ga_to_lastlock, ga_of_access, (Word)lk->appeared_at );
+ ga_to_lastlock = VG_(newFM)( hg_zalloc, hg_free, NULL );
+ VG_(addToFM)( ga_to_lastlock, ga_of_access, (Word)lk->appeared_at );
stats__ga_LL_adds++;
}
}
{
ExeContext* ec_hint = NULL;
if (ga_to_lastlock != NULL
- && HG_(lookupFM)(ga_to_lastlock,
+ && VG_(lookupFM)(ga_to_lastlock,
NULL, (Word*)&ec_hint, ga)) {
tl_assert(ec_hint != NULL);
return ec_hint;
locksToDelete = HG_(emptyWS)( univ_lsets );
/* Iterate over all locks in the range firstA .. lastA inclusive. */
- HG_(initIterAtFM)( map_locks, firstA );
- while (HG_(nextIterFM)( map_locks, (Word*)&gla, (Word*)&lk )
+ VG_(initIterAtFM)( map_locks, firstA );
+ while (VG_(nextIterFM)( map_locks, (Word*)&gla, (Word*)&lk )
&& gla <= lastA) {
tl_assert(is_sane_LockN(lk));
tl_assert(gla >= firstA);
them all, but that's too much hassle. So choose one
arbitrarily. */
if (lk->heldBy) {
- tl_assert(!HG_(isEmptyBag)(lk->heldBy));
- record_error_FreeMemLock( (Thread*)HG_(anyElementOfBag)(lk->heldBy),
+ tl_assert(!VG_(isEmptyBag)(lk->heldBy));
+ record_error_FreeMemLock( (Thread*)VG_(anyElementOfBag)(lk->heldBy),
lk );
/* remove lock from locksets of all owning threads */
remove_Lock_from_locksets_of_all_owning_Threads( lk );
/* Leave lk->heldBy in place; del_Lock below will free it up. */
}
}
- HG_(doneIterFM)( map_locks );
+ VG_(doneIterFM)( map_locks );
/* --- Step 5 --- */
SecMapIter itr;
SVal* w32p = NULL;
- HG_(initIterFM)( map_shmem );
- while (HG_(nextIterFM)( map_shmem,
+ VG_(initIterFM)( map_shmem );
+ while (VG_(nextIterFM)( map_shmem,
(Word*)&ga, (Word*)&sm )) {
tl_assert(sm);
stats_SMs++;
*w32p = wnew;
}
}
- HG_(doneIterFM)( map_shmem );
+ VG_(doneIterFM)( map_shmem );
if (SHOW_EXPENSIVE_STUFF)
VG_(printf)("shadow_mem_make_NoAccess: %d SMs, %d scanned\n",
stats_SMs, stats_SMs_scanned);
/* So the lock is held in w-mode. If it's held by some other
thread, then libpthread must be buggy. */
- tl_assert(HG_(sizeUniqueBag)(lk->heldBy) == 1); /* from precondition */
+ tl_assert(VG_(sizeUniqueBag)(lk->heldBy) == 1); /* from precondition */
- if (thr != (Thread*)HG_(anyElementOfBag)(lk->heldBy)) {
+ if (thr != (Thread*)VG_(anyElementOfBag)(lk->heldBy)) {
record_error_Misc( thr, "Bug in libpthread: write lock "
"granted on mutex/rwlock which is currently "
"wr-held by a different thread");
/* The lock is held. Is this thread one of the holders? If not,
report a bug in the client. */
- n = HG_(elemBag)( lock->heldBy, (Word)thr );
+ n = VG_(elemBag)( lock->heldBy, (Word)thr );
tl_assert(n >= 0);
if (n == 0) {
/* We are not a current holder of the lock. This is a bug in
the guest, and (per POSIX pthread rules) the unlock
attempt will fail. So just complain and do nothing
else. */
- Thread* realOwner = (Thread*)HG_(anyElementOfBag)( lock->heldBy );
+ Thread* realOwner = (Thread*)VG_(anyElementOfBag)( lock->heldBy );
tl_assert(is_sane_Thread(realOwner));
tl_assert(realOwner != thr);
tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock ));
if (n > 0) {
tl_assert(lock->heldBy);
- tl_assert(n == HG_(elemBag)( lock->heldBy, (Word)thr ));
+ tl_assert(n == VG_(elemBag)( lock->heldBy, (Word)thr ));
/* We still hold the lock. So either it's a recursive lock
or a rwlock which is currently r-held. */
tl_assert(lock->kind == LK_mbRec
} else {
/* We no longer hold the lock. */
if (lock->heldBy) {
- tl_assert(0 == HG_(elemBag)( lock->heldBy, (Word)thr ));
+ tl_assert(0 == VG_(elemBag)( lock->heldBy, (Word)thr ));
}
/* update this thread's lockset accordingly. */
thr->locksetA
shmem__flush_and_invalidate_scache();
stats_SMs = stats_SMs_scanned = stats_reExcls = 0;
- HG_(initIterFM)( map_shmem );
- while (HG_(nextIterFM)( map_shmem,
+ VG_(initIterFM)( map_shmem );
+ while (VG_(nextIterFM)( map_shmem,
(Word*)&ga, (Word*)&sm )) {
SecMapIter itr;
SVal* w32p = NULL;
*w32p = wnew;
}
}
- HG_(doneIterFM)( map_shmem );
+ VG_(doneIterFM)( map_shmem );
if (SHOW_EXPENSIVE_STUFF)
VG_(printf)("evh__post_thread_join: %d SMs, "
record_error_Misc( thr, "pthread_mutex_destroy of a locked mutex" );
/* remove lock from locksets of all owning threads */
remove_Lock_from_locksets_of_all_owning_Threads( lk );
- HG_(deleteBag)( lk->heldBy );
+ VG_(deleteBag)( lk->heldBy );
lk->heldBy = NULL;
lk->heldW = False;
lk->acquired_at = NULL;
&& (lk->kind == LK_nonRec || lk->kind == LK_rdwr)
&& lk->heldBy
&& lk->heldW
- && HG_(elemBag)( lk->heldBy, (Word)thr ) > 0 ) {
+ && VG_(elemBag)( lk->heldBy, (Word)thr ) > 0 ) {
/* uh, it's a non-recursive lock and we already w-hold it, and
this is a real lock operation (not a speculative "tryLock"
kind of thing). Duh. Deadlock coming up; but at least
static void map_cond_to_Segment_INIT ( void ) {
if (UNLIKELY(map_cond_to_Segment == NULL)) {
- map_cond_to_Segment = HG_(newFM)( hg_zalloc, hg_free, NULL );
+ map_cond_to_Segment = VG_(newFM)( hg_zalloc, hg_free, NULL );
tl_assert(map_cond_to_Segment != NULL);
}
}
new_seg->vts = tick_VTS( new_seg->thr, new_seg->prev->vts );
/* ... and add the binding. */
- HG_(addToFM)( map_cond_to_Segment, (Word)cond,
+ VG_(addToFM)( map_cond_to_Segment, (Word)cond,
(Word)(new_seg->prev) );
}
}
thr, "pthread_cond_{timed}wait called with un-held mutex");
} else
if (lk->heldBy != NULL
- && HG_(elemBag)( lk->heldBy, (Word)thr ) == 0) {
+ && VG_(elemBag)( lk->heldBy, (Word)thr ) == 0) {
lk_valid = False;
record_error_Misc(
thr, "pthread_cond_{timed}wait called with mutex "
/* and find out which thread signalled us; then add a dependency
edge back to it. */
signalling_seg = NULL;
- found = HG_(lookupFM)( map_cond_to_Segment,
+ found = VG_(lookupFM)( map_cond_to_Segment,
NULL, (Word*)&signalling_seg,
(Word)cond );
if (found) {
record_error_Misc( thr, "pthread_rwlock_destroy of a locked mutex" );
/* remove lock from locksets of all owning threads */
remove_Lock_from_locksets_of_all_owning_Threads( lk );
- HG_(deleteBag)( lk->heldBy );
+ VG_(deleteBag)( lk->heldBy );
lk->heldBy = NULL;
lk->heldW = False;
lk->acquired_at = NULL;
static void map_sem_to_Segment_stack_INIT ( void ) {
if (map_sem_to_Segment_stack == NULL) {
- map_sem_to_Segment_stack = HG_(newFM)( hg_zalloc, hg_free, NULL );
+ map_sem_to_Segment_stack = VG_(newFM)( hg_zalloc, hg_free, NULL );
tl_assert(map_sem_to_Segment_stack != NULL);
}
}
XArray* xa;
tl_assert(seg);
map_sem_to_Segment_stack_INIT();
- if (HG_(lookupFM)( map_sem_to_Segment_stack,
+ if (VG_(lookupFM)( map_sem_to_Segment_stack,
NULL, (Word*)&xa, (Word)sem )) {
tl_assert(xa);
VG_(addToXA)( xa, &seg );
} else {
xa = VG_(newXA)( hg_zalloc, hg_free, sizeof(Segment*) );
VG_(addToXA)( xa, &seg );
- HG_(addToFM)( map_sem_to_Segment_stack, (Word)sem, (Word)xa );
+ VG_(addToFM)( map_sem_to_Segment_stack, (Word)sem, (Word)xa );
}
}
XArray* xa;
Segment* seg;
map_sem_to_Segment_stack_INIT();
- if (HG_(lookupFM)( map_sem_to_Segment_stack,
+ if (VG_(lookupFM)( map_sem_to_Segment_stack,
NULL, (Word*)&xa, (Word)sem )) {
/* xa is the stack for this semaphore. */
Word sz = VG_(sizeXA)( xa );
Lock* me;
LAOGLinks* links;
VG_(printf)("laog (requested by %s) {\n", who);
- HG_(initIterFM)( laog );
+ VG_(initIterFM)( laog );
me = NULL;
links = NULL;
- while (HG_(nextIterFM)( laog, (Word*)&me,
+ while (VG_(nextIterFM)( laog, (Word*)&me,
(Word*)&links )) {
tl_assert(me);
tl_assert(links);
me = NULL;
links = NULL;
}
- HG_(doneIterFM)( laog );
+ VG_(doneIterFM)( laog );
VG_(printf)("}\n");
}
/* Update the out edges for src */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
+ if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
WordSetID outs_new;
tl_assert(links);
tl_assert(keyW == (Word)src);
links = hg_zalloc(sizeof(LAOGLinks));
links->inns = HG_(emptyWS)( univ_laog );
links->outs = HG_(singletonWS)( univ_laog, (Word)dst );
- HG_(addToFM)( laog, (Word)src, (Word)links );
+ VG_(addToFM)( laog, (Word)src, (Word)links );
}
/* Update the in edges for dst */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
+ if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
WordSetID inns_new;
tl_assert(links);
tl_assert(keyW == (Word)dst);
links = hg_zalloc(sizeof(LAOGLinks));
links->inns = HG_(singletonWS)( univ_laog, (Word)src );
links->outs = HG_(emptyWS)( univ_laog );
- HG_(addToFM)( laog, (Word)dst, (Word)links );
+ VG_(addToFM)( laog, (Word)dst, (Word)links );
}
tl_assert( (presentF && presentR) || (!presentF && !presentR) );
expo.src_ec = NULL;
expo.dst_ec = NULL;
tl_assert(laog_exposition);
- if (HG_(lookupFM)( laog_exposition, NULL, NULL, (Word)&expo )) {
+ if (VG_(lookupFM)( laog_exposition, NULL, NULL, (Word)&expo )) {
/* we already have it; do nothing */
} else {
LAOGLinkExposition* expo2 = hg_zalloc(sizeof(LAOGLinkExposition));
expo2->dst_ga = dst->guestaddr;
expo2->src_ec = src->acquired_at;
expo2->dst_ec = dst->acquired_at;
- HG_(addToFM)( laog_exposition, (Word)expo2, (Word)NULL );
+ VG_(addToFM)( laog_exposition, (Word)expo2, (Word)NULL );
}
}
}
/* Update the out edges for src */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
+ if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)src )) {
tl_assert(links);
tl_assert(keyW == (Word)src);
links->outs = HG_(delFromWS)( univ_laog, links->outs, (Word)dst );
/* Update the in edges for dst */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
+ if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)dst )) {
tl_assert(links);
tl_assert(keyW == (Word)dst);
links->inns = HG_(delFromWS)( univ_laog, links->inns, (Word)src );
LAOGLinks* links;
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
+ if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
tl_assert(links);
tl_assert(keyW == (Word)lk);
return links->outs;
LAOGLinks* links;
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
+ if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
tl_assert(links);
tl_assert(keyW == (Word)lk);
return links->inns;
LAOGLinks* links;
if ( !laog )
return; /* nothing much we can do */
- HG_(initIterFM)( laog );
+ VG_(initIterFM)( laog );
me = NULL;
links = NULL;
if (0) VG_(printf)("laog sanity check\n");
- while (HG_(nextIterFM)( laog, (Word*)&me,
+ while (VG_(nextIterFM)( laog, (Word*)&me,
(Word*)&links )) {
tl_assert(me);
tl_assert(links);
me = NULL;
links = NULL;
}
- HG_(doneIterFM)( laog );
+ VG_(doneIterFM)( laog );
return;
bad:
ret = NULL;
stack = VG_(newXA)( hg_zalloc, hg_free, sizeof(Lock*) );
- visited = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
+ visited = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
(void) VG_(addToXA)( stack, &src );
if (HG_(elemWS)( univ_lsets, dsts, (Word)here )) { ret = here; break; }
- if (HG_(lookupFM)( visited, NULL, NULL, (Word)here ))
+ if (VG_(lookupFM)( visited, NULL, NULL, (Word)here ))
continue;
- HG_(addToFM)( visited, (Word)here, 0 );
+ VG_(addToFM)( visited, (Word)here, 0 );
succs = laog__succs( here );
HG_(getPayloadWS)( &succs_words, &succs_size, univ_laog, succs );
(void) VG_(addToXA)( stack, &succs_words[i] );
}
- HG_(deleteFM)( visited, NULL, NULL );
+ VG_(deleteFM)( visited, NULL, NULL );
VG_(deleteXA)( stack );
return ret;
}
return;
if (!laog)
- laog = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
+ laog = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
if (!laog_exposition)
- laog_exposition = HG_(newFM)( hg_zalloc, hg_free,
+ laog_exposition = VG_(newFM)( hg_zalloc, hg_free,
cmp_LAOGLinkExposition );
/* First, the check. Complain if there is any path in laog from lk
key.src_ec = NULL;
key.dst_ec = NULL;
found = NULL;
- if (HG_(lookupFM)( laog_exposition,
+ if (VG_(lookupFM)( laog_exposition,
(Word*)&found, NULL, (Word)&key )) {
tl_assert(found != &key);
tl_assert(found->src_ga == key.src_ga);
UWord* ws_words;
if (!laog)
- laog = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
+ laog = VG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
if (!laog_exposition)
- laog_exposition = HG_(newFM)( hg_zalloc, hg_free,
+ laog_exposition = VG_(newFM)( hg_zalloc, hg_free,
cmp_LAOGLinkExposition );
HG_(getPayloadWS)( &ws_words, &ws_size, univ_lsets, locksToDelete );
static void map_pthread_t_to_Thread_INIT ( void ) {
if (UNLIKELY(map_pthread_t_to_Thread == NULL)) {
- map_pthread_t_to_Thread = HG_(newFM)( hg_zalloc, hg_free, NULL );
+ map_pthread_t_to_Thread = VG_(newFM)( hg_zalloc, hg_free, NULL );
tl_assert(map_pthread_t_to_Thread != NULL);
}
}
if (0)
VG_(printf)("XXXX: bind pthread_t %p to Thread* %p\n",
(void*)args[1], (void*)my_thr );
- HG_(addToFM)( map_pthread_t_to_Thread, (Word)args[1], (Word)my_thr );
+ VG_(addToFM)( map_pthread_t_to_Thread, (Word)args[1], (Word)my_thr );
break;
}
VG_(printf)("NOTIFY_JOIN_COMPLETE (tid %d): quitter = %p\n", (Int)tid,
(void*)args[1]);
map_pthread_t_to_Thread_INIT();
- found = HG_(lookupFM)( map_pthread_t_to_Thread,
+ found = VG_(lookupFM)( map_pthread_t_to_Thread,
NULL, (Word*)&thr_q, (Word)args[1] );
/* Can this fail? It would mean that our pthread_join
wrapper observed a successful join on args[1] yet that
if (!str)
str = "(null)";
if (!string_table) {
- string_table = HG_(newFM)( hg_zalloc, hg_free, string_table_cmp );
+ string_table = VG_(newFM)( hg_zalloc, hg_free, string_table_cmp );
tl_assert(string_table);
}
- if (HG_(lookupFM)( string_table,
+ if (VG_(lookupFM)( string_table,
NULL, (Word*)©, (Word)str )) {
tl_assert(copy);
if (0) VG_(printf)("string_table_strdup: %p -> %p\n", str, copy );
} else {
copy = VG_(strdup)(str);
tl_assert(copy);
- HG_(addToFM)( string_table, (Word)copy, (Word)copy );
+ VG_(addToFM)( string_table, (Word)copy, (Word)copy );
return copy;
}
}
stats__ga_LockN_to_P_queries++;
tl_assert( is_sane_LockN(lkn) );
if (!yaWFM) {
- yaWFM = HG_(newFM)( hg_zalloc, hg_free, lock_unique_cmp );
+ yaWFM = VG_(newFM)( hg_zalloc, hg_free, lock_unique_cmp );
tl_assert(yaWFM);
}
- if (!HG_(lookupFM)( yaWFM, NULL, (Word*)&lkp, (Word)lkn)) {
+ if (!VG_(lookupFM)( yaWFM, NULL, (Word*)&lkp, (Word)lkn)) {
lkp = hg_zalloc( sizeof(Lock) );
*lkp = *lkn;
lkp->admin = NULL;
lkp->heldW = False;
lkp->heldBy = NULL;
lkp->acquired_at = NULL;
- HG_(addToFM)( yaWFM, (Word)lkp, (Word)lkp );
+ VG_(addToFM)( yaWFM, (Word)lkp, (Word)lkp );
}
tl_assert( is_sane_LockP(lkp) );
return lkp;
VG_(printf)("L(ast)L(ock) map: %'8lu inserts (%d map size)\n",
stats__ga_LL_adds,
- (Int)(ga_to_lastlock ? HG_(sizeFM)( ga_to_lastlock ) : 0) );
+ (Int)(ga_to_lastlock ? VG_(sizeFM)( ga_to_lastlock ) : 0) );
VG_(printf)(" LockN-to-P map: %'8lu queries (%d map size)\n",
stats__ga_LockN_to_P_queries,
- (Int)(yaWFM ? HG_(sizeFM)( yaWFM ) : 0) );
+ (Int)(yaWFM ? VG_(sizeFM)( yaWFM ) : 0) );
VG_(printf)("string table map: %'8lu queries (%d map size)\n",
stats__string_table_queries,
- (Int)(string_table ? HG_(sizeFM)( string_table ) : 0) );
+ (Int)(string_table ? VG_(sizeFM)( string_table ) : 0) );
VG_(printf)(" LAOG: %'8d map size\n",
- (Int)(laog ? HG_(sizeFM)( laog ) : 0));
+ (Int)(laog ? VG_(sizeFM)( laog ) : 0));
VG_(printf)(" LAOG exposition: %'8d map size\n",
- (Int)(laog_exposition ? HG_(sizeFM)( laog_exposition ) : 0));
+ (Int)(laog_exposition ? VG_(sizeFM)( laog_exposition ) : 0));
VG_(printf)(" locks: %'8lu acquires, "
"%'lu releases\n",
stats__lockN_acquires,
/*--------------------------------------------------------------------*/
/*--- An AVL tree based finite map for word keys and word values. ---*/
/*--- Inspired by Haskell's "FiniteMap" library. ---*/
-/*--- hg_wordfm.h ---*/
+/*--- pub_tool_wordfm.h ---*/
/*--------------------------------------------------------------------*/
/*
- This file is part of Helgrind, a Valgrind tool for detecting errors
- in threaded programs.
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
Copyright (C) 2007-2008 Julian Seward
jseward@acm.org
The GNU General Public License is contained in the file COPYING.
*/
-#ifndef __HG_WORDFM_H
-#define __HG_WORDFM_H
+#ifndef __PUB_TOOL_WORDFM_H
+#define __PUB_TOOL_WORDFM_H
//------------------------------------------------------------------//
//--- WordFM ---//
WordSet, WordBag) now operate on unsigned words (UWord), whereas
they previously operated on signed words (Word). This became a
problem, when using unboxed comparisons (when kCmp == NULL), with
- the introduction of HG_(initIterAtFM), which allows iteration over
+ the introduction of VG_(initIterAtFM), which allows iteration over
parts of mappings. Iterating over a mapping in increasing order of
signed Word keys is not what callers expect when iterating through
maps whose keys represent addresses (Addr) since Addr is unsigned,
sections of the map, or the whole thing. If kCmp is NULL then the
ordering used is unsigned word ordering (UWord) on the key
values. */
-WordFM* HG_(newFM) ( void* (*alloc_nofail)( SizeT ),
+WordFM* VG_(newFM) ( void* (*alloc_nofail)( SizeT ),
void (*dealloc)(void*),
Word (*kCmp)(UWord,UWord) );
/* Free up the FM. If kFin is non-NULL, it is applied to keys
before the FM is deleted; ditto with vFin for vals. */
-void HG_(deleteFM) ( WordFM*, void(*kFin)(UWord), void(*vFin)(UWord) );
+void VG_(deleteFM) ( WordFM*, void(*kFin)(UWord), void(*vFin)(UWord) );
/* Add (k,v) to fm. If a binding for k already exists, it is updated
to map to this new v. In that case we should really return the
previous v so that caller can finalise it. Oh well. */
-void HG_(addToFM) ( WordFM* fm, UWord k, UWord v );
+void VG_(addToFM) ( WordFM* fm, UWord k, UWord v );
// Delete key from fm, returning associated key and val if found
-Bool HG_(delFromFM) ( WordFM* fm,
+Bool VG_(delFromFM) ( WordFM* fm,
/*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key );
// Look up in fm, assigning found key & val at spec'd addresses
-Bool HG_(lookupFM) ( WordFM* fm,
+Bool VG_(lookupFM) ( WordFM* fm,
/*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key );
// How many elements are there in fm?
-UWord HG_(sizeFM) ( WordFM* fm );
+UWord VG_(sizeFM) ( WordFM* fm );
// set up FM for iteration
-void HG_(initIterFM) ( WordFM* fm );
+void VG_(initIterFM) ( WordFM* fm );
// set up FM for iteration so that the first key subsequently produced
-// by HG_(nextIterFM) is the smallest key in the map >= start_at.
+// by VG_(nextIterFM) is the smallest key in the map >= start_at.
// Naturally ">=" is defined by the comparison function supplied to
-// HG_(newFM), as documented above.
-void HG_(initIterAtFM) ( WordFM* fm, UWord start_at );
+// VG_(newFM), as documented above.
+void VG_(initIterAtFM) ( WordFM* fm, UWord start_at );
// get next key/val pair. Will assert if fm has been modified
// or looked up in since initIterFM/initIterWithStartFM was called.
-Bool HG_(nextIterFM) ( WordFM* fm,
+Bool VG_(nextIterFM) ( WordFM* fm,
/*OUT*/UWord* pKey, /*OUT*/UWord* pVal );
// clear the I'm iterating flag
-void HG_(doneIterFM) ( WordFM* fm );
+void VG_(doneIterFM) ( WordFM* fm );
// Deep copy a FM. If dopyK is NULL, keys are copied verbatim.
// If non-null, dopyK is applied to each key to generate the
// is non-NULL but the result is NULL, it is assumed that dopyK
// could not allocate memory, in which case the copy is abandoned
// and NULL is returned. Ditto with dopyV for values.
-WordFM* HG_(dopyFM) ( WordFM* fm,
+WordFM* VG_(dopyFM) ( WordFM* fm,
UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) );
//------------------------------------------------------------------//
typedef struct _WordBag WordBag; /* opaque */
/* Allocate and initialise a WordBag */
-WordBag* HG_(newBag) ( void* (*alloc_nofail)( SizeT ),
+WordBag* VG_(newBag) ( void* (*alloc_nofail)( SizeT ),
void (*dealloc)(void*) );
/* Free up the Bag. */
-void HG_(deleteBag) ( WordBag* );
+void VG_(deleteBag) ( WordBag* );
/* Add a word. */
-void HG_(addToBag)( WordBag*, UWord );
+void VG_(addToBag)( WordBag*, UWord );
/* Find out how many times the given word exists in the bag. */
-UWord HG_(elemBag) ( WordBag*, UWord );
+UWord VG_(elemBag) ( WordBag*, UWord );
/* Delete a word from the bag. */
-Bool HG_(delFromBag)( WordBag*, UWord );
+Bool VG_(delFromBag)( WordBag*, UWord );
/* Is the bag empty? */
-Bool HG_(isEmptyBag)( WordBag* );
+Bool VG_(isEmptyBag)( WordBag* );
/* Does the bag have exactly one element? */
-Bool HG_(isSingletonTotalBag)( WordBag* );
+Bool VG_(isSingletonTotalBag)( WordBag* );
/* Return an arbitrary element from the bag. */
-UWord HG_(anyElementOfBag)( WordBag* );
+UWord VG_(anyElementOfBag)( WordBag* );
/* How many different / total elements are in the bag? */
-UWord HG_(sizeUniqueBag)( WordBag* ); /* fast */
-UWord HG_(sizeTotalBag)( WordBag* ); /* warning: slow */
+UWord VG_(sizeUniqueBag)( WordBag* ); /* fast */
+UWord VG_(sizeTotalBag)( WordBag* ); /* warning: slow */
/* Iterating over the elements of a bag. */
-void HG_(initIterBag)( WordBag* );
-Bool HG_(nextIterBag)( WordBag*, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount );
-void HG_(doneIterBag)( WordBag* );
+void VG_(initIterBag)( WordBag* );
+Bool VG_(nextIterBag)( WordBag*, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount );
+void VG_(doneIterBag)( WordBag* );
//------------------------------------------------------------------//
//--- end WordBag (unboxed words only) ---//
//--- Public interface ---//
//------------------------------------------------------------------//
-#endif /* ! __HG_WORDFM_H */
+#endif /* ! __PUB_TOOL_WORDFM_H */
/*--------------------------------------------------------------------*/
-/*--- end hg_wordfm.h ---*/
+/*--- end pub_tool_wordfm.h ---*/
/*--------------------------------------------------------------------*/