|
From: <sv...@va...> - 2005-09-19 19:27:56
|
Author: njn
Date: 2005-09-19 20:27:45 +0100 (Mon, 19 Sep 2005)
New Revision: 4682
Log:
Initialise the client arena after the others, so the tool has a chance
to set the redzone size beforehand.
Modified:
branches/ASPACEM/coregrind/m_mallocfree.c
Modified: branches/ASPACEM/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
--- branches/ASPACEM/coregrind/m_mallocfree.c 2005-09-19 17:12:04 UTC (re=
v 4681)
+++ branches/ASPACEM/coregrind/m_mallocfree.c 2005-09-19 19:27:45 UTC (re=
v 4682)
@@ -419,34 +419,20 @@
/* 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
- correctly initialised. */
+ correctly initialised. =20
+
+ We initialise the client arena separately (and later) because the cor=
e
+ must do non-client allocation before the tool has a chance to set the
+ client arena's redzone size.
+*/
static
-void ensure_mm_init ( void )
+void ensure_mm_init ( ArenaId aid )
{
- static Bool init_done =3D False;
- static SizeT client_redzone_szB =3D 16; //8; // default: be paranoi=
d
+ static Bool client_inited =3D False;
+ static Bool nonclient_inited =3D False;
+ static SizeT client_redzone_szB =3D 8; // default: be paranoid
=20
- 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;
- }
-
- 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,
+ /* We 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
by using addressibility maps, but not by the mechanism implemented
@@ -459,15 +445,45 @@
stays as 16 --- the extra 4 bytes in both are accounted for by the
larger prev/next ptr.
*/
- 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_redzone_szB, 1048576=
);
- arena_init ( VG_AR_DEMANGLE, "demangle", 4, 65536=
);
- arena_init ( VG_AR_EXECTXT, "exectxt", 4, 65536=
);
- arena_init ( VG_AR_ERRORS, "errors", 4, 65536=
);
+ if (VG_AR_CLIENT =3D=3D aid) {
+ if (client_inited) {
+ // 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 from the client arena.
+ if (VG_(needs).malloc_replacement)
+ vg_assert(client_redzone_szB =3D=3D VG_(tdict).tool_client_r=
edzone_szB);
+ return;
+ }
=20
- init_done =3D True;
+ // Check and set the client arena redzone size
+ 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);
+ }
+ }
+ // Initialise the client arena
+ arena_init ( VG_AR_CLIENT, "client", client_redzone_szB, 1048=
576 );
+ client_inited =3D True;
+
+ } else {
+ if (nonclient_inited) {
+ return;
+ }
+ // Initialise the non-client arenas
+ arena_init ( VG_AR_CORE, "core", 4, CORE_ARENA_MIN_=
SZB );
+ arena_init ( VG_AR_TOOL, "tool", 4, 1048=
576 );
+ arena_init ( VG_AR_SYMTAB, "symtab", 4, 1048=
576 );
+ arena_init ( VG_AR_DEMANGLE, "demangle", 4, 65=
536 );
+ arena_init ( VG_AR_EXECTXT, "exectxt", 4, 65=
536 );
+ arena_init ( VG_AR_ERRORS, "errors", 4, 65=
536 );
+ nonclient_inited =3D True;
+ }
+
# ifdef DEBUG_MALLOC
VG_(sanity_check_malloc_all)();
# endif
@@ -932,7 +948,7 @@
=20
VGP_PUSHCC(VgpMalloc);
=20
- ensure_mm_init();
+ ensure_mm_init(aid);
a =3D arenaId_to_ArenaP(aid);
=20
vg_assert(req_pszB < MAX_PSZB);
@@ -1025,7 +1041,7 @@
=20
VGP_PUSHCC(VgpMalloc);
=20
- ensure_mm_init();
+ ensure_mm_init(aid);
a =3D arenaId_to_ArenaP(aid);
=20
if (ptr =3D=3D NULL) {
@@ -1149,7 +1165,7 @@
=20
VGP_PUSHCC(VgpMalloc);
=20
- ensure_mm_init();
+ ensure_mm_init(aid);
a =3D arenaId_to_ArenaP(aid);
=20
vg_assert(req_pszB < MAX_PSZB);
@@ -1273,7 +1289,7 @@
=20
VGP_PUSHCC(VgpMalloc);
=20
- ensure_mm_init();
+ ensure_mm_init(aid);
a =3D arenaId_to_ArenaP(aid);
=20
vg_assert(req_pszB < MAX_PSZB);
|