|
From: <sv...@va...> - 2005-09-11 00:48:25
|
Author: sewardj
Date: 2005-09-11 01:48:18 +0100 (Sun, 11 Sep 2005)
New Revision: 4616
Log:
Many changes:
- make client loading work (m_ume)
- make client stack setup work
- get rid of hack_malloc() as it is no longer necessary
Modified:
branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
branches/ASPACEM/coregrind/m_main.c
branches/ASPACEM/coregrind/m_ume.c
branches/ASPACEM/coregrind/pub_core_aspacemgr.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-10 16:02:0=
3 UTC (rev 4615)
+++ branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-11 00:48:1=
8 UTC (rev 4616)
@@ -1658,9 +1658,6 @@
=20
i =3D find_nsegment_idx(startPoint);
=20
- if (0) VG_(debugLog)(0,"","startPoint %p, idx %d, reqlen %d\n",=20
- startPoint,i,reqLen);
-
/* Now examine holes from index i back round to i-1. Record the
index first fixed hole and the first floating hole which would
satisfy the request. */
@@ -1776,7 +1773,7 @@
static HChar* show_seg_kind ( NSegment* seg )
{
switch (seg->kind) {
- case SkFree: return "FREE";
+ case SkFree: return " ";
case SkAnon: return seg->isClient ? "anon" : "ANON";
case SkFile: return seg->isClient ? "file" : "FILE";
case SkResvn: return "RSVN";
@@ -1807,7 +1804,7 @@
case SkFree: {
VG_(debugLog)(
logLevel, "aspacem",
- "%3d: %s 0x%08llx-0x%08llx %s\n",
+ "%3d: %s %08llx-%08llx %s\n",
segNo,
show_seg_kind(seg),
(ULong)seg->start,
@@ -1820,7 +1817,7 @@
case SkAnon:
VG_(debugLog)(
logLevel, "aspacem",
- "%3d: %s 0x%08llx-0x%08llx %s %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%-7l=
ld (%d)\n",
+ "%3d: %s %08llx-%08llx %s %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%-7lld (=
%d)\n",
segNo,
show_seg_kind(seg),
(ULong)seg->start,
@@ -1839,7 +1836,7 @@
case SkFile:
VG_(debugLog)(
logLevel, "aspacem",
- "%3d: %s 0x%08llx-0x%08llx %s %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%-7l=
ld (%d)\n",
+ "%3d: %s %08llx-%08llx %s %c%c%c%c d=3D0x%03x i=3D%-7d o=3D%-7lld (=
%d)\n",
segNo,
show_seg_kind(seg),
(ULong)seg->start,
@@ -1858,7 +1855,7 @@
case SkResvn:
VG_(debugLog)(
logLevel, "aspacem",
- "%3d: %s 0x%08llx-0x%08llx %s %c%c%c%c (%s,%s,%llu)\n",
+ "%3d: %s %08llx-%08llx %s %c%c%c%c (%s,%s,%llu)\n",
segNo,
show_seg_kind(seg),
(ULong)seg->start,
@@ -1902,6 +1899,12 @@
">>>\n");
}
=20
+void VG_(show_nsegments) ( HChar* who )
+{
+ show_nsegments( 0, who );
+}
+
+
/* Add SEG to the collection, deleting/truncating any it overlaps */
static void add_segment ( NSegment* seg )
{
@@ -2034,9 +2037,10 @@
add_segment( &seg );
}
=20
-void VG_(new_aspacem_start) ( void )
+Addr VG_(new_aspacem_start) ( Addr sp_at_startup )
{
NSegment seg;
+ Addr suggested_clstack_top;
=20
aspacem_assert(sizeof(Word) =3D=3D sizeof(void*));
aspacem_assert(sizeof(Addr) =3D=3D sizeof(void*));
@@ -2054,26 +2058,45 @@
/* Establish address limits and block out unusable parts
accordingly. */
=20
- aspacem_minAddr =3D (Addr) 0x00000000;
+ VG_(debugLog)(2, "aspacem",=20
+ " sp_at_startup =3D 0x%llx (supplied)\n",=20
+ (ULong)sp_at_startup );
=20
+ aspacem_minAddr =3D (Addr) 0x04000000; // 64M
+
# if VG_WORDSIZE =3D=3D 8
aspacem_maxAddr =3D (Addr)0x400000000 - 1; // 16G
# else
- aspacem_maxAddr =3D (Addr) 0xC0000000 - 1; // 3G
+ aspacem_maxAddr =3D VG_PGROUNDDN( sp_at_startup ) - 1;
# endif
=20
- aspacem_cStart =3D (Addr)0x04000000; // 64M
- aspacem_vStart =3D (aspacem_minAddr + aspacem_maxAddr + 1) / 2;
+ aspacem_cStart =3D aspacem_minAddr; // 64M
+ aspacem_vStart =3D VG_PGROUNDUP((aspacem_minAddr + aspacem_maxAddr + =
1) / 2);
=20
+ suggested_clstack_top =3D aspacem_maxAddr - 16*1024*1024ULL
+ + VKI_PAGE_SIZE;
+
aspacem_assert(VG_IS_PAGE_ALIGNED(aspacem_minAddr));
aspacem_assert(VG_IS_PAGE_ALIGNED(aspacem_maxAddr + 1));
aspacem_assert(VG_IS_PAGE_ALIGNED(aspacem_cStart));
aspacem_assert(VG_IS_PAGE_ALIGNED(aspacem_vStart));
+ aspacem_assert(VG_IS_PAGE_ALIGNED(suggested_clstack_top + 1));
=20
- 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);
+ VG_(debugLog)(2, "aspacem",=20
+ " minAddr =3D 0x%08llx (computed)\n",=20
+ (ULong)aspacem_minAddr);
+ VG_(debugLog)(2, "aspacem",=20
+ " maxAddr =3D 0x%08llx (computed)\n",=20
+ (ULong)aspacem_maxAddr);
+ VG_(debugLog)(2, "aspacem",=20
+ " cStart =3D 0x%08llx (computed)\n",=20
+ (ULong)aspacem_cStart);
+ VG_(debugLog)(2, "aspacem",=20
+ " vStart =3D 0x%08llx (computed)\n",=20
+ (ULong)aspacem_vStart);
+ VG_(debugLog)(2, "aspacem",=20
+ "suggested_clstack_top =3D 0x%08llx (computed)\n",=20
+ (ULong)suggested_clstack_top);
=20
if (aspacem_cStart > Addr_MIN) {
init_resvn(&seg, Addr_MIN, aspacem_cStart-1);
@@ -2098,6 +2121,8 @@
VG_(parse_procselfmaps) ( read_maps_callback );
=20
show_nsegments(2, "With contents of /proc/self/maps");
+
+ return suggested_clstack_top;
}
=20
=20
@@ -2221,6 +2246,59 @@
}
=20
=20
+SysRes VG_(mmap_anon_float_client)
+ ( SizeT length, Int prot )
+{
+ SysRes sres;
+ NSegment seg;
+ Addr advised;
+ Bool ok;
+ MapRequest req;
+=20
+ /* Not allowable. */
+ if (length =3D=3D 0)
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+
+ /* Ask for an advisory. If it's negative, fail immediately. */
+ req.rkind =3D MAny;
+ req.start =3D 0;
+ req.len =3D length;
+ ok =3D VG_(aspacem_getAdvisory)( &req, True/*client*/, &advised );
+ if (!ok)
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+
+ /* We have been advised that the mapping is allowable at the
+ advised address. So hand it off to the kernel, and propagate
+ any resulting failure immediately. */
+ sres =3D do_mmap_NATIVE( advised, length, prot,=20
+ VKI_MAP_FIXED|VKI_MAP_PRIVATE
+ |VKI_MAP_ANONYMOUS, 0, 0 );
+ if (sres.isError)
+ return sres;
+
+ if (sres.val !=3D advised) {
+ /* I don't think this can happen. It means the kernel made a
+ fixed map succeed but not at the requested location. Try to
+ repair the damage, then return saying the mapping failed. */
+ (void)do_munmap_NATIVE( sres.val, length );
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+ }
+
+ /* Ok, the mapping succeeded. Now notify the interval map. */
+ init_nsegment( &seg );
+ seg.kind =3D SkAnon;
+ seg.isClient =3D True;
+ seg.start =3D advised;
+ seg.end =3D seg.start + VG_PGROUNDUP(length) - 1;
+ seg.hasR =3D toBool(prot & VKI_PROT_READ);
+ seg.hasW =3D toBool(prot & VKI_PROT_WRITE);
+ seg.hasX =3D toBool(prot & VKI_PROT_EXEC);
+ add_segment( &seg );
+
+ return sres;
+}
+
+
SysRes VG_(map_anon_float_valgrind)( SizeT length )
{
SysRes sres;
@@ -2275,6 +2353,28 @@
}
=20
=20
+SysRes VG_(munmap_client)( Addr base, SizeT length )
+{
+ NSegment seg;
+ SysRes sres;
+
+ if (length =3D=3D 0 || !VG_IS_PAGE_ALIGNED(base))
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+
+ sres =3D do_munmap_NATIVE( base, length );
+ if (sres.isError)
+ return sres;
+
+ init_nsegment( &seg );
+ seg.kind =3D SkFree;
+ seg.start =3D base;
+ seg.end =3D seg.start + VG_PGROUNDUP(length) - 1;
+ add_segment( &seg );
+
+ return sres;
+}
+
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
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-10 16:02:03 UTC (rev 4615=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-09-11 00:48:18 UTC (rev 4616=
)
@@ -104,31 +104,6 @@
=20
=20
/*=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=3D*/
-/*=3D=3D=3D Ultra-basic startup stuff =
=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=3D=3D=3D=3D*/
-
-// HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK A
-// temporary bootstrapping allocator, for use until such time as we
-// can get rid of the circularities in allocator dependencies at
-// startup. There is also a copy of this in m_ume.c.
-#define N_HACK_BYTES 10000
-static Int hack_bytes_used =3D 0;
-static HChar hack_bytes[N_HACK_BYTES];
-
-static void* hack_malloc ( Int n )
-{
- VG_(debugLog)(1, "main", " FIXME: hack_malloc(m_main)(%d)\n", n);
- while (n % 16) n++;
- if (hack_bytes_used + n > N_HACK_BYTES) {
- VG_(printf)("valgrind: N_HACK_BYTES(m_main) too low. Sorry.\n");
- VG_(exit)(0);
- }
- hack_bytes_used +=3D n;
- return (void*) &hack_bytes[hack_bytes_used - n];
-}
-
-
-/*=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=3D*/
/*=3D=3D=3D Global entities not referenced from generated code =
=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=3D=3D=3D=3D*/
=20
@@ -143,7 +118,15 @@
static Int vg_argc;
static Char **vg_argv;
=20
+/* This should get some address inside the stack on which we gained
+ control (eg, it could be the SP at startup). It doesn't matter
+ exactly where in the stack it is. This value is passed to the
+ address space manager at startup, which uses it to identify the
+ initial stack segment and hence the upper end of the usable address
+ space. */
+static Addr sp_at_startup_new =3D 0;
=20
+
/*=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=3D*/
/*=3D=3D=3D Counters, for profiling purposes only =
=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=3D=3D=3D=3D*/
@@ -374,13 +357,12 @@
Int preload_core_path_len =3D vgliblen + sizeof(preload_core_so) + 16=
;
Int preload_tool_path_len =3D vgliblen + VG_(strlen)(toolname) + 16=
;
Int preload_string_len =3D preload_core_path_len + preload_tool_pa=
th_len;
- /* FIXME */
- HChar* preload_string =3D /*VG_(malloc)*/ hack_malloc(preload_str=
ing_len);
+ HChar* preload_string =3D VG_(malloc)(preload_string_len);
vg_assert(preload_string);
=20
/* Determine if there's a vgpreload_<tool>.so file, and setup
preload_string. */
- preload_tool_path =3D /*VG_(malloc)*/ hack_malloc(preload_tool_path_l=
en);
+ preload_tool_path =3D VG_(malloc)(preload_tool_path_len);
vg_assert(preload_tool_path);
VG_(snprintf)(preload_tool_path, preload_tool_path_len,
"%s/vgpreload_%s.so", VG_(libdir), toolname);
@@ -391,7 +373,7 @@
VG_(snprintf)(preload_string, preload_string_len, "%s/%s",=20
VG_(libdir), preload_core_so);
}
- //FIXME VG_(free)(preload_tool);
+ VG_(free)(preload_tool_path);
=20
VG_(debugLog)(1, "main", "preload_string =3D %s\n", preload_string);
=20
@@ -401,7 +383,7 @@
envc++;
=20
/* Allocate a new space */
- ret =3D /* FIXME VG_(malloc)*/ hack_malloc (sizeof(HChar *) * (envc+1=
+1)); /* 1 new entry + NULL */
+ ret =3D VG_(malloc) (sizeof(HChar *) * (envc+1+1)); /* 1 new entry + =
NULL */
vg_assert(ret);
=20
/* copy it over */
@@ -415,7 +397,7 @@
for (cpp =3D ret; cpp && *cpp; cpp++) {
if (VG_(memcmp)(*cpp, ld_preload, ld_preload_len) =3D=3D 0) {
Int len =3D VG_(strlen)(*cpp) + preload_string_len;
- HChar *cp =3D /*FIXME VG_(malloc)*/ hack_malloc(len);
+ HChar *cp =3D VG_(malloc)(len);
vg_assert(cp);
=20
VG_(snprintf)(cp, len, "%s%s:%s",
@@ -432,7 +414,7 @@
/* Add the missing bits */
if (!ld_preload_done) {
Int len =3D ld_preload_len + preload_string_len;
- HChar *cp =3D /*FIXME VG_(malloc)*/ hack_malloc (len);
+ HChar *cp =3D VG_(malloc) (len);
vg_assert(cp);
=20
VG_(snprintf)(cp, len, "%s%s", ld_preload, preload_string);
@@ -440,7 +422,7 @@
ret[envc++] =3D cp;
}
=20
- //FIXME VG_(free)(preload_string);
+ VG_(free)(preload_string);
ret[envc] =3D NULL;
=20
return ret;
@@ -472,7 +454,7 @@
=20
The format of the stack is:
=20
- higher address +-----------------+
+ higher address +-----------------+ <- clstack_end
| Trampoline code |
+-----------------+
| |
@@ -496,10 +478,17 @@
| undefined |
: :
*/
-static Addr setup_client_stack(void* init_sp,
- char **orig_argv, char **orig_envp,=20
- const struct exeinfo *info,
- UInt** client_auxv)
+
+/* Allocate and create the initial client stack. It is allocated down
+ from clstack_end, which was previously determined by the address
+ space manager. A modified version of our auxv is copied into the
+ new stack. The returned value is the SP value for the client. */
+static=20
+Addr setup_client_stack( void* init_sp,
+ char **orig_argv, char **orig_envp,=20
+ const struct exeinfo *info,
+ UInt** client_auxv,
+ Addr clstack_end )
{
SysRes res;
char **cpp;
@@ -514,8 +503,11 @@
int argc; /* total argc */
int envc; /* total number of env vars */
unsigned stacksize; /* total client stack size */
- Addr cl_esp; /* client stack base (initial esp) */
+ Addr client_SP; /* client stack base (initial SP) */
+ Addr clstack_start;
=20
+ vg_assert(VG_IS_PAGE_ALIGNED(clstack_end+1));
+
/* use our own auxv as a prototype */
orig_auxv =3D VG_(find_auxv)(init_sp);
=20
@@ -574,38 +566,36 @@
=20
if (0) VG_(printf)("stacksize =3D %d\n", stacksize);
=20
- // decide where stack goes!
- VG_(clstk_end) =3D VG_(client_end);
+ /* client_SP is the client's stack pointer */
+ client_SP =3D clstack_end - stacksize;
+ client_SP =3D VG_ROUNDDN(client_SP, 16); /* make stack 16 byte aligne=
d */
=20
- /* cl_esp is the client's stack pointer */
- cl_esp =3D VG_(clstk_end) - stacksize;
- cl_esp =3D VG_ROUNDDN(cl_esp, 16); /* make stack 16 byte aligned */
-
/* base of the string table (aligned) */
- stringbase =3D strtab =3D (char *)(VG_(clstk_end)=20
- - VG_ROUNDUP(stringsize, sizeof(int)));
+ stringbase =3D strtab =3D (char *)clstack_end=20
+ - VG_ROUNDUP(stringsize, sizeof(int));
=20
- VG_(clstk_base) =3D VG_PGROUNDDN(cl_esp);
+ clstack_start =3D VG_PGROUNDDN(client_SP);
=20
- if (0)
+ if (1)
VG_(printf)("stringsize=3D%d auxsize=3D%d stacksize=3D%d\n"
- "clstk_base %p\n"
- "clstk_end %p\n",
+ "clstack_start %p\n"
+ "clstack_end %p\n",
stringsize, auxsize, stacksize,
- (void*)VG_(clstk_base), (void*)VG_(clstk_end));
+ (void*)clstack_start, (void*)clstack_end);
=20
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D alloc=
ate space =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
=20
/* allocate a stack - mmap enough space for the stack */
- res =3D VG_(mmap_native)((void *)VG_PGROUNDDN(cl_esp),=20
- VG_(clstk_end) - VG_PGROUNDDN(cl_esp),
- VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC,=20
- VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS|VKI_MAP_FIXED, -1, 0);
+ res =3D VG_(mmap_anon_fixed_client)(
+ (void *)clstack_start,
+ clstack_end - clstack_start + 1,
+ VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC
+ );
vg_assert(!res.isError);=20
=20
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D copy =
client stack =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
*/
=20
- ptr =3D (Addr*)cl_esp;
+ ptr =3D (Addr*)client_SP;
=20
/* --- argc --- */
*ptr++ =3D argc; /* client argc */
@@ -613,11 +603,11 @@
/* --- argv --- */
if (info->interp_name) {
*ptr++ =3D (Addr)copy_str(&strtab, info->interp_name);
-//FIXME free(info->interp_name);
+ VG_(free)(info->interp_name);
}
if (info->interp_args) {
*ptr++ =3D (Addr)copy_str(&strtab, info->interp_args);
-//FIXME free(info->interp_args);
+ VG_(free)(info->interp_args);
}
for (cpp =3D orig_argv; *cpp; ptr++, cpp++) {
*ptr =3D (Addr)copy_str(&strtab, *cpp);
@@ -732,12 +722,12 @@
=20
vg_assert((strtab-stringbase) =3D=3D stringsize);
=20
- /* We know the initial ESP is pointing at argc/argv */
- VG_(client_argc) =3D *(Int*)cl_esp;
- VG_(client_argv) =3D (Char**)(cl_esp + sizeof(HWord));
+ /* We know the initial SP is pointing at argc/argv */
+ VG_(client_argc) =3D *(Int*)client_SP;
+ VG_(client_argv) =3D (Char**)(client_SP + sizeof(HWord));
=20
- if (0) VG_(printf)("startup SP =3D %p\n", cl_esp);
- return cl_esp;
+ if (0) VG_(printf)("startup SP =3D %p\n", client_SP);
+ return client_SP;
}
=20
/*=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=3D*/
@@ -1242,7 +1232,7 @@
}
skip_arg:
if (arg !=3D vg_argv[i]) {
- //FIXME free(arg);
+ VG_(free)(arg);
}
}
=20
@@ -2039,9 +2029,9 @@
HChar** env;
Int need_help =3D 0; // 0 =3D no, 1 =3D --help, 2 =3D --help=
-debug
struct exeinfo info;
- Addr client_eip;
- Addr sp_at_startup; /* client's SP at the point we
- gained control. */
+ Addr initial_client_IP;
+ Addr initial_client_SP;
+ Addr clstack_top;
UInt* client_auxv;
Int loglevel, i;
struct vki_rlimit zero =3D { 0, 0 };
@@ -2081,13 +2071,13 @@
messages all through startup. */
VG_(debugLog_startup)(loglevel, "Stage 2 (main)");
VG_(debugLog)(1, "main", "Welcome to Valgrind version "=20
- VERSION " debug logging.\n");
+ VERSION " debug logging\n");
=20
//--------------------------------------------------------------
// Ensure we're on a plausible stack.
// p: logging
//--------------------------------------------------------------
- VG_(debugLog)(1, "main", "Checking we're on a plausible stack\n");
+ VG_(debugLog)(1, "main", "Checking current stack is plausible");
{ 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 */
@@ -2095,18 +2085,34 @@
/* 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_(debugLog)(0, "main", "Valgrind: FATAL: "
+ "Initial stack switched failed.\n");
+ VG_(debugLog)(0, "main", " Cannot continue. Sorry.\n");
VG_(exit)(1);
}
}
=20
//--------------------------------------------------------------
- // Start up the address space manager
+ // Ensure we have a plausible pointer to the stack on which
+ // we gained control (not the current stack!)
+ // p: logging
+ //--------------------------------------------------------------
+ VG_(debugLog)(1, "main", "Checking initial stack was noted\n");
+ if (sp_at_startup_new =3D=3D 0) {
+ VG_(debugLog)(0, "main", "Valgrind: FATAL: "
+ "Initial stack was not noted.\n");
+ VG_(debugLog)(0, "main", " Cannot continue. Sorry.\n");
+ VG_(exit)(1);
+ }
+
+
+ //--------------------------------------------------------------
+ // Start up the address space manager, and determine the
+ // approximate location of the client's stack
// p: logging, plausible-stack
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Starting the address space manager\n");
- VG_(new_aspacem_start)();
+ clstack_top =3D VG_(new_aspacem_start)( sp_at_startup_new );
VG_(debugLog)(1, "main", "Address space manager is running\n");
=20
//--------------------------------------------------------------
@@ -2151,19 +2157,17 @@
// at that point.
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Doing scan_auxv()\n");
- {
- void* init_sp =3D argv - 1;
- scan_auxv(init_sp);
+ { void* init_sp =3D argv - 1;
+ scan_auxv(init_sp);
}
=20
//--------------------------------------------------------------
// Look for alternative libdir =20
// p: none
//--------------------------------------------------------------
- {
- HChar *cp =3D VG_(getenv)(VALGRINDLIB);
- if (cp !=3D NULL)
- VG_(libdir) =3D cp;
+ { HChar *cp =3D VG_(getenv)(VALGRINDLIB);
+ if (cp !=3D NULL)
+ VG_(libdir) =3D cp;
}
=20
//--------------------------------------------------------------
@@ -2209,7 +2213,7 @@
// p: layout_remaining_space [so there's space]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Loading client\n");
- load_client(cl_argv, exec, need_help, &info, &client_eip);
+ load_client(cl_argv, exec, need_help, &info, &initial_client_IP);
=20
//--------------------------------------------------------------
// Everything in place, remove padding done by stage1
@@ -2233,18 +2237,19 @@
// p: fix_environment() [for 'env']
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Setup client stack\n");
- {=20
- void* init_sp =3D argv - 1;
+ { void* init_sp =3D argv - 1;
=20
- sp_at_startup =3D setup_client_stack(init_sp, cl_argv, env, &info,
- &client_auxv);
- //FIXME free(env);
+ initial_client_SP
+ =3D setup_client_stack(init_sp, cl_argv, env, &info,
+ &client_auxv,clstack_top);
+ VG_(free)(env);
}
=20
VG_(debugLog)(2, "main",
"Client info: "
- "entry=3D%p client esp=3D%p vg_argc=3D%d brkbase=3D%=
p\n",
- (void*)client_eip, (void*)sp_at_startup, vg_argc,=20
+ "entry=3D%p client_SP=3D%p vg_argc=3D%d brkbase=3D%p=
\n",
+ (void*)initial_client_IP,=20
+ (void*)initial_client_SP, vg_argc,=20
(void*)VG_(brk_base) );
=20
//=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
@@ -2263,8 +2268,8 @@
// Build segment map (Valgrind segments only)
// p: tl_pre_clo_init() [to setup new_mem_startup tracker]
//--------------------------------------------------------------
- VG_(debugLog)(1, "main", "Parse /proc/self/maps (round 1)\n");
- VG_(parse_procselfmaps) ( build_valgrind_map_callback );
+ //VG_(debugLog)(1, "main", "Parse /proc/self/maps (round 1)\n");
+ //VG_(parse_procselfmaps) ( build_valgrind_map_callback );
=20
//=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
// Can use VG_(arena_malloc)() with non-CORE arena after segments set=
up
@@ -2303,10 +2308,10 @@
// p: setup_client_stack() [for 'sp_at_startup']
// p: init tool [for 'new_mem_startup']
//--------------------------------------------------------------
- VG_(debugLog)(1, "main", "Parse /proc/self/maps (round 2)\n");
- sp_at_startup___global_arg =3D sp_at_startup;
- VG_(parse_procselfmaps) ( build_segment_map_callback ); /* everythin=
g */
- sp_at_startup___global_arg =3D 0;
+ //VG_(debugLog)(1, "main", "Parse /proc/self/maps (round 2)\n");
+ //sp_at_startup___global_arg =3D sp_at_startup;
+ //VG_(parse_procselfmaps) ( build_segment_map_callback ); /* everyth=
ing */
+ //sp_at_startup___global_arg =3D 0;
=20
//=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
// Can use VG_(map)() after segments set up
@@ -2367,7 +2372,8 @@
// setup_scheduler() [for the rest of state 1 stuff]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Initialise thread 1's state\n");
- init_thread1state(client_eip, sp_at_startup, &VG_(threads)[1].arch);
+ init_thread1state( initial_client_IP, initial_client_SP,=20
+ &VG_(threads)[1].arch);
=20
//--------------------------------------------------------------
// Initialise the pthread model
@@ -2742,10 +2748,12 @@
void _start_in_C ( UWord* pArgc );
void _start_in_C ( UWord* pArgc )
{
+ Int r;
Word argc =3D pArgc[0];
HChar** argv =3D (HChar**)&pArgc[1];
HChar** envp =3D (HChar**)&pArgc[1+argc+1];
- Int r =3D main( (Int)argc, argv, envp );
+ sp_at_startup_new =3D (Addr)pArgc;
+ r =3D main( (Int)argc, argv, envp );
VG_(exit)(r);
}
=20
Modified: branches/ASPACEM/coregrind/m_ume.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_ume.c 2005-09-10 16:02:03 UTC (rev 4615)
+++ branches/ASPACEM/coregrind/m_ume.c 2005-09-11 00:48:18 UTC (rev 4616)
@@ -55,33 +55,6 @@
#include "pub_core_ume.h"
=20
=20
-// HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK A
-// temporary bootstrapping allocator, for use until such time as we
-// can get rid of the circularites in allocator dependencies at
-// startup. There is also a copy of this in m_main.c.
-#define N_HACK_BYTES 10000
-static Int hack_bytes_used =3D 0;
-static HChar hack_bytes[N_HACK_BYTES];
-
-static void* hack_malloc ( Int n )
-{
- VG_(debugLog)(1, "ume", " FIXME: hack_malloc(m_ume)(%d)\n", n);
- while (n % 16) n++;
- if (hack_bytes_used + n > N_HACK_BYTES) {
- VG_(printf)("valgrind: N_HACK_BYTES(m_ume) too low. Sorry.\n");
- VG_(exit)(0);
- }
- hack_bytes_used +=3D n;
- return (void*) &hack_bytes[hack_bytes_used - n];
-}
-
-static HChar* hack_strdup ( HChar* str )
-{
- HChar* p =3D hack_malloc( 1 + VG_(strlen)(str) );
- VG_(strcpy)(p, str);
- return p;
-}
-
#if VG_WORDSIZE =3D=3D 8
#define ESZ(x) Elf64_##x
#elif VG_WORDSIZE =3D=3D 4
@@ -298,7 +271,7 @@
struct elfinfo *readelf(int fd, const char *filename)
{
SysRes sres;
- struct elfinfo *e =3D hack_malloc(sizeof(*e));
+ struct elfinfo *e =3D VG_(malloc)(sizeof(*e));
int phsz;
=20
vg_assert(e);
@@ -341,21 +314,21 @@
}
=20
phsz =3D sizeof(ESZ(Phdr)) * e->e.e_phnum;
- e->p =3D hack_malloc(phsz);
+ e->p =3D VG_(malloc)(phsz);
vg_assert(e->p);
=20
sres =3D VG_(pread)(fd, e->p, phsz, e->e.e_phoff);
if (sres.isError || sres.val !=3D phsz) {
VG_(printf)("valgrind: can't read phdr: %s\n",=20
VG_(strerror)(sres.val));
- //FIXME VG_(free)(e->p);
+ VG_(free)(e->p);
goto bad;
}
=20
return e;
=20
bad:
- //FIXME VG_(free)(e);
+ VG_(free)(e);
return NULL;
}
=20
@@ -412,12 +385,13 @@
//
// The condition handles the case of a zero-length segment.
if (VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr) > 0) {
- res =3D VG_(mmap_native)
- ((char *)VG_PGROUNDDN(addr),
+ res =3D VG_(mmap_file_fixed_client)
+ ((void *)VG_PGROUNDDN(addr),
VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr),
- prot, VKI_MAP_FIXED|VKI_MAP_PRIVATE,=20
+ prot, /*VKI_MAP_FIXED|VKI_MAP_PRIVATE, */
e->fd, VG_PGROUNDDN(off)
);
+ if (0) VG_(show_nsegments)("after native 1");
check_mmap(res, (char*)VG_PGROUNDDN(addr),
VG_PGROUNDUP(bss)-VG_PGROUNDDN(addr));
}
@@ -428,6 +402,7 @@
=20
bytes =3D VG_PGROUNDUP(brkaddr)-VG_PGROUNDUP(bss);
if (bytes > 0) {
+ VG_(debugLog)(0,"","mmap_native 2\n");
res =3D VG_(mmap_native)(
(Char *)VG_PGROUNDUP(bss), bytes,
prot, VKI_MAP_FIXED|VKI_MAP_ANONYMOUS|VKI_MAP_PRIVATE,=20
@@ -509,7 +484,7 @@
break;
=09
case PT_INTERP: {
- char *buf =3D hack_malloc(ph->p_filesz+1);
+ char *buf =3D VG_(malloc)(ph->p_filesz+1);
int j;
int intfd;
int baseaddr_set;
@@ -530,7 +505,7 @@
VG_(printf)("valgrind: m_ume.c: can't read interpreter\n");
return 1;
}
- //FIXME VG_(free)(buf);
+ VG_(free)(buf);
=20
baseaddr_set =3D 0;
for(j =3D 0; j < interp->e.e_phnum; j++) {
@@ -593,13 +568,20 @@
flags |=3D VKI_MAP_FIXED;
}
=20
- res =3D VG_(mmap_native)(base, interp_size, VKI_PROT_NONE, flags, =
-1, 0);
+ if (base)
+ res =3D VG_(mmap_anon_fixed_client)(base, interp_size, VKI_PROT=
_NONE);
+ else
+ res =3D VG_(mmap_anon_float_client)(interp_size, VKI_PROT_NONE)=
;
+
+ if (0) VG_(show_nsegments)("after native 3");
+
check_mmap(res, base, interp_size);
vg_assert(!res.isError);
base =3D (Char*)res.val;
=20
- baseoff =3D base - interp_addr;
+ VG_(munmap_client)( res.val, interp_size );
=20
+ baseoff =3D base - interp_addr;
mapelf(interp, (ESZ(Addr))baseoff);
=20
VG_(close)(interp->fd);
@@ -607,8 +589,8 @@
entry =3D baseoff + interp->e.e_entry;
info->interp_base =3D (ESZ(Addr))base;
=20
- //FIXME VG_(free)(interp->p);
- //FIXME VG_(free)(interp);
+ VG_(free)(interp->p);
+ VG_(free)(interp);
} else
entry =3D (void *)(ebase + e->e.e_entry);
=20
@@ -617,8 +599,8 @@
=20
info->init_eip =3D (Addr)entry;
=20
- //FIXME VG_(free)(e->p);
- //FIXME VG_(free)(e);
+ VG_(free)(e->p);
+ VG_(free)(e);
=20
return 0;
}
@@ -666,10 +648,10 @@
*cp =3D '\0';
}
=20
- info->interp_name =3D hack_strdup(interp);
+ info->interp_name =3D VG_(strdup)(interp);
vg_assert(NULL !=3D info->interp_name);
if (arg !=3D NULL && *arg !=3D '\0') {
- info->interp_args =3D hack_strdup(arg);
+ info->interp_args =3D VG_(strdup)(arg);
vg_assert(NULL !=3D info->interp_args);
}
=20
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-10 16:02:03 U=
TC (rev 4615)
+++ branches/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-11 00:48:18 U=
TC (rev 4616)
@@ -161,8 +161,13 @@
HChar
VgStack[VG_STACK_GUARD_SZB + VG_STACK_ACTIVE_SZB + VG_STACK_GUARD_SZB=
];
=20
-extern void VG_(new_aspacem_start) ( void );
+/* Takes a pointer to the sp at the time V gained control. This is
+ taken to be the highest usable address (more or less). Based on
+ that (and general consultation of tea leaves, etc) return a
+ suggested end address for the client's stack. */
+extern Addr VG_(new_aspacem_start) ( Addr sp_at_startup );
=20
+extern void VG_(show_nsegments) ( HChar* who );
=20
typedef
struct {
@@ -185,11 +190,17 @@
( void* startV, SizeT length, Int prot );
=20
extern
+SysRes VG_(mmap_anon_float_client)
+ ( SizeT length, Int prot );
+
+extern
SysRes VG_(map_anon_float_valgrind)( SizeT cszB );
=20
extern ULong VG_(aspacem_get_anonsize_total)( void );
=20
+extern SysRes VG_(munmap_client)( Addr base, SizeT length );
=20
+
#endif // __PUB_CORE_ASPACEMGR_H
=20
/*--------------------------------------------------------------------*/
|