From: Nicholas Nethercote Date: Mon, 9 Aug 2004 13:13:31 +0000 (+0000) Subject: Change VG_(scheduler)() slightly to remove two more global vars from X-Git-Tag: svn/VALGRIND_2_2_0~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b36a2a2c6ae22caa469bceb6691c5c57d4d0d21f;p=thirdparty%2Fvalgrind.git Change VG_(scheduler)() slightly to remove two more global vars from vg_include.h. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2578 --- diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index 183352bd3a..960aac5671 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -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 diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index 465fd9af88..f80a75bca3 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -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; diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index b3e4f69d39..f60387797e 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -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. diff --git a/coregrind/vg_signals.c b/coregrind/vg_signals.c index 8d3841a424..683b93adf3 100644 --- a/coregrind/vg_signals.c +++ b/coregrind/vg_signals.c @@ -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);