2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libjava / include / powerpc-signal.h
blob9c6ddac3700b782bbdf5c1c234fec4ffd05aa17d
1 // powerpc-signal.h - Catch runtime signals and turn them into exceptions
2 // on a powerpc based Linux system.
4 /* Copyright (C) 2003, 2006 Free Software Foundation
6 This file is part of libgcj.
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10 details. */
13 #ifndef JAVA_SIGNAL_H
14 #define JAVA_SIGNAL_H 1
16 #include <signal.h>
17 #include <sys/syscall.h>
19 #define HANDLE_SEGV 1
20 #undef HANDLE_FPE
22 #define SIGNAL_HANDLER(_name) \
23 static void _name (int /* _signal */, struct sigcontext *_sc)
25 /* MD_FALLBACK_FRAME_STATE_FOR takes care of special casing PC
26 before the faulting instruction, so we don't need to do anything
27 here. */
29 #define MAKE_THROW_FRAME(_exception)
31 /* For an explanation why we cannot simply use sigaction to
32 install the handlers, see i386-signal.h. */
34 /* We use kernel_old_sigaction here because we're calling the kernel
35 directly rather than via glibc. The sigaction structure that the
36 syscall uses is a different shape from the one in userland and not
37 visible to us in a header file so we define it here.
38 Additionally we want a proper prototype for the handler function
39 with the struct sigcontext pointer passed by the kernel as the 2nd
40 argument, which isn't there in userland headers.
42 Note that we explicitly avoid the SA_SIGINFO flag in INIT_SEGV and
43 INIT_FPE below. Using the ucontext pointer passed as 3rd argument
44 of a SA_SIGINFO type handler would need complicated backwards
45 compatibility hacks in MAKE_THROW_FRAME, as the ucontext layout
46 on PPC changed during the 2.5 kernel series. */
48 #ifndef __powerpc64__
49 struct kernel_old_sigaction {
50 void (*k_sa_handler) (int, struct sigcontext *);
51 unsigned long k_sa_mask;
52 unsigned long k_sa_flags;
53 void (*k_sa_restorer) (void);
56 #define INIT_SEGV \
57 do \
58 { \
59 struct kernel_old_sigaction kact; \
60 kact.k_sa_handler = catch_segv; \
61 kact.k_sa_mask = 0; \
62 kact.k_sa_flags = 0; \
63 if (syscall (SYS_sigaction, SIGSEGV, &kact, NULL) != 0) \
64 __asm__ __volatile__ (".long 0"); \
65 } \
66 while (0)
68 #define INIT_FPE \
69 do \
70 { \
71 struct kernel_old_sigaction kact; \
72 kact.k_sa_handler = catch_fpe; \
73 kact.k_sa_mask = 0; \
74 kact.k_sa_flags = 0; \
75 if (syscall (SYS_sigaction, SIGFPE, &kact, NULL) != 0) \
76 __asm__ __volatile__ (".long 0"); \
77 } \
78 while (0)
80 #else /* powerpc64 */
82 struct kernel_sigaction
84 void (*k_sa_handler) (int, struct sigcontext *);
85 unsigned long k_sa_flags;
86 void (*k_sa_restorer)(void);
87 unsigned long k_sa_mask;
90 #define INIT_SEGV \
91 do \
92 { \
93 struct kernel_sigaction kact; \
94 memset (&kact, 0, sizeof (kact)); \
95 kact.k_sa_handler = catch_segv; \
96 if (syscall (SYS_rt_sigaction, SIGSEGV, &kact, NULL, 8) != 0) \
97 __asm__ __volatile__ (".long 0"); \
98 } \
99 while (0)
101 #define INIT_FPE \
102 do \
104 struct kernel_sigaction kact; \
105 memset (&kact, 0, sizeof (kact)); \
106 kact.k_sa_handler = catch_fpe; \
107 if (syscall (SYS_rt_sigaction, SIGFPE, &kact, NULL, 8) != 0) \
108 __asm__ __volatile__ (".long 0"); \
110 while (0)
111 #endif
113 #endif /* JAVA_SIGNAL_H */