[mono/mono] 433017c0: [runtime]Add a wrapper around signal handlers to ease porting work.

"alexrp ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141f155fc08-e162b8fd-aeec-4927-9a78-038bd4482b27-000000@email.amazonses.com>
   Branch: refs/heads/mtvs-1.8-series
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/c5fbe7ae039b...433017c01185

   Commit: 433017c01185739599deb2fd8293b015892452be
   Author: Rodrigo Kumpera <[email protected]> (kumpera)
Committer: alexrp <[email protected]> (alexrp)
     Date: 2013-10-25 20:36:01 GMT
      URL: https://github.com/mono/mono/commit/433017c01185739599deb2fd8293b015892452be

[runtime]Add a wrapper around signal handlers to ease porting work.

Changed paths:
  M mono/io-layer/processes.c
  M mono/metadata/console-unix.c
  M mono/metadata/sgen-os-posix.c
  M mono/mini/mini-posix.c
  M mono/mini/mini.c
  M mono/mini/mini.h
Added paths:
  A mono/utils/mono-signal-handler.h

Modified: mono/io-layer/processes.c
===================================================================
@@ -76,6 +76,7 @@
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-membar.h>
 #include <mono/utils/mono-mutex.h>
+#include <mono/utils/mono-signal-handler.h>
 
 /* The process' environment strings */
 #if defined(__APPLE__) && !defined (__arm__)
@@ -2828,8 +2829,7 @@ gboolean SetProcessWorkingSetSize (gpointer process, size_t min, size_t max)
 }
 
 #if HAVE_SIGACTION
-static void
-mono_sigchld_signal_handler (int _dummy, siginfo_t *info, void *context)
+MONO_SIGNAL_HANDLER_FUNC (static, mono_sigchld_signal_handler, (int _dummy, siginfo_t *info, void *context))
 {
 	int status;
 	int pid;
@@ -2870,6 +2870,7 @@ gboolean SetProcessWorkingSetSize (gpointer process, size_t min, size_t max)
 	fprintf (stdout, "SIG CHILD handler: done looping.");
 #endif
 }
+
 #endif
 
 static void process_add_sigchld_handler (void)

Modified: mono/metadata/console-unix.c
===================================================================
@@ -31,6 +31,7 @@
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/threadpool.h>
+#include <mono/utils/mono-signal-handler.h>
 
 /* On solaris, curses.h must come before both termios.h and term.h */
 #ifdef HAVE_CURSES_H
@@ -272,8 +273,8 @@
 }
 
 static gboolean in_sigint;
-static void
-sigint_handler (int signo)
+
+MONO_SIGNAL_HANDLER_FUNC (static, sigint_handler, (int signo))
 {
 	int save_errno;
 	MONO_ARCH_SAVE_REGS;
@@ -291,8 +292,7 @@
 
 static struct sigaction save_sigcont, save_sigint, save_sigwinch;
 
-static void
-sigcont_handler (int signo, void *the_siginfo, void *data)
+MONO_SIGNAL_HANDLER_FUNC (static, sigcont_handler, (int signo, void *the_siginfo, void *data))
 {
 	int unused;
 	// Ignore error, there is not much we can do in the sigcont handler.
@@ -308,8 +308,7 @@
 		(*save_sigcont.sa_sigaction) (signo, the_siginfo, data);
 }
 
-static void
-sigwinch_handler (int signo, void *the_siginfo, void *data)
+MONO_SIGNAL_HANDLER_FUNC (static, sigwinch_handler, (int signo, void *the_siginfo, void *data))
 {
 	int dims = terminal_get_dimensions ();
 	if (dims != -1)
@@ -358,7 +357,7 @@
 	sigaction (SIGCONT, &sigcont, &save_sigcont);
 	
 	// Interrupt handler
-	sigint.sa_handler = sigint_handler;
+	sigint.sa_handler = (void *) sigint_handler;
 	sigint.sa_flags = 0;
 	sigemptyset (&sigint.sa_mask);
 	sigaction (SIGINT, &sigint, &save_sigint);

Modified: mono/metadata/sgen-os-posix.c
===================================================================
@@ -34,6 +34,7 @@
 #include "metadata/gc-internal.h"
 #include "metadata/sgen-archdep.h"
 #include "metadata/object-internals.h"
+#include "utils/mono-signal-handler.h"
 
 #if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
 const static int suspend_signal_num = SIGXFSZ;
@@ -121,8 +122,7 @@
 }
 
 /* LOCKING: assumes the GC lock is held (by the stopping thread) */
-static void
-suspend_handler (int sig, siginfo_t *siginfo, void *context)
+MONO_SIGNAL_HANDLER_FUNC (static, suspend_handler, (int sig, siginfo_t *siginfo, void *context))
 {
 	SgenThreadInfo *info;
 	int old_errno = errno;
@@ -133,8 +133,7 @@
 	errno = old_errno;
 }
 
-static void
-restart_handler (int sig)
+MONO_SIGNAL_HANDLER_FUNC (static, restart_handler, (int sig))
 {
 	SgenThreadInfo *info;
 	int old_errno = errno;
@@ -219,7 +218,7 @@
 		g_error ("failed sigaction");
 	}
 
-	sinfo.sa_handler = restart_handler;
+	sinfo.sa_handler = (void*) restart_handler;
 	if (sigaction (restart_signal_num, &sinfo, NULL) != 0) {
 		g_error ("failed sigaction");
 	}

Modified: mono/mini/mini-posix.c
===================================================================
@@ -54,6 +54,7 @@
 #include <mono/utils/mono-logger-internal.h>
 #include <mono/utils/mono-mmap.h>
 #include <mono/utils/dtrace.h>
+#include <mono/utils/mono-signal-handler.h>
 
 #include "mini.h"
 #include <string.h>
@@ -192,8 +193,7 @@
 	return FALSE;
 }
 
