|
[Valgrind-developers] valgrind: r4610 - in branches/ASPACEM: coregrind coregrind/m_aspacemgr include
From: <sv...@va...> - 2005-09-08 00:51:09
|
Author: sewardj
Date: 2005-09-08 01:51:03 +0100 (Thu, 08 Sep 2005)
New Revision: 4610
Log:
Save work-in-progress on aspacem (interval array and associated
infrastructure). Is still totally broken; do not try to use.
Modified:
branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
branches/ASPACEM/coregrind/m_aspacemgr/read_procselfmaps.c
branches/ASPACEM/coregrind/m_main.c
branches/ASPACEM/coregrind/pub_core_aspacemgr.h
branches/ASPACEM/include/pub_tool_basics.h
Modified: branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.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/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-06 13:04:4=
0 UTC (rev 4609)
+++ branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-08 00:51:0=
3 UTC (rev 4610)
@@ -31,6 +31,7 @@
*/
=20
#include "pub_core_basics.h"
+#include "pub_core_debuglog.h"
#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr.h :(
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
@@ -1314,6 +1315,606 @@
#endif
}
=20
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+
+static void aspacem_barf_toolow ( HChar* what )
+{
+ VG_(debugLog)(0, "aspacem", "Valgrind: FATAL: %s is too low.\n", what)=
;
+ VG_(debugLog)(0, "aspacem", " Increase it and rebuild. "
+ "Exiting now.\n");
+ VG_(exit)(1);
+}
+
+static void aspacem_assert_fail( const HChar* expr,
+ const Char* file,
+ Int line,=20
+ const Char* fn )
+{
+ VG_(debugLog)(0, "aspacem", "Valgrind: FATAL: assertion failed:\n");
+ VG_(debugLog)(0, "aspacem", " %s\n", expr);
+ VG_(debugLog)(0, "aspacem", " at %s:%d (%s)\n", file,line,fn);
+ VG_(debugLog)(0, "aspacem", "Exiting now.\n");
+ VG_(exit)(1);
+}
+
+#define aspacem_assert(expr) \
+ ((void) ((expr) ? 0 : \
+ (aspacem_assert_fail(#expr, \
+ __FILE__, __LINE__, \
+ __PRETTY_FUNCTION__))))
+
+
+
+#define Addr_MIN ((Addr)0)
+#define Addr_MAX ((Addr)(-1ULL))
+
+
+/* Describes the ways in which the ends of a segment may be moved. */
+typedef
+ enum {
+ MoFixed, // usual case -- cannot be moved
+ MoDownOK, // can be moved to a lower address
+ MoUpOK // can be moved to a higher address
+ }
+ Movable;
+
+static HChar* showMovable ( Movable m )
+{
+ switch (m) {
+ case MoFixed: return "Fixed";
+ case MoDownOK: return "MoveD";
+ case MoUpOK: return "MoveU";
+ default: return "?????";
+ }
+}
+
+typedef
+ enum {
+ SkFree, // unmapped space
+ SkAnon, // anonymous mapping
+ SkFile, // mapping to a file
+ SkResvn // reservation
+ }
+ MKind;
+
+/* Describes a segment. Invariants:
+
+ kind =3D=3D SkFree:
+ // the only meaningful fields are .start and .end
+
+ kind =3D=3D SkAnon:
+ // the segment may be resized if required
+ // there's no associated file:
+ dev=3D=3Dino=3D=3Dfoff =3D 0, fnidx =3D=3D -1
+ // segment may have permissions
+
+ kind =3D=3D SkFile
+ // the segment may not be resized:
+ moveLo =3D=3D moveHi =3D=3D NotMovable, maxlen =3D=3D 0
+ // there is an associated file
+ // segment may have permissions
+
+ kind =3D=3D SkResvn
+ // the segment may be resized if required
+ // there's no associated file:
+ dev=3D=3Dino=3D=3Dfoff =3D 0, fnidx =3D=3D -1
+ // segment has no permissions
+ hasR=3D=3DhasW=3D=3DhasX=3D=3DanyTranslated =3D=3D False
+
+ Also: if !isClient then anyTranslated=3D=3DFalse
+ (viz, not allowed to make translations from non-client areas)
+*/
+typedef
+ struct {
+ MKind kind;
+ Bool isClient;
+ /* Extent (SkFree, SkAnon, SkFile, SkResvn) */
+ Addr start; // lowest address in range
+ Addr end; // highest address in range
+ /* Resizability (SkAnon, SkResvn only) */
+ Movable moveLo; // if yes, can lower end be moved
+ Movable moveHi; // if yes, can upper end be moved
+ SizeT maxlen; // if yes, what's the max size?
+ /* Associated file (SkFile only) */
+ UInt dev;
+ UInt ino;
+ ULong offset;
+ Int fnIdx; // file name table index, if name is known
+ /* Permissions (SkAnon, SkFile only) */
+ Bool hasR;
+ Bool hasW;
+ Bool hasX;
+ Bool anyTranslated;
+ /* Admin */
+ Bool mark;
+ }
+ NSegment;
+
+/* Array [0 .. nsegments_used-1] of all mappings. */
+/* Sorted by .addr field. */
+/* I: len may not be zero. */
+/* I: overlapping segments are not allowed. */
+/* Each segment can optionally hold an index into the filename table. */
+
+static NSegment nsegments[VG_N_SEGMENTS];
+static Int nsegments_used =3D 0;
+
+
+
+
+/* check the interval array */
+static void check_nsegments ( void )
+{
+ Int i;
+ aspacem_assert(nsegments_used > 0);
+ aspacem_assert(nsegments[0].start =3D=3D Addr_MIN);
+ aspacem_assert(nsegments[nsegments_used-1].end =3D=3D Addr_MAX);
+ for (i =3D 1; i < nsegments_used; i++)
+ aspacem_assert(nsegments[i-1].end+1 =3D=3D nsegments[i].start);
+}
+
+
+
+
+
+
+/* Limits etc */
+
+// The smallest address that aspacem will try to allocate
+static Addr aspacem_minAddr;
+
+// The largest address that aspacem will try to allocate
+static Addr aspacem_maxAddr;
+
+// Where aspacem will start looking for client space
+static Addr aspacem_cStart;
+
+// Where aspacem will start looking for Valgrind space
+static Addr aspacem_vStart;
+
+
+Bool VG_(aspacem_getAdvisory)
+ ( MapRequest* req, Bool forClient, /*OUT*/Addr* result )
+{
+ return False;
+#if 0
+ /* Iterate over all holes in the address space, twice. In the first
+pass, find the first hole which is not below the search start
+point. */
+ Addr holeStart, holeEnd, holeLen;
+ Int i, j;
+
+ Addr minAddr =3D Addr_MIN;
+ Addr maxAddr =3D Addr_MAX;
+ Addr startPoint =3D forClient ? aspacem_cStart : aspacem_vStart;
+
+ Addr reqStart =3D req->rkind=3D=3DMAny ? 0 : req->start;
+ Addr reqEnd =3D reqStart + req->len - 1;
+ Addr reqLen =3D req->len;
+
+ Addr floatStart =3D 0;
+ Bool floatFound =3D False;
+
+ /* Don't waste time looking for a fixed match if not requested to. */
+ Bool fixedFound =3D req->rkind=3D=3DMAny ? True : False;
+
+ for (i =3D 0; i <=3D/*yes,really*/ nsegments_used; i++) {
+ holeEnd =3D i=3D=3Dnsegments_used
+ ? maxAddr
+ : nsegments[i].start - 1;
+ if (holeEnd >=3D startPoint)
+ break;
+ }
+
+ /* Now examine holes from index i back round to i-1. Record the
+ size and length of the first fixed hole and the first floating
+ hole which would satisfy the request. */
+ for (j =3D 0; j < nsegments_used; j++) {
+
+ holeStart =3D i=3D=3D0=20
+ ? minAddr=20
+ : nsegments[i-1].start + nsegments[i-1].len - 1;
+ holeEnd =3D i=3D=3Dnsegments_used
+ ? maxAddr
+ : nsegments[i].start - 1;
+
+ /* Clamp the hole to something plausible */
+ if (holeStart < aspacem_minAddr) holeStart =3D aspacem_minAddr;
+ if (holeEnd > aspacem_maxAddr) holeEnd =3D aspacem_maxAddr;
+
+ /* If it still looks viable, see if it's any use to us. */
+ if (holeStart < holeEnd) {
+
+ holeLen =3D holeEnd - holeStart + 1;
+
+ if (!fixedFound=20
+ && holeStart <=3D reqStart && reqEnd <=3D holeEnd) {
+ fixedFound =3D True;
+ }
+
+ if (!floatFound
+ && holeLen >=3D reqLen) {
+ floatFound =3D True;
+ floatStart =3D holeStart;
+ }
+ }
+
+ /* Don't waste time searching once we've found what we wanted. */
+ if (fixedFound && floatFound)
+ break;
+
+ i++;
+ if (i >=3D nsegments_used) i =3D 0;
+ }
+
+ /* Now see if we found anything which can satisfy the request. */
+ switch (req->rkind) {
+ case MFixed:
+ if (fixedFound) {
+ *result =3D req->start;
+ return True;
+ } else {
+ return False;
+ }
+ break;
+ case MHint:
+ if (fixedFound) {
+ *result =3D req->start;
+ return True;
+ }
+ if (floatFound) {
+ *result =3D floatStart;
+ return True;
+ }
+ return False;
+ case MAny:
+ if (floatFound) {
+ *result =3D floatStart;
+ return True;
+ }
+ return False;
+
+ default: break;
+ }
+ /*NOTREACHED*/
+ aspacemgr_barf("getAdvisory: unknown request kind");
+ return False;
+#endif
+}
+
+
+
+static void init_nsegment ( /*OUT*/NSegment* seg )
+{
+ seg->kind =3D SkAnon;
+ seg->isClient =3D False;
+ seg->start =3D 0;
+ seg->end =3D 0;
+ seg->moveLo =3D MoFixed;
+ seg->moveHi =3D MoFixed;
+ seg->maxlen =3D 0;
+ seg->dev =3D 0;
+ seg->ino =3D 0;
+ seg->offset =3D 0;
+ seg->fnIdx =3D -1;
+ seg->hasR =3D seg->hasR =3D seg->hasW =3D False;
+ seg->anyTranslated =3D False;
+ seg->mark =3D False;
+}
+
+static void init_resvn ( /*OUT*/NSegment* seg, Addr start, Addr end )
+{
+ aspacem_assert(start < end);
+ init_nsegment(seg);
+ seg->kind =3D SkResvn;
+ seg->start =3D start;
+ seg->end =3D end;
+}
+
+static HChar* show_seg_kind ( NSegment* seg )
+{
+ switch (seg->kind) {
+ case SkFree: return "FREE";
+ case SkAnon: return seg->isClient ? "ANON" : "anon";
+ case SkFile: return seg->isClient ? "FILE" : "file";
+ case SkResvn: return seg->isClient ? "RSVN" : "rsvn";
+ default: return "????";
+ }
+}
+
+static void show_nsegment ( Int logLevel, Int segNo, NSegment* seg )
+{
+ switch (seg->kind) {
+ case SkFree: {
+ ULong len =3D ((ULong)seg->end) - ((ULong)seg->start) + 1;
+ HChar* fmt;
+ if (len >=3D 1024*1024ULL) {
+ len /=3D 1024*1024ULL;
+ fmt =3D "%3d: %s 0x%08llx-0x%08llx %6llum\n";
+ } else {
+ fmt =3D "%3d: %s 0x%08llx-0x%08llx %7llu\n";
+ }
+ VG_(debugLog)(
+ logLevel, "aspacem",
+ fmt,
+ segNo,
+ show_seg_kind(seg),
+ (ULong)seg->start,
+ (ULong)seg->end,
+ len
+ );
+ break;
+ }
+
+ case SkAnon:
+ VG_(debugLog)(
+ logLevel, "aspacem",
+ "%3d: %s 0x%08llx-0x%08llx %7llu %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%=
-7lld (%d)\n",
+ segNo,
+ show_seg_kind(seg),
+ (ULong)seg->start,
+ (ULong)seg->end,
+ ((ULong)seg->end) - ((ULong)seg->start) + 1,
+ seg->hasR ? 'r' : '-',=20
+ seg->hasW ? 'w' : '-',=20
+ seg->hasX ? 'x' : '-',=20
+ seg->anyTranslated ? 'T' : '-',=20
+ seg->dev,
+ seg->ino,
+ (Long)seg->offset,
+ seg->fnIdx
+ );
+ break;
+ case SkFile:
+ VG_(debugLog)(
+ logLevel, "aspacem",
+ "%3d: %s 0x%08llx-0x%08llx %7llu %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%=
-7lld (%d)\n",
+ segNo,
+ show_seg_kind(seg),
+ (ULong)seg->start,
+ (ULong)seg->end,
+ ((ULong)seg->end) - ((ULong)seg->start) + 1,
+ seg->hasR ? 'r' : '-',=20
+ seg->hasW ? 'w' : '-',=20
+ seg->hasX ? 'x' : '-',=20
+ seg->anyTranslated ? 'T' : '-',=20
+ seg->dev,
+ seg->ino,
+ (Long)seg->offset,
+ seg->fnIdx
+ );
+ break;
+ case SkResvn:
+ VG_(debugLog)(
+ logLevel, "aspacem",
+ "%3d: %s 0x%08llx-0x%08llx %7llu %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%=
-7lld (%d) (%s,%s,%llu)\n",
+ segNo,
+ show_seg_kind(seg),
+ (ULong)seg->start,
+ (ULong)seg->end,
+ ((ULong)seg->end) - ((ULong)seg->start) + 1,
+ seg->hasR ? 'r' : '-',=20
+ seg->hasW ? 'w' : '-',=20
+ seg->hasX ? 'x' : '-',=20
+ seg->anyTranslated ? 'T' : '-',=20
+ seg->dev,
+ seg->ino,
+ (Long)seg->offset,
+ seg->fnIdx,
+ showMovable(seg->moveLo),
+ showMovable(seg->moveHi),
+(ULong)seg->maxlen
+ );
+ break;
+
+ default:
+ VG_(debugLog)(
+ logLevel, "aspacem",
+ "%3d: ???? UNKNOWN SEGMENT KIND\n",
+segNo );
+ break;
+ }
+}
+
+/* Print out the segment array (debugging only!). */
+static void show_nsegments ( Int logLevel, HChar* who )
+{
+ Int i;
+ VG_(debugLog)(logLevel, "aspacem",
+ "<<< SHOW_SEGMENTS: %s (%d segments, %d segnames)\n",=20
+ who, segments_used, segnames_used);
+ for (i =3D 0; i < segnames_used; i++) {
+ if (!segnames[i].inUse)
+ continue;
+ VG_(debugLog)(logLevel, "aspacem",
+ "(%2d) %s\n", i, segnames[i].fname);
+ }
+ for (i =3D 0; i < nsegments_used; i++)
+ show_nsegment( logLevel, i, &nsegments[i] );
+ VG_(debugLog)(logLevel, "aspacem",
+ ">>>\n");
+}
+
+/* Add SEG to the collection, deleting/truncating any it overlaps */
+static void add_segment ( NSegment* seg )
+{
+ Int nDeld, i, j, k;
+ Addr iStart, iEnd;
+
+ Addr dStart =3D seg->start;
+ Addr dEnd =3D seg->end;
+ =20
+ aspacem_assert(dStart <=3D dEnd);
+
+ nDeld =3D 0;
+
+ for (i =3D 0; i < nsegments_used; i++) {
+
+ nsegments[i].mark =3D False;
+
+ iStart =3D nsegments[i].start;
+ iEnd =3D nsegments[i].end;
+
+ /* no-overlap cases */
+ if (iEnd < dStart) continue;
+ if (dEnd < iStart) continue;
+
+ if (dStart <=3D iStart && iEnd <=3D dEnd) {
+ /* i is completely overlapped. Mark it for deletion. */
+ nsegments[i].mark =3D True;
+ nDeld++;
+ continue;
+ }
+
+ if (iStart < dStart && iEnd > dEnd) {
+ /* deleted interval is completely contained within i. This
+ means i has to be split into two pieces. As a result, first
+ move the following elements up by one place to make space for
+ the new part. */
+ if (nsegments_used >=3D VG_N_SEGMENTS)
+ aspacem_barf_toolow("VG_N_SEGMENTS");
+ for (j =3D nsegments_used-1; j > i; j--)
+ nsegments[j+1] =3D nsegments[j];
+ nsegments_used++;
+ nsegments[i+1] =3D nsegments[i];
+ nsegments[i].end =3D dStart-1;
+ nsegments[i+1].start =3D dEnd+1;
+ nsegments[i+1].offset +=3D (nsegments[i+1].start - nsegments[i].st=
art);
+ continue;
+ }
+
+ if (iStart < dStart && iEnd <=3D dEnd && iEnd >=3D dStart) {
+ /* interval to be deleted straddles upper boundary of i. */
+ nsegments[i].end =3D dStart-1;
+ continue;
+ }
+
+ if (iEnd > dEnd && iStart >=3D dStart && iStart <=3D dEnd) {
+ /* interval to be deleted straddles lower boundary of i. */
+ nsegments[i].offset +=3D (dEnd+1 - nsegments[i].start);
+ nsegments[i].start =3D dEnd+1;
+ continue;
+ }
+
+ /* I don't think we can get here */
+ aspacem_assert(0);
+ }
+
+ /* Get rid of the intervals marked for deletion. */
+ if (nDeld > 0) {
+ j =3D 0;
+ for (i =3D 0; i < nsegments_used; i++) {
+ if (nsegments[i].mark)
+ continue;
+ nsegments[j] =3D nsegments[i];
+ j++;
+ }
+ nsegments_used -=3D nDeld;
+ }
+
+ /* At this point, there should be a gap dStart .. dEnd inclusive.
+ Find the gap and insert the new interval in it. Set k so that
+ all entries >=3D k must be moved up 1, and the new interval placed
+ at k. */
+ if (nsegments_used >=3D VG_N_SEGMENTS)
+ aspacem_barf_toolow("VG_N_SEGMENTS");
+ if (nsegments_used =3D=3D 0) {
+ k =3D 0;
+ } else {
+ for (i =3D 0; i < nsegments_used; i++)
+ if (nsegments[i].start =3D=3D dEnd+1)
+ break;
+ k =3D i;
+ }
+
+ aspacem_assert(k >=3D 0 && k <=3D nsegments_used);
+ for (j =3D nsegments_used-1; j >=3D k; j--)
+ nsegments[j+1] =3D nsegments[j];
+ nsegments_used++;
+
+ nsegments[k] =3D *seg;
+
+ check_nsegments();
+}
+
+
+
+static void read_maps_callback (=20
+ Addr addr, SizeT len, UInt prot,
+ UInt dev, UInt ino, ULong foff, const UChar* filename )
+{
+ NSegment seg;
+ init_nsegment( &seg );
+ seg.start =3D addr;
+ seg.end =3D addr+len-1;
+ seg.dev =3D dev;
+ seg.ino =3D ino;
+ seg.offset =3D foff;
+ seg.hasR =3D toBool(prot & VKI_PROT_READ);
+ seg.hasW =3D toBool(prot & VKI_PROT_WRITE);
+ seg.hasX =3D toBool(prot & VKI_PROT_EXEC);
+
+ seg.kind =3D SkAnon;
+ if (filename) {=20
+ seg.kind =3D SkFile;
+ seg.fnIdx =3D allocate_segname( filename );
+ }
+
+ show_nsegment( 0,0, &seg );
+ add_segment( &seg );
+}
+
+void VG_(new_aspacem_start) ( void )
+{
+ NSegment seg;
+
+ /* Add a single interval covering the entire address space. */
+ init_nsegment(&seg);
+ seg.kind =3D SkFree;
+ seg.start =3D Addr_MIN;
+ seg.end =3D Addr_MAX;
+ nsegments[0] =3D seg;
+ nsegments_used =3D 1;
+
+ /* Establish address limits and block out unusable parts
+ accordingly. */
+
+ aspacem_minAddr =3D (Addr) 0x00000000;
+
+# if VG_WORDSIZE =3D=3D 8
+ aspacem_maxAddr =3D (Addr)0x400000000 - 1; // 16G
+# else
+ aspacem_maxAddr =3D (Addr) 0xC0000000 - 1; // 3G
+# endif
+
+ aspacem_cStart =3D (Addr)0x04000000; // 64M
+ aspacem_vStart =3D (aspacem_minAddr + aspacem_maxAddr + 1) / 2;
+
+ VG_(debugLog)(2, "aspacem", "minAddr =3D 0x%llx\n", (ULong)aspacem_mi=
nAddr);
+ VG_(debugLog)(2, "aspacem", "maxAddr =3D 0x%llx\n", (ULong)aspacem_ma=
xAddr);
+ VG_(debugLog)(2, "aspacem", " cStart =3D 0x%llx\n", (ULong)aspacem_cS=
tart);
+ VG_(debugLog)(2, "aspacem", " vStart =3D 0x%llx\n", (ULong)aspacem_vS=
tart);
+
+ if (aspacem_cStart > Addr_MIN) {
+ init_resvn(&seg, Addr_MIN, aspacem_cStart-1);
+ add_segment(&seg);
+ }
+
+ if (aspacem_maxAddr < Addr_MAX) {
+ init_resvn(&seg, aspacem_maxAddr+1, Addr_MAX);
+ add_segment(&seg);
+ }
+
+ show_nsegments(2, "Initial layout");
+
+ VG_(debugLog)(2, "aspacem", "Reading /proc/self/maps\n");
+ VG_(parse_procselfmaps) ( read_maps_callback );
+
+ show_nsegments(2, "With contents of /proc/self/maps");
+}
+
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: branches/ASPACEM/coregrind/m_aspacemgr/read_procselfmaps.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/ASPACEM/coregrind/m_aspacemgr/read_procselfmaps.c 2005-09-06=
13:04:40 UTC (rev 4609)
+++ branches/ASPACEM/coregrind/m_aspacemgr/read_procselfmaps.c 2005-09-08=
00:51:03 UTC (rev 4610)
@@ -266,7 +266,6 @@
if (ww =3D=3D 'w') prot |=3D VKI_PROT_WRITE;
if (xx =3D=3D 'x') prot |=3D VKI_PROT_EXEC;
=20
- //if (start < VG_(valgrind_last))
(*record_mapping) ( start, endPlusOne-start,=20
prot, maj * 256 + min, ino,
foffset, filename );
Modified: branches/ASPACEM/coregrind/m_main.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/ASPACEM/coregrind/m_main.c 2005-09-06 13:04:40 UTC (rev 4609=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-09-08 00:51:03 UTC (rev 4610=
)
@@ -2026,6 +2026,11 @@
*/
=20
=20
+/* When main() is entered, we should be on the following stack, not
+ the one the kernel gave us. */
+VgStack VG_(the_root_stack);
+
+
Int main(Int argc, HChar **argv, HChar **envp)
{
HChar** cl_argv;
@@ -2076,6 +2081,28 @@
messages all through startup. */
VG_(debugLog_startup)(loglevel, "Stage 2 (main)");
=20
+ //--------------------------------------------------------------
+ // Start up the address space manager
+ // p: logging
+ //--------------------------------------------------------------
+ VG_(debugLog)(1, "main", "Starting the address space manager\n");
+
+ /* Ensure we're on a plausible stack. */
+ { HChar* limLo =3D (HChar*)(&VG_(the_root_stack)[0]);
+ HChar* limHi =3D limLo + sizeof(VG_(the_root_stack));
+ HChar* aLocal =3D (HChar*)&zero; /* any auto local will do */
+ if (aLocal < limLo || aLocal >=3D limHi) {
+ /* something's wrong. Stop. */
+ VG_(debugLog)(0, "main", "Root stack %p to %p, a local %p\n",
+ limLo, limHi, aLocal );
+ VG_(debugLog)(0, "main", "FATAL: Initial stack switched failed.\=
n");
+ VG_(debugLog)(0, "main", " Cannot continue. Sorry.\n");
+ VG_(exit)(1);
+ }
+ }
+
+ VG_(new_aspacem_start)();
+
//=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
// Command line argument handling order:
// * If --help/--help-debug are present, show usage message=20
@@ -2653,18 +2680,23 @@
*/
=20
/* The kernel hands control to _start, which extracts the initial
- stack pointer and calls onwards to _start_in_C. */
+ stack pointer and calls onwards to _start_in_C. This also switches t=
he new stack. */
#if defined(VGP_x86_linux)
asm("\n"
"\t.globl _start\n"
"\t.type _start,@function\n"
"_start:\n"
"\tmovl %esp,%eax\n"
- "\tandl $~15,%esp\n" /* Make sure stack is 16 byte aligned */
- "\tpushl %eax\n" /* Push junk to preserve alignment */
- "\tpushl %eax\n" /* Push junk to preserve alignment */
- "\tpushl %eax\n" /* Push junk to preserve alignment */
- "\tpushl %eax\n" /* Pass pointer to argc to _start_in_C */
+ /* set up the new stack in %eax */
+ "\tmovl $vgPlain_the_root_stack, %eax\n"
+ "\taddl $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %eax\n"
+ "\taddl $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %eax\n"
+ "\tsubl $16, %eax\n"
+ "\tandl $~15, %eax\n"
+ /* install it, and collect the original one */
+ "\txchgl %eax, %esp\n"
+ /* call _start_in_C, passing it the startup %esp */
+ "\tpushl %eax\n"
"\tcall _start_in_C\n"
"\thlt\n"
);
Modified: branches/ASPACEM/coregrind/pub_core_aspacemgr.h
=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/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-06 13:04:40 U=
TC (rev 4609)
+++ branches/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-08 00:51:03 U=
TC (rev 4610)
@@ -151,6 +151,31 @@
// Pointercheck
extern Bool VG_(setup_pointercheck) ( Addr client_base, Addr client_end =
);
=20
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+
+#define VG_STACK_GUARD_SZB 8192
+#define VG_STACK_ACTIVE_SZB 65536
+
+typedef
+ HChar
+ VgStack[VG_STACK_GUARD_SZB + VG_STACK_ACTIVE_SZB + VG_STACK_GUARD_SZB=
];
+
+extern void VG_(new_aspacem_start) ( void );
+
+
+typedef
+ struct {
+ enum { MFixed, MHint, MAny } rkind;
+ Addr start;
+ Addr len;
+ }
+ MapRequest;
+
+extern
+Bool VG_(aspacem_getAdvisory)
+ ( MapRequest* req, Bool forClient, /*OUT*/Addr* result );
+
#endif // __PUB_CORE_ASPACEMGR_H
=20
/*--------------------------------------------------------------------*/
Modified: branches/ASPACEM/include/pub_tool_basics.h
=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/ASPACEM/include/pub_tool_basics.h 2005-09-06 13:04:40 UTC (r=
ev 4609)
+++ branches/ASPACEM/include/pub_tool_basics.h 2005-09-08 00:51:03 UTC (r=
ev 4610)
@@ -106,7 +106,7 @@
SysRes;
=20
/* ---------------------------------------------------------------------
- Miscellaneous (word size, endianness, regparmness)
+ Miscellaneous (word size, endianness, regparmness, stringification)
------------------------------------------------------------------ */
=20
/* Word size: this is going to be either 4 or 8. */
@@ -132,6 +132,10 @@
# error Unknown arch
#endif
=20
+/* Macro games */
+#define VG_STRINGIFZ(__str) #__str
+#define VG_STRINGIFY(__str) VG_STRINGIFZ(__str)
+
#endif /* __PUB_TOOL_BASICS_H */
=20
/*--------------------------------------------------------------------*/
|