]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fixed stack red zone handling.
authorBart Van Assche <bvanassche@acm.org>
Sun, 16 Mar 2008 17:29:20 +0000 (17:29 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 16 Mar 2008 17:29:20 +0000 (17:29 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7713

exp-drd/drd_main.c
exp-drd/drd_suppression.c
exp-drd/drd_thread.c
exp-drd/drd_thread.h

index db33579222719a01d80f38561fc1bedfafdc94be..6033dc468eaf08c38641c2e41157722f3bf6d430 100644 (file)
@@ -162,7 +162,7 @@ static void drd_trace_mem_access(const Addr addr, const SizeT size,
                : access_type == eStart
                ? "start"
                : access_type == eEnd
-               ? "end"
+               ? "end  "
                : "????",
                addr,
                size,
@@ -464,7 +464,7 @@ static void drd_stop_using_mem(const Addr a1, const SizeT len)
 
   if (a1 <= drd_trace_address && drd_trace_address < a2)
   {
-    drd_trace_mem_access(a1, len, eStart);
+    drd_trace_mem_access(a1, len, eEnd);
   }
   thread_stop_using_mem(a1, a2);
   clientobj_stop_using_mem(a1, a2);
@@ -485,8 +485,8 @@ void drd_start_using_mem_w_perms(const Addr a, const SizeT len,
 /* Assumption: stacks grow downward.                                     */
 static void drd_start_using_mem_stack(const Addr a, const SizeT len)
 {
-  thread_set_stack_min(thread_get_running_tid(), a);
-  drd_start_using_mem(a, len);
+  thread_set_stack_min(thread_get_running_tid(), a - VG_STACK_REDZONE_SZB);
+  drd_start_using_mem(a - VG_STACK_REDZONE_SZB, len + VG_STACK_REDZONE_SZB);
 }
 
 /* Called by the core when the stack of a thread shrinks, to indicate that */
@@ -494,8 +494,9 @@ static void drd_start_using_mem_stack(const Addr a, const SizeT len)
 /* Assumption: stacks grow downward.                                       */
 static void drd_stop_using_mem_stack(const Addr a, const SizeT len)
 {
-  thread_set_stack_min(thread_get_running_tid(), a + len);
-  drd_stop_using_mem(a, len);
+  thread_set_stack_min(thread_get_running_tid(),
+                       a + len - VG_STACK_REDZONE_SZB);
+  drd_stop_using_mem(a - VG_STACK_REDZONE_SZB, len + VG_STACK_REDZONE_SZB);
 }
 
 static void drd_start_using_mem_stack_signal(const Addr a, const SizeT len)
@@ -584,24 +585,28 @@ void drd_trace_addr(const Addr addr)
 }
 
 /* Called after a thread has performed its last memory access. */
-static void drd_thread_finished(ThreadId tid)
+static void drd_thread_finished(ThreadId vg_tid)
 {
   DrdThreadId drd_tid;
 
-  tl_assert(VG_(get_running_tid)() == tid);
+  tl_assert(VG_(get_running_tid)() == vg_tid);
 
-  drd_tid = VgThreadIdToDrdThreadId(tid);
+  drd_tid = VgThreadIdToDrdThreadId(vg_tid);
   if (drd_trace_fork_join)
   {
     VG_(message)(Vg_DebugMsg,
                  "drd_thread_finished tid = %d/%d%s",
-                 tid,
+                 vg_tid,
                  drd_tid,
                  thread_get_joinable(drd_tid)
                  ? ""
                  : " (which is a detached thread)");
 
   }
+  drd_stop_using_mem(thread_get_stack_min(drd_tid),
+                     thread_get_stack_max(drd_tid)
+                     - thread_get_stack_min(drd_tid));
+  thread_stop_recording(drd_tid);
   thread_finished(drd_tid);
 }
 
index cad09c42f9ce9ffcb4c7a7165ce6116228a3bbfc..91fcbdea7bf8e2659b75071b348d895bb81d65e0 100644 (file)
@@ -61,7 +61,7 @@ void drd_start_suppression(const Addr a1, const Addr a2,
   }
 
   tl_assert(a1 < a2);
-  tl_assert(! drd_is_any_suppressed(a1, a2));
+  // tl_assert(! drd_is_any_suppressed(a1, a2));
   bm_access_range_store(s_suppressed, a1, a2);
 }
 
index dc598183521856b7fec8e16c91241cdfcaf30c01..45eb2351db62f125499e20db86b8006f11cbaf0e 100644 (file)
@@ -246,21 +246,11 @@ Addr thread_get_stack_min(const DrdThreadId tid)
   return s_threadinfo[tid].stack_min;
 }
 
-DrdThreadId thread_lookup_stackaddr(const Addr a,
-                                    Addr* const stack_min,
-                                    Addr* const stack_max)
+Addr thread_get_stack_max(const DrdThreadId tid)
 {
-  unsigned i;
-  for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
-  {
-    if (s_threadinfo[i].stack_min <= a && a <= s_threadinfo[i].stack_max)
-    {
-      *stack_min = s_threadinfo[i].stack_min;
-      *stack_max = s_threadinfo[i].stack_max;
-      return i;
-    }
-  }
-  return DRD_INVALID_THREADID;
+  tl_assert(0 <= tid && tid < DRD_N_THREADS
+            && tid != DRD_INVALID_THREADID);
+  return s_threadinfo[tid].stack_max;
 }
 
 /**
@@ -295,9 +285,6 @@ void thread_finished(const DrdThreadId tid)
   tl_assert(0 <= tid && tid < DRD_N_THREADS
             && tid != DRD_INVALID_THREADID);
 
-  thread_stop_using_mem(s_threadinfo[tid].stack_min,
-                        s_threadinfo[tid].stack_max);
-
   s_threadinfo[tid].vg_thread_exists = False;
 
   if (s_threadinfo[tid].detached_posix_thread)
@@ -606,11 +593,11 @@ void thread_combine_vc2(DrdThreadId tid, const VectorClock* const vc)
  */
 void thread_stop_using_mem(const Addr a1, const Addr a2)
 {
-  DrdThreadId other_user = DRD_INVALID_THREADID;
+  DrdThreadId other_user;
+  unsigned i;
 
   /* For all threads, mark the range [ a1, a2 [ as no longer in use. */
-
-  unsigned i;
+  other_user = DRD_INVALID_THREADID;
   for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
   {
     Segment* p;
@@ -681,7 +668,7 @@ static void show_call_stack(const DrdThreadId tid,
 {
   const ThreadId vg_tid = DrdThreadIdToVgThreadId(tid);
 
-  VG_(message)(Vg_UserMsg, "%s (thread %d)", msg, tid);
+  VG_(message)(Vg_UserMsg, "%s (thread %d)", msg, /*vg_tid,*/ tid);
 
   if (vg_tid != VG_INVALID_THREADID)
   {
index 24e3506c0eae133d885895c42951c02dcc1dbb58..290d4ea68b109f1ebeacfd3e2903565775da8f5d 100644 (file)
@@ -102,9 +102,7 @@ void thread_delete(const DrdThreadId tid);
 void thread_finished(const DrdThreadId tid);
 void thread_set_stack_startup(const DrdThreadId tid, const Addr stack_startup);
 Addr thread_get_stack_min(const DrdThreadId tid);
-DrdThreadId thread_lookup_stackaddr(const Addr a,
-                                    Addr* const stack_min,
-                                    Addr* const stack_max);
+Addr thread_get_stack_max(const DrdThreadId tid);
 void thread_set_pthreadid(const DrdThreadId tid, const PThreadId ptid);
 Bool thread_get_joinable(const DrdThreadId tid);
 void thread_set_joinable(const DrdThreadId tid, const Bool joinable);