vg_include.h.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2578
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 );
// 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. */
/* 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
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);
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.
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);
//--------------------------------------------------------------
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;
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;
/* 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
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.
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);