Author: florian
Date: Wed May 13 15:02:17 2015
New Revision: 15223
Log:
Replace NSegment::isCH with NSegment::whatsit which tells what this
segment is part of: heap, stack, break area. So it's a generalisation
of sorts.
This is handy occasionally and also improves the segment listing.
The change affects the mergeability of segments. Previously, the
SkAnonC segment that makes up the mapped part of the extensible client stack
could be merged with an adjacent SkAnonC segment. This is no longer the case.
And likewise for the SkAnonC segment that is the client break area.
I'm not unduly concerned. Even before this change it was possible for
two neighbouring SkAnonC segments to exist, namely, if one was part of the
client heap (isCH == 1) and the other was not (isCH == 0).
So it was never (well.... since r4789) true that segments were "maximally
merged".
Modified:
branches/ASPACEM_TWEAKS/coregrind/m_addrinfo.c
branches/ASPACEM_TWEAKS/coregrind/m_aspacemgr/aspacemgr-linux.c
branches/ASPACEM_TWEAKS/include/pub_tool_aspacemgr.h
branches/ASPACEM_TWEAKS/memcheck/mc_leakcheck.c
Modified: branches/ASPACEM_TWEAKS/coregrind/m_addrinfo.c
==============================================================================
--- branches/ASPACEM_TWEAKS/coregrind/m_addrinfo.c (original)
+++ branches/ASPACEM_TWEAKS/coregrind/m_addrinfo.c Wed May 13 15:02:17 2015
@@ -264,10 +264,7 @@
const NSegment *seg = VG_(am_find_nsegment) (a);
/* Special case to detect the brk data segment. */
- if (seg != NULL
- && seg->kind == SkAnonC
- && VG_(brk_limit) >= seg->start
- && VG_(brk_limit) <= seg->end+1) {
+ if (seg != NULL && seg->whatsit == WiClientBreak) {
/* Address a is in a Anon Client segment which contains
VG_(brk_limit). So, this segment is the brk data segment
as initimg-linux.c:setup_client_dataseg maps an anonymous
Modified: branches/ASPACEM_TWEAKS/coregrind/m_aspacemgr/aspacemgr-linux.c
==============================================================================
--- branches/ASPACEM_TWEAKS/coregrind/m_aspacemgr/aspacemgr-linux.c (original)
+++ branches/ASPACEM_TWEAKS/coregrind/m_aspacemgr/aspacemgr-linux.c Wed May 13 15:02:17 2015
@@ -436,7 +436,7 @@
(ULong)seg->start, (ULong)seg->end, len_buf,
seg->hasR ? 'r' : '-', seg->hasW ? 'w' : '-',
seg->hasX ? 'x' : '-', seg->hasT ? 'T' : '-',
- seg->isCH ? 'H' : '-',
+ seg->whatsit,
show_ShrinkMode(seg->smode),
seg->dev, seg->ino, seg->offset,
ML_(am_segname_get_seqnr)(seg->fnIdx), seg->fnIdx,
@@ -471,7 +471,7 @@
(ULong)seg->start, (ULong)seg->end, len_buf,
seg->hasR ? 'r' : '-', seg->hasW ? 'w' : '-',
seg->hasX ? 'x' : '-', seg->hasT ? 'T' : '-',
- seg->isCH ? 'H' : '-'
+ seg->whatsit
);
break;
@@ -484,7 +484,7 @@
(ULong)seg->start, (ULong)seg->end, len_buf,
seg->hasR ? 'r' : '-', seg->hasW ? 'w' : '-',
seg->hasX ? 'x' : '-', seg->hasT ? 'T' : '-',
- seg->isCH ? 'H' : '-',
+ seg->whatsit,
seg->dev, seg->ino, seg->offset,
ML_(am_segname_get_seqnr)(seg->fnIdx), seg->fnIdx
);
@@ -498,7 +498,7 @@
(ULong)seg->start, (ULong)seg->end, len_buf,
seg->hasR ? 'r' : '-', seg->hasW ? 'w' : '-',
seg->hasX ? 'x' : '-', seg->hasT ? 'T' : '-',
- seg->isCH ? 'H' : '-',
+ seg->whatsit,
show_ShrinkMode(seg->smode)
);
break;
@@ -610,25 +610,26 @@
s->smode == SmFixed
&& s->dev == 0 && s->ino == 0 && s->offset == 0 && s->fnIdx == -1
&& !s->hasR && !s->hasW && !s->hasX && !s->hasT
- && !s->isCH;
+ && s->whatsit == WiUnknown;
case SkAnonC: case SkAnonV: case SkShmC:
return
s->smode == SmFixed
&& s->dev == 0 && s->ino == 0 && s->offset == 0 && s->fnIdx == -1
- && (s->kind==SkAnonC ? True : !s->isCH);
+ && (s->kind==SkAnonC ? True : s->whatsit == WiUnknown);
case SkFileC: case SkFileV:
return
s->smode == SmFixed
&& ML_(am_sane_segname)(s->fnIdx)
- && !s->isCH;
+ && s->whatsit == WiUnknown;
case SkResvn:
return
s->dev == 0 && s->ino == 0 && s->offset == 0 && s->fnIdx == -1
&& !s->hasR && !s->hasW && !s->hasX && !s->hasT
- && !s->isCH;
+ && (s->whatsit == WiClientBreak || s->whatsit == WiClientStack ||
+ s->whatsit == WiUnknown);
default:
return False;
@@ -660,7 +661,7 @@
case SkAnonC: case SkAnonV:
if (s1->hasR == s2->hasR && s1->hasW == s2->hasW
- && s1->hasX == s2->hasX && s1->isCH == s2->isCH) {
+ && s1->hasX == s2->hasX && s1->whatsit == s2->whatsit) {
s1->end = s2->end;
s1->hasT |= s2->hasT;
return True;
@@ -1452,7 +1453,8 @@
seg->mode = 0;
seg->offset = 0;
seg->fnIdx = -1;
- seg->hasR = seg->hasW = seg->hasX = seg->hasT = seg->isCH = False;
+ seg->hasR = seg->hasW = seg->hasX = seg->hasT = False;
+ seg->whatsit = WiUnknown;
}
/* Make an NSegment which holds a reservation. */
@@ -2592,7 +2594,7 @@
Addr addr = sr_Res(res);
Int ix = find_nsegment_idx(addr);
- nsegments[ix].isCH = True;
+ nsegments[ix].whatsit = WiClientHeap;
}
return res;
}
@@ -2735,8 +2737,8 @@
falls entirely within a single free segment. The returned Bool
indicates whether the creation succeeded. */
-static Bool create_reservation (Addr start, SizeT length,
- ShrinkMode smode, SSizeT extra)
+static Bool create_reservation (Addr start, SizeT length, ShrinkMode smode,
+ SSizeT extra, WhatsIt whatsit)
{
Int startI, endI;
NSegment seg;
@@ -2780,6 +2782,8 @@
reservation. */
seg.end = end1;
seg.smode = smode;
+ seg.whatsit = whatsit;
+
add_segment( &seg );
AM_SANITY_CHECK;
@@ -2931,7 +2935,8 @@
/* Try to create the data seg and associated reservation where
BASE says. */
- ok = create_reservation(resvn_start, resvn_size, SmLower, anon_size);
+ ok = create_reservation(resvn_start, resvn_size, SmLower, anon_size,
+ WiClientBreak);
if (!ok) {
/* Hmm, that didn't work. Well, let aspacem suggest an address
@@ -2940,7 +2945,8 @@
( 0/*floating*/, anon_size + resvn_size, &ok );
if (ok) {
resvn_start = anon_start + anon_size;
- ok = create_reservation(resvn_start, resvn_size, SmLower, anon_size);
+ ok = create_reservation(resvn_start, resvn_size, SmLower, anon_size,
+ WiClientBreak);
}
}
@@ -2949,7 +2955,12 @@
if (!ok)
return VG_(mk_SysRes_Error)( VKI_ENOMEM );
- return VG_(am_mmap_anon_fixed_client)( anon_start, anon_size, prot );
+ SysRes sres = VG_(am_mmap_anon_fixed_client)( anon_start, anon_size, prot );
+ if (! sr_isError(sres)) {
+ NSegment *seg = nsegments + find_nsegment_idx(sr_Res(sres));
+ seg->whatsit = WiClientBreak;
+ }
+ return sres;
}
/* Resize the client brk segment from OLDBRK to NEWBRK. Return an error if
@@ -3044,9 +3055,16 @@
/* Create a shrinkable reservation followed by an anonymous
segment. Together these constitute a growdown stack. */
- ok = create_reservation(resvn_start, resvn_size, SmUpper, anon_size);
- if (ok)
- return VG_(am_mmap_anon_fixed_client)( anon_start, anon_size, prot );
+ ok = create_reservation(resvn_start, resvn_size, SmUpper, anon_size,
+ WiClientStack);
+ if (ok) {
+ SysRes sres = VG_(am_mmap_anon_fixed_client)(anon_start, anon_size, prot);
+ if (! sr_isError(sres)) {
+ NSegment *seg = nsegments + find_nsegment_idx(sr_Res(sres));
+ seg->whatsit = WiClientStack;
+ }
+ return sres;
+ }
return VG_(mk_SysRes_Error)( VKI_ENOMEM );
}
@@ -3066,11 +3084,9 @@
const NSegment *seg = VG_(am_find_nsegment)(addr);
aspacem_assert(seg != NULL);
- /* TODO: the test "seg->kind == SkAnonC" is really inadequate,
- because although it tests whether the segment is mapped
- _somehow_, it doesn't check that it has the right permissions
- (r,w, maybe x) ? */
if (seg->kind == SkAnonC) {
+ /* Ought to be the extensible stack segment */
+ aspacem_assert(seg->whatsit == WiClientStack);
/* ADDR is already mapped. Nothing to do. */
*new_stack_base = seg->start; // not really "new" :)
return sres;
Modified: branches/ASPACEM_TWEAKS/include/pub_tool_aspacemgr.h
==============================================================================
--- branches/ASPACEM_TWEAKS/include/pub_tool_aspacemgr.h (original)
+++ branches/ASPACEM_TWEAKS/include/pub_tool_aspacemgr.h Wed May 13 15:02:17 2015
@@ -59,6 +59,17 @@
}
ShrinkMode;
+/* Describes what this segment is being part of. Encoding was chosen
+ to simplify printing. */
+typedef
+ enum {
+ WiClientHeap = 'H', // SkAnonC ONLY
+ WiClientStack = 'S', // SkAnonC and SkResvn ONLY
+ WiClientBreak = 'B', // SkAnonC and SkResvn ONLY
+ WiUnknown = '-'
+ }
+ WhatsIt;
+
/* Describes a segment. Invariants:
kind == SkFree:
@@ -111,7 +122,8 @@
Bool hasX;
Bool hasT; // True --> translations have (or MAY have)
// been taken from this segment
- Bool isCH; // True --> is client heap (SkAnonC ONLY)
+ /* Identifies what this segment is part of */
+ WhatsIt whatsit;
}
NSegment;
Modified: branches/ASPACEM_TWEAKS/memcheck/mc_leakcheck.c
==============================================================================
--- branches/ASPACEM_TWEAKS/memcheck/mc_leakcheck.c (original)
+++ branches/ASPACEM_TWEAKS/memcheck/mc_leakcheck.c Wed May 13 15:02:17 2015
@@ -1629,7 +1629,7 @@
seg->kind == SkShmC);
if (!(seg->hasR && seg->hasW)) continue;
- if (seg->isCH) continue;
+ if (seg->whatsit == WiClientHeap) continue;
// Don't poke around in device segments as this may cause
// hangs. Include /dev/zero just in case someone allocated
|