-static void
-SIG_HANDLER_SIGNATURE (sigabrt_signal_handler)
+SIG_HANDLER_FUNC (static, sigabrt_signal_handler)
 {
 	MonoJitInfo *ji = NULL;
 	GET_CONTEXT;
@@ -207,8 +207,7 @@
 	}
 }
 
-static void
-SIG_HANDLER_SIGNATURE (sigusr1_signal_handler)
+SIG_HANDLER_FUNC (static, sigusr1_signal_handler)
 {
 	gboolean running_managed;
 	MonoException *exc;
@@ -281,6 +280,7 @@
 	mono_arch_handle_exception (ctx, exc);
 }
 
+
 #if defined(__i386__) || defined(__x86_64__)
 #define FULL_STAT_PROFILER_BACKTRACE 1
 #define CURRENT_FRAME_GET_BASE_POINTER(f) (* (gpointer*)(f))
@@ -298,8 +298,7 @@
 
 #if defined(__ia64__) || defined(__sparc__) || defined(sparc) || defined(__s390__) || defined(s390)
 
-static void
-SIG_HANDLER_SIGNATURE (sigprof_signal_handler)
+SIG_HANDLER_FUNC (static, sigprof_signal_handler)
 {
 	if (mono_chain_signal (SIG_HANDLER_PARAMS))
 		return;
@@ -309,8 +308,7 @@
 
 #else
 
-static void
-SIG_HANDLER_SIGNATURE (sigprof_signal_handler)
+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 ();
@@ -388,8 +386,7 @@
 
 #endif
 
-static void
-SIG_HANDLER_SIGNATURE (sigquit_signal_handler)
+SIG_HANDLER_FUNC (static, sigquit_signal_handler)
 {
 	gboolean res;
 
@@ -419,8 +416,7 @@
 	mono_chain_signal (SIG_HANDLER_PARAMS);
 }
 
-static void
-SIG_HANDLER_SIGNATURE (sigusr2_signal_handler)
+SIG_HANDLER_FUNC (static, sigusr2_signal_handler)
 {
 	gboolean enabled = mono_trace_is_enabled ();
 

Modified: mono/mini/mini.c
===================================================================
@@ -58,6 +58,7 @@
 #include <mono/utils/mono-tls.h>
 #include <mono/utils/mono-hwcap.h>
 #include <mono/utils/dtrace.h>
+#include <mono/utils/mono-signal-handler.h>
 
 #include "mini.h"
 #include "mini-llvm.h"
@@ -6514,8 +6515,7 @@ void *mono_global_codeman_reserve (int size)
 	return runtime_invoke (obj, params, exc, info->compiled_method);
 }
 
-void
-SIG_HANDLER_SIGNATURE (mono_sigfpe_signal_handler)
+SIG_HANDLER_FUNC (, mono_sigfpe_signal_handler)
 {
 	MonoException *exc = NULL;
 	MonoJitInfo *ji;
@@ -6549,8 +6549,7 @@ void *mono_global_codeman_reserve (int size)
 	mono_arch_handle_exception (ctx, exc);
 }
 
-void
-SIG_HANDLER_SIGNATURE (mono_sigill_signal_handler)
+SIG_HANDLER_FUNC (, mono_sigill_signal_handler)
 {
 	MonoException *exc;
 	GET_CONTEXT;
@@ -6564,8 +6563,7 @@ void *mono_global_codeman_reserve (int size)
 #define HAVE_SIG_INFO
 #endif
 
-void
-SIG_HANDLER_SIGNATURE (mono_sigsegv_signal_handler)
+SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler)
 {
 	MonoJitInfo *ji;
 	MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
@@ -6644,8 +6642,7 @@ void *mono_global_codeman_reserve (int size)
 #endif
 }
 
-void
-SIG_HANDLER_SIGNATURE (mono_sigint_signal_handler)
+SIG_HANDLER_FUNC (, mono_sigint_signal_handler)
 {
 	MonoException *exc;
 	GET_CONTEXT;

Modified: mono/mini/mini.h
===================================================================
@@ -2734,15 +2734,19 @@ enum {
 
 #ifdef MONO_ARCH_USE_SIGACTION
 #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
 

Added: mono/utils/mono-signal-handler.h
===================================================================
@@ -0,0 +1,29 @@
+/*
+ * mono-signal-handler.h: Handle signal handler differences across platforms
+ *
+ * Copyright (C) 2013 Xamarin Inc
+ */
+
+#ifndef __MONO_SIGNAL_HANDLER_H__
+#define __MONO_SIGNAL_HANDLER_H__
+
+#include "config.h"
+
+#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.
+
+*/
+#ifndef MONO_SIGNAL_HANDLER_FUNC
+#define MONO_SIGNAL_HANDLER_FUNC(access, name, arglist) access void name arglist
+#endif
+
+#endif


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.