* src/vm/jit/arm/md-abi.c (md_param_alloc): Align stack arguments as well.
[cacao.git] / src / vm / signal.c
index 7ab147db3941b1a17e9893d1c91bda3511d088ce..f1f1b462b970606fc4ecfecbfb54ea29c6f4a9db 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: signal.c 7486 2007-03-08 13:50:07Z twisti $
+   $Id: signal.c 7831 2007-04-26 12:48:16Z twisti $
 
 */
 
 
 #include "config.h"
 
+#include <assert.h>
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
 # include "threads/threads-common.h"
 #endif
 
+#include "vm/exceptions.h"
 #include "vm/signallocal.h"
 #include "vm/vm.h"
 
 #include "vmcore/options.h"
 
-
-/* global variables ***********************************************************/
-
-#if defined(ENABLE_THREADS)
-static threadobject *thread_signal;
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/statistics.h"
 #endif
 
 
@@ -89,6 +88,10 @@ void signal_init(void)
 
        (void) memory_mmap_anon(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED);
 
+       /* check if we get into trouble with our hardware-exceptions */
+
+       assert(OFFSET(java_bytearray, data) > EXCEPTION_HARDWARE_PATCHER);
+
        /* Block the following signals (SIGINT for <ctrl>-c, SIGQUIT for
           <ctrl>-\).  We enable them later in signal_thread, but only for
           this thread. */
@@ -128,21 +131,39 @@ void signal_init(void)
                act.sa_sigaction = md_signal_handler_sigsegv;
                act.sa_flags     = SA_NODEFER | SA_SIGINFO;
 
-#if defined(SIGSEGV)
+#  if defined(SIGSEGV)
                sigaction(SIGSEGV, &act, NULL);
-#endif
+#  endif
 
-#if defined(SIGBUS)
+#  if defined(SIGBUS)
                sigaction(SIGBUS, &act, NULL);
-#endif
+#  endif
 
-#if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
+#  if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
                /* SIGFPE handler */
 
                act.sa_sigaction = md_signal_handler_sigfpe;
                act.sa_flags     = SA_NODEFER | SA_SIGINFO;
                sigaction(SIGFPE, &act, NULL);
-#endif
+#  endif
+
+#  if defined(__ARM__)
+               /* XXX use better defines for that (in arch.h) */
+               /* SIGILL handler */
+
+               act.sa_sigaction = md_signal_handler_sigill;
+               act.sa_flags     = SA_NODEFER | SA_SIGINFO;
+               sigaction(SIGILL, &act, NULL);
+#  endif
+
+#  if defined(__POWERPC__)
+               /* XXX use better defines for that (in arch.h) */
+               /* SIGTRAP handler */
+
+               act.sa_sigaction = md_signal_handler_sigtrap;
+               act.sa_flags     = SA_NODEFER | SA_SIGINFO;
+               sigaction(SIGTRAP, &act, NULL);
+#  endif
 # if defined(ENABLE_INTRP)
        }
 # endif
@@ -185,14 +206,24 @@ static void signal_thread(void)
        if (sigemptyset(&mask) != 0)
                vm_abort("signal_thread: sigemptyset failed: %s", strerror(errno));
 
-       sigaddset(&mask, SIGINT);
+       if (sigaddset(&mask, SIGINT) != 0)
+               vm_abort("signal_thread: sigaddset failed: %s", strerror(errno));
+
 #if !defined(__FREEBSD__)
-       sigaddset(&mask, SIGQUIT);
+       if (sigaddset(&mask, SIGQUIT) != 0)
+               vm_abort("signal_thread: sigaddset failed: %s", strerror(errno));
 #endif
 
        while (true) {
                /* just wait for a signal */
 
+               /* XXX We don't check for an error here, although the man-page
+                  states sigwait does not return an error (which is wrong!),
+                  but it seems to make problems with Boehm-GC.  We should
+                  revisit this code with our new exact-GC. */
+
+/*             if (sigwait(&mask, &sig) != 0) */
+/*                     vm_abort("signal_thread: sigwait failed: %s", strerror(errno)); */
                (void) sigwait(&mask, &sig);
 
                switch (sig) {
@@ -235,15 +266,9 @@ bool signal_start_thread(void)
 
        name = utf_new_char("Signal Handler");
 
-       thread_signal = threads_create_thread(name);
-
-       if (thread_signal == NULL)
+       if (!threads_thread_start_internal(name, signal_thread))
                return false;
 
-       /* actually start the signal handler thread */
-
-       threads_start_thread(thread_signal, signal_thread);
-
        /* everything's ok */
 
        return true;