powerpc-signal.h 3.3 KB

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