|
From: <sv...@va...> - 2006-02-22 13:23:41
|
Author: dirk
Date: 2006-02-22 13:23:33 +0000 (Wed, 22 Feb 2006)
New Revision: 5678
Log:
backport "calloc does not always zero memory" (v5647)
Modified:
branches/VALGRIND_3_1_BRANCH/coregrind/m_syswrap/syswrap-generic.c
Modified: branches/VALGRIND_3_1_BRANCH/coregrind/m_syswrap/syswrap-generi=
c.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/VALGRIND_3_1_BRANCH/coregrind/m_syswrap/syswrap-generic.c 20=
06-02-22 13:22:42 UTC (rev 5677)
+++ branches/VALGRIND_3_1_BRANCH/coregrind/m_syswrap/syswrap-generic.c 20=
06-02-22 13:23:33 UTC (rev 5678)
@@ -947,6 +947,23 @@
if (seg && seg->hasT)
VG_(discard_translations)( newbrk, VG_(brk_limit) - newbrk,=20
"do_brk(shrink)" );
+ /* Since we're being lazy and not unmapping pages, we have to
+ zero out the area, so that if the area later comes back into
+ circulation, it will be filled with zeroes, as if it really
+ had been unmapped and later remapped. Be a bit paranoid and
+ try hard to ensure we're not going to segfault by doing the
+ write - check both ends of the range are in the same segment
+ and that segment is writable. */
+ if (seg) {
+ /* pre: newbrk < VG_(brk_limit)=20
+ =3D> newbrk <=3D VG_(brk_limit)-1 */
+ NSegment* seg2;
+ vg_assert(newbrk < VG_(brk_limit));
+ seg2 =3D VG_(am_find_nsegment)( VG_(brk_limit)-1 );
+ if (seg2 && seg =3D=3D seg2 && seg->hasW)
+ VG_(memset)( (void*)newbrk, 0, VG_(brk_limit) - newbrk );
+ }
+
VG_(brk_limit) =3D newbrk;
return newbrk;
}
|