valgrind: r3824 - trunk/coregrind/m_syscalls

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

valgrind: r3824 - trunk/coregrind/m_syscalls

svn-2
Author: sewardj
Date: 2005-05-31 16:41:42 +0100 (Tue, 31 May 2005)
New Revision: 3824

Modified:
   trunk/coregrind/m_syscalls/syscalls-amd64-linux.c
Log:
Unbreak amd64 build.


Modified: trunk/coregrind/m_syscalls/syscalls-amd64-linux.c
===================================================================
--- trunk/coregrind/m_syscalls/syscalls-amd64-linux.c 2005-05-31 13:08:03 UTC (rev 3823)
+++ trunk/coregrind/m_syscalls/syscalls-amd64-linux.c 2005-05-31 15:41:42 UTC (rev 3824)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "ume.h"                /* for jmp_with_stack */
+#include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_syscalls.h"
@@ -245,64 +246,116 @@
    return ((Addr)p) - tst->os_state.valgrind_stack_base;
 }
 
-/*
-   Allocate a stack for the main thread, and call VGA_(thread_wrapper)
-   on that stack.
- */
-void VGA_(main_thread_wrapper)(ThreadId tid)
+
+/* Run a thread all the way to the end, then do appropriate exit actions
+   (this is the last-one-out-turn-off-the-lights bit).
+*/
+static void run_a_thread_NORETURN ( Word tidW )
 {
-   UWord* rsp = allocstack(tid);
+   ThreadId tid = (ThreadId)tidW;
 
-   vg_assert(tid == VG_(master_tid));
+   VG_(debugLog)(1, "syscalls-x86-linux",
+                    "run_a_thread_NORETURN(tid=%lld): "
+                       "VGO_(thread_wrapper) called\n",
+                       (ULong)tidW);
 
-   call_on_new_stack_0_1(
-      (Addr)rsp,             /* stack */
-      0,                     /*bogus return address*/
-      VGA_(thread_wrapper),  /* fn to call */
-      (Word)tid              /* arg to give it */
-   );
+   /* Run the thread all the way through. */
+   VgSchedReturnCode src = VGO_(thread_wrapper)(tid);  
 
+   VG_(debugLog)(1, "syscalls-x86-linux",
+                    "run_a_thread_NORETURN(tid=%lld): "
+                       "VGO_(thread_wrapper) done\n",
+                       (ULong)tidW);
+
+   Int c = VG_(count_living_threads)();
+   vg_assert(c >= 1); /* stay sane */
+
+   if (c == 1) {
+
+      VG_(debugLog)(1, "syscalls-x86-linux",
+                       "run_a_thread_NORETURN(tid=%lld): "
+                          "last one standing\n",
+                          (ULong)tidW);
+
+      /* We are the last one standing.  Keep hold of the lock and
+         carry on to show final tool results, then exit the entire system. */
+      VG_(shutdown_actions_NORETURN)(tid, src);
+
+   } else {
+
+      VG_(debugLog)(1, "syscalls-x86-linux",
+                       "run_a_thread_NORETURN(tid=%lld): "
+                          "not last one standing\n",
+                          (ULong)tidW);
+
+      /* OK, thread is dead, but others still exist.  Just exit. */
+      ThreadState *tst = VG_(get_ThreadState)(tid);
+
+      /* This releases the run lock */
+      VG_(exit_thread)(tid);
+      vg_assert(tst->status == VgTs_Zombie);
+
+      /* We have to use this sequence to terminate the thread to
+         prevent a subtle race.  If VG_(exit_thread)() had left the
+         ThreadState as Empty, then it could have been reallocated,
+         reusing the stack while we're doing these last cleanups.
+         Instead, VG_(exit_thread) leaves it as Zombie to prevent
+         reallocation.  We need to make sure we don't touch the stack
+         between marking it Empty and exiting.  Hence the
+         assembler. */
+      asm volatile (
+         "movl %1, %0\n" /* set tst->status = VgTs_Empty */
+         "movq %2, %%rax\n"    /* set %rax = __NR_exit */
+         "movq %3, %%rdi\n"    /* set %rdi = tst->os_state.exitcode */
+         "syscall\n" /* exit(tst->os_state.exitcode) */
+         : "=m" (tst->status)
+         : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode));
+
+      VG_(core_panic)("Thread exit failed?\n");
+   }
+
    /*NOTREACHED*/
    vg_assert(0);
 }
 
