static gboolean in_sigint;
-MONO_SIGNAL_HANDLER_FUNC (static, sigint_handler, (int signo))
+MONO_SIG_HANDLER_FUNC (static, sigint_handler)
{
int save_errno;
MONO_ARCH_SAVE_REGS;
static struct sigaction save_sigcont, save_sigint, save_sigwinch;
-MONO_SIGNAL_HANDLER_FUNC (static, sigcont_handler, (int signo, void *the_siginfo, void *data))
+MONO_SIG_HANDLER_FUNC (static, sigcont_handler)
{
int unused;
// Ignore error, there is not much we can do in the sigcont handler.
if (save_sigcont.sa_sigaction != NULL &&
save_sigcont.sa_sigaction != (void *)SIG_DFL &&
save_sigcont.sa_sigaction != (void *)SIG_IGN)
- (*save_sigcont.sa_sigaction) (signo, the_siginfo, data);
+ (*save_sigcont.sa_sigaction) (MONO_SIG_HANDLER_PARAMS);
}
-MONO_SIGNAL_HANDLER_FUNC (static, sigwinch_handler, (int signo, void *the_siginfo, void *data))
+MONO_SIG_HANDLER_FUNC (static, sigwinch_handler)
{
int dims = terminal_get_dimensions ();
if (dims != -1)
if (save_sigwinch.sa_sigaction != NULL &&
save_sigwinch.sa_sigaction != (void *)SIG_DFL &&
save_sigwinch.sa_sigaction != (void *)SIG_IGN)
- (*save_sigwinch.sa_sigaction) (signo, the_siginfo, data);
+ (*save_sigwinch.sa_sigaction) (MONO_SIG_HANDLER_PARAMS);
}
/*
}
/* LOCKING: assumes the GC lock is held (by the stopping thread) */
-MONO_SIGNAL_HANDLER_FUNC (static, suspend_handler, (int sig, siginfo_t *siginfo, void *context))
+MONO_SIG_HANDLER_FUNC (static, suspend_handler)
{
/*
* The suspend signal handler potentially uses syscalls that
* must restore those to the values they had when we
* interrupted.
*/
-
SgenThreadInfo *info;
int old_errno = errno;
int hp_save_index = mono_hazard_pointer_save_for_signal_handler ();
+ MONO_SIG_HANDLER_GET_CONTEXT;
info = mono_thread_info_current ();
- suspend_thread (info, context);
+ suspend_thread (info, ctx);
mono_hazard_pointer_restore_for_signal_handler (hp_save_index);
errno = old_errno;
}
-MONO_SIGNAL_HANDLER_FUNC (static, restart_handler, (int sig))
+MONO_SIG_HANDLER_FUNC (static, restart_handler)
{
SgenThreadInfo *info;
int old_errno = errno;
gboolean
-SIG_HANDLER_SIGNATURE (mono_chain_signal)
+MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal)
{
return FALSE;
}
* was called, false otherwise.
*/
gboolean
-SIG_HANDLER_SIGNATURE (mono_chain_signal)
+MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal)
{
- int signal = _dummy;
+ int signal = MONO_SIG_HANDLER_GET_SIGNO ();
struct sigaction *saved_handler = get_saved_signal_handler (signal);
-
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
if (saved_handler && saved_handler->sa_handler) {
if (!(saved_handler->sa_flags & SA_SIGINFO)) {
return FALSE;
}
-SIG_HANDLER_FUNC (static, sigabrt_signal_handler)
+MONO_SIG_HANDLER_FUNC (static, sigabrt_signal_handler)
{
MonoJitInfo *ji = NULL;
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
if (mono_thread_internal_current ())
- ji = mono_jit_info_table_find (mono_domain_get (), mono_arch_ip_from_context(ctx));
+ ji = mono_jit_info_table_find (mono_domain_get (), mono_arch_ip_from_context (ctx));
if (!ji) {
- if (mono_chain_signal (SIG_HANDLER_PARAMS))
+ if (mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
mono_handle_native_sigsegv (SIGABRT, ctx);
}
}
-SIG_HANDLER_FUNC (static, sigusr1_signal_handler)
+MONO_SIG_HANDLER_FUNC (static, sigusr1_signal_handler)
{
gboolean running_managed;
MonoException *exc;
MonoInternalThread *thread = mono_thread_internal_current ();
MonoDomain *domain = mono_domain_get ();
void *ji;
-
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
if (!thread || !domain) {
/* The thread might not have started up yet */
#ifdef SIGPROF
#if defined(__ia64__) || defined(__sparc__) || defined(sparc) || defined(__s390__) || defined(s390)
-SIG_HANDLER_FUNC (static, sigprof_signal_handler)
+MONO_SIG_HANDLER_FUNC (static, sigprof_signal_handler)
{
- if (mono_chain_signal (SIG_HANDLER_PARAMS))
+ if (mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
NOT_IMPLEMENTED;
#else
-SIG_HANDLER_FUNC (static, sigprof_signal_handler)
+MONO_SIG_HANDLER_FUNC (static, sigprof_signal_handler)
{
int call_chain_depth = mono_profiler_stat_get_call_chain_depth ();
MonoProfilerCallChainStrategy call_chain_strategy = mono_profiler_stat_get_call_chain_strategy ();
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
if (call_chain_depth == 0) {
mono_profiler_stat_hit (mono_arch_ip_from_context (ctx), ctx);
mono_profiler_stat_call_chain (current_frame_index, & ips [0], ctx);
}
- mono_chain_signal (SIG_HANDLER_PARAMS);
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
}
#endif
#endif
-SIG_HANDLER_FUNC (static, sigquit_signal_handler)
+MONO_SIG_HANDLER_FUNC (static, sigquit_signal_handler)
{
gboolean res;
-
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
/* We use this signal to start the attach agent too */
res = mono_attach_start ();
mono_print_thread_dump (ctx);
}
- mono_chain_signal (SIG_HANDLER_PARAMS);
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
}
-SIG_HANDLER_FUNC (static, sigusr2_signal_handler)
+MONO_SIG_HANDLER_FUNC (static, sigusr2_signal_handler)
{
gboolean enabled = mono_trace_is_enabled ();
mono_trace_enable (!enabled);
- mono_chain_signal (SIG_HANDLER_PARAMS);
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
}
static void
return runtime_invoke (obj, params, exc, info->compiled_method);
}
-SIG_HANDLER_FUNC (, mono_sigfpe_signal_handler)
+MONO_SIG_HANDLER_FUNC (, mono_sigfpe_signal_handler)
{
MonoException *exc = NULL;
MonoJitInfo *ji;
-#if !(defined(MONO_ARCH_USE_SIGACTION) || defined(HOST_WIN32))
- void *info = NULL;
-#endif
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
ji = mono_jit_info_table_find (mono_domain_get (), mono_arch_ip_from_context (ctx));
#endif
if (!ji) {
- if (!mono_do_crash_chaining && mono_chain_signal (SIG_HANDLER_PARAMS))
+ if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
mono_handle_native_sigsegv (SIGSEGV, ctx);
if (mono_do_crash_chaining) {
- mono_chain_signal (SIG_HANDLER_PARAMS);
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}
mono_arch_handle_exception (ctx, exc);
}
-SIG_HANDLER_FUNC (, mono_sigill_signal_handler)
+MONO_SIG_HANDLER_FUNC (, mono_sigill_signal_handler)
{
MonoException *exc;
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
exc = mono_get_exception_execution_engine ("SIGILL");
#define HAVE_SIG_INFO
#endif
-SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler)
+MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler)
{
MonoJitInfo *ji;
MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
gpointer fault_addr = NULL;
-
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
#if defined(MONO_ARCH_SOFT_DEBUG_SUPPORTED) && defined(HAVE_SIG_INFO)
if (mono_arch_is_single_step_event (info, ctx)) {
/* The thread might no be registered with the runtime */
if (!mono_domain_get () || !jit_tls) {
- if (!mono_do_crash_chaining && mono_chain_signal (SIG_HANDLER_PARAMS))
+ if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
mono_handle_native_sigsegv (SIGSEGV, ctx);
if (mono_do_crash_chaining) {
- mono_chain_signal (SIG_HANDLER_PARAMS);
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}
g_assert_not_reached ();
} else {
/* The original handler might not like that it is executed on an altstack... */
- if (!ji && mono_chain_signal (SIG_HANDLER_PARAMS))
+ if (!ji && mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
mono_arch_handle_altstack_exception (ctx, info->si_addr, FALSE);
#else
if (!ji) {
- if (!mono_do_crash_chaining && mono_chain_signal (SIG_HANDLER_PARAMS))
+ if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
mono_handle_native_sigsegv (SIGSEGV, ctx);
if (mono_do_crash_chaining) {
- mono_chain_signal (SIG_HANDLER_PARAMS);
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}
#endif
}
-SIG_HANDLER_FUNC (, mono_sigint_signal_handler)
+MONO_SIG_HANDLER_FUNC (, mono_sigint_signal_handler)
{
MonoException *exc;
- GET_CONTEXT;
+ MONO_SIG_HANDLER_GET_CONTEXT;
exc = mono_get_exception_execution_engine ("Interrupted (SIGINT).");
#include <mono/utils/mono-tls.h>
#include <mono/utils/atomic.h>
#include <mono/utils/mono-conc-hashtable.h>
+#include <mono/utils/mono-signal-handler.h>
#define MONO_BREAKPOINT_ARRAY_SIZE 64
/*
* Signal handling
*/
-#ifdef MONO_GET_CONTEXT
-#define GET_CONTEXT MONO_GET_CONTEXT
-#endif
-
-#ifndef GET_CONTEXT
-#ifdef HOST_WIN32
-/* seh_vectored_exception_handler () passes in a CONTEXT* */
-#define GET_CONTEXT \
- void *ctx = context;
-#else
-#ifdef MONO_ARCH_USE_SIGACTION
-#define GET_CONTEXT \
- void *ctx = context;
-#elif defined(__HAIKU__)
-#define GET_CONTEXT \
- void *ctx = ®s;
-#else
-#define GET_CONTEXT \
- void **_p = (void **)&_dummy; \
- struct sigcontext *ctx = (struct sigcontext *)++_p;
-#endif
-#endif
-#endif
-
-#if defined(MONO_ARCH_USE_SIGACTION) && !defined(HOST_WIN32)
-#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, siginfo_t *info, void *context)
-#define SIG_HANDLER_FUNC(access, ftn) MONO_SIGNAL_HANDLER_FUNC (access, ftn, (int _dummy, siginfo_t *info, void *context))
-#define SIG_HANDLER_PARAMS _dummy, info, context
-#elif defined(HOST_WIN32)
-#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, EXCEPTION_POINTERS *info, void *context)
-#define SIG_HANDLER_FUNC(access, ftn) MONO_SIGNAL_HANDLER_FUNC (access, ftn, (int _dummy, EXCEPTION_POINTERS *info, void *context))
-#define SIG_HANDLER_PARAMS _dummy, info, context
-#elif defined(__HAIKU__)
-#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, void *userData, vregs regs)
-#define SIG_HANDLER_FUNC(access, ftn) MONO_SIGNAL_HANDLER_FUNC (access, ftn, (int _dummy, void *userData, vregs regs))
-#define SIG_HANDLER_PARAMS _dummy, userData, regs
-#else
-#define SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy)
-#define SIG_HANDLER_FUNC(access, ftn) MONO_SIGNAL_HANDLER_FUNC (access, ftn, (int _dummy))
-#define SIG_HANDLER_PARAMS _dummy
-#endif
-void SIG_HANDLER_SIGNATURE (mono_sigfpe_signal_handler) MONO_INTERNAL;
-void SIG_HANDLER_SIGNATURE (mono_sigill_signal_handler) MONO_INTERNAL;
-void SIG_HANDLER_SIGNATURE (mono_sigsegv_signal_handler) MONO_INTERNAL;
-void SIG_HANDLER_SIGNATURE (mono_sigint_signal_handler) MONO_INTERNAL;
-gboolean SIG_HANDLER_SIGNATURE (mono_chain_signal) MONO_INTERNAL;
+void MONO_SIG_HANDLER_SIGNATURE (mono_sigfpe_signal_handler) MONO_INTERNAL;
+void MONO_SIG_HANDLER_SIGNATURE (mono_sigill_signal_handler) MONO_INTERNAL;
+void MONO_SIG_HANDLER_SIGNATURE (mono_sigsegv_signal_handler) MONO_INTERNAL;
+void MONO_SIG_HANDLER_SIGNATURE (mono_sigint_signal_handler) MONO_INTERNAL;
+gboolean MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal) MONO_INTERNAL;
#ifdef MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
#define ARCH_HAVE_DELEGATE_TRAMPOLINES 1
#ifdef ENABLE_EXTENSION_MODULE
#include "../../../mono-extensions/mono/utils/mono-signal-handler.h"
#endif
-/*
-Not all platforms support signal handlers in the same way. Some have the same concept but
-for some weird reason pass different kind of arguments.
-
-All signal handler helpers should go here so they can be properly shared across the JIT,
-utils and sgen.
-
-TODO: Cleanup & move mini's macros to here so they can leveraged by other parts.
-*/
+/* Don't use this */
#ifndef MONO_SIGNAL_HANDLER_FUNC
#define MONO_SIGNAL_HANDLER_FUNC(access, name, arglist) access void name arglist
#endif
+/*
+ * Macros to work around signal handler differences on various platforms.
+ *
+ * To declare a signal handler function:
+ * void MONO_SIG_HANDLER_SIGNATURE (handler_func)
+ * To define a signal handler function:
+ * MONO_SIG_HANDLER_FUNC(access, name)
+ * To call another signal handler function:
+ * handler_func (SIG_HANDLER_PARAMS);
+ * To obtain the signal number:
+ * int signo = MONO_SIG_HANDLER_GET_SIGNO ();
+ * To obtain the signal context:
+ * MONO_SIG_HANDLER_GET_CONTEXT ().
+ * This will define a variable name 'ctx'.
+ */
+
+#ifdef HOST_WIN32
+#define MONO_SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, EXCEPTION_POINTERS *info, void *context)
+#define MONO_SIG_HANDLER_FUNC(access, ftn) MONO_SIGNAL_HANDLER_FUNC (access, ftn, (int _dummy, EXCEPTION_POINTERS *info, void *context))
+#define MONO_SIG_HANDLER_PARAMS _dummy, info, context
+#define MONO_SIG_HANDLER_GET_SIGNO() (_dummy)
+/* seh_vectored_exception_handler () passes in a CONTEXT* */
+#define MONO_SIG_HANDLER_GET_CONTEXT \
+ void *ctx = context;
+#else
+/* sigaction */
+#define MONO_SIG_HANDLER_SIGNATURE(ftn) ftn (int _dummy, siginfo_t *info, void *context)
+#define MONO_SIG_HANDLER_FUNC(access, ftn) MONO_SIGNAL_HANDLER_FUNC (access, ftn, (int _dummy, siginfo_t *info, void *context))
+#define MONO_SIG_HANDLER_PARAMS _dummy, info, context
+#define MONO_SIG_HANDLER_GET_SIGNO() (_dummy)
+#define MONO_SIG_HANDLER_GET_CONTEXT \
+ void *ctx = context;
+#endif
+
#endif