From: Nicholas Nethercote Date: Mon, 13 Sep 2004 13:16:40 +0000 (+0000) Subject: Arch-abstraction: X-Git-Tag: svn/VALGRIND_3_0_0~1576 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe64d52a7b70de0f073299a8fdd73c4605c7b0c3;p=thirdparty%2Fvalgrind.git Arch-abstraction: - in vg_scheduler.c, abstract out some stack manipulations. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2711 --- diff --git a/coregrind/core.h b/coregrind/core.h index 074899c6fe..ac9b0add94 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -1502,6 +1502,9 @@ extern void VGA_(init_thread) ( arch_thread_t* ); extern void VGA_(cleanup_thread) ( arch_thread_t* ); extern void VGA_(setup_child) ( arch_thread_t*, arch_thread_t* ); +extern void VGA_(set_arg_and_bogus_ret) ( ThreadId tid, UWord arg, Addr ret ); +extern void VGA_(thread_initial_stack) ( ThreadId tid, UWord arg, Addr ret ); + // Symtab stuff extern UInt* VGA_(reg_addr_from_BB) ( Int reg ); extern UInt* VGA_(reg_addr_from_tst) ( Int reg, arch_thread_t* ); diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index 1cac4f95d9..7c8acdcaca 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -1159,17 +1159,10 @@ void make_thread_jump_to_cancelhdlr ( ThreadId tid ) vg_libpthread.c. */ vg_assert(VG_(threads)[tid].cancel_pend != NULL); - /* Push a suitable arg, and mark it as readable. */ - SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - 4); - * (UInt*)(VG_(threads)[tid].arch.m_esp) = (UInt)PTHREAD_CANCELED; - VG_TRACK( post_mem_write, VG_(threads)[tid].arch.m_esp, sizeof(void*) ); - - /* Push a bogus return address. It will not return, but we still - need to have it so that the arg is at the correct stack offset. - Don't mark as readable; any attempt to read this is and internal - valgrind bug since thread_exit_wrapper should not return. */ - SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - 4); - * (UInt*)(VG_(threads)[tid].arch.m_esp) = 0xBEADDEEF; + /* Set an argument and bogus return address. The return address will not + be used, but we still need to have it so that the arg is at the + correct stack offset. */ + VGA_(set_arg_and_bogus_ret)(tid, (UInt)PTHREAD_CANCELED, 0xBEADDEEF); /* .cancel_pend will hold &thread_exit_wrapper */ ARCH_INSTR_PTR(VG_(threads)[tid].arch) = (UInt)VG_(threads)[tid].cancel_pend; @@ -1710,8 +1703,7 @@ void do__quit ( ThreadId tid ) } -/* Should never be entered. If it is, will be on the simulated - CPU. */ +/* Should never be entered. If it is, will be on the simulated CPU. */ static void do__apply_in_new_thread_bogusRA ( void ) { @@ -1804,22 +1796,11 @@ void do__apply_in_new_thread ( ThreadId parent_tid, VG_TRACK ( die_mem_stack, VG_(threads)[tid].stack_base, VG_(threads)[tid].stack_size - VG_AR_CLIENT_STACKBASE_REDZONE_SZB); - VG_TRACK ( ban_mem_stack, VG_(threads)[tid].arch.m_esp, + VG_TRACK ( ban_mem_stack, ARCH_STACK_PTR(VG_(threads)[tid].arch), VG_AR_CLIENT_STACKBASE_REDZONE_SZB ); - /* push two args */ - SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - 8); - - VG_TRACK ( new_mem_stack, (Addr)VG_(threads)[tid].arch.m_esp, 2 * 4 ); - VG_TRACK ( pre_mem_write, Vg_CorePThread, tid, "new thread: stack", - (Addr)VG_(threads)[tid].arch.m_esp, 2 * 4 ); - - /* push arg and (bogus) return address */ - * (UInt*)(VG_(threads)[tid].arch.m_esp+4) = (UInt)arg; - * (UInt*)(VG_(threads)[tid].arch.m_esp) - = (UInt)&do__apply_in_new_thread_bogusRA; - - VG_TRACK ( post_mem_write, VG_(threads)[tid].arch.m_esp, 2 * 4 ); + VGA_(thread_initial_stack)(tid, (UWord)arg, + (Addr)&do__apply_in_new_thread_bogusRA); /* this is where we start */ ARCH_INSTR_PTR(VG_(threads)[tid].arch) = (UInt)fn; diff --git a/coregrind/x86/state.c b/coregrind/x86/state.c index 05bb401665..3ed1a1bfda 100644 --- a/coregrind/x86/state.c +++ b/coregrind/x86/state.c @@ -490,6 +490,40 @@ void VGA_(setup_child) ( arch_thread_t *regs, arch_thread_t *parent_regs ) VG_(baseBlock)[VGOFF_(tls_ptr)] = (UInt) regs->tls; } +void VGA_(set_arg_and_bogus_ret)( ThreadId tid, UWord arg, Addr ret ) +{ + /* Push the arg, and mark it as readable. */ + SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - sizeof(UWord)); + * (UInt*)(VG_(threads)[tid].arch.m_esp) = arg; + VG_TRACK( post_mem_write, VG_(threads)[tid].arch.m_esp, sizeof(void*) ); + + /* Don't mark the pushed return address as readable; any attempt to read + this is an internal valgrind bug since thread_exit_wrapper() should not + return. */ + SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - sizeof(UWord)); + * (UInt*)(VG_(threads)[tid].arch.m_esp) = ret; +} + +void VGA_(thread_initial_stack)(ThreadId tid, UWord arg, Addr ret) +{ + Addr esp = (Addr)ARCH_STACK_PTR(VG_(threads)[tid].arch); + + /* push two args */ + esp -= 8; + SET_PTHREQ_ESP(tid, esp); + + VG_TRACK ( new_mem_stack, esp, 2 * 4 ); + VG_TRACK ( pre_mem_write, Vg_CorePThread, tid, "new thread: stack", + esp, 2 * 4 ); + + /* push arg and (bogus) return address */ + *(UWord*)(esp+4) = arg; + *(UWord*)(esp) = ret; + + VG_TRACK ( post_mem_write, esp, 2 * 4 ); +} + + /*------------------------------------------------------------*/ /*--- Symtab stuff ---*/ /*------------------------------------------------------------*/