drd: Set up red zone before the first instruction of a thread is run.

Avoids that DRD sporadically reports mysterious false positive conflicting accesses on
amd64 like e.g. the following:

$ ./vg-in-place --fair-sched=yes --tool=drd --read-var-info=yes --check-stack-var=yes --show-confl-seg=no drd/tests/annotate_smart_pointer 50 50
==18170== drd, a thread error detector
==18170== Copyright (C) 2006-2011, and GNU GPL'd, by Bart Van Assche.
==18170== Using Valgrind-3.8.0.SVN and LibVEX; rerun with -h for copyright info
==18170== Command: ./annotate_smart_pointer 50 50
==18170==
==18170== Conflicting store by thread 1 at 0x7fefff8a0 size 8
==18170==    at 0x400FCE: AnnotateCondVarSignal (unified_annotations.h:32)
==18170== Allocation context: unknown.
==18170==
==18170== Conflicting load by thread 1 at 0x7fefff8a0 size 8
==18170==    at 0x400FDD: AnnotateCondVarSignal (unified_annotations.h:34)
==18170==    by 0x401071: U_AnnotateHappensBefore (unified_annotations.h:46)
==18170==    by 0x4018DD: smart_ptr<counter>::set(counter*, AtomicInt32*) (annotate_smart_pointer.cpp:239)
==18170==    by 0x401778: smart_ptr<counter>::operator=(counter*) (annotate_smart_pointer.cpp:208)
==18170==    by 0x401377: main (annotate_smart_pointer.cpp:326)
==18170== Allocation context: unknown.






























git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12332 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/drd/drd_main.c b/drd/drd_main.c
index 5889f4c..a48dc37 100644
--- a/drd/drd_main.c
+++ b/drd/drd_main.c
@@ -602,10 +602,16 @@
 void drd_post_thread_create(const ThreadId vg_created)
 {
    DrdThreadId drd_created;
+   Addr stack_max;
 
    tl_assert(vg_created != VG_INVALID_THREADID);
 
    drd_created = DRD_(thread_post_create)(vg_created);
+
+   /* Set up red zone before the code in glibc's clone.S is run. */
+   stack_max = DRD_(thread_get_stack_max)(drd_created);
+   drd_start_using_mem_stack2(drd_created, stack_max, 0);
+
    if (DRD_(thread_get_trace_fork_join)())
    {
       DRD_(trace_msg)("drd_post_thread_create created = %d", drd_created);