From cc276fe3c96965ba39b9fba3b588a1eaa3941d86 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Mar 2012 17:15:51 -0800 Subject: rt: Be more precise with VALGRIND_MAKE_MEM_UNDEFINED --- src/rt/rust_task.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/rt/rust_task.cpp') diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index c6e0aa159da..71f4949888f 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -571,7 +571,6 @@ rust_task::new_stack(size_t requested_sz) { LOG(this, mem, "reusing existing stack"); stk = stk->prev; A(thread, stk->prev == NULL, "Bogus stack ptr"); - prepare_valgrind_stack(stk); return; } else { LOG(this, mem, "existing stack is not big enough"); @@ -637,12 +636,29 @@ rust_task::del_stack() { void * rust_task::next_stack(size_t stk_sz, void *args_addr, size_t args_sz) { + stk_seg *maybe_next_stack = NULL; + if (stk != NULL) { + maybe_next_stack = stk->prev; + } + new_stack(stk_sz + args_sz); A(thread, stk->end - (uintptr_t)stk->data >= stk_sz + args_sz, "Did not receive enough stack"); uint8_t *new_sp = (uint8_t*)stk->end; // Push the function arguments to the new stack new_sp = align_down(new_sp - args_sz); + + // When reusing a stack segment we need to tell valgrind that this area of + // memory is accessible before writing to it, because the act of popping + // the stack previously made all of the stack inaccessible. + if (maybe_next_stack == stk) { + // I don't know exactly where the region ends that valgrind needs us + // to mark accessible. On x86_64 these extra bytes aren't needed, but + // on i386 we get errors without. + int fudge_bytes = 16; + reuse_valgrind_stack(stk, new_sp - fudge_bytes); + } + memcpy(new_sp, args_addr, args_sz); A(thread, rust_task_thread::get_task() == this, "Recording the stack limit for the wrong thread"); -- cgit 1.4.1-3-g733a5