]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Make VG_(last_run_tid) and VG_(sigstack) local.
authorNicholas Nethercote <n.nethercote@gmail.com>
Sat, 7 Aug 2004 18:16:56 +0000 (18:16 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sat, 7 Aug 2004 18:16:56 +0000 (18:16 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2575

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

index f70dcb9f2fd066585905ec5a981469831f05aebc..6e13616ab891dbc728c1589d44f1149fd3241373 100644 (file)
 /* Max number of callers for context in a suppression. */
 #define VG_N_SUPP_CALLERS  4
 
-/* Valgrind's signal stack size, in words */
-#define VG_SIGSTACK_SIZE_W    10000
-
 /* Useful macros */
 /* a - alignment - must be a power of 2 */
 #define ROUNDDN(p, a)  ((Addr)(p) & ~((a)-1))
@@ -934,7 +931,8 @@ typedef
 
 
 /* The scheduler. */
-extern VgSchedReturnCode VG_(scheduler) ( Int* exit_code );
+extern VgSchedReturnCode VG_(scheduler) ( Int* exit_code,
+                                          ThreadId* last_run_thread );
 
 extern void VG_(scheduler_init) ( void );
 
@@ -1024,6 +1022,7 @@ extern void VG_(synth_fault)        (ThreadId tid);
 extern void VG_(synth_fault_mapping)(ThreadId tid, Addr addr);
 extern void VG_(synth_fault_perms)  (ThreadId tid, Addr addr);
 
+extern void VG_(get_sigstack_bounds)( Addr* low, Addr* high );
 
 /* ---------------------------------------------------------------------
    Exports of vg_mylibc.c
@@ -1252,12 +1251,6 @@ extern Bool VG_(need_to_handle_esp_assignment) ( void );
 extern void VG_(unimplemented) ( Char* msg )
             __attribute__((__noreturn__));
 
-/* Similarly, we have to ask for signals to be delivered on an alternative
-   stack, since it is possible, although unlikely, that we'll have to run
-   client code from inside the Valgrind-installed signal handler.  If this
-   happens it will be done by vg_deliver_signal_immediately(). */
-extern UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W];
-
 /* Valgrind's argc and argv */
 extern Int    VG_(vg_argc);
 extern Char **VG_(vg_argv);
@@ -1268,9 +1261,6 @@ extern void VG_(start_debugger) ( Int tid );
 /* Counts downwards in vg_run_innerloop. */
 extern UInt VG_(dispatch_ctr);
 
-/* This is the ThreadId of the last thread the scheduler ran. */
-extern ThreadId VG_(last_run_tid);
-
 /* 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 */
index 41897a44c5d9d14905d14b9dce444f597122ca09..1c6be6c9e3287df36a74b849567b6586b2d3dd12 100644 (file)
@@ -148,8 +148,6 @@ Char** VG_(client_envp);
 /* ---------------------------------------------------------------------
    Running stuff                            
    ------------------------------------------------------------------ */
-/* Our signal delivery stack. */
-UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W];
 
 /* jmp_buf for fatal signals;  VG_(fatal_signal_jmpbuf_ptr) is NULL until
    the time is right that it can be used. */
@@ -163,9 +161,6 @@ UInt VG_(dispatch_ctr);
 /* 64-bit counter for the number of basic blocks done. */
 ULong VG_(bbs_done);
 
-/* This is the ThreadId of the last thread the scheduler ran. */
-ThreadId VG_(last_run_tid) = 0;
-
 /* Tell the logging mechanism whether we are logging to a file
    descriptor or a socket descriptor. */
 Bool VG_(logging_to_filedes) = True;
@@ -2679,6 +2674,8 @@ int main(int argc, char **argv)
    Int exitcode = 0;
    vki_rlimit zero = { 0, 0 };
    Int padfile;
+   ThreadId last_run_tid = 0;    // Last thread the scheduler ran.
+
 
    //============================================================
    // Nb: startup is complex.  Prerequisites are shown at every step.
