]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Change VG_(scheduler)() slightly to remove two more global vars from
authorNicholas Nethercote <n.nethercote@gmail.com>
Mon, 9 Aug 2004 13:13:31 +0000 (13:13 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 9 Aug 2004 13:13:31 +0000 (13:13 +0000)
vg_include.h.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2578

coregrind/vg_include.h
coregrind/vg_main.c
coregrind/vg_scheduler.c
coregrind/vg_signals.c

index 183352bd3a65ea3dad46bef302c479053fb4d25e..960aac5671b616b0cb055c1c6f22e8102b8a2104 100644 (file)
@@ -930,9 +930,9 @@ typedef
    VgSchedReturnCode;
 
 
-/* The scheduler. */
-extern VgSchedReturnCode VG_(scheduler) ( Int* exit_code,
-                                          ThreadId* last_run_thread );
+// The scheduler.  'fatal_sigNo' is only set if VgSrc_FatalSig is returned.
+extern VgSchedReturnCode VG_(scheduler) 
+            ( Int* exit_code, ThreadId* last_run_thread, Int* fatal_sigNo );
 
 extern void VG_(scheduler_init) ( void );
 
@@ -941,6 +941,9 @@ extern void VG_(pp_sched_status) ( void );
 // Longjmp back to the scheduler and thus enter the sighandler immediately.
 extern void VG_(resume_scheduler) ( Int sigNo, vki_ksiginfo_t *info );
 
+// Longjmp, ending the scheduler, when a fatal signal occurs in the client.
+extern void VG_(scheduler_handle_fatal_signal)( Int sigNo );
+
 /* The red-zone size which we put at the bottom (highest address) of
    thread stacks, for paranoia reasons.  This can be arbitrary, and
    doesn't really need to be set at compile time. */
@@ -1285,10 +1288,6 @@ extern void VG_(start_debugger) ( Int tid );
 /* Counts downwards in vg_run_innerloop. */
 extern UInt VG_(dispatch_ctr);
 
-/* If we're doing the default action of a fatal signal */
-extern jmp_buf* VG_(fatal_signal_jmpbuf_ptr);
-extern Int      VG_(fatal_sigNo);              /* the fatal signal */
-
 /* --- Counters, for informational purposes only. --- */
 
 // These counters must be declared here because they're maintained by
index 465fd9af88d2e67e6795bd61e231dfffdb5a9498..f80a75bca37880b95917c7959703fef6d0703ce1 100644 (file)
@@ -149,12 +149,6 @@ Char** VG_(client_envp);
    Running stuff                            
    ------------------------------------------------------------------ */
 
-/* jmp_buf for fatal signals;  VG_(fatal_signal_jmpbuf_ptr) is NULL until
-   the time is right that it can be used. */
-       Int      VG_(fatal_sigNo) = -1;
-       jmp_buf* VG_(fatal_signal_jmpbuf_ptr) = NULL;
-static jmp_buf  fatal_signal_jmpbuf;
-
 /* Counts downwards in VG_(run_innerloop). */
 UInt VG_(dispatch_ctr);
 
@@ -2747,6 +2741,7 @@ int main(int argc, char **argv)
    UInt * client_auxv;
    VgSchedReturnCode src;
    Int exitcode = 0;
+   Int fatal_sigNo = -1;
    vki_rlimit zero = { 0, 0 };
    Int padfile;
    ThreadId last_run_tid = 0;    // Last thread the scheduler ran.
@@ -3043,14 +3038,9 @@ int main(int argc, char **argv)
    VGP_POPCC(VgpStartup);
    VGP_PUSHCC(VgpSched);
 
-   VG_(fatal_signal_jmpbuf_ptr) = &fatal_signal_jmpbuf;
-   if (__builtin_setjmp(VG_(fatal_signal_jmpbuf_ptr)) == 0) {
-      src = VG_(scheduler)( &exitcode, &last_run_tid );
-   } else {
-      src = VgSrc_FatalSig;
-   }
-   VGP_POPCC(VgpSched);
+   src = VG_(scheduler)( &exitcode, &last_run_tid, &fatal_sigNo );
 
+   VGP_POPCC(VgpSched);
 
 
    //--------------------------------------------------------------
@@ -3113,8 +3103,8 @@ int main(int argc, char **argv)
 
       case VgSrc_FatalSig:
         /* We were killed by a fatal signal, so replicate the effect */
-        vg_assert(VG_(fatal_sigNo) != -1);
-        VG_(kill_self)(VG_(fatal_sigNo));
+        vg_assert(fatal_sigNo != -1);
+        VG_(kill_self)(fatal_sigNo);
         VG_(core_panic)("main(): signal was supposed to be fatal");
         break;
 
index b3e4f69d39a2c40f2849d30f20fd00a3bd6ce16b..f60387797e45df1c6fac621be7dd6c1210e188cf 100644 (file)
@@ -839,12 +839,19 @@ void idle ( void )
    The scheduler proper.
    ------------------------------------------------------------------ */
 
+// For handling of the default action of a fatal signal.
+// jmp_buf for fatal signals;  VG_(fatal_signal_jmpbuf_ptr) is NULL until
+// the time is right that it can be used.
+static jmp_buf  fatal_signal_jmpbuf;
+static jmp_buf* fatal_signal_jmpbuf_ptr;
+static Int      fatal_sigNo;              // the fatal signal, if it happens
+
 /* Run user-space threads until either
    * Deadlock occurs
    * One thread asks to shutdown Valgrind
    * The specified number of basic blocks has gone by.
 */
-VgSchedReturnCode VG_(scheduler) ( Int* exitcode, ThreadId* last_run_tid )
+VgSchedReturnCode do_scheduler ( Int* exitcode, ThreadId* last_run_tid )
 {
    ThreadId tid, tid_next;
    UInt     trc;
@@ -1214,6 +1221,21 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode, ThreadId* last_run_tid )
    /* NOTREACHED */
 }
 
