Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack probe CFI information for amd64 and i386 #8848

Merged
merged 2 commits into from Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -131,6 +131,10 @@ Working version
(Gabriel Scherer and Florian Angeletti,
review by Florian Angeletti and Gabriel Radanne)

- #8848: Fix x86 stack probe CFI information in caml_c_call and
caml_call_gc
(Tom Kelly, review by Xavier Leroy)

OCaml 4.09.0
------------

Expand Down
12 changes: 6 additions & 6 deletions runtime/amd64.S
Expand Up @@ -277,11 +277,11 @@
# define PREPARE_FOR_C_CALL subq $32, %rsp; CFI_ADJUST(32)
# define CLEANUP_AFTER_C_CALL addq $32, %rsp; CFI_ADJUST(-32)
/* Stack probing mustn't be larger than the page size */
# define STACK_PROBE_SIZE $4096
# define STACK_PROBE_SIZE 4096
#else
# define PREPARE_FOR_C_CALL
# define CLEANUP_AFTER_C_CALL
# define STACK_PROBE_SIZE $32768
# define STACK_PROBE_SIZE 32768
#endif

/* Registers holding arguments of C functions. */
Expand Down Expand Up @@ -323,9 +323,9 @@ FUNCTION(G(caml_call_gc))
LBL(caml_call_gc):
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subq STACK_PROBE_SIZE, %rsp
subq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(STACK_PROBE_SIZE);
movq %rax, 0(%rsp)
addq STACK_PROBE_SIZE, %rsp
addq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(-STACK_PROBE_SIZE);
/* Build array of registers, save it into caml_gc_regs */
#ifdef WITH_FRAME_POINTERS
ENTER_FUNCTION ;
Expand Down Expand Up @@ -540,9 +540,9 @@ LBL(caml_c_call):
subq $8, %rsp; CFI_ADJUST(8) /* equivalent to pushq %r12 */
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subq STACK_PROBE_SIZE, %rsp
subq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(STACK_PROBE_SIZE);
movq %rax, 0(%rsp)
addq STACK_PROBE_SIZE, %rsp
addq $(STACK_PROBE_SIZE), %rsp; CFI_ADJUST(-STACK_PROBE_SIZE);
/* Make the exception handler and alloc ptr available to the C code */
STORE_VAR(%r15, caml_young_ptr)
STORE_VAR(%r14, caml_exception_pointer)
Expand Down
12 changes: 8 additions & 4 deletions runtime/i386.S
Expand Up @@ -78,6 +78,10 @@
#define CFI_ADJUST(n)
#endif

#if !defined(SYS_mingw) && !defined(SYS_cygwin)
#define STACK_PROBE_SIZE 16384
#endif

/* PR#6038: GCC and Clang seem to require 16-byte alignment nowadays,
even if only MacOS X's ABI formally requires it. */
#define ALIGN_STACK(amount) subl $ amount, %esp ; CFI_ADJUST(amount)
Expand Down Expand Up @@ -109,9 +113,9 @@ LBL(105):
#if !defined(SYS_mingw) && !defined(SYS_cygwin)
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subl $16384, %esp
subl $(STACK_PROBE_SIZE), %esp; CFI_ADJUST(STACK_PROBE_SIZE);
movl %eax, 0(%esp)
addl $16384, %esp
addl $(STACK_PROBE_SIZE), %esp; CFI_ADJUST(-STACK_PROBE_SIZE);
#endif
/* Build array of registers, save it into caml_gc_regs */
pushl %ebp; CFI_ADJUST(4)
Expand Down Expand Up @@ -234,9 +238,9 @@ FUNCTION(caml_c_call)
#if !defined(SYS_mingw) && !defined(SYS_cygwin)
/* Touch the stack to trigger a recoverable segfault
if insufficient space remains */
subl $16384, %esp
subl $(STACK_PROBE_SIZE), %esp; CFI_ADJUST(STACK_PROBE_SIZE);
movl %eax, 0(%esp)
addl $16384, %esp
addl $(STACK_PROBE_SIZE), %esp; CFI_ADJUST(-STACK_PROBE_SIZE);
#endif
/* Call the function (address in %eax) */
jmp *%eax
Expand Down