From c85fd1fe35669ec6b653451ca1c966899ffca394 Mon Sep 17 00:00:00 2001 From: Gavin Whelan Date: Tue, 4 Mar 2014 14:48:59 -0800 Subject: [PATCH] Fixed Linux specific bug causing lack of stack overflow traces. --- v/loop.c | 12 ++++++++++-- v/main.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/v/loop.c b/v/loop.c index b1e76dd5e..c6a588d80 100644 --- a/v/loop.c +++ b/v/loop.c @@ -42,6 +42,14 @@ typedef enum { volatile u2_kill Sigcause; // reasons for exception +static void _lo_cont(void *arg1, void *arg2, void *arg3) +{ + (void)(arg1); + (void)(arg2); + (void)(arg3); + siglongjmp(Signal_buf, 1); +} + static void _lo_signal_handle_over(int emergency, stackoverflow_context_t scp) { @@ -60,7 +68,7 @@ _lo_signal_handle_over(int emergency, stackoverflow_context_t scp) #endif { Sigcause = sig_overflow; - longjmp(Signal_buf, 1); + sigsegv_leave_handler(_lo_cont, NULL, NULL, NULL); } } @@ -329,7 +337,7 @@ u2_lo_soft(u2_reck* rec_u, c3_w sec_w, u2_funk fun_f, u2_noun arg) u2_unix_ef_hold(); _lo_signal_deep(sec_w); - if ( 0 != setjmp(Signal_buf) ) { + if ( 0 != sigsetjmp(Signal_buf, 1) ) { u2_noun tax, pre, mok; // return to blank state diff --git a/v/main.c b/v/main.c index 64fb278dd..ec50a5ed5 100644 --- a/v/main.c +++ b/v/main.c @@ -246,6 +246,14 @@ static uint8_t Sigstk[SIGSTKSZ]; volatile enum { sig_none, sig_overflow, sig_interrupt } Sigcause; +static void _main_cont(void *arg1, void *arg2, void *arg3) +{ + (void)(arg1); + (void)(arg2); + (void)(arg3); + siglongjmp(Signal_buf, 1); +} + static void overflow_handler(int emergency, stackoverflow_context_t scp) { @@ -254,7 +262,7 @@ overflow_handler(int emergency, stackoverflow_context_t scp) exit(1); } else { Sigcause = sig_overflow; - longjmp(Signal_buf, 1); + sigsegv_leave_handler(_main_cont, NULL, NULL, NULL); } } @@ -367,7 +375,7 @@ main(c3_i argc, // we get a signal, we force the system back into the just-booted state. // If anything goes wrong during boot (above), it's curtains. { - if ( 0 != setjmp(Signal_buf) ) { + if ( 0 != sigsetjmp(Signal_buf, 1) ) { switch ( Sigcause ) { case sig_overflow: printf("[stack overflow]\r\n"); break; case sig_interrupt: printf("[interrupt]\r\n"); break;