]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin: also clean up client stack creation
authorPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 5 Dec 2025 20:59:34 +0000 (21:59 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Fri, 5 Dec 2025 21:08:45 +0000 (22:08 +0100)
Make stringbase and strtab be based off clstack_end + 1
rather than clstack_end. clstack_end is the address of the
last byte of the stack, not one past the end of the stack.
That means that it is not word aligned. Adding 1 makes
the calculation word aligned.

Depending on the length of the string table with rounding
it could happen that the executable_path pointer would
overwrite the start of argv[0] in the string table.

I think that that there are supposed to be 0-16 bytes between
the end of the pointers and the string table (or is that
ELF?).

coregrind/m_initimg/initimg-darwin.c

index 3ddc9806c68b330dcef3ec4a9fa821c78dac7f52..0befeaef399a40bb3205ab76ae85c64254b2fd83 100644 (file)
@@ -360,16 +360,8 @@ Addr setup_client_stack( void*  init_sp,
       stringsize += VG_(strlen)(*cpp) + 1;
    }
 
-   // @todo PJF there is a bug in the size calculation or rounding
-   // somewhere. This should be "+= 2" (one of the pointer to exec
-   // path and one for the terminating NULL pointer). When I run
-   // "./tests/vg_regtest none/tests" from a Korn shell script
-   // then the allexec32/64 tests fail because they print out "argv[0]".
-   // I think that what happens is that writing to "ptr" overwrites the
-   // start of strtab resulting in the argv[0] the exe name being a
-   // string starting with 8 \0s (not tested)
-   /* Darwin executable_path + NULL */
-   auxsize += 3 * sizeof(Word);
+   /* NULL separator and executable path */
+   auxsize += 2 * sizeof(HChar **);
    if (info->executable_path) {
        stringsize += 1 + VG_(strlen)(info->executable_path);
    }
@@ -395,7 +387,7 @@ Addr setup_client_stack( void*  init_sp,
    client_SP = VG_ROUNDDN(client_SP, 32); /* make stack 32 byte aligned */
 
    /* base of the string table (aligned) */
-   stringbase = strtab = (HChar *)clstack_end 
+   stringbase = strtab = (HChar *)clstack_end + 1
                          - VG_ROUNDUP(stringsize, sizeof(int));
 
    /* The max stack size */