Change the way Valgrind exits.

Until now, valgrind waited for ld.so to call the .fini code in
valgrind.so, and took this as its cue to switch back to the real CPU
for the rest of the journey.

This is a problem if ld.so subsequently calls other .so's .fini code
and threading is in use, because they do pthread_* calls which cannot
be handled by valgrind's libpthread.so without valgrind actually being
active.

So we ignore the call to valgrind's .fini code, and run the program
all the way up to the point where it calls syscall exit() to
disappear.  This makes the order in which the .fini sections are run
irrelevant, since Valgrind has control during all of them, and so
threading facilities are still available for all of them.

This change means Mozilla 1.0RC1 now exits a lot more cleanly than it
did.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@201 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h
index af23b40..4b36e44 100644
--- a/coregrind/vg_include.h
+++ b/coregrind/vg_include.h
@@ -437,7 +437,6 @@
 In vg_constants.h:
 #define VG_USERREQ__SIGNAL_RETURNS          0x4001
 #define VG_USERREQ__PTHREAD_RETURNS         0x4002
-#define VG_USERREQ__SHUTDOWN_VALGRIND       0x4003
 */
 
 
@@ -602,9 +601,17 @@
 
 /* Return codes from the scheduler. */
 typedef
-   enum { VgSrc_Deadlock, VgSrc_Shutdown, VgSrc_BbsDone }
+   enum { 
+      VgSrc_Deadlock,    /* no runnable threads and no prospect of any
+                            even if we wait for a long time */
+      VgSrc_ExitSyscall, /* client called exit().  This is the normal
+                            route out. */
+      VgSrc_BbsDone      /* In a debugging run, the specified number of
+                            bbs has been completed. */
+   }
    VgSchedReturnCode;
 
+
 /* The scheduler. */
 extern VgSchedReturnCode VG_(scheduler) ( void );
 
@@ -1320,6 +1327,9 @@
 /* The current LRU epoch. */
 extern UInt VG_(current_epoch);
 
+/* This is the ThreadId of the last thread the scheduler ran. */
+extern ThreadId VG_(last_run_tid);
+
 
 /* --- Counters, for informational purposes only. --- */
 
@@ -1549,7 +1559,6 @@
    Exports of vg_startup.S
    ------------------------------------------------------------------ */
 
-extern void VG_(shutdown);
 extern void VG_(switch_to_real_CPU) ( void );
 
 extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,