From: Julian Seward Date: Mon, 28 Aug 2006 12:28:51 +0000 (+0000) Subject: Merge r6003,4 (fix for: cachegrind/callgrind causes executable to die) X-Git-Tag: svn/VALGRIND_3_2_1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1ca40ae2c1ba3b51298254cf90bfcd6c9c1c9c4;p=thirdparty%2Fvalgrind.git Merge r6003,4 (fix for: cachegrind/callgrind causes executable to die) git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6025 --- diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c index 253b062068..cca026f4c8 100644 --- a/coregrind/m_aspacemgr/aspacemgr.c +++ b/coregrind/m_aspacemgr/aspacemgr.c @@ -2884,6 +2884,9 @@ Bool VG_(am_extend_map_client)( /*OUT*/Bool* need_discard, NSegment seg_copy = *seg; SizeT seg_old_len = seg->end + 1 - seg->start; + if (0) + VG_(am_show_nsegments)(0, "VG_(am_extend_map_client) BEFORE"); + if (seg->kind != SkFileC && seg->kind != SkAnonC) return False; @@ -2905,6 +2908,9 @@ Bool VG_(am_extend_map_client)( /*OUT*/Bool* need_discard, if (sres.isError) { AM_SANITY_CHECK; return False; + } else { + /* the area must not have moved */ + aspacem_assert(sres.val == seg->start); } *need_discard = any_Ts_in_range( seg_copy.end+1, delta ); @@ -2912,6 +2918,9 @@ Bool VG_(am_extend_map_client)( /*OUT*/Bool* need_discard, seg_copy.end += delta; add_segment( &seg_copy ); + if (0) + VG_(am_show_nsegments)(0, "VG_(am_extend_map_client) AFTER"); + AM_SANITY_CHECK; return True; } @@ -2964,6 +2973,8 @@ Bool VG_(am_relocate_nooverlap_client)( /*OUT*/Bool* need_discard, if (sres.isError) { AM_SANITY_CHECK; return False; + } else { + aspacem_assert(sres.val == new_addr); } *need_discard = any_Ts_in_range( old_addr, old_len ) diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index ebb8d0578e..5801afce17 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -187,6 +187,8 @@ SysRes do_mremap( Addr old_addr, SizeT old_len, old_addr,old_len,new_addr,new_len, flags & VKI_MREMAP_MAYMOVE ? "MAYMOVE" : "", flags & VKI_MREMAP_FIXED ? "FIXED" : ""); + if (0) + VG_(am_show_nsegments)(0, "do_remap: before"); if (flags & ~(VKI_MREMAP_FIXED | VKI_MREMAP_MAYMOVE)) goto eINVAL; @@ -327,6 +329,18 @@ SysRes do_mremap( Addr old_addr, SizeT old_len, /* VG_(am_get_advisory_client_simple) interprets zero to mean non-fixed, which is not what we want */ advised = VG_(am_get_advisory_client_simple)( needA, needL, &ok ); + if (ok) { + /* VG_(am_get_advisory_client_simple) (first arg == 0, meaning + this-or-nothing) is too lenient, and may allow us to trash + the next segment along. So make very sure that the proposed + new area really is free. This is perhaps overly + conservative, but it fixes #129866. */ + NSegment* segLo = VG_(am_find_nsegment)( needA ); + NSegment* segHi = VG_(am_find_nsegment)( needA + needL - 1 ); + if (segLo == NULL || segHi == NULL + || segLo != segHi || segLo->kind != SkFree) + ok = False; + } if (ok && advised == needA) { ok = VG_(am_extend_map_client)( &d, old_seg, needL ); if (ok) { @@ -374,6 +388,17 @@ SysRes do_mremap( Addr old_addr, SizeT old_len, /* VG_(am_get_advisory_client_simple) interprets zero to mean non-fixed, which is not what we want */ advised = VG_(am_get_advisory_client_simple)( needA, needL, &ok ); + if (ok) { + /* VG_(am_get_advisory_client_simple) (first arg == 0, meaning + this-or-nothing) is too lenient, and may allow us to trash + the next segment along. So make very sure that the proposed + new area really is free. */ + NSegment* segLo = VG_(am_find_nsegment)( needA ); + NSegment* segHi = VG_(am_find_nsegment)( needA + needL - 1 ); + if (segLo == NULL || segHi == NULL + || segLo != segHi || segLo->kind != SkFree) + ok = False; + } if (!ok || advised != needA) goto eNOMEM; ok = VG_(am_extend_map_client)( &d, old_seg, needL );