From: Julian Seward Date: Sun, 7 Sep 2014 16:08:20 +0000 (+0000) Subject: More stack-end-semantics fixups for MacOS following r14422 and r14392. X-Git-Tag: svn/VALGRIND_3_10_0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f30ed1a2f3f28b70677c441d58c817ea2432eb6d;p=thirdparty%2Fvalgrind.git More stack-end-semantics fixups for MacOS following r14422 and r14392. May fix #338878. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14488 --- diff --git a/coregrind/m_initimg/initimg-darwin.c b/coregrind/m_initimg/initimg-darwin.c index 2ae934e4c2..42ef4091aa 100644 --- a/coregrind/m_initimg/initimg-darwin.c +++ b/coregrind/m_initimg/initimg-darwin.c @@ -395,7 +395,7 @@ Addr setup_client_stack( void* init_sp, if (0) VG_(printf)("stacksize = %d\n", stacksize); /* client_SP is the client's stack pointer */ - client_SP = clstack_end - stacksize; + client_SP = clstack_end + 1 - stacksize; client_SP = VG_ROUNDDN(client_SP, 32); /* make stack 32 byte aligned */ /* base of the string table (aligned) */ @@ -406,7 +406,7 @@ Addr setup_client_stack( void* init_sp, clstack_max_size = VG_PGROUNDUP(clstack_max_size); /* Darwin stack is chosen by the ume loader */ - clstack_start = clstack_end - clstack_max_size; + clstack_start = clstack_end + 1 - clstack_max_size; /* Record stack extent -- needed for stack-change code. */ /* GrP fixme really? */ @@ -518,6 +518,8 @@ static void record_system_memory(void) IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii ) { ExeInfo info; + VG_(memset)( &info, 0, sizeof(info) ); + HChar** env = NULL; IIFinaliseImageInfo iifii; diff --git a/coregrind/m_ume/macho.c b/coregrind/m_ume/macho.c index fbdae5bee7..8d9789ae7d 100644 --- a/coregrind/m_ume/macho.c +++ b/coregrind/m_ume/macho.c @@ -301,7 +301,12 @@ load_genericthread(vki_uint8_t **stack_end, if (flavor == i386_THREAD_STATE && count == i386_THREAD_STATE_COUNT) { i386_thread_state_t *state = (i386_thread_state_t *)p; if (entry) *entry = (vki_uint8_t *)state->__eip; - if (stack_end) *stack_end = (vki_uint8_t *)(state->__esp ? state->__esp : VKI_USRSTACK); + if (stack_end) { + *stack_end = (vki_uint8_t *)(state->__esp ? state->__esp + : VKI_USRSTACK); + vg_assert(VG_IS_PAGE_ALIGNED(*stack_end)); + (*stack_end)--; + } if (customstack) *customstack = state->__esp; return 0; } @@ -310,7 +315,12 @@ load_genericthread(vki_uint8_t **stack_end, if (flavor == x86_THREAD_STATE64 && count == x86_THREAD_STATE64_COUNT){ x86_thread_state64_t *state = (x86_thread_state64_t *)p; if (entry) *entry = (vki_uint8_t *)state->__rip; - if (stack_end) *stack_end = (vki_uint8_t *)(state->__rsp ? state->__rsp : VKI_USRSTACK64); + if (stack_end) { + *stack_end = (vki_uint8_t *)(state->__rsp ? state->__rsp + : VKI_USRSTACK64); + vg_assert(VG_IS_PAGE_ALIGNED(*stack_end)); + (*stack_end)--; + } if (customstack) *customstack = state->__rsp; return 0; } @@ -364,7 +374,7 @@ load_unixthread(vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, if (!customstack) { // Map the stack vki_size_t stacksize = VG_PGROUNDUP(default_stack_size()); - vm_address_t stackbase = VG_PGROUNDDN(stack_end-stacksize); + vm_address_t stackbase = VG_PGROUNDDN(stack_end+1-stacksize); SysRes res; res = VG_(am_mmap_anon_fixed_client)(stackbase, stacksize, VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC);