From: Bart Van Assche Date: Sun, 16 Mar 2008 17:29:20 +0000 (+0000) Subject: Fixed stack red zone handling. X-Git-Tag: svn/VALGRIND_3_4_0~855 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5425ee1fbe4814f4cbfd90820906e3d292fe6b2b;p=thirdparty%2Fvalgrind.git Fixed stack red zone handling. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7713 --- diff --git a/exp-drd/drd_main.c b/exp-drd/drd_main.c index db33579222..6033dc468e 100644 --- a/exp-drd/drd_main.c +++ b/exp-drd/drd_main.c @@ -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); } diff --git a/exp-drd/drd_suppression.c b/exp-drd/drd_suppression.c index cad09c42f9..91fcbdea7b 100644 --- a/exp-drd/drd_suppression.c +++ b/exp-drd/drd_suppression.c @@ -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); } diff --git a/exp-drd/drd_thread.c b/exp-drd/drd_thread.c index dc59818352..45eb2351db 100644 --- a/exp-drd/drd_thread.c +++ b/exp-drd/drd_thread.c @@ -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) { diff --git a/exp-drd/drd_thread.h b/exp-drd/drd_thread.h index 24e3506c0e..290d4ea68b 100644 --- a/exp-drd/drd_thread.h +++ b/exp-drd/drd_thread.h @@ -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);