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
29 $Id: signal.c 6219 2006-12-19 19:20:37Z twisti $
42 #if defined(__DARWIN__)
43 /* If we compile with -ansi on darwin, <sys/types.h> is not
44 included. So let's do it here. */
45 # include <sys/types.h>
50 #if defined(ENABLE_THREADS)
51 # include "threads/native/threads.h"
54 #include "mm/memory.h"
55 #include "vm/signallocal.h"
56 #include "vm/options.h"
58 #include "vm/jit/stacktrace.h"
61 /* function prototypes ********************************************************/
63 void signal_handler_sighup(int sig, siginfo_t *siginfo, void *_p);
64 void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p);
65 void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p);
68 /* signal_init *****************************************************************
70 Initializes the signal subsystem and installs the signal handler.
72 *******************************************************************************/
74 void signal_init(void)
76 #if !defined(__CYGWIN__)
81 /* mmap a memory page at address 0x0, so our hardware-exceptions
84 pagesize = getpagesize();
86 (void) memory_mmap_anon(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED);
88 #if defined(ENABLE_GC_BOEHM)
89 /* Allocate something so the garbage collector's signal handlers
95 /* install signal handlers we need to convert to exceptions */
97 sigemptyset(&act.sa_mask);
99 #if defined(ENABLE_JIT)
100 # if defined(ENABLE_INTRP)
103 /* catch NullPointerException/StackOverFlowException */
105 act.sa_sigaction = md_signal_handler_sigsegv;
106 act.sa_flags = SA_NODEFER | SA_SIGINFO;
109 sigaction(SIGSEGV, &act, NULL);
113 sigaction(SIGBUS, &act, NULL);
116 /* catch ArithmeticException */
118 #if SUPPORT_HARDWARE_DIVIDE_BY_ZERO
119 act.sa_sigaction = md_signal_handler_sigfpe;
120 act.sa_flags = SA_NODEFER | SA_SIGINFO;
121 sigaction(SIGFPE, &act, NULL);
123 # if defined(ENABLE_INTRP)
126 #endif /* !defined(ENABLE_INTRP) */
128 #if defined(ENABLE_THREADS)
129 /* catch SIGHUP for threads_thread_interrupt */
131 act.sa_sigaction = signal_handler_sighup;
133 sigaction(SIGHUP, &act, NULL);
136 /* catch SIGINT for exiting properly on <ctrl>-c */
138 act.sa_sigaction = signal_handler_sigint;
139 act.sa_flags = SA_NODEFER | SA_SIGINFO;
140 sigaction(SIGINT, &act, NULL);
142 #if defined(ENABLE_THREADS)
143 /* catch SIGQUIT for thread dump */
145 # if !defined(__FREEBSD__)
146 act.sa_sigaction = signal_handler_sigquit;
147 act.sa_flags = SA_SIGINFO;
148 sigaction(SIGQUIT, &act, NULL);
152 #if defined(ENABLE_THREADS) && defined(ENABLE_PROFILING)
153 /* install signal handler for profiling sampling */
155 act.sa_sigaction = md_signal_handler_sigusr2;
156 act.sa_flags = SA_SIGINFO;
157 sigaction(SIGUSR2, &act, NULL);
160 #endif /* !defined(__CYGWIN__) */
164 /* signal_handler_sighup *******************************************************
166 This handler is required by threads_thread_interrupt and does
169 *******************************************************************************/
171 #if defined(ENABLE_THREADS)
172 void signal_handler_sighup(int sig, siginfo_t *siginfo, void *_p)
179 /* signal_handler_sigquit ******************************************************
181 Handle for SIGQUIT (<ctrl>-\) which print a stacktrace for every
184 *******************************************************************************/
186 #if defined(ENABLE_THREADS)
187 void signal_handler_sigquit(int sig, siginfo_t *siginfo, void *_p)
196 /* signal_handler_sigint *******************************************************
198 Handler for SIGINT (<ctrl>-c) which shuts down CACAO properly with
201 *******************************************************************************/
203 void signal_handler_sigint(int sig, siginfo_t *siginfo, void *_p)
205 /* if we are already in Runtime.exit(), just do it hardcore */
208 fprintf(stderr, "Caught SIGINT while already shutting down. Shutdown aborted...\n");
212 /* exit the vm properly */
219 * These are local overrides for various environment variables in Emacs.
220 * Please do not remove this and leave it at the end of the file, where
221 * Emacs will automagically detect them.
222 * ---------------------------------------------------------------------
225 * indent-tabs-mode: t