Mark Wielaard 79b01d
commit b28a423827a1c7917c6f3f3eba23b9432077dfbd
Mark Wielaard 79b01d
Author: florian <florian@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Mark Wielaard 79b01d
Date:   Sat Jan 16 21:44:31 2016 +0000
Mark Wielaard 79b01d
Mark Wielaard 79b01d
    In ML_(am_allocate_segname) do not set the reference count of the
Mark Wielaard 79b01d
    slot to 1. Rather do that in add_segment which is where the segment
Mark Wielaard 79b01d
    refering to that name actually comes into existence.
Mark Wielaard 79b01d
    Properly handle the case in add_segment where the to-be-added segment
Mark Wielaard 79b01d
    and one (or more) of the segments it replaces have the same name
Mark Wielaard 79b01d
    This may occur when doing a mremap.
Mark Wielaard 79b01d
    
Mark Wielaard 79b01d
    
Mark Wielaard 79b01d
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15761 a5019735-40e9-0310-863c-91ae7b9d1cf9
Mark Wielaard 79b01d
Mark Wielaard 79b01d
diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c
Mark Wielaard 79b01d
index 0a8f675..f6c1a41 100644
Mark Wielaard 79b01d
--- a/coregrind/m_aspacemgr/aspacemgr-linux.c
Mark Wielaard 79b01d
+++ b/coregrind/m_aspacemgr/aspacemgr-linux.c
Mark Wielaard 79b01d
@@ -1445,6 +1445,15 @@ static void add_segment ( const NSegment* seg )
Mark Wielaard 79b01d
 
Mark Wielaard 79b01d
    split_nsegments_lo_and_hi( sStart, sEnd, &iLo, &iHi );
Mark Wielaard 79b01d
 
Mark Wielaard 79b01d
+   /* Increase the reference count of SEG's name. We need to do this
Mark Wielaard 79b01d
+      *before* decreasing the reference count of the names of the replaced
Mark Wielaard 79b01d
+      segments. Consider the case where the segment name of SEG and one of
Mark Wielaard 79b01d
+      the replaced segments are the same. If the refcount of that name is 1,
Mark Wielaard 79b01d
+      then decrementing first would put the slot for that name on the free
Mark Wielaard 79b01d
+      list. Attempting to increment the refcount later would then fail
Mark Wielaard 79b01d
+      because the slot is no longer allocated. */
Mark Wielaard 79b01d
+   ML_(am_inc_refcount)(seg->fnIdx);
Mark Wielaard 79b01d
+
Mark Wielaard 79b01d
    /* Now iLo .. iHi inclusive is the range of segment indices which
Mark Wielaard 79b01d
       seg will replace.  If we're replacing more than one segment,
Mark Wielaard 79b01d
       slide those above the range down to fill the hole. Before doing
Mark Wielaard 79b01d
diff --git a/coregrind/m_aspacemgr/aspacemgr-segnames.c b/coregrind/m_aspacemgr/aspacemgr-segnames.c
Mark Wielaard 79b01d
index ef3d3ef..8e74356 100644
Mark Wielaard 79b01d
--- a/coregrind/m_aspacemgr/aspacemgr-segnames.c
Mark Wielaard 79b01d
+++ b/coregrind/m_aspacemgr/aspacemgr-segnames.c
Mark Wielaard 79b01d
@@ -309,7 +309,7 @@ ML_(am_allocate_segname)(const HChar *name)
Mark Wielaard 79b01d
             freeslot_chain = next_freeslot;
Mark Wielaard 79b01d
          else
Mark Wielaard 79b01d
             put_slotindex(prev, next_freeslot);
Mark Wielaard 79b01d
-         put_refcount(ix, 1);
Mark Wielaard 79b01d
+         put_refcount(ix, 0);
Mark Wielaard 79b01d
          put_slotsize(ix, size);
Mark Wielaard 79b01d
          VG_(strcpy)(segnames + ix, name);
Mark Wielaard 79b01d
          ++num_segnames;
Mark Wielaard 79b01d
@@ -336,7 +336,7 @@ ML_(am_allocate_segname)(const HChar *name)
Mark Wielaard 79b01d
 
Mark Wielaard 79b01d
    /* copy it in */
Mark Wielaard 79b01d
    ix = segnames_used;
Mark Wielaard 79b01d
-   put_refcount(ix, 1);
Mark Wielaard 79b01d
+   put_refcount(ix, 0);
Mark Wielaard 79b01d
    put_slotsize(ix, len + 1);
Mark Wielaard 79b01d
    VG_(strcpy)(segnames + ix, name);
Mark Wielaard 79b01d
    segnames_used += need;
Mark Wielaard 2279cb
commit e345eb50c0c5e96ac60b2bc21fbe9f281c20b9e6
Mark Wielaard 2279cb
Author: florian <florian@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Mark Wielaard 2279cb
Date:   Sat Jan 16 21:12:57 2016 +0000
Mark Wielaard 2279cb
Mark Wielaard 2279cb
    Remove code that has no effect. Looks like a leftover from early
Mark Wielaard 2279cb
    debugging days.
Mark Wielaard 2279cb
    
Mark Wielaard 2279cb
    
Mark Wielaard 2279cb
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15760 a5019735-40e9-0310-863c-91ae7b9d1cf9
Mark Wielaard 2279cb
Mark Wielaard 2279cb
diff --git a/coregrind/m_aspacemgr/aspacemgr-segnames.c b/coregrind/m_aspacemgr/aspacemgr-segnames.c
Mark Wielaard 2279cb
index 761608d..ef3d3ef 100644
Mark Wielaard 2279cb
--- a/coregrind/m_aspacemgr/aspacemgr-segnames.c
Mark Wielaard 2279cb
+++ b/coregrind/m_aspacemgr/aspacemgr-segnames.c
Mark Wielaard 2279cb
@@ -250,9 +250,7 @@ dec_refcount(UInt ix)
Mark Wielaard 2279cb
          UInt size = get_slotsize(ix);
Mark Wielaard 2279cb
          /* Chain this slot in the freelist */
Mark Wielaard 2279cb
          put_slotindex(ix, freeslot_chain);
Mark Wielaard 2279cb
-         get_slotindex(ix);
Mark Wielaard 2279cb
          put_slotsize(ix + slotsize_size, size);
Mark Wielaard 2279cb
-         get_slotindex(ix);
Mark Wielaard 2279cb
          freeslot_chain = ix;
Mark Wielaard 2279cb
          --num_segnames;
Mark Wielaard 2279cb
          if (0) VG_(am_show_nsegments)(0, "AFTER DECREASE rc -> 0");