+VgSchedReturnCode VG_(scheduler) ( Int* exitcode, ThreadId* last_run_tid,
+                                   Int* fatal_sigNo_ptr )
+{
+   VgSchedReturnCode src;
+
+   fatal_signal_jmpbuf_ptr = &fatal_signal_jmpbuf;
+   if (__builtin_setjmp( fatal_signal_jmpbuf_ptr ) == 0) {
+      src = do_scheduler( exitcode, last_run_tid );
+   } else {
+      src = VgSrc_FatalSig;
+      *fatal_sigNo_ptr = fatal_sigNo;
+   }
+   return src;
+}
+
 void VG_(need_resched) ( ThreadId prefer )
 {
    /* Tell the scheduler now might be a good time to find a new
@@ -1249,6 +1271,13 @@ void VG_(need_resched) ( ThreadId prefer )
    prefer_sched = prefer;
 }
 
+void VG_(scheduler_handle_fatal_signal) ( Int sigNo )
+{
+   if (NULL != fatal_signal_jmpbuf_ptr) {
+      fatal_sigNo = sigNo;
+      __builtin_longjmp(*fatal_signal_jmpbuf_ptr, 1);
+   }
+}
 
 /* ---------------------------------------------------------------------
    The pthread implementation.
index 8d3841a424565c4d0364150508a35987ad14d01f..683b93adf35143cd96af370c07995af1c6182e56 100644 (file)
@@ -1803,10 +1803,7 @@ static void vg_default_action(const vki_ksiginfo_t *info, ThreadId tid)
         VG_(setrlimit)(VKI_RLIMIT_CORE, &zero);
       }
 
-      if (NULL != VG_(fatal_signal_jmpbuf_ptr)) {
-        VG_(fatal_sigNo) = sigNo;
-        __builtin_longjmp(*VG_(fatal_signal_jmpbuf_ptr), 1);
-      }
+      VG_(scheduler_handle_fatal_signal)( sigNo );
    }
 
    VG_(kill_self)(sigNo);