rt: Implement 32-bit __morestack for mac
This commit is contained in:
parent
c254936f32
commit
292663b8ef
|
@ -5,18 +5,24 @@
|
|||
// LLVM generates a call to this to allocate more stack space in a function
|
||||
// prolog when we run out.
|
||||
|
||||
#if defined(__APPLE__) || defined(_WIN32)
|
||||
#define UPCALL_NEW_STACK _upcall_new_stack
|
||||
#define UPCALL_DEL_STACK _upcall_del_stack
|
||||
#define RUST_GET_TASK _rust_get_task
|
||||
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
|
||||
#if defined(__APPLE__)
|
||||
#define RUST_GET_TASK L_rust_get_task$stub
|
||||
#define UPCALL_CALL_C L_upcall_call_shim_on_c_stack$stub
|
||||
#define MORESTACK ___morestack
|
||||
#else
|
||||
#if defined(__linux__)
|
||||
#define UPCALL_NEW_STACK upcall_new_stack
|
||||
#define UPCALL_DEL_STACK upcall_del_stack
|
||||
#define RUST_GET_TASK rust_get_task
|
||||
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
|
||||
#define MORESTACK __morestack
|
||||
#else
|
||||
#define UPCALL_NEW_STACK _upcall_new_stack
|
||||
#define UPCALL_DEL_STACK _upcall_del_stack
|
||||
#define RUST_GET_TASK _rust_get_task
|
||||
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
|
||||
#define MORESTACK __morestack
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// FIXME: Future LLVM patches remove these 8 alignment bytes from
|
||||
|
@ -43,7 +49,7 @@
|
|||
.type MORESTACK,@function
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
MORESTACK:
|
||||
|
||||
pushl %ebp
|
||||
|
@ -51,25 +57,33 @@ MORESTACK:
|
|||
|
||||
// FIXME (1226): main is compiled with the split-stack prologue,
|
||||
// causing it to call __morestack, so we have to jump back out
|
||||
subl $24,%esp
|
||||
subl $20,%esp
|
||||
calll RUST_GET_TASK
|
||||
testl %eax,%eax
|
||||
jz .L$bail
|
||||
|
||||
// The arguments to rust_new_stack2
|
||||
movl 36(%esp),%eax // Size of stack arguments
|
||||
movl 32(%esp),%eax // Size of stack arguments
|
||||
movl %eax,16(%esp)
|
||||
leal 44+ALIGNMENT(%esp),%eax // Address of stack arguments
|
||||
leal 40+ALIGNMENT(%esp),%eax // Address of stack arguments
|
||||
movl %eax,12(%esp)
|
||||
movl 32(%esp),%eax // The amount of stack needed
|
||||
movl 28(%esp),%eax // The amount of stack needed
|
||||
movl %eax,8(%esp)
|
||||
|
||||
#ifdef __APPLE__
|
||||
call 1f
|
||||
1: popl %ebx
|
||||
movl L_upcall_new_stack$non_lazy_ptr-1b(%ebx),%ecx
|
||||
movl %ecx, 4(%esp)
|
||||
#else
|
||||
movl $UPCALL_NEW_STACK,4(%esp)
|
||||
#endif
|
||||
|
||||
leal 8(%esp), %eax
|
||||
movl %eax,(%esp)
|
||||
call UPCALL_CALL_C
|
||||
|
||||
movl 28(%esp),%edx // Grab the return pointer.
|
||||
movl 24(%esp),%edx // Grab the return pointer.
|
||||
addl $RETURN_OFFSET,%edx // Skip past the `add esp,4` and the `ret`.
|
||||
|
||||
movl %eax,%esp // Switch stacks.
|
||||
|
@ -81,7 +95,15 @@ MORESTACK:
|
|||
// Switch back to the rust stack
|
||||
movl %ebp, %esp
|
||||
|
||||
#ifdef __APPLE__
|
||||
call 1f
|
||||
1: popl %ebx
|
||||
movl L_upcall_del_stack$non_lazy_ptr-1b(%ebx),%ecx
|
||||
pushl %ecx
|
||||
#else
|
||||
pushl $UPCALL_DEL_STACK
|
||||
#endif
|
||||
|
||||
pushl $0
|
||||
call UPCALL_CALL_C
|
||||
|
||||
|
@ -90,10 +112,10 @@ MORESTACK:
|
|||
retl $8
|
||||
|
||||
.L$bail:
|
||||
movl 28(%esp),%edx
|
||||
movl 24(%esp),%edx
|
||||
addl $RETURN_OFFSET,%edx
|
||||
|
||||
addl $24, %esp
|
||||
addl $20, %esp
|
||||
popl %ebp
|
||||
addl $4+8+ALIGNMENT,%esp
|
||||
|
||||
|
@ -107,13 +129,25 @@ MORESTACK:
|
|||
|
||||
#ifdef __APPLE__
|
||||
|
||||
.section __IMPORT,__pointers,non_lazy_symbol_pointers
|
||||
rust_new_stack_sym:
|
||||
.indirect_symbol RUST_NEW_STACK
|
||||
.long 0
|
||||
rust_del_stack_sym:
|
||||
.indirect_symbol RUST_DEL_STACK
|
||||
.long 0
|
||||
.section __IMPORT,__pointers,non_lazy_symbol_pointers
|
||||
L_upcall_new_stack$non_lazy_ptr:
|
||||
.indirect_symbol _upcall_new_stack
|
||||
.long 0
|
||||
L_upcall_del_stack$non_lazy_ptr:
|
||||
.indirect_symbol _upcall_del_stack
|
||||
.long 0
|
||||
|
||||
.section __IMPORT,__jump_table,symbol_stubs,pure_instructions+self_modifying_code,5
|
||||
|
||||
// Linker will replace the hlts (the ascii) with jmp
|
||||
L_rust_get_task$stub:
|
||||
.indirect_symbol _rust_get_task
|
||||
.ascii "\364\364\364\364\364"
|
||||
|
||||
L_upcall_call_shim_on_c_stack$stub:
|
||||
.indirect_symbol _upcall_call_shim_on_c_stack
|
||||
.ascii "\364\364\364\364\364"
|
||||
|
||||
.subsections_via_symbols
|
||||
#endif
|
||||
|
||||
|
|
|
@ -14,6 +14,14 @@ RECORD_SP:
|
|||
movl %eax, %gs:48
|
||||
ret
|
||||
#else
|
||||
#if defined(__APPLE__)
|
||||
RECORD_SP:
|
||||
movl $0x48+90*4, %eax
|
||||
movl 4(%esp), %ecx
|
||||
movl %ecx, %gs:(%eax)
|
||||
ret
|
||||
#else
|
||||
RECORD_SP:
|
||||
ret
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue