Fixed stack red zone handling.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7713 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/exp-drd/drd_main.c b/exp-drd/drd_main.c
index db33579..6033dc4 100644
--- a/exp-drd/drd_main.c
+++ b/exp-drd/drd_main.c
@@ -162,7 +162,7 @@
                : access_type == eStart
                ? "start"
                : access_type == eEnd
-               ? "end"
+               ? "end  "
                : "????",
                addr,
                size,
@@ -464,7 +464,7 @@
 
   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 @@
 /* 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 @@
 /* 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 @@
 }
 
 /* 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);
 }