]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge r6003,4 (fix for: cachegrind/callgrind causes executable to die)
authorJulian Seward <jseward@acm.org>
Mon, 28 Aug 2006 12:28:51 +0000 (12:28 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 28 Aug 2006 12:28:51 +0000 (12:28 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6025

coregrind/m_aspacemgr/aspacemgr.c
coregrind/m_syswrap/syswrap-generic.c

index 253b062068700265809d297be30ad06d93813638..cca026f4c876184202965ff8586af328a572e591 100644 (file)
@@ -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 )
index ebb8d0578e5fb29aa18f317e561d655ee6ffa1ab..5801afce17f119b408b54fa5076da916e3ee309d 100644 (file)
@@ -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 );