2002-04-19 David S. Miller <davem@redhat.com>
[official-gcc.git] / libjava / include / dwarf2-signal.h
blob08287056705a16e2b233805af75d3e490250ff9d
1 // dwarf2-signal.h - Catch runtime signals and turn them into exceptions.
3 /* Copyright (C) 2000, 2001 Free Software Foundation
5 This file is part of libgcj.
7 Use this file for a target for which the dwarf2 unwinder in libgcc
8 can unwind through signal handlers.
10 This software is copyrighted work licensed under the terms of the
11 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 details. */
14 #ifndef JAVA_SIGNAL_H
15 #define JAVA_SIGNAL_H 1
17 #include <signal.h>
18 #include <sys/syscall.h>
20 #define HANDLE_SEGV 1
21 #undef HANDLE_FPE
23 #define SIGNAL_HANDLER(_name) \
24 static void _Jv_##_name (int, siginfo_t *_sip, void *_p)
26 class java::lang::Throwable;
28 // Unwind the stack to the point at which the signal was generated and
29 // then throw an exception. With the dwarf2 unwinder we don't usually
30 // need to do anything, with some minor exceptions.
32 #ifdef __alpha__
33 #define MAKE_THROW_FRAME(_exception) \
34 do \
35 { \
36 /* Alpha either leaves PC pointing at a faulting instruction or the \
37 following instruction, depending on the signal. SEGV always does \
38 the former, so we adjust the saved PC to point to the following \
39 instruction; this is what the handler in libgcc expects. */ \
40 struct sigcontext *_sc = (struct sigcontext *)_p; \
41 _sc->sc_pc += 4; \
42 } \
43 while (0)
45 #elif defined(__ia64__)
47 #define MAKE_THROW_FRAME(_exception) \
48 do \
49 { \
50 /* IA-64 either leaves PC pointing at a faulting instruction or the \
51 following instruction, depending on the signal. SEGV always does \
52 the former, so we adjust the saved PC to point to the following \
53 instruction; this is what the handler in libgcc expects. */ \
54 /* Note that we are lying to the unwinder here, which expects the \
55 faulting pc, not pc+1. But we claim the unwind information can't \
56 be changed by such a ld or st instruction, so it doesn't matter. */ \
57 struct sigcontext *_sc = (struct sigcontext *)_p; \
58 _sc->sc_ip++; \
59 } \
60 while (0)
61 #elif defined(__sparc__)
62 /* We could do the unwind of the signal frame quickly by hand here like
63 sparc-signal.h does under Solaris, but that makes debugging unwind
64 failures almost impossible. */
65 #if !defined(__arch64__)
66 #define MAKE_THROW_FRAME(_exception) \
67 do \
68 { \
69 /* Sparc-32 leaves PC pointing at a faulting instruction \
70 always. So we adjust the saved PC to point to the following \
71 instruction; this is what the handler in libgcc expects. */ \
72 /* Note that we are lying to the unwinder here, which expects the \
73 faulting pc, not pc+1. But we claim the unwind information can't \
74 be changed by such a ld or st instruction, so it doesn't matter. */ \
75 struct sig_regs { \
76 unsigned int psr, pc, npc, y, u_regs[16]; \
77 } *regp; \
78 unsigned int insn; \
79 __asm__ __volatile__("ld [%%i7 + 8], %0" : "=r" (insn)); \
80 if (insn == 0x821020d8) \
81 regp = (struct sig_regs *) _sip; \
82 else \
83 regp = (struct sig_regs *) (_sip + 1); \
84 regp->pc = regp->npc; \
85 regp->npc += 4; \
86 } \
87 while (0)
88 #else
89 #define MAKE_THROW_FRAME(_exception) \
90 do \
91 { \
92 /* Sparc-64 leaves PC pointing at a faulting instruction \
93 always. So we adjust the saved PC to point to the following \
94 instruction; this is what the handler in libgcc expects. */ \
95 /* Note that we are lying to the unwinder here, which expects the \
96 faulting pc, not pc+1. But we claim the unwind information can't \
97 be changed by such a ld or st instruction, so it doesn't matter. */ \
98 struct pt_regs { \
99 unsigned long u_regs[16]; \
100 unsigned long tstate, tpc, tnpc; \
101 unsigned int y, fprs; \
102 } *regp = (struct pt_regs *) (_sip + 1); \
103 regp->tpc = regp->tnpc; \
104 regp->tnpc += 4; \
106 while (0)
107 #endif
108 #else
109 #define MAKE_THROW_FRAME(_exception) \
110 do \
112 (void)_p; \
114 while (0)
115 #endif
117 #if !(defined(__ia64__) || defined(__sparc__))
118 #define INIT_SEGV \
119 do \
121 nullp = new java::lang::NullPointerException (); \
122 struct sigaction act; \
123 act.sa_sigaction = _Jv_catch_segv; \
124 sigemptyset (&act.sa_mask); \
125 act.sa_flags = SA_SIGINFO; \
126 syscall (SYS_sigaction, SIGSEGV, &act, NULL); \
128 while (0)
130 #define INIT_FPE \
131 do \
133 arithexception = new java::lang::ArithmeticException \
134 (JvNewStringLatin1 ("/ by zero")); \
135 struct sigaction act; \
136 act.sa_sigaction = _Jv_catch_fpe; \
137 sigemptyset (&act.sa_mask); \
138 act.sa_flags = SA_SIGINFO; \
139 syscall (SYS_sigaction, SIGFPE, &act, NULL); \
141 while (0)
143 /* We use syscall(SYS_sigaction) in INIT_SEGV and INIT_FPE instead of
144 * sigaction() because on some systems the pthreads wrappers for
145 * signal handlers are not compiled with unwind information, so it's
146 * not possible to unwind through them. This is a problem that will
147 * go away once all systems have pthreads libraries that are
148 * compiled with full unwind info. */
150 #else /* __ia64__ || __sparc__ */
152 // FIXME: We shouldn't be using libc_sigaction here, since it should
153 // be glibc private. But using syscall here would mean translating to
154 // the kernel's struct sigaction and argument sequence, which we
155 // shouldn't either. The right solution is to call sigaction and to
156 // make sure that we can unwind correctly through the pthread signal
157 // wrapper.
158 extern "C" int __libc_sigaction (int __sig,
159 __const struct sigaction *__restrict __act,
160 struct sigaction *__restrict __oact) throw ();
162 #define INIT_SEGV \
163 do \
165 nullp = new java::lang::NullPointerException (); \
166 struct sigaction act; \
167 act.sa_sigaction = _Jv_catch_segv; \
168 sigemptyset (&act.sa_mask); \
169 act.sa_flags = SA_SIGINFO; \
170 __libc_sigaction (SIGSEGV, &act, NULL); \
172 while (0)
174 #define INIT_FPE \
175 do \
177 arithexception = new java::lang::ArithmeticException \
178 (JvNewStringLatin1 ("/ by zero")); \
179 struct sigaction act; \
180 act.sa_sigaction = _Jv_catch_fpe; \
181 sigemptyset (&act.sa_mask); \
182 act.sa_flags = SA_SIGINFO; \
183 __libc_sigaction (SIGFPE, &act, NULL); \
185 while (0)
186 #endif /* __ia64__ || __sparc__ */
187 #endif /* JAVA_SIGNAL_H */