Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: signal.c 7258 2007-01-30 13:53:35Z twisti $
+ $Id: signal.c 7811 2007-04-25 18:33:30Z twisti $
*/
#include "config.h"
+#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include "vm/types.h"
-#include "mm/memory.h"
-
-#include "native/jni.h"
-#include "native/include/java_lang_Thread.h"
+#include "arch.h"
-#if defined(WITH_CLASSPATH_GNU)
-# include "native/include/java_lang_VMThread.h"
-#endif
+#include "mm/memory.h"
#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
+# include "threads/threads-common.h"
#endif
-#include "vm/builtin.h"
+#include "vm/exceptions.h"
#include "vm/signallocal.h"
-#include "vm/stringlocal.h"
#include "vm/vm.h"
-#include "vm/jit/stacktrace.h"
#include "vmcore/options.h"
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/statistics.h"
+#endif
+
/* global variables ***********************************************************/
(void) memory_mmap_anon(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED);
-#if 0
+ /* 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. */
if (sigprocmask(SIG_BLOCK, &mask, NULL) != 0)
vm_abort("signal_init: sigprocmask failed: %s", strerror(errno));
-#endif
#if defined(ENABLE_GC_BOEHM)
/* Allocate something so the garbage collector's signal handlers
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
sigset_t mask;
int sig;
- sigemptyset(&mask);
- sigaddset(&mask, SIGINT);
+ if (sigemptyset(&mask) != 0)
+ vm_abort("signal_thread: sigemptyset failed: %s", strerror(errno));
+
+ 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 */
- sigwait(&mask, &sig);
- log_println("signal caught: %d", sig);
+ /* 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) {
case SIGINT:
case SIGQUIT:
/* print a thread dump */
-
+#if defined(ENABLE_THREADS)
threads_dump();
+#endif
#if defined(ENABLE_STATISTICS)
if (opt_stat)
bool signal_start_thread(void)
{
#if defined(ENABLE_THREADS)
-#if defined(WITH_CLASSPATH_GNU)
- java_lang_VMThread *vmt;
-#endif
+ utf *name;
- /* create the finalizer object */
+ name = utf_new_char("Signal Handler");
- thread_signal = (threadobject *) builtin_new(class_java_lang_Thread);
+ thread_signal = threads_thread_create_internal(name);
if (thread_signal == NULL)
return false;
-#if defined(WITH_CLASSPATH_GNU)
- vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
-
- vmt->thread = (java_lang_Thread *) thread_signal;
-
- thread_signal->o.vmThread = vmt;
-#endif
-
- thread_signal->flags = THREAD_FLAG_DAEMON;
-
- thread_signal->o.name = javastring_new_from_ascii("Signal Handler");
-#if defined(ENABLE_JAVASE)
- thread_signal->o.daemon = true;
-#endif
- thread_signal->o.priority = 5;
-
- /* actually start the finalizer thread */
+ /* actually start the signal handler thread */
threads_start_thread(thread_signal, signal_thread);
return true;
#else
-#error FIX ME!
+#warning FIX ME!
#endif
}