aboutsummaryrefslogtreecommitdiff
path: root/lib/darwin/inject.c
diff options
context:
space:
mode:
authorcomex2015-03-01 19:35:12 -0500
committercomex2015-03-01 19:35:12 -0500
commitf3456372119e32c13b7bbe059f6c73815b7361cf (patch)
treee4225e52f5f9299e56588bf6da09a28109a545d4 /lib/darwin/inject.c
parentminor changes (diff)
downloadsubstitute-f3456372119e32c13b7bbe059f6c73815b7361cf.tar.gz
fix stack alignment
Diffstat (limited to '')
-rw-r--r--lib/darwin/inject.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/darwin/inject.c b/lib/darwin/inject.c
index 6e0c50e..0f67ccb 100644
--- a/lib/darwin/inject.c
+++ b/lib/darwin/inject.c
@@ -381,7 +381,7 @@ got_symbol:;
return true;
}
-static int do_baton(const char *filename, size_t filelen, bool is64,
+static int do_baton(const char *filename, size_t filelen, cpu_type_t cputype,
mach_vm_address_t target_stackpage_end,
mach_vm_address_t *target_stack_top_p,
uint64_t sym_addrs[static 5],
@@ -391,13 +391,16 @@ static int do_baton(const char *filename, size_t filelen, bool is64,
mach_port_t task,
char **error) {
int ret;
+ bool is64 = !!(cputype & CPU_ARCH_ABI64);
size_t baton_len = 8 * (is64 ? 8 : 4);
size_t shuttles_len = nshuttle * sizeof(struct shuttle);
size_t filelen_rounded = (filelen + 7) & ~7;
size_t total_len = baton_len + shuttles_len + filelen_rounded;
mach_vm_address_t target_stack_top = target_stackpage_end - total_len;
- target_stack_top &= ~7;
+ target_stack_top &= ~15;
+ if (cputype == CPU_TYPE_X86_64)
+ target_stack_top -= 8;
*target_stack_top_p = target_stack_top;
char *stackbuf = calloc(total_len, 1);
if (!stackbuf) {
@@ -639,7 +642,7 @@ int substitute_dlopen_in_pid(int pid, const char *filename, int options,
dlsym_addr,
munmap_addr};
mach_vm_address_t target_stack_top;
- if ((ret = do_baton(filename, filelen, cputype & CPU_ARCH_ABI64,
+ if ((ret = do_baton(filename, filelen, cputype,
target_code_page, &target_stack_top,
sym_addrs, shuttle, nshuttle, &target_shuttle, &sem_port,
task, error)))