]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
More stack-end-semantics fixups for MacOS following r14422 and r14392.
authorJulian Seward <jseward@acm.org>
Sun, 7 Sep 2014 16:08:20 +0000 (16:08 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 7 Sep 2014 16:08:20 +0000 (16:08 +0000)
May fix #338878.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14488

coregrind/m_initimg/initimg-darwin.c
coregrind/m_ume/macho.c

index 2ae934e4c2386c0783e26a080ad276e26c14f51f..42ef4091aab99a8a553019bc998537c628097dee 100644 (file)
@@ -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;
index fbdae5bee73d943592d78148aae8707c441f7583..8d9789ae7ded7602344120bde16c23c46d912f52 100644 (file)
@@ -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);