]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix 373046 - Stacks registered by core are never deregistered
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 28 Nov 2016 19:34:06 +0000 (19:34 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 28 Nov 2016 19:34:06 +0000 (19:34 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16159

NEWS
coregrind/m_scheduler/scheduler.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/pub_core_threadstate.h

diff --git a/NEWS b/NEWS
index 3ff733d3b1ea07ed33d417561106389667309177..9531e8d8c52bd483809ff0c5b39fa23e4c7c807e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -79,7 +79,7 @@ where XXXXXX is the bug number as listed below.
 372120  c++ demangler demangles symbols which are not c++
 372504  Hanging on exit_group
 372600  process loops forever when fatal signals are arriving quickly
-
+373046  Stacks registered by core are never deregistered
 
 
 Release 3.12.0 (20 October 2016)
index 036389858e6b9f7bdbaac459bf5c09bd9b8ff410..49f51d6279b33c378aa83df9fe835780caab96cb 100644 (file)
@@ -488,6 +488,7 @@ static void os_state_clear(ThreadState *tst)
 {
    tst->os_state.lwpid       = 0;
    tst->os_state.threadgroup = 0;
+   tst->os_state.stk_id = NULL_STK_ID;
 #  if defined(VGO_linux)
    /* no other fields to clear */
 #  elif defined(VGO_darwin)
@@ -504,7 +505,6 @@ static void os_state_clear(ThreadState *tst)
 #  if defined(VGP_x86_solaris)
    tst->os_state.thrptr = 0;
 #  endif
-   tst->os_state.stk_id = (UWord)-1;
    tst->os_state.ustack = NULL;
    tst->os_state.in_door_return = False;
    tst->os_state.door_return_procedure = 0;
index 6ef6a90d04036b16d9820872578e5fb4dde16546..28972ae4553a63eba489d124fdf1cfc99de76771 100644 (file)
@@ -84,11 +84,14 @@ void ML_(guess_and_register_stack) (Addr sp, ThreadState* tst)
       tst->client_stack_highest_byte = (Addr)VG_PGROUNDUP(sp)-1;
       tst->client_stack_szB = tst->client_stack_highest_byte - seg->start + 1;
 
-      VG_(register_stack)(seg->start, tst->client_stack_highest_byte);
+      tst->os_state.stk_id 
+         = VG_(register_stack)(seg->start, tst->client_stack_highest_byte);
 
       if (debug)
-        VG_(printf)("tid %u: guessed client stack range [%#lx-%#lx]\n",
-                    tst->tid, seg->start, tst->client_stack_highest_byte);
+        VG_(printf)("tid %u: guessed client stack range [%#lx-%#lx]"
+                     " as stk_id %lu\n",
+                    tst->tid, seg->start, tst->client_stack_highest_byte,
+                     tst->os_state.stk_id);
    } else {
       VG_(message)(Vg_UserMsg,
                    "!? New thread %u starts with SP(%#lx) unmapped\n",
index af10b92b604cb78560d17e7f25454c36b03366dc..725ad782e9ea3af52a876eca00a6a0eaa9e6c41c 100644 (file)
@@ -52,6 +52,7 @@
 #include "pub_core_options.h"
 #include "pub_core_scheduler.h"
 #include "pub_core_signals.h"
+#include "pub_core_stacks.h"
 #include "pub_core_syscall.h"
 #include "pub_core_syswrap.h"
 #include "pub_core_inner.h"
@@ -162,6 +163,10 @@ static void run_a_thread_NORETURN ( Word tidW )
    c = VG_(count_living_threads)();
    vg_assert(c >= 1); /* stay sane */
 
+   /* Deregister thread's stack. */
+   if (tst->os_state.stk_id != NULL_STK_ID)
+      VG_(deregister_stack)(tst->os_state.stk_id);
+
    // Tell the tool this thread is exiting
    VG_TRACK( pre_thread_ll_exit, tid );
 
index f3d956cff2e1007456535499d6ea970dee4e03b7..3307e758773770fba42f81993e96600f27b3d76c 100644 (file)
@@ -114,6 +114,8 @@ typedef
    ThreadArchState;
 
 
+#define NULL_STK_ID (~(UWord)0)
+
 /* OS-specific thread state.  IMPORTANT: if you add fields to this,
    you _must_ add code to os_state_clear() to initialise those
    fields. */
@@ -129,6 +131,12 @@ typedef
       Addr valgrind_stack_base;    // Valgrind's stack (VgStack*)
       Addr valgrind_stack_init_SP; // starting value for SP
 
+      /* Client stack is registered as stk_id (on linux/darwin, by
+         ML_(guess_and_register_stack)).
+         Stack id NULL_STK_ID means that the user stack is not (yet)
+         registered. */
+      UWord stk_id;
+
       /* exit details */
       Word exitcode; // in the case of exitgroup, set by someone else
       Int  fatalsig; // fatal signal
@@ -281,10 +289,6 @@ typedef
          the 64-bit offset associated with a %fs value of zero. */
 #     endif
 
-      /* Stack id (value (UWord)(-1) means that there is no stack). This
-         tracks a stack that is set in restore_stack(). */
-      UWord stk_id;
-
       /* Simulation of the kernel's lwp->lwp_ustack. Set in the PRE wrapper
          of the getsetcontext syscall, for SETUSTACK. Used in
          VG_(save_context)(), VG_(restore_context)() and