Skip to content

Commit

Permalink
Fix stack alignment and auxv for macho APE loader (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr authored Nov 5, 2023
1 parent a12ad17 commit 4f100d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ape/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,11 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
os = OPENBSD;
}

/* xnu passes auxv as an array of strings */
if (os == XNU) {
*auxv = 0;
}

/* detect netbsd and find end of words */
pagesz = 0;
for (ap = auxv; ap[0]; ap += 2) {
Expand Down
2 changes: 2 additions & 0 deletions ape/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifdef __aarch64__

_start: mov x1,sp
and sp,x1,#-16
mov x29,0
bl ApeLoader
.endfn _start,globl
Expand All @@ -33,6 +34,7 @@ XnuEntrypoint:
mov $_HOSTXNU,%dl // xnu's not unix!
ElfEntrypoint:
mov %rsp,%rsi // save real stack
andq $-16,%rsp // force SSE alignment
call ApeLoader
.endfn ElfEntrypoint,globl
.endfn XnuEntrypoint,globl
Expand Down

0 comments on commit 4f100d2

Please sign in to comment.