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

Restore minor heap pointer after a Stack_overflow #10633

Merged
merged 3 commits into from
Sep 14, 2021
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
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ Working version
- #10603, #10611: Fix if condition marked as inconstant in flambda
(Vincent Laviron and Pierre Chambart, report by Marcello Seri)

- #10633: Stack overflow recovery in ocamlopt for AMD64/Linux and ARM/Linux
was not restoring the minor heap pointer correctly
(Stephen Dolan, review by Xavier Leroy)


OCaml 4.13.0
-------------

Expand Down
6 changes: 4 additions & 2 deletions runtime/signals_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ DECLARE_SIGNAL_HANDLER(segv_handler)
#endif
#else
/* Raise a Stack_overflow exception straight from this signal handler */
#if defined(CONTEXT_YOUNG_PTR) && defined(CONTEXT_EXCEPTION_POINTER)
Caml_state->exception_pointer == (char *) CONTEXT_EXCEPTION_POINTER;
#if defined(CONTEXT_YOUNG_PTR)
Caml_state->young_ptr = (value *) CONTEXT_YOUNG_PTR;
#endif
#if defined(CONTEXT_EXCEPTION_POINTER)
Caml_state->exception_pointer = (char *) CONTEXT_EXCEPTION_POINTER;
#endif
caml_raise_stack_overflow();
#endif
Expand Down
6 changes: 4 additions & 2 deletions runtime/signals_osdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
typedef unsigned long context_reg;
#define CONTEXT_PC (context->uc_mcontext.arm_pc)
#define CONTEXT_SP (context->uc_mcontext.arm_sp)
#define CONTEXT_EXCEPTION_POINTER (context->uc_mcontext.arm_fp)
#define CONTEXT_YOUNG_PTR (context->uc_mcontext.arm_r8)
#define CONTEXT_EXCEPTION_PTR (context->uc_mcontext.arm_r8)
#define CONTEXT_YOUNG_PTR (context->uc_mcontext.arm_r10)
#define CONTEXT_FAULTING_ADDRESS ((char *) context->uc_mcontext.fault_address)

/****************** ARM64, Linux */
Expand All @@ -158,6 +158,7 @@
#define CONTEXT_PC (context->uc_mcontext.pc)
#define CONTEXT_SP (context->uc_mcontext.sp)
#define CONTEXT_C_ARG_1 (context->uc_mcontext.regs[0])
#define CONTEXT_EXCEPTION_POINTER (context->uc_mcontext.regs[26])
#define CONTEXT_YOUNG_PTR (context->uc_mcontext.regs[27])
#define CONTEXT_FAULTING_ADDRESS ((char *) context->uc_mcontext.fault_address)

Expand All @@ -181,6 +182,7 @@
#define CONTEXT_PC (CONTEXT_STATE.__pc)
#define CONTEXT_SP (CONTEXT_STATE.__sp)
#define CONTEXT_C_ARG_1 (CONTEXT_STATE.__x[0])
#define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.__x[26])
#define CONTEXT_YOUNG_PTR (CONTEXT_STATE.__x[27])
#define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)

Expand Down
5 changes: 4 additions & 1 deletion testsuite/tests/runtime-errors/stackoverflow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ let rec f x =
raise Stack_overflow

let _ =
let p = Sys.opaque_identity (ref 42) in
begin
try
ignore(f 0)
with Stack_overflow ->
print_string "Stack overflow caught"; print_newline()
end ;
for i = 1 to 1000 do ignore (Sys.opaque_identity (ref 1_000_000)) done;
(* GPR#1289 *)
Printexc.record_backtrace true;
begin
try
ignore(f 0)
with Stack_overflow ->
print_string "second Stack overflow caught"; print_newline()
end
end;
print_string "!p = "; print_int !p; print_newline ()
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ x = 20000
x = 10000
x = 0
second Stack overflow caught
!p = 42
1 change: 1 addition & 0 deletions testsuite/tests/runtime-errors/stackoverflow.reference
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ x = 20000
x = 10000
x = 0
second Stack overflow caught
!p = 42