X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fvm%2Fsignal.c;h=c8e5a31dbbdf7368601310fc8adff4db5a4361ea;hb=e5fa2ec49132996e9faf569583facd32e36f66e2;hp=d4520fcd82487535ef6663c952442ed808bc9336;hpb=530ee4cb3c1223db18505eac94353792893a7328;p=cacao.git diff --git a/src/vm/signal.c b/src/vm/signal.c index d4520fcd8..c8e5a31db 100644 --- a/src/vm/signal.c +++ b/src/vm/signal.c @@ -26,17 +26,24 @@ Authors: Christian Thalinger - Changes: - - $Id: signal.c 4921 2006-05-15 14:24:36Z twisti $ + $Id: signal.c 6256 2006-12-28 12:30:09Z twisti $ */ #include "config.h" +#include #include #include +#include +#include + +#if defined(__DARWIN__) +/* If we compile with -ansi on darwin, is not + included. So let's do it here. */ +# include +#endif #include "vm/types.h" @@ -44,6 +51,7 @@ # include "threads/native/threads.h" #endif +#include "mm/memory.h" #include "vm/signallocal.h" #include "vm/options.h" #include "vm/vm.h" @@ -52,9 +60,9 @@ /* function prototypes ********************************************************/ -void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p); +void signal_handler_sighup(int sig, siginfo_t *siginfo, void *_p); void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p); -void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p); +void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p); /* signal_init ***************************************************************** @@ -65,38 +73,50 @@ void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p); void signal_init(void) { +#if !defined(__CYGWIN__) + int pagesize; struct sigaction act; + /* mmap a memory page at address 0x0, so our hardware-exceptions + work. */ + + pagesize = getpagesize(); + + (void) memory_mmap_anon(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED); + +#if defined(ENABLE_GC_BOEHM) + /* Allocate something so the garbage collector's signal handlers + are installed. */ + + (void) GCNEW(u1); +#endif + /* install signal handlers we need to convert to exceptions */ sigemptyset(&act.sa_mask); - #if defined(ENABLE_JIT) # if defined(ENABLE_INTRP) if (!opt_intrp) { # endif /* catch NullPointerException/StackOverFlowException */ - if (!checknull) { - act.sa_sigaction = md_signal_handler_sigsegv; - act.sa_flags = SA_NODEFER | SA_SIGINFO; + act.sa_sigaction = md_signal_handler_sigsegv; + act.sa_flags = SA_NODEFER | SA_SIGINFO; #if defined(SIGSEGV) - sigaction(SIGSEGV, &act, NULL); + sigaction(SIGSEGV, &act, NULL); #endif #if defined(SIGBUS) - sigaction(SIGBUS, &act, NULL); + sigaction(SIGBUS, &act, NULL); #endif - } - /* catch ArithmeticException */ -#if defined(__I386__) || defined(__X86_64__) +#if SUPPORT_HARDWARE_DIVIDE_BY_ZERO act.sa_sigaction = md_signal_handler_sigfpe; - act.sa_flags = SA_NODEFER | SA_SIGINFO; + act.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGFPE, &act, NULL); #endif # if defined(ENABLE_INTRP) @@ -104,36 +124,61 @@ void signal_init(void) # endif #endif /* !defined(ENABLE_INTRP) */ +#if defined(ENABLE_THREADS) + /* catch SIGHUP for threads_thread_interrupt */ + + act.sa_sigaction = signal_handler_sighup; + act.sa_flags = 0; + sigaction(SIGHUP, &act, NULL); +#endif /* catch SIGINT for exiting properly on -c */ act.sa_sigaction = signal_handler_sigint; - act.sa_flags = SA_NODEFER | SA_SIGINFO; + act.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGINT, &act, NULL); - - +#if defined(ENABLE_THREADS) /* catch SIGQUIT for thread dump */ -#if defined(ENABLE_THREADS) -#if !defined(__FREEBSD__) +# if !defined(__FREEBSD__) act.sa_sigaction = signal_handler_sigquit; - act.sa_flags = SA_SIGINFO; + act.sa_flags = SA_SIGINFO; sigaction(SIGQUIT, &act, NULL); +# endif +#endif - /* XXX boehm uses SIGUSR1 for suspend on freebsd */ +#if defined(ENABLE_THREADS) && defined(ENABLE_PROFILING) + /* install signal handler for profiling sampling */ - act.sa_sigaction = signal_handler_sigusr1; - act.sa_flags = SA_SIGINFO; - sigaction(SIGUSR1, &act, NULL); -#endif + act.sa_sigaction = md_signal_handler_sigusr2; + act.sa_flags = SA_SIGINFO; + sigaction(SIGUSR2, &act, NULL); #endif + +#endif /* !defined(__CYGWIN__) */ } +/* signal_handler_sighup ******************************************************* + + This handler is required by threads_thread_interrupt and does + nothing. + +*******************************************************************************/ + +#if defined(ENABLE_THREADS) +void signal_handler_sighup(int sig, siginfo_t *siginfo, void *_p) +{ + /* do nothing */ +} +#endif + + /* signal_handler_sigquit ****************************************************** - XXX + Handle for SIGQUIT (-\) which print a stacktrace for every + running thread. *******************************************************************************/ @@ -169,22 +214,6 @@ void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p) } -/* signal_handler_sigusr1 ****************************************************** - - XXX - -*******************************************************************************/ - -#if defined(ENABLE_THREADS) -void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p) -{ - /* call stacktrace function */ - - stacktrace_dump_trace(); -} -#endif - - /* * These are local overrides for various environment variables in Emacs. * Please do not remove this and leave it at the end of the file, where