mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 15:38:22 +00:00
Fix issue with stack creation on OpenBSD
This commit is contained in:
parent
2e54c8f9fc
commit
e1699c5b68
1 changed files with 18 additions and 2 deletions
|
@ -38,10 +38,12 @@ cosmo: push %rbp
|
||||||
mov %rsi,%r13
|
mov %rsi,%r13
|
||||||
mov %rdx,%r14
|
mov %rdx,%r14
|
||||||
mov %rcx,%r15
|
mov %rcx,%r15
|
||||||
|
|
||||||
#ifdef SYSDEBUG
|
#ifdef SYSDEBUG
|
||||||
call __strace_init
|
call __strace_init
|
||||||
mov %eax,%r12d
|
mov %eax,%r12d
|
||||||
#endif /* SYSDEBUG */
|
#endif /* SYSDEBUG */
|
||||||
|
|
||||||
#ifdef __FAST_MATH__
|
#ifdef __FAST_MATH__
|
||||||
push %rax
|
push %rax
|
||||||
stmxcsr (%rsp)
|
stmxcsr (%rsp)
|
||||||
|
@ -49,7 +51,11 @@ cosmo: push %rbp
|
||||||
ldmxcsr (%rsp)
|
ldmxcsr (%rsp)
|
||||||
pop %rax
|
pop %rax
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// run assembly init
|
||||||
call _init
|
call _init
|
||||||
|
|
||||||
|
// call constructors
|
||||||
ezlea __init_array_start,ax # static ctors in forward order
|
ezlea __init_array_start,ax # static ctors in forward order
|
||||||
.weak __init_array_start # could be called multiple times
|
.weak __init_array_start # could be called multiple times
|
||||||
ezlea __init_array_end,cx # idempotency recommended
|
ezlea __init_array_end,cx # idempotency recommended
|
||||||
|
@ -64,11 +70,14 @@ cosmo: push %rbp
|
||||||
pop %rax
|
pop %rax
|
||||||
add $8,%rax
|
add $8,%rax
|
||||||
jmp 1b
|
jmp 1b
|
||||||
|
|
||||||
|
// call main()
|
||||||
2: call .Largs
|
2: call .Largs
|
||||||
.weak main
|
.weak main
|
||||||
call main
|
call main
|
||||||
xchg %eax,%edi
|
xchg %eax,%edi
|
||||||
call exit
|
call exit
|
||||||
|
|
||||||
.Largs: mov %r12d,%edi
|
.Largs: mov %r12d,%edi
|
||||||
mov %r13,%rsi
|
mov %r13,%rsi
|
||||||
mov %r14,%rdx
|
mov %r14,%rdx
|
||||||
|
@ -103,6 +112,7 @@ cosmo: push %rbp
|
||||||
jnz 9f
|
jnz 9f
|
||||||
push %rdi
|
push %rdi
|
||||||
push %rsi
|
push %rsi
|
||||||
|
|
||||||
// allocate stack
|
// allocate stack
|
||||||
movabs $ape_stack_vaddr,%rdi
|
movabs $ape_stack_vaddr,%rdi
|
||||||
mov $ape_stack_memsz,%esi
|
mov $ape_stack_memsz,%esi
|
||||||
|
@ -118,16 +128,22 @@ cosmo: push %rbp
|
||||||
pop %rdi
|
pop %rdi
|
||||||
cmp $-1,%rax
|
cmp $-1,%rax
|
||||||
je 9f
|
je 9f
|
||||||
|
|
||||||
// switch stacks
|
// switch stacks
|
||||||
|
//
|
||||||
|
// we subtract 8 because the openbsd kernel always checks rsp
|
||||||
|
// is on a MAP_STACK interval non-inclusively of stack + size
|
||||||
leave
|
leave
|
||||||
pop %rcx
|
pop %rcx # return address
|
||||||
|
sub $8,%r8d # openbsd:stackbound
|
||||||
lea (%rax,%r8),%rsp
|
lea (%rax,%r8),%rsp
|
||||||
mov $ape_stack_align,%eax # openbsd:stackbound
|
mov $ape_stack_align,%eax
|
||||||
neg %rax
|
neg %rax
|
||||||
and %rax,%rsp
|
and %rax,%rsp
|
||||||
push %rcx
|
push %rcx
|
||||||
push %rbp
|
push %rbp
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
|
|
||||||
9: nop
|
9: nop
|
||||||
.init.end 304,_init_stack
|
.init.end 304,_init_stack
|
||||||
.weak ape_stack_prot
|
.weak ape_stack_prot
|
||||||
|
|
Loading…
Add table
Reference in a new issue