1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 2004 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../LICENSE. */
12 /***********************************************************************/
14 /* $Id: signals_osdep.h 9194 2009-03-28 15:18:31Z xleroy $ */
16 /* Processor- and OS-dependent signal interface */
18 /****************** Alpha, all OS */
20 #if defined(TARGET_alpha)
22 #define DECLARE_SIGNAL_HANDLER(name) \
23 static void name(int sig, int code, struct sigcontext * context)
25 #define SET_SIGACT(sigact,name) \
26 sigact.sa_handler = (void (*)(int)) (name); \
29 typedef long context_reg;
30 #define CONTEXT_PC (context->sc_pc)
31 #define CONTEXT_EXCEPTION_POINTER (context->sc_regs[15])
32 #define CONTEXT_YOUNG_LIMIT (context->sc_regs[13])
33 #define CONTEXT_YOUNG_PTR (context->sc_regs[14])
35 /****************** AMD64, Linux */
37 #elif defined(TARGET_amd64) && defined (SYS_linux)
39 #define DECLARE_SIGNAL_HANDLER(name) \
40 static void name(int sig, siginfo_t * info, ucontext_t * context)
42 #define SET_SIGACT(sigact,name) \
43 sigact.sa_sigaction = (void (*)(int,siginfo_t *,void *)) (name); \
44 sigact.sa_flags = SA_SIGINFO
46 typedef greg_t context_reg;
47 #define CONTEXT_PC (context->uc_mcontext.gregs[REG_RIP])
48 #define CONTEXT_EXCEPTION_POINTER (context->uc_mcontext.gregs[REG_R14])
49 #define CONTEXT_YOUNG_PTR (context->uc_mcontext.gregs[REG_R15])
50 #define CONTEXT_FAULTING_ADDRESS ((char *) context->uc_mcontext.gregs[REG_CR2])
52 /****************** AMD64, MacOSX */
54 #elif defined(TARGET_amd64) && defined (SYS_macosx)
56 #define DECLARE_SIGNAL_HANDLER(name) \
57 static void name(int sig, siginfo_t * info, void * context)
59 #define SET_SIGACT(sigact,name) \
60 sigact.sa_sigaction = (name); \
61 sigact.sa_flags = SA_SIGINFO | SA_64REGSET
63 #include <sys/ucontext.h>
64 #include <AvailabilityMacros.h>
66 #if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
67 #define CONTEXT_REG(r) r
69 #define CONTEXT_REG(r) __##r
72 #define CONTEXT_STATE (((ucontext_t *)context)->uc_mcontext->CONTEXT_REG(ss))
73 #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(rip))
74 #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.CONTEXT_REG(r14))
75 #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.CONTEXT_REG(r15))
76 #define CONTEXT_SP (CONTEXT_STATE.CONTEXT_REG(rsp))
77 #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)
79 /****************** AMD64, Solaris x86 */
81 #elif defined(TARGET_amd64) && defined (SYS_solaris)
85 #define DECLARE_SIGNAL_HANDLER(name) \
86 static void name(int sig, siginfo_t * info, ucontext_t * context)
88 #define SET_SIGACT(sigact,name) \
89 sigact.sa_sigaction = (void (*)(int,siginfo_t *,void *)) (name); \
90 sigact.sa_flags = SA_SIGINFO
92 typedef greg_t context_reg;
93 #define CONTEXT_PC (context->uc_mcontext.gregs[REG_RIP])
94 #define CONTEXT_EXCEPTION_POINTER (context->uc_mcontext.gregs[REG_R14])
95 #define CONTEXT_YOUNG_PTR (context->uc_mcontext.gregs[REG_R15])
96 #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)
98 /****************** I386, Linux */
100 #elif defined(TARGET_i386) && defined(SYS_linux_elf)
102 #define DECLARE_SIGNAL_HANDLER(name) \
103 static void name(int sig, struct sigcontext context)
105 #define SET_SIGACT(sigact,name) \
106 sigact.sa_handler = (void (*)(int)) (name); \
109 #define CONTEXT_FAULTING_ADDRESS ((char *) context.cr2)
111 /****************** I386, BSD */
113 #elif defined(TARGET_i386) && defined(SYS_bsd)
115 #define DECLARE_SIGNAL_HANDLER(name) \
116 static void name(int sig, siginfo_t * info, void * context)
118 #define SET_SIGACT(sigact,name) \
119 sigact.sa_sigaction = (name); \
120 sigact.sa_flags = SA_SIGINFO
122 #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)
124 /****************** I386, MacOS X */
126 #elif defined(TARGET_i386) && defined(SYS_macosx)
128 #define DECLARE_SIGNAL_HANDLER(name) \
129 static void name(int sig, siginfo_t * info, void * context)
131 #define SET_SIGACT(sigact,name) \
132 sigact.sa_sigaction = (name); \
133 sigact.sa_flags = SA_SIGINFO
135 #include <sys/ucontext.h>
136 #include <AvailabilityMacros.h>
138 #if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
139 #define CONTEXT_REG(r) r
141 #define CONTEXT_REG(r) __##r
144 #define CONTEXT_STATE (((ucontext_t *)context)->uc_mcontext->CONTEXT_REG(ss))
145 #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(eip))
146 #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)
148 /****************** I386, Solaris x86 */
150 #elif defined(TARGET_i386) && defined(SYS_solaris)
152 #define DECLARE_SIGNAL_HANDLER(name) \
153 static void name(int sig, siginfo_t * info, void * context)
155 #define SET_SIGACT(sigact,name) \
156 sigact.sa_sigaction = (name); \
157 sigact.sa_flags = SA_SIGINFO
159 #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)
161 /****************** MIPS, all OS */
163 #elif defined(TARGET_mips)
165 #define DECLARE_SIGNAL_HANDLER(name) \
166 static void name(int sig, int code, struct sigcontext * context)
168 #define SET_SIGACT(sigact,name) \
169 sigact.sa_handler = (void (*)(int)) (name); \
172 typedef int context_reg;
173 #define CONTEXT_PC (context->sc_pc)
174 #define CONTEXT_EXCEPTION_POINTER (context->sc_regs[30])
175 #define CONTEXT_YOUNG_LIMIT (context->sc_regs[22])
176 #define CONTEXT_YOUNG_PTR (context->sc_regs[23])
178 /****************** PowerPC, MacOS X */
180 #elif defined(TARGET_power) && defined(SYS_rhapsody)
182 #define DECLARE_SIGNAL_HANDLER(name) \
183 static void name(int sig, siginfo_t * info, void * context)
185 #include <sys/ucontext.h>
186 #include <AvailabilityMacros.h>
189 #define SET_SIGACT(sigact,name) \
190 sigact.sa_sigaction = (name); \
191 sigact.sa_flags = SA_SIGINFO | SA_64REGSET
193 typedef unsigned long long context_reg;
195 #define CONTEXT_MCONTEXT (((ucontext64_t *)context)->uc_mcontext64)
197 #define SET_SIGACT(sigact,name) \
198 sigact.sa_sigaction = (name); \
199 sigact.sa_flags = SA_SIGINFO
201 typedef unsigned long context_reg;
203 #define CONTEXT_MCONTEXT (((ucontext_t *)context)->uc_mcontext)
206 #if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
207 #define CONTEXT_REG(r) r
209 #define CONTEXT_REG(r) __##r
212 #define CONTEXT_STATE (CONTEXT_MCONTEXT->CONTEXT_REG(ss))
213 #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(srr0))
214 #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.CONTEXT_REG(r29))
215 #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.CONTEXT_REG(r30))
216 #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.CONTEXT_REG(r31))
217 #define CONTEXT_SP (CONTEXT_STATE.CONTEXT_REG(r1))
218 #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr)
220 /****************** PowerPC, ELF (Linux) */
222 #elif defined(TARGET_power) && defined(SYS_elf)
224 #define DECLARE_SIGNAL_HANDLER(name) \
225 static void name(int sig, struct sigcontext * context)
227 #define SET_SIGACT(sigact,name) \
228 sigact.sa_handler = (void (*)(int)) (name); \
231 typedef unsigned long context_reg;
232 #define CONTEXT_PC (context->regs->nip)
233 #define CONTEXT_EXCEPTION_POINTER (context->regs->gpr[29])
234 #define CONTEXT_YOUNG_LIMIT (context->regs->gpr[30])
235 #define CONTEXT_YOUNG_PTR (context->regs->gpr[31])
237 /****************** PowerPC, BSD */
239 #elif defined(TARGET_power) && defined(SYS_bsd)
241 #define DECLARE_SIGNAL_HANDLER(name) \
242 static void name(int sig, int code, struct sigcontext * context)
244 #define SET_SIGACT(sigact,name) \
245 sigact.sa_handler = (void (*)(int)) (name); \
248 typedef unsigned long context_reg;
249 #define CONTEXT_EXCEPTION_POINTER (context->sc_frame.fixreg[29])
250 #define CONTEXT_YOUNG_LIMIT (context->sc_frame.fixreg[30])
251 #define CONTEXT_YOUNG_PTR (context->sc_frame.fixreg[31])
253 /****************** SPARC, Solaris */
255 #elif defined(TARGET_sparc) && defined(SYS_solaris)
257 #include <ucontext.h>
259 #define DECLARE_SIGNAL_HANDLER(name) \
260 static void name(int sig, siginfo_t * info, ucontext_t * context)
262 #define SET_SIGACT(sigact,name) \
263 sigact.sa_sigaction = (void (*)(int,siginfo_t *,void *)) (name); \
264 sigact.sa_flags = SA_SIGINFO
266 typedef long context_reg;
267 #define CONTEXT_PC (context->uc_mcontext.gregs[REG_PC])
268 /* Local register number N is saved on the stack N words
269 after the stack pointer */
270 #define SPARC_L_REG(n) ((long *)(context->uc_mcontext.gregs[REG_SP]))[n]
271 #define CONTEXT_EXCEPTION_POINTER (SPARC_L_REG(5))
272 #define CONTEXT_YOUNG_LIMIT (SPARC_L_REG(7))
273 #define CONTEXT_YOUNG_PTR (SPARC_L_REG(6))
275 /******************** Default */
279 #define DECLARE_SIGNAL_HANDLER(name) \
280 static void name(int sig)
282 #define SET_SIGACT(sigact,name) \
283 sigact.sa_handler = (name); \