|
From: <sv...@va...> - 2005-09-14 08:12:08
|
Author: tom
Date: 2005-09-14 09:12:05 +0100 (Wed, 14 Sep 2005)
New Revision: 4653
Log:
Fixup stack handling for amd64. Also removed a redundant line of code
from the x86 code.
Modified:
branches/ASPACEM/coregrind/m_syswrap/syswrap-amd64-linux.c
branches/ASPACEM/coregrind/m_syswrap/syswrap-x86-linux.c
Modified: branches/ASPACEM/coregrind/m_syswrap/syswrap-amd64-linux.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_syswrap/syswrap-amd64-linux.c 2005-09-14=
08:10:28 UTC (rev 4652)
+++ branches/ASPACEM/coregrind/m_syswrap/syswrap-amd64-linux.c 2005-09-14=
08:12:05 UTC (rev 4653)
@@ -61,70 +61,46 @@
Note. Why is this stuff here?
------------------------------------------------------------------ */
=20
-/*=20
- Allocate a stack for this thread.
+/* Allocate a stack for this thread. They're allocated lazily, and
+ never freed. */
=20
- They're allocated lazily, but never freed.
- */
-#define FILL 0xdeadbeefcabafeed
+/* Allocate a stack for this thread, if it doesn't already have one.
+ Returns the initial stack pointer value to use, or 0 if allocation
+ failed. */
=20
-// Valgrind's stack size, in words.
-#define STACK_SIZE_W 16384
-
-static UWord* allocstack(ThreadId tid)
+static Addr allocstack(ThreadId tid)
{
- ThreadState *tst =3D VG_(get_ThreadState)(tid);
- UWord* rsp;
+ ThreadState* tst =3D VG_(get_ThreadState)(tid);
+ VgStack* stack;
+ Addr initial_SP;
=20
- if (tst->os_state.valgrind_stack_base =3D=3D 0) {
- void *stk =3D VG_(mmap)(0, STACK_SIZE_W * sizeof(UWord) + VKI_PAGE=
_SIZE,
- VKI_PROT_READ|VKI_PROT_WRITE,
- VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS,
- SF_VALGRIND,
- -1, 0);
+ /* Either the stack_base and stack_init_SP are both zero (in which
+ case a stack hasn't been allocated) or they are both non-zero,
+ in which case it has. */
=20
- if (stk !=3D (void *)-1) {
- VG_(mprotect)(stk, VKI_PAGE_SIZE, VKI_PROT_NONE); /* guard page */
- tst->os_state.valgrind_stack_base =3D ((Addr)stk) + VKI_PAGE_SIZE;
- tst->os_state.valgrind_stack_szB =3D STACK_SIZE_W * sizeof(UWord);
- } else=20
- return (UWord*)-1;
- }
+ if (tst->os_state.valgrind_stack_base =3D=3D 0)
+ vg_assert(tst->os_state.valgrind_stack_init_SP =3D=3D 0);
=20
- for (rsp =3D (UWord*) tst->os_state.valgrind_stack_base;=20
- rsp < (UWord*)(tst->os_state.valgrind_stack_base +
- tst->os_state.valgrind_stack_szB);=20
- rsp++)
- *rsp =3D FILL;
- /* rsp is left at top of stack */
+ if (tst->os_state.valgrind_stack_base !=3D 0)
+ vg_assert(tst->os_state.valgrind_stack_init_SP !=3D 0);
=20
- if (0)
- VG_(printf)("stack for tid %d at %p (%llx); rsp=3D%p\n",
- tid, tst->os_state.valgrind_stack_base,
- *(UWord*)(tst->os_state.valgrind_stack_base), rsp);
+ /* If no stack is present, allocate one. */
=20
- return rsp;
-}
+ if (tst->os_state.valgrind_stack_base =3D=3D 0) {
+ stack =3D VG_(am_alloc_VgStack)( &initial_SP );
+ if (stack) {
+ tst->os_state.valgrind_stack_base =3D (Addr)stack;
+ tst->os_state.valgrind_stack_init_SP =3D initial_SP;
+ }
+ }
=20
-/* NB: this is identical the the x86 version. */
-/* Return how many bytes of this stack have not been used */
-SSizeT VG_(stack_unused)(ThreadId tid)
-{
- ThreadState *tst =3D VG_(get_ThreadState)(tid);
- UWord* p;
-
- for (p =3D (UWord*)tst->os_state.valgrind_stack_base;=20
- p && (p < (UWord*)(tst->os_state.valgrind_stack_base +
- tst->os_state.valgrind_stack_szB));=20
- p++)
- if (*p !=3D FILL)
- break;
-
if (0)
- VG_(printf)("p=3D%p %llx tst->os_state.valgrind_stack_base=3D%p\n"=
,
- p, *p, tst->os_state.valgrind_stack_base);
-
- return ((Addr)p) - tst->os_state.valgrind_stack_base;
+ VG_(printf)( "stack for tid %d at %p; init_SP=3D%p\n",
+ tid,=20
+ (void*)tst->os_state.valgrind_stack_base,=20
+ (void*)tst->os_state.valgrind_stack_init_SP );
+ =20
+ return tst->os_state.valgrind_stack_init_SP;
}
=20
=20
@@ -246,9 +222,13 @@
{
VG_(debugLog)(1, "syswrap-amd64-linux",=20
"entering VG_(main_thread_wrapper_NORETURN)\n");
-#if 0
- UWord* rsp =3D allocstack(tid);
=20
+ Addr rsp =3D allocstack(tid);
+
+ /* If we can't even allocate the first thread's stack, we're hosed.
+ Give up. */
+ vg_assert2(rsp !=3D 0, "Cannot allocate main thread's stack.");
+
/* shouldn't be any other threads around yet */
vg_assert( VG_(count_living_threads)() =3D=3D 1 );
=20
@@ -258,10 +238,7 @@
run_a_thread_NORETURN, /* fn to call */
(Word)tid /* arg to give it */
);
-#endif
=20
- run_a_thread_NORETURN( tid );
-
/*NOTREACHED*/
vg_assert(0);
}
@@ -401,7 +378,7 @@
vg_assert(VG_(is_running_thread)(ptid));
vg_assert(VG_(is_valid_tid)(ctid));
=20
- stack =3D allocstack(ctid);
+ stack =3D (UWord*)allocstack(ctid);
=20
/* Copy register state
=20
Modified: branches/ASPACEM/coregrind/m_syswrap/syswrap-x86-linux.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_syswrap/syswrap-x86-linux.c 2005-09-14 0=
8:10:28 UTC (rev 4652)
+++ branches/ASPACEM/coregrind/m_syswrap/syswrap-x86-linux.c 2005-09-14 0=
8:12:05 UTC (rev 4653)
@@ -239,8 +239,6 @@
(Word)tid /* arg to give it */
);
=20
- run_a_thread_NORETURN( tid );
-
/*NOTREACHED*/
vg_assert(0);
}
|