ac_expensive_sanity_check);
VG_(needs_shadow_memory) ();
- VG_(malloc_funcs) (MAC_(malloc),
+ VG_(needs_malloc_replacement) (MAC_(malloc),
MAC_(__builtin_new),
MAC_(__builtin_vec_new),
MAC_(memalign),
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_profile.h"
+#include "pub_core_tooliface.h"
#include "valgrind.h"
//zz#include "memcheck/memcheck.h"
}
}
-static Bool init_done = False;
-static SizeT client_malloc_redzone_szB = 8; // default: be paranoid
-
-// Nb: this must be called before the client arena is initialised, ie.
-// before any memory is allocated.
-void VG_(set_client_malloc_redzone_szB)(SizeT rz_szB)
-{
- if (init_done) {
- VG_(printf)(
- "\nTool error:\n"
- "%s cannot be called after the first allocation.\n",
- __PRETTY_FUNCTION__);
- VG_(exit)(1);
- }
- // This limit is no special figure, just something not too big
- if (rz_szB > 128) {
- VG_(printf)(
- "\nTool error:\n"
- " %s passed a too-big value (%llu)",
- __PRETTY_FUNCTION__, (ULong)rz_szB);
- VG_(exit)(1);
- }
- client_malloc_redzone_szB = rz_szB;
-}
-
/* This library is self-initialising, as it makes this more self-contained,
less coupled with the outside world. Hence VG_(arena_malloc)() and
VG_(arena_free)() below always call ensure_mm_init() to ensure things are
static
void ensure_mm_init ( void )
{
+ static Bool init_done = False;
+ static SizeT client_redzone_szB = 8; // default: be paranoid
+
if (init_done) {
+ // This assertion ensures that a tool cannot try to change the client
+ // redzone size with VG_(needs_malloc_replacement)() after this module
+ // has done its first allocation.
+ if (VG_(needs).malloc_replacement)
+ vg_assert(client_redzone_szB == VG_(tdict).tool_client_redzone_szB);
return;
}
+ if (VG_(needs).malloc_replacement) {
+ client_redzone_szB = VG_(tdict).tool_client_redzone_szB;
+ // 128 is no special figure, just something not too big
+ if (client_redzone_szB > 128) {
+ VG_(printf)( "\nTool error:\n"
+ " specified redzone size is too big (%llu)\n",
+ (ULong)client_redzone_szB);
+ VG_(exit)(1);
+ }
+ }
+
/* Use checked red zones (of various sizes) for our internal stuff,
and an unchecked zone of arbitrary size for the client. Of
course the client's red zone can be checked by the tool, eg.
arena_init ( VG_AR_CORE, "core", 4, CORE_ARENA_MIN_SZB );
arena_init ( VG_AR_TOOL, "tool", 4, 1048576 );
arena_init ( VG_AR_SYMTAB, "symtab", 4, 1048576 );
- arena_init ( VG_AR_CLIENT, "client", client_malloc_redzone_szB, 1048576 );
+ arena_init ( VG_AR_CLIENT, "client", client_redzone_szB, 1048576 );
arena_init ( VG_AR_DEMANGLE, "demangle", 12/*paranoid*/, 65536 );
arena_init ( VG_AR_EXECTXT, "exectxt", 4, 65536 );
arena_init ( VG_AR_ERRORS, "errors", 4, 65536 );
case VG_USERREQ__GET_MALLOCFUNCS: {
struct vg_mallocfunc_info *info = (struct vg_mallocfunc_info *)arg[1];
- info->tl_malloc = VG_(tdict).malloc_malloc;
- info->tl_calloc = VG_(tdict).malloc_calloc;
- info->tl_realloc = VG_(tdict).malloc_realloc;
- info->tl_memalign = VG_(tdict).malloc_memalign;
- info->tl___builtin_new = VG_(tdict).malloc___builtin_new;
- info->tl___builtin_vec_new = VG_(tdict).malloc___builtin_vec_new;
- info->tl_free = VG_(tdict).malloc_free;
- info->tl___builtin_delete = VG_(tdict).malloc___builtin_delete;
- info->tl___builtin_vec_delete = VG_(tdict).malloc___builtin_vec_delete;
+ info->tl_malloc = VG_(tdict).tool_malloc;
+ info->tl_calloc = VG_(tdict).tool_calloc;
+ info->tl_realloc = VG_(tdict).tool_realloc;
+ info->tl_memalign = VG_(tdict).tool_memalign;
+ info->tl___builtin_new = VG_(tdict).tool___builtin_new;
+ info->tl___builtin_vec_new = VG_(tdict).tool___builtin_vec_new;
+ info->tl_free = VG_(tdict).tool_free;
+ info->tl___builtin_delete = VG_(tdict).tool___builtin_delete;
+ info->tl___builtin_vec_delete = VG_(tdict).tool___builtin_vec_delete;
info->arena_payload_szB = VG_(arena_payload_szB);
info->clo_trace_malloc = VG_(clo_trace_malloc);
*/
#include "pub_core_basics.h"
-#include "pub_core_mallocfree.h" // For VG_(set_client_malloc_redzone_szB)()
#include "pub_core_tooliface.h"
// The core/tool dictionary of functions (initially zeroed, as we want it)
.tool_errors = False,
.libc_freeres = False,
.basic_block_discards = False,
- .no_longer_used_1 = False,
.command_line_options = False,
.client_requests = False,
- .no_longer_used_0 = False,
.syscall_wrapper = False,
.sanity_checks = False,
.data_syms = False,
.shadow_memory = False,
+ .malloc_replacement = False,
};
/* static */
VG_(tdict).tool_expensive_sanity_check = expen;
}
-
-/*--------------------------------------------------------------------*/
-/* Replacing malloc() */
-
-extern void VG_(malloc_funcs)(
+void VG_(needs_malloc_replacement)(
void* (*malloc) ( ThreadId, SizeT ),
void* (*__builtin_new) ( ThreadId, SizeT ),
void* (*__builtin_vec_new) ( ThreadId, SizeT ),
SizeT client_malloc_redzone_szB
)
{
- VG_(tdict).malloc_malloc = malloc;
- VG_(tdict).malloc___builtin_new = __builtin_new;
- VG_(tdict).malloc___builtin_vec_new = __builtin_vec_new;
- VG_(tdict).malloc_memalign = memalign;
- VG_(tdict).malloc_calloc = calloc;
- VG_(tdict).malloc_free = free;
- VG_(tdict).malloc___builtin_delete = __builtin_delete;
- VG_(tdict).malloc___builtin_vec_delete = __builtin_vec_delete;
- VG_(tdict).malloc_realloc = realloc;
-
- VG_(set_client_malloc_redzone_szB)( client_malloc_redzone_szB );
+ VG_(needs).malloc_replacement = True;
+ VG_(tdict).tool_malloc = malloc;
+ VG_(tdict).tool___builtin_new = __builtin_new;
+ VG_(tdict).tool___builtin_vec_new = __builtin_vec_new;
+ VG_(tdict).tool_memalign = memalign;
+ VG_(tdict).tool_calloc = calloc;
+ VG_(tdict).tool_free = free;
+ VG_(tdict).tool___builtin_delete = __builtin_delete;
+ VG_(tdict).tool___builtin_vec_delete = __builtin_vec_delete;
+ VG_(tdict).tool_realloc = realloc;
+ VG_(tdict).tool_client_redzone_szB = client_malloc_redzone_szB;
}
Bool core_errors;
Bool tool_errors;
Bool basic_block_discards;
- Bool no_longer_used_1; // for backwards compatibility
Bool command_line_options;
Bool client_requests;
- Bool no_longer_used_0; // for backwards compatibility
Bool syscall_wrapper;
Bool sanity_checks;
Bool data_syms;
Bool shadow_memory;
+ Bool malloc_replacement;
}
VgNeeds;
Bool (*tool_cheap_sanity_check)(void);
Bool (*tool_expensive_sanity_check)(void);
+ // VG_(needs).malloc_replacement
+ void* (*tool_malloc) (ThreadId, SizeT);
+ void* (*tool___builtin_new) (ThreadId, SizeT);
+ void* (*tool___builtin_vec_new) (ThreadId, SizeT);
+ void* (*tool_memalign) (ThreadId, SizeT, SizeT);
+ void* (*tool_calloc) (ThreadId, SizeT, SizeT);
+ void (*tool_free) (ThreadId, void*);
+ void (*tool___builtin_delete) (ThreadId, void*);
+ void (*tool___builtin_vec_delete)(ThreadId, void*);
+ void* (*tool_realloc) (ThreadId, void*, SizeT);
+ SizeT tool_client_redzone_szB;
+
// -- Event tracking functions ------------------------------------
void (*track_new_mem_startup) (Addr, SizeT, Bool, Bool, Bool);
void (*track_new_mem_stack_signal)(Addr, SizeT);
void (*track_init_shadow_page)(Addr);
- // -- malloc/free replacements -----------------------------------
- void* (*malloc_malloc) (ThreadId, SizeT);
- void* (*malloc___builtin_new) (ThreadId, SizeT);
- void* (*malloc___builtin_vec_new) (ThreadId, SizeT);
- void* (*malloc_memalign) (ThreadId, SizeT, SizeT);
- void* (*malloc_calloc) (ThreadId, SizeT, SizeT);
- void (*malloc_free) (ThreadId, void*);
- void (*malloc___builtin_delete) (ThreadId, void*);
- void (*malloc___builtin_vec_delete)(ThreadId, void*);
- void* (*malloc_realloc) (ThreadId, void*, SizeT);
-
} VgToolInterface;
extern VgToolInterface VG_(tdict);
hg_print_debug_usage);
VG_(needs_shadow_memory) ();
- VG_(malloc_funcs) (hg_malloc,
+ VG_(needs_malloc_replacement) (hg_malloc,
hg___builtin_new,
hg___builtin_vec_new,
hg_memalign,
/* Does the tool need shadow memory allocated? */
extern void VG_(needs_shadow_memory)( void );
-/* ------------------------------------------------------------------ */
-/* Malloc replacement */
-
+/* Does the tool replace malloc() and friends with its own versions? */
// The 'p' prefix avoids GCC complaints about overshadowing global names.
-extern void VG_(malloc_funcs)(
+extern void VG_(needs_malloc_replacement)(
void* (*pmalloc) ( ThreadId tid, SizeT n ),
void* (*p__builtin_new) ( ThreadId tid, SizeT n ),
void* (*p__builtin_vec_new) ( ThreadId tid, SizeT n ),
ms_print_usage,
ms_print_debug_usage);
VG_(needs_client_requests) (ms_handle_client_request);
-
- // Malloc replacement
- VG_(malloc_funcs) (ms_malloc,
+ VG_(needs_malloc_replacement) (ms_malloc,
ms___builtin_new,
ms___builtin_vec_new,
ms_memalign,
mc_expensive_sanity_check);
VG_(needs_shadow_memory) ();
- VG_(malloc_funcs) (MAC_(malloc),
+ VG_(needs_malloc_replacement) (MAC_(malloc),
MAC_(__builtin_new),
MAC_(__builtin_vec_new),
MAC_(memalign),