Fix stack memory, undefined behavior, etc.

This commit is contained in:
Justine Tunney 2023-08-15 19:09:35 -07:00
parent 110559ce6a
commit 507d7a0b0b
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 41 additions and 186 deletions

View file

@ -67,16 +67,11 @@ _start:
lea 16(%rsp,%rbx,8),%rdx // envp
mov %rsp,__oldstack(%rip)
// setup a stack frame
// align stack to GetStackSize() so GetStackAddr() is fast
.weak ape_stack_memsz
mov $ape_stack_memsz,%r9d
mov $16,%r8d
test %r9d,%r9d
cmovnz %r9,%r8
neg %r8
and %r8,%rsp
// setup backtraces
xor %ebp,%ebp
// make process stack (8mb) follow thread stack (256kb) alignment
and $-(256*1024),%rsp
// bofram 9f
#if SupportsWindows()
@ -126,6 +121,10 @@ _start:
// this is the first argument to cosmo() below
mov x0,sp
// make process stack (8mb) conform to thread stack (256kb) alignment
mov x1,sp
and sp,x1,-(256*1024)
// second arg shall be struct Syslib passed by ape-m1.c
// used to talk to apple's authoritarian libraries
// should be set to zero on other platforms