@@ -2973,7 +2970,7 @@ int main(int argc, char **argv)
 
    VG_(fatal_signal_jmpbuf_ptr) = &fatal_signal_jmpbuf;
    if (__builtin_setjmp(VG_(fatal_signal_jmpbuf_ptr)) == 0) {
-      src = VG_(scheduler)( &exitcode );
+      src = VG_(scheduler)( &exitcode, &last_run_tid );
    } else {
       src = VgSrc_FatalSig;
    }
@@ -3012,8 +3009,8 @@ int main(int argc, char **argv)
 
    /* We're exiting, so nuke all the threads and clean up the proxy LWPs */
    vg_assert(src == VgSrc_FatalSig ||
-            VG_(threads)[VG_(last_run_tid)].status == VgTs_Runnable ||
-            VG_(threads)[VG_(last_run_tid)].status == VgTs_WaitJoiner);
+            VG_(threads)[last_run_tid].status == VgTs_Runnable ||
+            VG_(threads)[last_run_tid].status == VgTs_WaitJoiner);
    VG_(nuke_all_threads_except)(VG_INVALID_THREADID);
 
    //--------------------------------------------------------------
@@ -3021,7 +3018,7 @@ int main(int argc, char **argv)
    //--------------------------------------------------------------
    switch (src) {
       case VgSrc_ExitSyscall: /* the normal way out */
-         vg_assert(VG_(last_run_tid) > 0 && VG_(last_run_tid) < VG_N_THREADS);
+         vg_assert(last_run_tid > 0 && last_run_tid < VG_N_THREADS);
         VG_(proxy_shutdown)();
 
          /* The thread's %EBX at the time it did __NR_exit() will hold
index 1724aadb97e81360af8ef719eb946fa15b9c2135..3dd68df87e88fe85909f993ef2dec81f8539147b 100644 (file)
@@ -1089,13 +1089,13 @@ static inline ExeContext *get_real_execontext(Addr ret)
 {
    ExeContext *ec;
    Addr esp, ebp;
-   Addr stacktop;
+   Addr stacktop, sigstack_low, sigstack_high;
 
    asm("movl %%ebp, %0; movl %%esp, %1" : "=r" (ebp), "=r" (esp));
    stacktop = VG_(valgrind_end);
-   if (esp >= (Addr)&VG_(sigstack)[0] && 
-       esp < (Addr)&VG_(sigstack)[VG_SIGSTACK_SIZE_W])
-      stacktop = (Addr)&VG_(sigstack)[VG_SIGSTACK_SIZE_W];
+   VG_(get_sigstack_bounds)( &sigstack_low, &sigstack_high );
+   if (esp >= sigstack_low && esp < sigstack_high)
+      stacktop = sigstack_high;
       
    ec = VG_(get_ExeContext2)(ret, ebp, esp, stacktop);
 
index 81843bd1f05726081d28bad9ed943b8eb581ef02..b3e4f69d39a2c40f2849d30f20fd00a3bd6ce16b 100644 (file)
@@ -844,7 +844,7 @@ void idle ( void )
    * One thread asks to shutdown Valgrind
    * The specified number of basic blocks has gone by.
 */
-VgSchedReturnCode VG_(scheduler) ( Int* exitcode )
+VgSchedReturnCode VG_(scheduler) ( Int* exitcode, ThreadId* last_run_tid )
 {
    ThreadId tid, tid_next;
    UInt     trc;
@@ -855,7 +855,7 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode )
 
    /* Start with the root thread.  tid in general indicates the
       currently runnable/just-finished-running thread. */
-   VG_(last_run_tid) = tid = 1;
+   *last_run_tid = tid = 1;
 
    /* This is the top level scheduler loop.  It falls into three
       phases. */
@@ -975,7 +975,7 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode )
       /* Actually run thread tid. */
       while (True) {
 
-         VG_(last_run_tid) = tid;
+         *last_run_tid = tid;
 
          /* For stats purposes only. */
          n_scheduling_events_MINOR++;
index 9f7d88938b0cd2f9b6444880ea06374f1a46c5dc..8d3841a424565c4d0364150508a35987ad14d01f 100644 (file)
 #define DEBUG_SIGNALS
 
 
-/*
-   - The following causes an infinite loop: start Hugs, Feb 2001 
-     version, and do Control-C at the prompt.  There is an infinite
-     series of sigints delivered (to the client); but also seemingly
-     to valgrind, which is very strange.  I don't know why.
-
-     [I haven't re-tested this, but this is likely fixed - JSGF]
-*/
-
-
 /* ---------------------------------------------------------------------
    Forwards decls.
    ------------------------------------------------------------------ */
@@ -103,6 +93,24 @@ static void proxy_sigvg_handler        ( Int sigNo, vki_ksiginfo_t *info, struct vki
 static Bool is_correct_sigmask(void);
 static const Char *signame(Int sigNo);
 
+/* ---------------------------------------------------------------------
+   Signal stack
+   ------------------------------------------------------------------ */
+
+/* Valgrind's signal stack size, in words */
+#define VG_SIGSTACK_SIZE_W    10000
+
+/* We have to ask for signals to be delivered on an alternative
+   stack, since it is possible, although unlikely, that we'll have to run
+   client code from inside the Valgrind-installed signal handler. */
+static Addr sigstack[VG_SIGSTACK_SIZE_W];
+
+extern void VG_(get_sigstack_bounds)( Addr* low, Addr* high )
+{
+   *low  = (Addr) & sigstack[0];
+   *high = (Addr) & sigstack[VG_SIGSTACK_SIZE_W]; 
+}
+
 /* ---------------------------------------------------------------------
    HIGH LEVEL STUFF TO DO WITH SIGNALS: POLICY (MOSTLY)
    ------------------------------------------------------------------ */
@@ -2042,9 +2050,9 @@ void vg_sync_signalhandler ( Int sigNo, vki_ksiginfo_t *info, struct vki_ucontex
    /* Sanity check.  Ensure we're really running on the signal stack
       we asked for. */
    if (!(
-         ((Char*)(&(VG_(sigstack)[0])) <= (Char*)(&dummy_local))
+         ((Char*)(&(sigstack[0])) <= (Char*)(&dummy_local))
          &&
-         ((Char*)(&dummy_local) < (Char*)(&(VG_(sigstack)[VG_SIGSTACK_SIZE_W])))
+         ((Char*)(&dummy_local) < (Char*)(&(sigstack[VG_SIGSTACK_SIZE_W])))
          )
       ) {
      VG_(message)(Vg_DebugMsg, 
@@ -2058,8 +2066,8 @@ void vg_sync_signalhandler ( Int sigNo, vki_ksiginfo_t *info, struct vki_ucontex
          "rebuild your prog without -p/-pg");
    }
 
-   vg_assert((Char*)(&(VG_(sigstack)[0])) <= (Char*)(&dummy_local));
-   vg_assert((Char*)(&dummy_local) < (Char*)(&(VG_(sigstack)[VG_SIGSTACK_SIZE_W])));
+   vg_assert((Char*)(&(sigstack[0])) <= (Char*)(&dummy_local));
+   vg_assert((Char*)(&dummy_local) < (Char*)(&(sigstack[VG_SIGSTACK_SIZE_W])));
 
    /* Special fault-handling case. We can now get signals which can
       act upon and immediately restart the faulting instruction.
@@ -2359,7 +2367,7 @@ void VG_(sigstartup_actions) ( void )
    VG_(proxy_setsigmask)(1);
 
    /* Register an alternative stack for our own signal handler to run on. */
-   altstack_info.ss_sp = &(VG_(sigstack)[0]);
+   altstack_info.ss_sp = &(sigstack[0]);
    altstack_info.ss_size = VG_SIGSTACK_SIZE_W * sizeof(UInt);
    altstack_info.ss_flags = 0;
    ret = VG_(ksigaltstack)(&altstack_info, NULL);