dwarf2-signal.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // dwarf2-signal.h - Catch runtime signals and turn them into exceptions.
  2. /* Copyright (C) 2000, 2001, 2009, 2011, 2014 Free Software Foundation
  3. This file is part of libgcj.
  4. Use this file for a target for which the dwarf2 unwinder in libgcc
  5. can unwind through signal handlers.
  6. This software is copyrighted work licensed under the terms of the
  7. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  8. details. */
  9. #ifndef JAVA_SIGNAL_H
  10. #define JAVA_SIGNAL_H 1
  11. #include <signal.h>
  12. #include <sys/syscall.h>
  13. #define HANDLE_SEGV 1
  14. #undef HANDLE_FPE
  15. #define SIGNAL_HANDLER(_name) \
  16. static void _Jv_##_name (int, siginfo_t *, \
  17. void *_p __attribute__ ((__unused__)))
  18. // Unwind the stack to the point at which the signal was generated and
  19. // then throw an exception. With the dwarf2 unwinder we don't usually
  20. // need to do anything, with some minor exceptions.
  21. #ifdef __ia64__
  22. #define MAKE_THROW_FRAME(_exception) \
  23. do \
  24. { \
  25. /* IA-64 either leaves PC pointing at a faulting instruction or the \
  26. following instruction, depending on the signal. SEGV always does \
  27. the former, so we adjust the saved PC to point to the following \
  28. instruction; this is what the handler in libgcc expects. */ \
  29. /* Note that we are lying to the unwinder here, which expects the \
  30. faulting pc, not pc+1. But we claim the unwind information can't \
  31. be changed by such a ld or st instruction, so it doesn't matter. */ \
  32. struct sigcontext *_sc = (struct sigcontext *)_p; \
  33. _sc->sc_ip++; \
  34. } \
  35. while (0)
  36. #else
  37. #define MAKE_THROW_FRAME(_exception)
  38. #endif
  39. #if defined(__sparc__)
  40. #if defined(__arch64__)
  41. extern "C" {
  42. static void __rt_sigreturn_stub(void)
  43. {
  44. __asm__("mov %0, %%g1\n\t"
  45. "ta 0x6d\n\t"
  46. : /* no outputs */
  47. : "i" (__NR_rt_sigreturn));
  48. }
  49. struct kernel_sigaction
  50. {
  51. void (*k_sa_sigaction)(int,siginfo_t *,void *);
  52. unsigned long k_sa_flags;
  53. void (*k_sa_restorer)(void);
  54. sigset_t k_sa_mask;
  55. };
  56. }
  57. #define INIT_SEGV \
  58. do \
  59. { \
  60. struct kernel_sigaction act; \
  61. unsigned long stub = ((unsigned long)&__rt_sigreturn_stub); \
  62. act.k_sa_sigaction = _Jv_catch_segv; \
  63. sigemptyset (&act.k_sa_mask); \
  64. act.k_sa_flags = SA_SIGINFO; \
  65. act.k_sa_restorer = NULL; \
  66. syscall (SYS_rt_sigaction, SIGSEGV, &act, NULL, \
  67. stub - 8, _NSIG / 8); \
  68. } \
  69. while (0)
  70. #define INIT_FPE \
  71. do \
  72. { \
  73. struct kernel_sigaction act; \
  74. unsigned long stub = ((unsigned long)&__rt_sigreturn_stub); \
  75. act.k_sa_sigaction = _Jv_catch_fpe; \
  76. sigemptyset (&act.k_sa_mask); \
  77. act.k_sa_flags = SA_SIGINFO; \
  78. act.k_sa_restorer = NULL; \
  79. syscall (SYS_rt_sigaction, SIGFPE, &act, NULL, \
  80. stub - 8, _NSIG / 8); \
  81. } \
  82. while (0)
  83. #else /* __arch64__ */
  84. extern "C" {
  85. struct kernel_sigaction
  86. {
  87. void (*k_sa_sigaction)(int,siginfo_t *,void *);
  88. unsigned long k_sa_mask, k_sa_flags;
  89. void (*k_sa_restorer)(void);
  90. };
  91. }
  92. #define INIT_SEGV \
  93. do \
  94. { \
  95. struct kernel_sigaction act; \
  96. act.k_sa_sigaction = _Jv_catch_segv; \
  97. act.k_sa_mask = 0; \
  98. act.k_sa_flags = SA_SIGINFO; \
  99. act.k_sa_restorer = NULL; \
  100. syscall (SYS_sigaction, -SIGSEGV, &act, NULL); \
  101. } \
  102. while (0)
  103. #define INIT_FPE \
  104. do \
  105. { \
  106. struct kernel_sigaction act; \
  107. act.k_sa_sigaction = _Jv_catch_fpe; \
  108. act.k_sa_mask = 0; \
  109. act.k_sa_flags = SA_SIGINFO; \
  110. act.k_sa_restorer = NULL; \
  111. syscall (SYS_sigaction, -SIGFPE, &act, NULL); \
  112. } \
  113. while (0)
  114. #endif
  115. #elif !defined(__ia64__)
  116. #define INIT_SEGV \
  117. do \
  118. { \
  119. struct sigaction act; \
  120. act.sa_sigaction = _Jv_catch_segv; \
  121. sigemptyset (&act.sa_mask); \
  122. act.sa_flags = SA_SIGINFO; \
  123. syscall (SYS_sigaction, SIGSEGV, &act, NULL); \
  124. } \
  125. while (0)
  126. #define INIT_FPE \
  127. do \
  128. { \
  129. struct sigaction act; \
  130. act.sa_sigaction = _Jv_catch_fpe; \
  131. sigemptyset (&act.sa_mask); \
  132. act.sa_flags = SA_SIGINFO; \
  133. syscall (SYS_sigaction, SIGFPE, &act, NULL); \
  134. } \
  135. while (0)
  136. /* We use syscall(SYS_sigaction) in INIT_SEGV and INIT_FPE instead of
  137. * sigaction() because on some systems the pthreads wrappers for
  138. * signal handlers are not compiled with unwind information, so it's
  139. * not possible to unwind through them. This is a problem that will
  140. * go away once all systems have pthreads libraries that are
  141. * compiled with full unwind info. */
  142. #else /* __ia64__ */
  143. // On IA64, unwind information is mandatory, so we can unwind
  144. // correctly through glibc frames. Thus we call the ordinary
  145. // sigaction.
  146. #define INIT_SEGV \
  147. do \
  148. { \
  149. struct sigaction act; \
  150. act.sa_sigaction = _Jv_catch_segv; \
  151. sigemptyset (&act.sa_mask); \
  152. act.sa_flags = SA_SIGINFO; \
  153. sigaction (SIGSEGV, &act, NULL); \
  154. } \
  155. while (0)
  156. #define INIT_FPE \
  157. do \
  158. { \
  159. struct sigaction act; \
  160. act.sa_sigaction = _Jv_catch_fpe; \
  161. sigemptyset (&act.sa_mask); \
  162. act.sa_flags = SA_SIGINFO; \
  163. sigaction (SIGFPE, &act, NULL); \
  164. } \
  165. while (0)
  166. #endif /* __ia64__ || __sparc__ */
  167. #endif /* JAVA_SIGNAL_H */