|
From: <sv...@va...> - 2005-08-24 22:38:04
|
Author: njn
Date: 2005-08-24 23:38:00 +0100 (Wed, 24 Aug 2005)
New Revision: 4492
Log:
Fix a problem I introduced in r4208 when reducing the space used by
heap blocks. The minimum size for redzones is now sizeof(void*), but
I forgot to ensure this. Massif was asking for 0 byte redzones, and this
was screwing things up on 64-bit platforms, and Massif was dying very
quickly. This should fix bugs #111090 and #111285.
The fact that Massif was this badly broken but there were only 2 bug repo=
rts
indicates that not many people are using it, at least not on AMD64.
I also added a regtest that does some basic malloc/realloc/free testing
for Massif, which would have caught this problem.
Added:
trunk/massif/tests/basic_malloc.c
trunk/massif/tests/basic_malloc.stderr.exp
trunk/massif/tests/basic_malloc.vgtest
Modified:
trunk/coregrind/m_mallocfree.c
trunk/massif/tests/Makefile.am
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-08-24 19:55:51 UTC (rev 4491)
+++ trunk/coregrind/m_mallocfree.c 2005-08-24 22:38:00 UTC (rev 4492)
@@ -59,9 +59,9 @@
/* Layout of an in-use block:
=20
this block total szB (sizeof(SizeT) bytes)
- red zone bytes (depends on Arena.rz_szB, but > sizeof(vo=
id*))
+ red zone bytes (depends on Arena.rz_szB, but >=3D sizeof=
(void*))
(payload bytes)
- red zone bytes (depends on Arena.rz_szB, but > sizeof(vo=
id*))
+ red zone bytes (depends on Arena.rz_szB, but >=3D sizeof=
(void*))
this block total szB (sizeof(SizeT) bytes)
=20
Layout of a block on the free list:
@@ -375,7 +375,12 @@
SizeT i;
Arena* a =3D arenaId_to_ArenaP(aid);
=20
- vg_assert(rz_szB < 128); // ensure reasonable size
+ // Ensure redzones are a reasonable size. They must always be at lea=
st
+ // the size of a pointer, for holding the prev/next pointer (see the =
layout
+ // details at the top of this file).
+ vg_assert(rz_szB < 128);
+ if (rz_szB < sizeof(void*)) rz_szB =3D sizeof(void*);
+ =20
vg_assert((min_sblock_szB % VKI_PAGE_SIZE) =3D=3D 0);
a->name =3D name;
a->clientmem =3D ( VG_AR_CLIENT =3D=3D aid ? True : False );
Modified: trunk/massif/tests/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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/tests/Makefile.am 2005-08-24 19:55:51 UTC (rev 4491)
+++ trunk/massif/tests/Makefile.am 2005-08-24 22:38:00 UTC (rev 4492)
@@ -1,7 +1,13 @@
noinst_SCRIPTS =3D filter_stderr
=20
EXTRA_DIST =3D $(noinst_SCRIPTS) \
+ basic_malloc.stderr.exp basic_malloc.vgtest \
toobig-allocs.stderr.exp toobig-allocs.vgtest \
true_html.stderr.exp true_html.vgtest \
true_text.stderr.exp true_text.vgtest
=20
+AM_CFLAGS =3D $(WERROR) -Winline -Wall -Wshadow -g=20
+
+check_PROGRAMS =3D \
+ basic_malloc
+
Added: trunk/massif/tests/basic_malloc.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/tests/basic_malloc.c 2005-08-24 19:55:51 UTC (rev 4491)
+++ trunk/massif/tests/basic_malloc.c 2005-08-24 22:38:00 UTC (rev 4492)
@@ -0,0 +1,31 @@
+// In 3.0.0, Massif was badly broken on 64-bit platforms because it aske=
d
+// zero-sized redzones, and the allocator was forgetting to round the si=
ze
+// up to sizeof(void*), which is the minimum. This caused bugs #111090 =
and
+// #111285. This test is just a gentle allocation exercise which was
+// failing.
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NN 100
+
+int main(void)
+{=20
+ int i;
+ char* a[NN];
+
+ for (i =3D i; i < NN; i++) {
+ a[i] =3D malloc(i);
+ }
+ =20
+ for (i =3D i; i < NN; i++) {
+ a[i] =3D realloc(a[i], NN - i);
+ }
+ =20
+ for (i =3D i; i < NN; i++) {
+ free(a[i]);
+ }
+ =20
+ return 0;
+}
+
Added: trunk/massif/tests/basic_malloc.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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/tests/basic_malloc.stderr.exp 2005-08-24 19:55:51 UTC (r=
ev 4491)
+++ trunk/massif/tests/basic_malloc.stderr.exp 2005-08-24 22:38:00 UTC (r=
ev 4492)
@@ -0,0 +1,6 @@
+
+
+Total spacetime: =20
+heap: =20
+heap admin: =20
+stack(s): =20
Added: trunk/massif/tests/basic_malloc.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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/tests/basic_malloc.vgtest 2005-08-24 19:55:51 UTC (rev 4=
491)
+++ trunk/massif/tests/basic_malloc.vgtest 2005-08-24 22:38:00 UTC (rev 4=
492)
@@ -0,0 +1,2 @@
+prog: basic_malloc
+cleanup: rm massif.*.*
|