{
Int i, r, sz_exename;
ULong obj_mtime, pdb_mtime;
- Char exename[VKI_PATH_MAX];
+ HChar exename[VKI_PATH_MAX];
Char* pdbname = NULL;
Char* dot;
SysRes sres;
#include "priv_misc.h" /* self */
-void* ML_(dinfo_zalloc) ( HChar* cc, SizeT szB ) {
+void* ML_(dinfo_zalloc) ( const HChar* cc, SizeT szB ) {
void* v;
vg_assert(szB > 0);
v = VG_(arena_malloc)( VG_AR_DINFO, cc, szB );
VG_(arena_free)( VG_AR_DINFO, v );
}
-UChar* ML_(dinfo_strdup) ( HChar* cc, const UChar* str ) {
+UChar* ML_(dinfo_strdup) ( const HChar* cc, const UChar* str ) {
return VG_(arena_strdup)( VG_AR_DINFO, cc, str );
}
-UChar* ML_(dinfo_memdup) ( HChar* cc, UChar* str, SizeT nStr ) {
+UChar* ML_(dinfo_memdup) ( const HChar* cc, UChar* str, SizeT nStr ) {
UChar* dst = VG_(arena_malloc)( VG_AR_DINFO, cc, nStr );
tl_assert(dst);
VG_(memcpy)(dst, str, nStr);
/* Allocate(zeroed), free, strdup, memdup, all in VG_AR_DINFO. */
-void* ML_(dinfo_zalloc)( HChar* cc, SizeT szB );
+void* ML_(dinfo_zalloc)( const HChar* cc, SizeT szB );
void ML_(dinfo_free)( void* v );
-UChar* ML_(dinfo_strdup)( HChar* cc, const UChar* str );
-UChar* ML_(dinfo_memdup)( HChar* cc, UChar* str, SizeT nStr );
+UChar* ML_(dinfo_strdup)( const HChar* cc, const UChar* str );
+UChar* ML_(dinfo_memdup)( const HChar* cc, UChar* str, SizeT nStr );
/* Extract (possibly unaligned) data of various sizes from a buffer. */
Short ML_(read_Short)( UChar* data );
*/
static void gen_suppression(Error* err)
{
- Char xtra[256]; /* assumed big enough (is overrun-safe) */
+ HChar xtra[256]; /* assumed big enough (is overrun-safe) */
Bool anyXtra;
const HChar* name;
ExeContext* ec;
static int gdbserver_exited = 0;
/* alloc and free functions for xarray and similar. */
-static void* gs_alloc (HChar* cc, SizeT sz)
+static void* gs_alloc (const HChar* cc, SizeT sz)
{
void* res = VG_(arena_malloc)(VG_AR_CORE, cc, sz);
vg_assert (res);
// elastic, in that it can be bigger than asked-for to ensure alignment.
typedef
struct {
- Char* name;
+ const HChar* name;
Bool clientmem; // Allocates in the client address space?
SizeT rz_szB; // Red zone size in bytes
SizeT min_sblock_szB; // Minimum superblock size in bytes
// Set and get the cost-center field of a block.
static __inline__
-void set_cc ( Block* b, HChar* cc )
+void set_cc ( Block* b, const HChar* cc )
{
UByte* b2 = (UByte*)b;
vg_assert( VG_(clo_profile_heap) );
- *(HChar**)&b2[0] = cc;
+ *(const HChar**)&b2[0] = cc;
}
static __inline__
-HChar* get_cc ( Block* b )
+const HChar* get_cc ( Block* b )
{
UByte* b2 = (UByte*)b;
vg_assert( VG_(clo_profile_heap) );
- return *(HChar**)&b2[0];
+ return *(const HChar**)&b2[0];
}
//---------------------------------------------------------------------------
// It might be overriden by VG_(clo_redzone_size) or VG_(clo_core_redzone_size).
// it might be made bigger to ensure that VG_MIN_MALLOC_SZB is observed.
static
-void arena_init ( ArenaId aid, Char* name, SizeT rz_szB,
+void arena_init ( ArenaId aid, const HChar* name, SizeT rz_szB,
SizeT min_sblock_szB, SizeT min_unsplittable_sblock_szB )
{
SizeT i;
/*------------------------------------------------------------*/
__attribute__((noreturn))
-void VG_(out_of_memory_NORETURN) ( HChar* who, SizeT szB )
+void VG_(out_of_memory_NORETURN) ( const HChar* who, SizeT szB )
{
static Int outputTrial = 0;
// We try once to output the full memory state followed by the below message.
// And then we abandon.
ULong tot_alloc = VG_(am_get_anonsize_total)();
- Char* s1 =
+ const HChar* s1 =
"\n"
" Valgrind's memory management: out of memory:\n"
" %s's request for %llu bytes failed.\n"
#define N_AN_CCS 1000
-typedef struct { ULong nBytes; ULong nBlocks; HChar* cc; } AnCC;
+typedef struct {
+ ULong nBytes;
+ ULong nBlocks;
+ const HChar* cc;
+} AnCC;
static AnCC anCCs[N_AN_CCS];
Bool thisFree, lastWasFree;
SizeT b_bszB;
- HChar* cc;
+ const HChar* cc;
UInt n_ccs = 0;
//return;
a = arenaId_to_ArenaP(aid);
return ((req_pszB + n) & (~n));
}
-void* VG_(arena_malloc) ( ArenaId aid, HChar* cc, SizeT req_pszB )
+void* VG_(arena_malloc) ( ArenaId aid, const HChar* cc, SizeT req_pszB )
{
SizeT req_bszB, frag_bszB, b_bszB;
UInt lno, i;
. . . . . . .
*/
-void* VG_(arena_memalign) ( ArenaId aid, HChar* cc,
+void* VG_(arena_memalign) ( ArenaId aid, const HChar* cc,
SizeT req_alignB, SizeT req_pszB )
{
SizeT base_pszB_req, base_pszB_act, frag_bszB;
/*--- Services layered on top of malloc/free. ---*/
/*------------------------------------------------------------*/
-void* VG_(arena_calloc) ( ArenaId aid, HChar* cc,
+void* VG_(arena_calloc) ( ArenaId aid, const HChar* cc,
SizeT nmemb, SizeT bytes_per_memb )
{
SizeT size;
- UChar* p;
+ void* p;
size = nmemb * bytes_per_memb;
vg_assert(size >= nmemb && size >= bytes_per_memb);// check against overflow
}
-void* VG_(arena_realloc) ( ArenaId aid, HChar* cc,
+void* VG_(arena_realloc) ( ArenaId aid, const HChar* cc,
void* ptr, SizeT req_pszB )
{
Arena* a;
SizeT old_pszB;
- UChar *p_new;
+ void* p_new;
Block* b;
ensure_mm_init(aid);
/* Inline just for the wrapper VG_(strdup) below */
-__inline__ Char* VG_(arena_strdup) ( ArenaId aid, HChar* cc,
+__inline__ Char* VG_(arena_strdup) ( ArenaId aid, const HChar* cc,
const Char* s )
{
Int i;
// All just wrappers to avoid exposing arenas to tools.
-void* VG_(malloc) ( HChar* cc, SizeT nbytes )
+void* VG_(malloc) ( const HChar* cc, SizeT nbytes )
{
return VG_(arena_malloc) ( VG_AR_TOOL, cc, nbytes );
}
VG_(arena_free) ( VG_AR_TOOL, ptr );
}
-void* VG_(calloc) ( HChar* cc, SizeT nmemb, SizeT bytes_per_memb )
+void* VG_(calloc) ( const HChar* cc, SizeT nmemb, SizeT bytes_per_memb )
{
return VG_(arena_calloc) ( VG_AR_TOOL, cc, nmemb, bytes_per_memb );
}
-void* VG_(realloc) ( HChar* cc, void* ptr, SizeT size )
+void* VG_(realloc) ( const HChar* cc, void* ptr, SizeT size )
{
return VG_(arena_realloc) ( VG_AR_TOOL, cc, ptr, size );
}
-Char* VG_(strdup) ( HChar* cc, const Char* s )
+Char* VG_(strdup) ( const HChar* cc, const Char* s )
{
return VG_(arena_strdup) ( VG_AR_TOOL, cc, s );
}
SizeT keyOff; // key offset
OSetCmp_t cmp; // compare a key and an element, or NULL
OSetAlloc_t alloc; // allocator
- HChar* cc; // cc for allocator
+ const HChar* cc; // cc for allocator
OSetFree_t free; // deallocator
PoolAlloc* node_pa; // (optional) pool allocator for nodes.
SizeT maxEltSize; // for node_pa, must be > 0. Otherwise unused.
// The underscores avoid GCC complaints about overshadowing global names.
AvlTree* VG_(OSetGen_Create)(PtrdiffT _keyOff, OSetCmp_t _cmp,
- OSetAlloc_t _alloc, HChar* _cc,
+ OSetAlloc_t _alloc, const HChar* _cc,
OSetFree_t _free)
{
AvlTree* t;
}
AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT _keyOff, OSetCmp_t _cmp,
- OSetAlloc_t _alloc, HChar* _cc,
+ OSetAlloc_t _alloc, const HChar* _cc,
OSetFree_t _free,
SizeT _poolSize,
SizeT _maxEltSize)
return t;
}
-AvlTree* VG_(OSetWord_Create)(OSetAlloc_t _alloc, HChar* _cc,
+AvlTree* VG_(OSetWord_Create)(OSetAlloc_t _alloc, const HChar* _cc,
OSetFree_t _free)
{
return VG_(OSetGen_Create)(/*keyOff*/0, /*cmp*/NULL, _alloc, _cc, _free);
UWord nrRef; /* nr reference to this pool allocator */
UWord elemSzB; /* element size */
UWord nPerPool; /* # elems per pool */
- void* (*alloc)(HChar*, SizeT); /* pool allocator */
- HChar* cc; /* pool allocator's cc */
+ void* (*alloc)(const HChar*, SizeT); /* pool allocator */
+ const HChar* cc; /* pool allocator's cc */
void (*free)(void*); /* 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 *
PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
- void* (*alloc)(HChar*, SizeT),
- HChar* cc,
+ void* (*alloc)(const HChar*, SizeT),
+ const HChar* cc,
void (*free_fn)(void*) )
{
PoolAlloc* pa;
static void maybe_add_active ( Active /*by value; callee copies*/ );
-static void* dinfo_zalloc(HChar* ec, SizeT);
+static void* dinfo_zalloc(const HChar* ec, SizeT);
static void dinfo_free(void*);
-static HChar* dinfo_strdup(HChar* ec, HChar*);
+static HChar* dinfo_strdup(const HChar* ec, const HChar*);
static Bool is_plausible_guest_addr(Addr);
-static void show_redir_state ( HChar* who );
-static void show_active ( HChar* left, Active* act );
+static void show_redir_state ( const HChar* who );
+static void show_active ( const HChar* left, Active* act );
static void handle_maybe_load_notifier( const UChar* soname,
HChar* symbol, Addr addr );
pointing to files inside the valgrind build directories. */
struct vg_stat newdi_stat;
SysRes newdi_res;
- Char in_vglib_filename[VKI_PATH_MAX];
+ HChar in_vglib_filename[VKI_PATH_MAX];
struct vg_stat in_vglib_stat;
SysRes in_vglib_res;
/*--- MISC HELPERS ---*/
/*------------------------------------------------------------*/
-static void* dinfo_zalloc(HChar* ec, SizeT n) {
+static void* dinfo_zalloc(const HChar* ec, SizeT n) {
void* p;
vg_assert(n > 0);
p = VG_(arena_malloc)(VG_AR_DINFO, ec, n);
return VG_(arena_free)(VG_AR_DINFO, p);
}
-static HChar* dinfo_strdup(HChar* ec, HChar* str)
+static HChar* dinfo_strdup(const HChar* ec, const HChar* str)
{
return VG_(arena_strdup)(VG_AR_DINFO, ec, str);
}
/*--- SANITY/DEBUG ---*/
/*------------------------------------------------------------*/
-static void show_spec ( HChar* left, Spec* spec )
+static void show_spec ( const HChar* left, Spec* spec )
{
VG_(message)( Vg_DebugMsg,
"%s%25s %30s %s-> (%04d.%d) 0x%08llx\n",
(ULong)spec->to_addr );
}
-static void show_active ( HChar* left, Active* act )
+static void show_active ( const HChar* left, Active* act )
{
Bool ok;
HChar name1[64] = "";
(ULong)act->to_addr, name2 );
}
-static void show_redir_state ( HChar* who )
+static void show_redir_state ( const HChar* who )
{
TopSpec* ts;
Spec* sp;
SWAStackElem;
struct _SparseWA {
- void* (*alloc_nofail)(HChar*,SizeT);
- HChar* cc;
+ void* (*alloc_nofail)(const HChar*,SizeT);
+ const HChar* cc;
void (*dealloc)(void*);
LevelN* root;
SWAStackElem iterStack[8];
}
-SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(HChar* cc, SizeT),
- HChar* cc,
+SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(const HChar* cc, SizeT),
+ const HChar* cc,
void(*dealloc)(void*) )
{
SparseWA* swa;
/*--- Misc ---*/
/*-------------------------------------------------------------*/
-static void* ttaux_malloc ( HChar* tag, SizeT n )
+static void* ttaux_malloc ( const HChar* tag, SizeT n )
{
return VG_(arena_malloc)(VG_AR_TTAUX, tag, n);
}
struct _WordFM {
AvlNode* root;
- void* (*alloc_nofail)( HChar*, SizeT );
- HChar* cc;
+ void* (*alloc_nofail)( const HChar*, SizeT );
+ const HChar* cc;
void (*dealloc)(void*);
Word (*kCmp)(UWord,UWord);
AvlNode* nodeStack[WFM_STKMAX]; // Iterator node stack
AvlNode* avl_dopy ( AvlNode* nd,
UWord(*dopyK)(UWord),
UWord(*dopyV)(UWord),
- void*(alloc_nofail)(HChar*,SizeT),
- HChar* cc )
+ void*(alloc_nofail)(const HChar*,SizeT),
+ const HChar* cc )
{
AvlNode* nyu;
if (! nd)
/* Initialise a WordFM. */
static void initFM ( WordFM* fm,
- void* (*alloc_nofail)( HChar*, SizeT ),
- HChar* cc,
+ void* (*alloc_nofail)( const HChar*, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*),
Word (*kCmp)(UWord,UWord) )
{
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* VG_(newFM) ( void* (*alloc_nofail)( HChar*, SizeT ),
- HChar* cc,
+WordFM* VG_(newFM) ( void* (*alloc_nofail)( const HChar*, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*),
Word (*kCmp)(UWord,UWord) )
{
WordFM* fm;
};
-WordBag* VG_(newBag) ( void* (*alloc_nofail)( HChar*, SizeT ),
- HChar* cc,
+WordBag* VG_(newBag) ( void* (*alloc_nofail)( const HChar*, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*) )
{
WordBag* bag = alloc_nofail(cc, sizeof(WordBag));
/* See pub_tool_xarray.h for details of what this is all about. */
struct _XArray {
- void* (*alloc) ( HChar*, SizeT ); /* alloc fn (nofail) */
- HChar* cc; /* cost centre for alloc */
+ void* (*alloc) ( const HChar*, SizeT ); /* alloc fn (nofail) */
+ const HChar* cc; /* cost centre for alloc */
void (*free) ( void* ); /* free fn */
Int (*cmpFn) ( void*, void* ); /* cmp fn (may be NULL) */
Word elemSzB; /* element size in bytes */
};
-XArray* VG_(newXA) ( void*(*alloc_fn)(HChar*,SizeT),
- HChar* cc,
+XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT),
+ const HChar* cc,
void(*free_fn)(void*),
Word elemSzB )
{
return xa;
}
-XArray* VG_(cloneXA)( HChar* cc, XArray* xao )
+XArray* VG_(cloneXA)( const HChar* cc, XArray* xao )
{
struct _XArray* xa = (struct _XArray*)xao;
struct _XArray* nyu;
- HChar* nyu_cc;
+ const HChar* nyu_cc;
vg_assert(xa);
vg_assert(xa->alloc);
vg_assert(xa->free);
int keepcost; /* top-most, releasable (via malloc_trim) space */
};
-extern void* VG_(arena_malloc) ( ArenaId arena, HChar* cc, SizeT nbytes );
+extern void* VG_(arena_malloc) ( ArenaId arena, const HChar* cc, SizeT nbytes );
extern void VG_(arena_free) ( ArenaId arena, void* ptr );
-extern void* VG_(arena_calloc) ( ArenaId arena, HChar* cc,
+extern void* VG_(arena_calloc) ( ArenaId arena, const HChar* cc,
SizeT nmemb, SizeT bytes_per_memb );
-extern void* VG_(arena_realloc) ( ArenaId arena, HChar* cc,
+extern void* VG_(arena_realloc) ( ArenaId arena, const HChar* cc,
void* ptr, SizeT size );
-extern void* VG_(arena_memalign)( ArenaId aid, HChar* cc,
+extern void* VG_(arena_memalign)( ArenaId aid, const HChar* cc,
SizeT req_alignB, SizeT req_pszB );
-extern Char* VG_(arena_strdup) ( ArenaId aid, HChar* cc,
+extern Char* VG_(arena_strdup) ( ArenaId aid, const HChar* cc,
const Char* s);
extern SizeT VG_(arena_malloc_usable_size) ( ArenaId aid, void* payload );
/* Replacements for Valgrind core functionality. */
-void* VG_(malloc)(HChar* cc, SizeT nbytes)
+void* VG_(malloc)(const HChar* cc, SizeT nbytes)
{ return malloc(nbytes); }
void VG_(free)(void* p)
{ return free(p); }
/* Replacements for Valgrind core functionality. */
-void* VG_(malloc)(HChar* cc, SizeT nbytes)
+void* VG_(malloc)(const HChar* cc, SizeT nbytes)
{ return malloc(nbytes); }
-void* VG_(realloc)(HChar* cc, void* p, SizeT size)
+void* VG_(realloc)(const HChar* cc, void* p, SizeT size)
{ return realloc(p, size); }
void VG_(free)(void* p)
{ return free(p); }
&& tid != VG_INVALID_THREADID;
}
-static void* sg_malloc ( HChar* cc, SizeT n ) {
+static void* sg_malloc ( const HChar* cc, SizeT n ) {
void* p;
tl_assert(n > 0);
p = VG_(malloc)( cc, n );
}
StackTreeNode;
-static void pp_StackTree ( WordFM* sitree, HChar* who )
+static void pp_StackTree ( WordFM* sitree, const HChar* who )
{
UWord keyW, valW;
VG_(printf)("<<< BEGIN pp_StackTree %s\n", who );
}
static void GlobalTree__pp ( WordFM* /* of (GlobalTreeNode,void) */ gitree,
- HChar* who )
+ const HChar* who )
{
UWord keyW, valW;
GlobalTreeNode* nd;
qc->nInUse = 0;
}
-static void QCache__pp ( QCache* qc, HChar* who )
+static void QCache__pp ( QCache* qc, const HChar* who )
{
Word i;
VG_(printf)("<<< QCache with %ld elements (%s)\n", qc->nInUse, who);
/*--- Very basic stuff ---*/
/*----------------------------------------------------------------*/
-void* HG_(zalloc) ( HChar* cc, SizeT n )
+void* HG_(zalloc) ( const HChar* cc, SizeT n )
{
void* p;
tl_assert(n > 0);
VG_(free)(p);
}
-Char* HG_(strdup) ( HChar* cc, const Char* s )
+Char* HG_(strdup) ( const HChar* cc, const Char* s )
{
return VG_(strdup)( cc, s );
}
#define HG_(str) VGAPPEND(vgHelgrind_,str)
-void* HG_(zalloc) ( HChar* cc, SizeT n );
+void* HG_(zalloc) ( const HChar* cc, SizeT n );
void HG_(free) ( void* p );
-Char* HG_(strdup) ( HChar* cc, const Char* s );
+Char* HG_(strdup) ( const HChar* cc, const Char* s );
static inline Bool HG_(is_sane_ThreadId) ( ThreadId coretid ) {
return coretid >= 0 && coretid < VG_N_THREADS;
vec2ix. The entry of the dead WVs in ix2vec are used to maintain a
linked list of free (to be re-used) ix2vec entries. */
struct _WordSetU {
- void* (*alloc)(HChar*,SizeT);
- HChar* cc;
+ void* (*alloc)(const HChar*,SizeT);
+ const HChar* cc;
void (*dealloc)(void*);
WordFM* vec2ix; /* WordVec-to-WordSet mapping tree */
WordVec** ix2vec; /* WordSet-to-WordVec mapping array */
causes failures on a 64-bit platform. */
tl_assert(wv_new->owner == wsu);
have = VG_(lookupFM)( wsu->vec2ix,
- (Word*)&wv_old, (Word*)&ix_old,
- (Word)wv_new );
+ (UWord*)&wv_old, (UWord*)&ix_old,
+ (UWord)wv_new );
if (have) {
tl_assert(wv_old != wv_new);
tl_assert(wv_old);
tl_assert(wsu->ix2vec[ws] == NULL || is_dead(wsu,wsu->ix2vec[ws]));
wsu->ix2vec_free = (WordVec **) wsu->ix2vec[ws];
wsu->ix2vec[ws] = wv_new;
- VG_(addToFM)( wsu->vec2ix, (Word)wv_new, ws );
+ VG_(addToFM)( wsu->vec2ix, (UWord)wv_new, ws );
if (HG_DEBUG) VG_(printf)("aodW %s re-use free %d %p\n", wsu->cc, (Int)ws, wv_new );
return ws;
} else {
}
-WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( HChar*, SizeT ),
- HChar* cc,
+WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( const HChar*, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*),
Word cacheSize )
{
wsu->ix2vec_free = &wsu->ix2vec[ws];
VG_(delFromFM) ( wsu->vec2ix,
- (Word*)&wv_in_vec2ix, (Word*)&wv_ix,
- (Word)wv );
+ (UWord*)&wv_in_vec2ix, (UWord*)&wv_ix,
+ (UWord)wv );
if (HG_DEBUG) VG_(printf)("dieWS wv_ix %d\n", (Int)wv_ix);
tl_assert (wv_ix);
VG_(printf)("}");
}
-void HG_(ppWSUstats) ( WordSetU* wsu, HChar* name )
+void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name )
{
VG_(printf)(" WordSet \"%s\":\n", name);
VG_(printf)(" addTo %10lu (%lu uncached)\n",
typedef UInt WordSet; /* opaque, small int index */
/* Allocate and initialise a WordSetU */
-WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( HChar*, SizeT ),
- HChar* cc,
+WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( const HChar*, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*),
Word cacheSize );
UWord HG_(cardinalityWSU) ( WordSetU* );
/* Show performance stats for this WordSetU. */
-void HG_(ppWSUstats) ( WordSetU* wsu, HChar* name );
+void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name );
/* Element-level operations on WordSets. Note that the WordSet
// will abort if they can't allocate the memory).
// The 'cc' is a string that identifies the allocation point. It's used when
// --profile-heap=yes is specified.
-extern void* VG_(malloc) ( HChar* cc, SizeT nbytes );
+extern void* VG_(malloc) ( const HChar* cc, SizeT nbytes );
extern void VG_(free) ( void* p );
-extern void* VG_(calloc) ( HChar* cc, SizeT n, SizeT bytes_per_elem );
-extern void* VG_(realloc) ( HChar* cc, void* p, SizeT size );
-extern Char* VG_(strdup) ( HChar* cc, const Char* s );
+extern void* VG_(calloc) ( const HChar* cc, SizeT n, SizeT bytes_per_elem );
+extern void* VG_(realloc) ( const HChar* cc, void* p, SizeT size );
+extern Char* VG_(strdup) ( const HChar* cc, const Char* s );
// Returns the usable size of a heap-block. It's the asked-for size plus
// possibly some more due to rounding up.
// TODO: move somewhere else
// Call here to bomb the system when out of memory (mmap anon fails)
__attribute__((noreturn))
-extern void VG_(out_of_memory_NORETURN) ( HChar* who, SizeT szB );
+extern void VG_(out_of_memory_NORETURN) ( const HChar* who, SizeT szB );
#endif // __PUB_TOOL_MALLOCFREE_H
// - Free: frees a chunk of memory allocated with Alloc.
typedef Word (*OSetCmp_t) ( const void* key, const void* elem );
-typedef void* (*OSetAlloc_t) ( HChar* cc, SizeT szB );
+typedef void* (*OSetAlloc_t) ( const HChar* cc, SizeT szB );
typedef void (*OSetFree_t) ( void* p );
/*--------------------------------------------------------------------*/
// to allow the destruction of any attached resources; if NULL it is not
// called.
-extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc, HChar* cc,
+extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc, const HChar* cc,
OSetFree_t _free );
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, HChar* cc,
+ OSetAlloc_t alloc, const HChar* cc,
OSetFree_t _free);
extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp,
- OSetAlloc_t alloc, HChar* cc,
+ OSetAlloc_t alloc,
+ const HChar* cc,
OSetFree_t _free,
SizeT poolSize,
SizeT maxEltSize);
is, if it returns it must have succeeded.) */
PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
- void* (*alloc)(HChar*, SizeT),
- HChar* cc,
+ void* (*alloc)(const HChar*, SizeT),
+ const HChar* cc,
void (*free_fn)(void*) );
typedef struct _SparseWA SparseWA; /* opaque */
// Create a new one, using the specified allocator/deallocator
-SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(HChar* cc, SizeT),
- HChar* cc,
+SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(const HChar* cc, SizeT),
+ const HChar* cc,
void(*dealloc)(void*) );
// Delete one, and free all associated storage
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* VG_(newFM) ( void* (*alloc_nofail)( HChar* cc, SizeT ),
- HChar* cc,
+WordFM* VG_(newFM) ( void* (*alloc_nofail)( const HChar* cc, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*),
Word (*kCmp)(UWord,UWord) );
typedef struct _WordBag WordBag; /* opaque */
/* Allocate and initialise a WordBag */
-WordBag* VG_(newBag) ( void* (*alloc_nofail)( HChar* cc, SizeT ),
- HChar* cc,
+WordBag* VG_(newBag) ( void* (*alloc_nofail)( const HChar* cc, SizeT ),
+ const HChar* cc,
void (*dealloc)(void*) );
/* Free up the Bag. */
/* Create new XArray, using given allocation and free function, and
for elements of the specified size. Alloc fn must not fail (that
is, if it returns it must have succeeded.) */
-extern XArray* VG_(newXA) ( void*(*alloc_fn)(HChar*,SizeT),
- HChar* cc,
+extern XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT),
+ const HChar* cc,
void(*free_fn)(void*),
Word elemSzB );
space (but did return NULL rather than merely abort.) Space for
the clone (and all additions to it) is billed to 'cc' unless that
is NULL, in which case the parent's cost-center is used. */
-extern XArray* VG_(cloneXA)( HChar* cc, XArray* xa );
+extern XArray* VG_(cloneXA)( const HChar* cc, XArray* xa );
/* Get the raw array and size so callers can index it really fast.
This is dangerous in the sense that there's no range or
static MC_Chunk**
-find_active_chunks(UInt* pn_chunks)
+find_active_chunks(Int* pn_chunks)
{
// Our goal is to construct a set of chunks that includes every
// mempool chunk, and every malloc region that *doesn't* contain a
static OSet* ocacheL2 = NULL;
-static void* ocacheL2_malloc ( HChar* cc, SizeT szB ) {
+static void* ocacheL2_malloc ( const HChar* cc, SizeT szB ) {
return VG_(malloc)(cc, szB);
}
static void ocacheL2_free ( void* v ) {
return seed;
}
-static void* allocate_node(HChar* cc, SizeT szB)
+static void* allocate_node(const HChar* cc, SizeT szB)
{ return malloc(szB); }
static void free_node(void* p)
//---------------------------------------------------------------------------
-// Word example
+// UWord example
//---------------------------------------------------------------------------
// This example shows that an element can be a single value (in this
void example1singleset(OSet* oset, char *descr)
{
Int i, n;
- Word v, prev;
- Word* vs[NN];
- Word *pv;
+ UWord v, prev;
+ UWord* vs[NN];
+ UWord *pv;
// Try some operations on an empty OSet to ensure they don't screw up.
vg_assert( ! VG_(OSetGen_Contains)(oset, &v) );
}
seed = 0;
for (i = 0; i < NN; i++) {
- Word r1 = myrandom() % NN;
- Word r2 = myrandom() % NN;
- Word* tmp= vs[r1];
+ UWord r1 = myrandom() % NN;
+ UWord r2 = myrandom() % NN;
+ UWord* tmp= vs[r1];
vs[r1] = vs[r2];
vs[r2] = tmp;
}
NULL,
allocate_node, "oset_test.1",
free_node,
- 101, sizeof(Word));
+ 101, sizeof(UWord));
example1singleset(oset, "single oset, pool allocator");
// Destroy the OSet
(0,
NULL,
allocate_node, "oset_test.1", free_node,
- 101, sizeof(Word));
+ 101, sizeof(UWord));
oset_empty_clone = VG_(OSetGen_EmptyClone) (oset);
example1singleset(oset, "oset, shared pool");
example1singleset(oset_empty_clone, "cloned oset, shared pool");
void example1b(void)
{
Int i, n;
- Word v = 0, prev;
- Word vs[NN];
+ UWord v = 0, prev;
+ UWord vs[NN];
// Create a static OSet of Ints. This one uses fast (built-in)
// comparisons.
}
seed = 0;
for (i = 0; i < NN; i++) {
- Word r1 = myrandom() % NN;
- Word r2 = myrandom() % NN;
- Word tmp = vs[r1];
+ UWord r1 = myrandom() % NN;
+ UWord r2 = myrandom() % NN;
+ UWord tmp = vs[r1];
vs[r1] = vs[r2];
vs[r2] = tmp;
}
prev = -1;
VG_(OSetWord_ResetIter)(oset);
while ( VG_(OSetWord_Next)(oset, &v) ) {
- Word curr = v;
+ UWord curr = v;
assert(prev < curr);
prev = curr;
n++;