X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fsignal.c;h=f8f4d33f403857ecc03dc9e46ddf8bb7e79dcef0;hb=71f58437848c55c6080febb791b2646b4de46e95;hp=e7e8c31b840205adf12a125e08b28a77175ef0a5;hpb=1d0765c6a1a98f391333376173c28c3778b46246;p=cacao.git diff --git a/src/vm/signal.c b/src/vm/signal.c index e7e8c31b8..f8f4d33f4 100644 --- a/src/vm/signal.c +++ b/src/vm/signal.c @@ -1,9 +1,9 @@ /* src/vm/signal.c - machine independent signal functions - Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates, - R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner, - C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger, - Institut f. Computersprachen - TU Wien + Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel, + C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, + E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, + J. Wenninger, Institut f. Computersprachen - TU Wien This file is part of CACAO. @@ -19,41 +19,41 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. - Contact: cacao@complang.tuwien.ac.at + Contact: cacao@cacaojvm.org Authors: Christian Thalinger - Changes: - - $Id: signal.c 3378 2005-10-06 13:14:48Z twisti $ + $Id: signal.c 6123 2006-12-05 21:10:54Z twisti $ */ -#include - #include "config.h" -#include "cacao/cacao.h" +#include +#include + +#include "vm/types.h" -#if defined(USE_THREADS) && defined(NATIVE_THREADS) +#if defined(ENABLE_THREADS) # include "threads/native/threads.h" #endif +#include "mm/memory.h" +#include "vm/signallocal.h" #include "vm/options.h" +#include "vm/vm.h" #include "vm/jit/stacktrace.h" /* function prototypes ********************************************************/ -void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p); -void signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p); -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 ***************************************************************** @@ -64,91 +64,121 @@ void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p); void signal_init(void) { +#if !defined(__CYGWIN__) struct sigaction act; + /* Allocate something so the garbage collector's signal handlers + are installed. */ + +#if defined(ENABLE_GC_BOEHM) + (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 = 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__) - act.sa_sigaction = signal_handler_sigfpe; - act.sa_flags = SA_NODEFER | SA_SIGINFO; + act.sa_sigaction = md_signal_handler_sigfpe; + act.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGFPE, &act, NULL); #endif # if defined(ENABLE_INTRP) } # endif -#endif /* !defined(__INTRP__) */ +#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(USE_THREADS) && defined(NATIVE_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. *******************************************************************************/ -#if defined(USE_THREADS) && defined(NATIVE_THREADS) +#if defined(ENABLE_THREADS) void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p) { /* do thread dump */ - thread_dump(); + threads_dump(); } #endif /* signal_handler_sigint ******************************************************* - XXX + Handler for SIGINT (-c) which shuts down CACAO properly with + Runtime.exit(I)V. *******************************************************************************/ @@ -156,31 +186,17 @@ void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p) { /* if we are already in Runtime.exit(), just do it hardcore */ - if (cacao_exiting) + if (vm_exiting) { + fprintf(stderr, "Caught SIGINT while already shutting down. Shutdown aborted...\n"); exit(0); + } /* exit the vm properly */ - cacao_exit(0); + vm_exit(0); } -/* signal_handler_sigusr1 ****************************************************** - - XXX - -*******************************************************************************/ - -#if defined(USE_THREADS) && defined(NATIVE_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