[m-rev.] diff: Fix MR_init_signal_action in signal() case.

Peter Wang novalazy at gmail.com
Tue Oct 6 10:18:17 AEDT 2015


FFS

MR_init_signal_action had no effect in the code path for platforms
without `sigaction'.  On affected platforms the handlers for SIGSEGV and
SIGBUS would not be installed correctly so the default signal handlers
would be invoked when the program crashed (or perhaps it would try to
call a function at an arbitrary address).

More noticeably, the `signal' call in `MR_set_signal_action' would
sometimes would return SIG_ERR and cause the program to terminate
immediately with the message:

    Mercury runtime: cannot set SIGSEGV handler: No error

The affected platforms are probably Windows with MinGW/MinGW-w64.
Unix platforms should have `sigaction', Cygwin seems to have `sigaction',
and for MSVC we use "structured exceptions" instead.

runtime/mercury_signal.c:
    Fix the bug.

diff --git a/runtime/mercury_signal.c b/runtime/mercury_signal.c
index bcb2c7a..b846e63 100644
--- a/runtime/mercury_signal.c
+++ b/runtime/mercury_signal.c
@@ -132,7 +132,7 @@ MR_init_signal_action(MR_signal_action *act, MR_Code *handler,
     act->MR_SIGACTION_FIELD = handler;
 #else /* not MR_HAVE_SIGACTION */
 
-    act = handler;
+    *act = handler;
 
 #endif /* not MR_HAVE_SIGACTION */
 }
-- 
2.1.2



More information about the reviews mailing list