|
From: <sv...@va...> - 2005-06-21 03:20:54
|
Author: njn
Date: 2005-06-21 04:20:17 +0100 (Tue, 21 Jun 2005)
New Revision: 3979
Log:
Malloc replacement worked very much like a 'need', but wasn't one.
I've changed it so it now is, which makes it consistent with the
other 'needs'. Because of this, I was also able to invert the dependence
between m_mallocfree and m_tooliface, which is related to setting
the redzone size for client heap blocks. As a result, m_tooliface
now doesn't depend on anything except pub_core_basics.h, hooray!
=20
Modified:
trunk/addrcheck/ac_main.c
trunk/coregrind/m_mallocfree.c
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/m_tooliface.c
trunk/coregrind/pub_core_tooliface.h
trunk/helgrind/hg_main.c
trunk/include/pub_tool_tooliface.h
trunk/massif/ms_main.c
trunk/memcheck/mc_main.c
Modified: trunk/addrcheck/ac_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/addrcheck/ac_main.c 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/addrcheck/ac_main.c 2005-06-21 03:20:17 UTC (rev 3979)
@@ -1344,7 +1344,7 @@
ac_expensive_sanity_check);
VG_(needs_shadow_memory) ();
=20
- VG_(malloc_funcs) (MAC_(malloc),
+ VG_(needs_malloc_replacement) (MAC_(malloc),
MAC_(__builtin_new),
MAC_(__builtin_vec_new),
MAC_(memalign),
Modified: trunk/coregrind/m_mallocfree.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_mallocfree.c 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/coregrind/m_mallocfree.c 2005-06-21 03:20:17 UTC (rev 3979)
@@ -37,6 +37,7 @@
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_profile.h"
+#include "pub_core_tooliface.h"
#include "valgrind.h"
=20
//zz#include "memcheck/memcheck.h"
@@ -386,31 +387,6 @@
}
}
=20
-static Bool init_done =3D False;
-static SizeT client_malloc_redzone_szB =3D 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)",=20
- __PRETTY_FUNCTION__, (ULong)rz_szB);
- VG_(exit)(1);
- }
- client_malloc_redzone_szB =3D rz_szB;
-}
-
/* This library is self-initialising, as it makes this more self-contain=
ed,
less coupled with the outside world. Hence VG_(arena_malloc)() and
VG_(arena_free)() below always call ensure_mm_init() to ensure things=
are
@@ -418,10 +394,29 @@
static
void ensure_mm_init ( void )
{
+ static Bool init_done =3D False;
+ static SizeT client_redzone_szB =3D 8; // default: be paranoid
+
if (init_done) {
+ // This assertion ensures that a tool cannot try to change the cli=
ent
+ // redzone size with VG_(needs_malloc_replacement)() after this mo=
dule
+ // has done its first allocation.
+ if (VG_(needs).malloc_replacement)
+ vg_assert(client_redzone_szB =3D=3D VG_(tdict).tool_client_redz=
one_szB);
return;
}
=20
+ if (VG_(needs).malloc_replacement) {
+ client_redzone_szB =3D 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",=20
+ (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.=20
@@ -437,7 +432,7 @@
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, 10=
48576 );
+ 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 );
Modified: trunk/coregrind/m_scheduler/scheduler.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_scheduler/scheduler.c 2005-06-21 01:54:38 UTC (rev =
3978)
+++ trunk/coregrind/m_scheduler/scheduler.c 2005-06-21 03:20:17 UTC (rev =
3979)
@@ -980,15 +980,15 @@
case VG_USERREQ__GET_MALLOCFUNCS: {
struct vg_mallocfunc_info *info =3D (struct vg_mallocfunc_info *)arg[1=
];
=20
- info->tl_malloc =3D VG_(tdict).malloc_malloc;
- info->tl_calloc =3D VG_(tdict).malloc_calloc;
- info->tl_realloc =3D VG_(tdict).malloc_realloc;
- info->tl_memalign =3D VG_(tdict).malloc_memalign;
- info->tl___builtin_new =3D VG_(tdict).malloc___builtin_new;
- info->tl___builtin_vec_new =3D VG_(tdict).malloc___builtin_vec_new;
- info->tl_free =3D VG_(tdict).malloc_free;
- info->tl___builtin_delete =3D VG_(tdict).malloc___builtin_delete;
- info->tl___builtin_vec_delete =3D VG_(tdict).malloc___builtin_vec_dele=
te;
+ info->tl_malloc =3D VG_(tdict).tool_malloc;
+ info->tl_calloc =3D VG_(tdict).tool_calloc;
+ info->tl_realloc =3D VG_(tdict).tool_realloc;
+ info->tl_memalign =3D VG_(tdict).tool_memalign;
+ info->tl___builtin_new =3D VG_(tdict).tool___builtin_new;
+ info->tl___builtin_vec_new =3D VG_(tdict).tool___builtin_vec_new;
+ info->tl_free =3D VG_(tdict).tool_free;
+ info->tl___builtin_delete =3D VG_(tdict).tool___builtin_delete;
+ info->tl___builtin_vec_delete =3D VG_(tdict).tool___builtin_vec_delete=
;
=20
info->arena_payload_szB =3D VG_(arena_payload_szB);
info->clo_trace_malloc =3D VG_(clo_trace_malloc);
Modified: trunk/coregrind/m_tooliface.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_tooliface.c 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/coregrind/m_tooliface.c 2005-06-21 03:20:17 UTC (rev 3979)
@@ -30,7 +30,6 @@
*/
=20
#include "pub_core_basics.h"
-#include "pub_core_mallocfree.h" // For VG_(set_client_malloc_redzone=
_szB)()
#include "pub_core_tooliface.h"
=20
// The core/tool dictionary of functions (initially zeroed, as we want i=
t)
@@ -87,14 +86,13 @@
.tool_errors =3D False,
.libc_freeres =3D False,
.basic_block_discards =3D False,
- .no_longer_used_1 =3D False,
.command_line_options =3D False,
.client_requests =3D False,
- .no_longer_used_0 =3D False,
.syscall_wrapper =3D False,
.sanity_checks =3D False,
.data_syms =3D False,
.shadow_memory =3D False,
+ .malloc_replacement =3D False,
};
=20
/* static */
@@ -233,11 +231,7 @@
VG_(tdict).tool_expensive_sanity_check =3D expen;
}
=20
-
-/*--------------------------------------------------------------------*/
-/* 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 ),
@@ -250,17 +244,17 @@
SizeT client_malloc_redzone_szB
)
{
- VG_(tdict).malloc_malloc =3D malloc;
- VG_(tdict).malloc___builtin_new =3D __builtin_new;
- VG_(tdict).malloc___builtin_vec_new =3D __builtin_vec_new;
- VG_(tdict).malloc_memalign =3D memalign;
- VG_(tdict).malloc_calloc =3D calloc;
- VG_(tdict).malloc_free =3D free;
- VG_(tdict).malloc___builtin_delete =3D __builtin_delete;
- VG_(tdict).malloc___builtin_vec_delete =3D __builtin_vec_delete;
- VG_(tdict).malloc_realloc =3D realloc;
-
- VG_(set_client_malloc_redzone_szB)( client_malloc_redzone_szB );
+ VG_(needs).malloc_replacement =3D True;
+ VG_(tdict).tool_malloc =3D malloc;
+ VG_(tdict).tool___builtin_new =3D __builtin_new;
+ VG_(tdict).tool___builtin_vec_new =3D __builtin_vec_new;
+ VG_(tdict).tool_memalign =3D memalign;
+ VG_(tdict).tool_calloc =3D calloc;
+ VG_(tdict).tool_free =3D free;
+ VG_(tdict).tool___builtin_delete =3D __builtin_delete;
+ VG_(tdict).tool___builtin_vec_delete =3D __builtin_vec_delete;
+ VG_(tdict).tool_realloc =3D realloc;
+ VG_(tdict).tool_client_redzone_szB =3D client_malloc_redzone_szB;
}
=20
=20
Modified: trunk/coregrind/pub_core_tooliface.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_tooliface.h 2005-06-21 01:54:38 UTC (rev 397=
8)
+++ trunk/coregrind/pub_core_tooliface.h 2005-06-21 03:20:17 UTC (rev 397=
9)
@@ -84,14 +84,13 @@
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;
}=20
VgNeeds;
=20
@@ -141,6 +140,18 @@
Bool (*tool_cheap_sanity_check)(void);
Bool (*tool_expensive_sanity_check)(void);
=20
+ // 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);
@@ -192,17 +203,6 @@
=20
void (*track_init_shadow_page)(Addr);
=20
- // -- 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;
=20
extern VgToolInterface VG_(tdict);
Modified: trunk/helgrind/hg_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/helgrind/hg_main.c 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/helgrind/hg_main.c 2005-06-21 03:20:17 UTC (rev 3979)
@@ -3392,7 +3392,7 @@
hg_print_debug_usage);
VG_(needs_shadow_memory) ();
=20
- VG_(malloc_funcs) (hg_malloc,
+ VG_(needs_malloc_replacement) (hg_malloc,
hg___builtin_new,
hg___builtin_vec_new,
hg_memalign,
Modified: trunk/include/pub_tool_tooliface.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/pub_tool_tooliface.h 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/include/pub_tool_tooliface.h 2005-06-21 03:20:17 UTC (rev 3979)
@@ -253,11 +253,9 @@
/* Does the tool need shadow memory allocated? */
extern void VG_(needs_shadow_memory)( void );
=20
-/* ------------------------------------------------------------------ */
-/* 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 ),
Modified: trunk/massif/ms_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/massif/ms_main.c 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/massif/ms_main.c 2005-06-21 03:20:17 UTC (rev 3979)
@@ -1802,9 +1802,7 @@
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,
Modified: trunk/memcheck/mc_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/mc_main.c 2005-06-21 01:54:38 UTC (rev 3978)
+++ trunk/memcheck/mc_main.c 2005-06-21 03:20:17 UTC (rev 3979)
@@ -2554,7 +2554,7 @@
mc_expensive_sanity_check);
VG_(needs_shadow_memory) ();
=20
- VG_(malloc_funcs) (MAC_(malloc),
+ VG_(needs_malloc_replacement) (MAC_(malloc),
MAC_(__builtin_new),
MAC_(__builtin_vec_new),
MAC_(memalign),
|