1 /* src/vm/signal.c - machine independent signal functions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
31 $Id: signal.c 4357 2006-01-22 23:33:38Z twisti $
43 #include "cacao/cacao.h"
45 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
46 # include "threads/native/threads.h"
49 #include "vm/signallocal.h"
50 #include "vm/options.h"
51 #include "vm/jit/stacktrace.h"
54 /* function prototypes ********************************************************/
56 void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p);
57 void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p);
58 void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p);
61 /* signal_init *****************************************************************
63 Initializes the signal subsystem and installs the signal handler.
65 *******************************************************************************/
67 void signal_init(void)
71 /* install signal handlers we need to convert to exceptions */
73 sigemptyset(&act.sa_mask);
76 #if defined(ENABLE_JIT)
77 # if defined(ENABLE_INTRP)
80 /* catch NullPointerException/StackOverFlowException */
83 act.sa_sigaction = md_signal_handler_sigsegv;
84 act.sa_flags = SA_NODEFER | SA_SIGINFO;
87 sigaction(SIGSEGV, &act, NULL);
91 sigaction(SIGBUS, &act, NULL);
96 /* catch ArithmeticException */
98 #if defined(__I386__) || defined(__X86_64__)
99 act.sa_sigaction = md_signal_handler_sigfpe;
100 act.sa_flags = SA_NODEFER | SA_SIGINFO;
101 sigaction(SIGFPE, &act, NULL);
103 # if defined(ENABLE_INTRP)
106 #endif /* !defined(ENABLE_INTRP) */
109 /* catch SIGINT for exiting properly on <ctrl>-c */
111 act.sa_sigaction = signal_handler_sigint;
112 act.sa_flags = SA_NODEFER | SA_SIGINFO;
113 sigaction(SIGINT, &act, NULL);
117 /* catch SIGQUIT for thread dump */
119 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
120 #if !defined(__FREEBSD__)
121 act.sa_sigaction = signal_handler_sigquit;
122 act.sa_flags = SA_SIGINFO;
123 sigaction(SIGQUIT, &act, NULL);
125 /* XXX boehm uses SIGUSR1 for suspend on freebsd */
127 act.sa_sigaction = signal_handler_sigusr1;
128 act.sa_flags = SA_SIGINFO;
129 sigaction(SIGUSR1, &act, NULL);
135 /* signal_handler_sigquit ******************************************************
139 *******************************************************************************/
141 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
142 void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p)
151 /* signal_handler_sigint *******************************************************
153 Handler for SIGINT (<ctrl>-c) which shuts down CACAO properly with
156 *******************************************************************************/
158 void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p)
160 /* if we are already in Runtime.exit(), just do it hardcore */
163 fprintf(stderr, "Catched SIGINT while already shutting down. Shutdown aborted...\n");
167 /* exit the vm properly */
173 /* signal_handler_sigusr1 ******************************************************
177 *******************************************************************************/
179 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
180 void signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
182 /* call stacktrace function */
184 stacktrace_dump_trace();
190 * These are local overrides for various environment variables in Emacs.
191 * Please do not remove this and leave it at the end of the file, where
192 * Emacs will automagically detect them.
193 * ---------------------------------------------------------------------
196 * indent-tabs-mode: t