SizeT fixedSzb; /* If using VG_(allocFixedEltDedupPA), size of elements */
Bool strPA; /* True if this is a string dedup pool */
SizeT eltAlign;
- void* (*alloc_fn)(const HChar*, SizeT); /* pool allocator */
+ Alloc_Fn_t alloc_fn; /* pool allocator */
const HChar* cc; /* pool allocator's cost centre */
- void (*free_fn)(void*); /* pool allocator's deallocation function */
+ Free_Fn_t free_fn; /* pool allocator's deallocation function */
/* XArray of void* (pointers to pools). The pools themselves.
Each element is a pointer to a block of size at least PoolSzB bytes.
The last block might be smaller due to a call to shrink_block. */
DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB,
SizeT eltAlign,
- void* (*alloc_fn)(const HChar*, SizeT),
+ Alloc_Fn_t alloc_fn,
const HChar* cc,
- void (*free_fn)(void*) )
+ Free_Fn_t free_fn )
{
DedupPoolAlloc* ddpa;
vg_assert(poolSzB >= eltAlign);
struct _OSet {
SizeT keyOff; // key offset
OSetCmp_t cmp; // compare a key and an element, or NULL
- OSetAlloc_t alloc_fn; // allocator
+ Alloc_Fn_t alloc_fn; // allocator
const HChar* cc; // cost centre for allocator
- OSetFree_t free_fn; // deallocator
+ Free_Fn_t free_fn; // deallocator
PoolAlloc* node_pa; // (optional) pool allocator for nodes.
SizeT maxEltSize; // for node_pa, must be > 0. Otherwise unused.
UInt nElems; // number of elements in the tree
// The underscores avoid GCC complaints about overshadowing global names.
AvlTree* VG_(OSetGen_Create)(PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc_fn, const HChar* cc,
- OSetFree_t free_fn)
+ Alloc_Fn_t alloc_fn, const HChar* cc,
+ Free_Fn_t free_fn)
{
AvlTree* t;
}
AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc_fn, const HChar* cc,
- OSetFree_t free_fn,
+ Alloc_Fn_t alloc_fn, const HChar* cc,
+ Free_Fn_t free_fn,
SizeT poolSize,
SizeT maxEltSize)
{
return t;
}
-AvlTree* VG_(OSetWord_Create)(OSetAlloc_t alloc_fn, const HChar* cc,
- OSetFree_t free_fn)
+AvlTree* VG_(OSetWord_Create)(Alloc_Fn_t alloc_fn, const HChar* cc,
+ Free_Fn_t free_fn)
{
return VG_(OSetGen_Create)(/*keyOff*/0, /*cmp*/NULL, alloc_fn, cc, free_fn);
}
UWord nrRef; /* nr reference to this pool allocator */
UWord elemSzB; /* element size */
UWord nPerPool; /* # elems per pool */
- void* (*alloc_fn)(const HChar*, SizeT); /* pool allocator */
- const HChar* cc; /* pool allocator's cost centre */
- void (*free_fn)(void*); /* pool allocator's free-er */
+ Alloc_Fn_t alloc_fn; /* pool allocator */
+ const HChar* cc; /* pool allocator's cost centre */
+ Free_Fn_t free_fn; /* pool allocator's free-er */
/* XArray of void* (pointers to pools). The pools themselves.
Each element is a pointer to a block of size (elemSzB *
nPerPool) bytes. */
PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
- void* (*alloc_fn)(const HChar*, SizeT),
+ Alloc_Fn_t alloc_fn,
const HChar* cc,
- void (*free_fn)(void*) )
+ Free_Fn_t free_fn )
{
PoolAlloc* pa;
vg_assert(0 == (elemSzB % sizeof(UWord)));
struct _RangeMap {
- void* (*alloc_fn) ( const HChar*, SizeT ); /* alloc fn (nofail) */
+ Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
- void (*free_fn) ( void* ); /* free fn */
+ Free_Fn_t free_fn; /* free fn */
XArray* ranges;
};
static void show ( const RangeMap* rm );
-RangeMap* VG_(newRangeMap) ( void*(*alloc_fn)(const HChar*,SizeT),
+RangeMap* VG_(newRangeMap) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
- void(*free_fn)(void*),
+ Free_Fn_t free_fn,
UWord initialVal )
{
/* check user-supplied info .. */
/* See pub_tool_xarray.h for details of what this is all about. */
struct _XArray {
- void* (*alloc_fn) ( const HChar*, SizeT ); /* alloc fn (nofail) */
+ Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
- void (*free_fn) ( void* ); /* free fn */
+ Free_Fn_t free_fn; /* free fn */
Int (*cmpFn) ( const void*, const void* ); /* cmp fn (may be NULL) */
Word elemSzB; /* element size in bytes */
void* arr; /* pointer to elements */
};
-XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT),
+XArray* VG_(newXA) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
- void(*free_fn)(void*),
+ Free_Fn_t free_fn,
Word elemSzB )
{
XArray* xa;
struct _XT_shared {
UWord nrRef; /* nr of XTrees referencing this shared memory. */
- void* (*alloc_fn)( const HChar*, SizeT ); /* alloc fn (nofail) */
+ Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
- void (*free_fn)( void* ); /* free fn */
+ Free_Fn_t free_fn; /* free fn */
/* The data associated to each ec is stored in 2 arrays:
an xec array, shared between an xt and all its snapshots.
(with the index ecu/4). */
#define NO_OFFSET 0xffffffff
-static XT_shared* new_XT_shared (void* (*alloc_fn)(const HChar*, SizeT),
+static XT_shared* new_XT_shared (Alloc_Fn_t alloc_fn,
const HChar* cc,
void (*free_fn)(void*))
{
struct _XTree {
- void* (*alloc_fn)( const HChar*, SizeT ); /* alloc fn (nofail) */
+ Alloc_Fn_t alloc_fn; /* alloc fn (nofail) */
const HChar* cc; /* cost centre for alloc */
- void (*free_fn)( void* ); /* free fn */
+ Free_Fn_t free_fn; /* free fn */
Word dataSzB; /* data size in bytes */
XT_init_data_t init_data_fn;
XT_add_data_t add_data_fn;
};
-XTree* VG_(XT_create) ( void*(*alloc_fn)(const HChar*, SizeT),
+XTree* VG_(XT_create) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
- void(*free_fn) (void*),
+ Free_Fn_t free_fn,
Word dataSzB,
XT_init_data_t init_data_fn,
XT_add_data_t add_data_fn,
/* ThreadIds are simply indices into the VG_(threads)[] array. */
typedef UInt ThreadId;
+/* Many data structures need to allocate and release memory.
+ The allocation/release functions must be provided by the caller.
+ The Alloc_Fn_t function must allocate a chunk of memory of size szB.
+ cc is the Cost Centre for this allocated memory. This constant string
+ is used to provide Valgrind's heap profiling, activated by
+ --profile-heap=no|yes.
+ The corresponding Free_Fn_t frees the memory chunk p. */
+
+typedef void* (*Alloc_Fn_t) ( const HChar* cc, SizeT szB );
+typedef void (*Free_Fn_t) ( void* p );
+
/* An abstraction of syscall return values.
Linux/MIPS32 and Linux/MIPS64:
When _isError == False,
This function never returns NULL. */
extern DedupPoolAlloc* VG_(newDedupPA) ( SizeT poolSzB,
SizeT eltAlign,
- void* (*alloc)(const HChar*, SizeT),
+ Alloc_Fn_t alloc_fn,
const HChar* cc,
- void (*free_fn)(void*) );
+ Free_Fn_t free_fn );
/* Allocates or retrieve element from ddpa with eltSzB bytes to store elt.
This function never returns NULL.
typedef struct _OSet OSet;
-// - Cmp: returns -1, 0 or 1 if key is <, == or > elem.
-// - Alloc: allocates a chunk of memory.
-// - Free: frees a chunk of memory allocated with Alloc.
-
+// - OSetCmp_t: returns -1, 0 or 1 if key is <, == or > elem.
typedef Word (*OSetCmp_t) ( const void* key, const void* elem );
-typedef void* (*OSetAlloc_t) ( const HChar* cc, SizeT szB );
-typedef void (*OSetFree_t) ( void* p );
/*--------------------------------------------------------------------*/
/*--- Creating and destroying OSets (UWord) ---*/
// to allow the destruction of any attached resources; if NULL it is not
// called.
-extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc_fn, const HChar* cc,
- OSetFree_t free_fn );
+extern OSet* VG_(OSetWord_Create) ( Alloc_Fn_t alloc_fn, const HChar* cc,
+ Free_Fn_t free_fn );
extern void VG_(OSetWord_Destroy) ( OSet* os );
/*--------------------------------------------------------------------*/
// lead to assertions in Valgrind's allocator.
extern OSet* VG_(OSetGen_Create) ( PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc_fn, const HChar* cc,
- OSetFree_t free_fn);
+ Alloc_Fn_t alloc_fn, const HChar* cc,
+ Free_Fn_t free_fn);
extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc_fn,
+ Alloc_Fn_t alloc_fn,
const HChar* cc,
- OSetFree_t free_fn,
+ Free_Fn_t free_fn,
SizeT poolSize,
SizeT maxEltSize);
// Same as VG_(OSetGen_Create) but created OSet will use a pool allocator to
This function never returns NULL. */
extern PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
- void* (*alloc)(const HChar*, SizeT),
+ Alloc_Fn_t alloc_fn,
const HChar* cc,
- void (*free_fn)(void*) );
+ Free_Fn_t free_fn );
/* Free all memory associated with a PoolAlloc. */
succeeded.) The new array will contain a single range covering the
entire key space, which will be bound to the value |initialVal|.
This function never returns NULL. */
-RangeMap* VG_(newRangeMap) ( void*(*alloc_fn)(const HChar*,SizeT),
+RangeMap* VG_(newRangeMap) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
- void(*free_fn)(void*),
+ Free_Fn_t free_fn,
UWord initialVal );
/* Free all memory associated with a RangeMap. */
for elements of the specified size. alloc_fn must not return NULL (that
is, if it returns it must have succeeded.)
This function never returns NULL. */
-extern XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT),
+extern XArray* VG_(newXA) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
- void(*free_fn)(void*),
+ Free_Fn_t free_fn,
Word elemSzB );
/* Free all memory associated with an XArray. */
alloc_fn must not return NULL (that is, if it returns it must have
succeeded.).
See respective typedef for *_fn arguments. */
-extern XTree* VG_(XT_create) ( void*(*alloc_fn)(const HChar*, SizeT),
+extern XTree* VG_(XT_create) ( Alloc_Fn_t alloc_fn,
const HChar* cc,
- void(*free_fn) (void*),
+ Free_Fn_t free_fn,
Word dataSzB,
XT_init_data_t init_data_fn,
XT_add_data_t add_data_fn,