-static Int start_thread(void *arg)
+
+/*
+   Allocate a stack for the main thread, and run it all the way to the
+   end.  
+*/
+void VGP_(main_thread_wrapper_NORETURN)(ThreadId tid)
 {
-   ThreadState *tst = (ThreadState *)arg;
-   ThreadId tid = tst->tid;
+   VG_(debugLog)(1, "syscalls-amd64-linux",
+                    "entering VGP_(main_thread_wrapper_NORETURN)\n");
 
-   VGA_(thread_wrapper)(tid);
+   UWord* rsp = allocstack(tid);
 
-   /* OK, thread is dead; this releases the run lock */
-   VG_(exit_thread)(tid);
+   /* shouldn't be any other threads around yet */
+   vg_assert( VG_(count_living_threads)() == 1 );
 
-   vg_assert(tst->status == VgTs_Zombie);
+   call_on_new_stack_0_1(
+      (Addr)rsp,              /* stack */
+      0,                      /*bogus return address*/
+      run_a_thread_NORETURN,  /* fn to call */
+      (Word)tid               /* arg to give it */
+   );
 
-   /* Poke the reaper */
-   if (VG_(clo_trace_signals))
-      VG_(message)(Vg_DebugMsg, "Sending SIGVGCHLD to master tid=%d lwp=%d",
-   VG_(master_tid), VG_(threads)[VG_(master_tid)].os_state.lwpid);
+   /*NOTREACHED*/
+   vg_assert(0);
+}
 
-   VG_(tkill)(VG_(threads)[VG_(master_tid)].os_state.lwpid, VKI_SIGVGCHLD);
 
-   /* We have to use this sequence to terminate the thread to prevent
-      a subtle race.  If VG_(exit_thread)() had left the ThreadState
-      as Empty, then it could have been reallocated, reusing the stack
-      while we're doing these last cleanups.  Instead,
-      VG_(exit_thread) leaves it as Zombie to prevent reallocation.
-      We need to make sure we don't touch the stack between marking it
-      Empty and exiting.  Hence the assembler. */
-   asm volatile (
-      "movl %1, %0\n" /* set tst->status = VgTs_Empty */
-      "movq %2, %%rax\n"    /* set %rax = __NR_exit */
-      "movq %3, %%rdi\n"    /* set %rdi = tst->os_state.exitcode */
-      "syscall\n" /* exit(tst->os_state.exitcode) */
-      : "=m" (tst->status)
-      : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode));
+static Int start_thread_NORETURN ( void* arg )
+{
+   ThreadState* tst = (ThreadState*)arg;
+   ThreadId     tid = tst->tid;
 
-   VG_(core_panic)("Thread exit failed?\n");
+   run_a_thread_NORETURN ( (Word)tid );
+   /*NOTREACHED*/
+   vg_assert(0);
 }
 
+
 /* ---------------------------------------------------------------------
    clone() handling
    ------------------------------------------------------------------ */
@@ -398,7 +451,7 @@
    VG_(sigprocmask)(VKI_SIG_SETMASK, &blockall, &savedmask);
 
    /* Create the new thread */
-   ret = VG_(clone)(start_thread, stack, flags, &VG_(threads)[ctid],
+   ret = VG_(clone)(start_thread_NORETURN, stack, flags, &VG_(threads)[ctid],
     child_tidptr, parent_tidptr, NULL);
 
    VG_(sigprocmask)(VKI_SIG_SETMASK, &savedmask, NULL);



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Valgrind-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers