sigaction.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA.
  15. Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
  16. */
  17. #include <errno.h>
  18. #include <signal.h>
  19. #include <string.h>
  20. #include <sys/syscall.h>
  21. #include <bits/kernel_sigaction.h>
  22. #define SA_RESTORER 0x04000000
  23. extern __typeof(sigaction) __libc_sigaction;
  24. #ifdef __NR_rt_sigaction
  25. /* Experimentally off - libc_hidden_proto(memcpy) */
  26. #if _MIPS_SIM != _ABIO32
  27. # ifdef __NR_rt_sigreturn
  28. static void restore_rt (void) __asm__ ("__restore_rt");
  29. # endif
  30. # ifdef __NR_sigreturn
  31. static void restore (void) __asm__ ("__restore");
  32. # endif
  33. #endif
  34. /* If ACT is not NULL, change the action for SIG to *ACT.
  35. If OACT is not NULL, put the old action for SIG in *OACT. */
  36. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  37. {
  38. int result;
  39. struct kernel_sigaction kact, koact;
  40. enum {
  41. SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
  42. ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
  43. };
  44. if (act) {
  45. kact.k_sa_handler = act->sa_handler;
  46. memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
  47. kact.sa_flags = act->sa_flags;
  48. # ifdef HAVE_SA_RESTORER
  49. # if _MIPS_SIM == _ABIO32
  50. kact.sa_restorer = act->sa_restorer;
  51. # else
  52. kact.sa_restorer = &restore_rt;
  53. # endif
  54. # endif
  55. }
  56. /* NB: kernel (as of 2.6.25) will return EINVAL
  57. * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
  58. result = __syscall_rt_sigaction(sig,
  59. act ? &kact : NULL,
  60. oact ? &koact : NULL,
  61. sizeof(kact.sa_mask));
  62. if (oact && result >= 0) {
  63. oact->sa_handler = koact.k_sa_handler;
  64. memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
  65. oact->sa_flags = koact.sa_flags;
  66. # ifdef HAVE_SA_RESTORER
  67. oact->sa_restorer = koact.sa_restorer;
  68. # endif
  69. }
  70. return result;
  71. }
  72. #else
  73. extern void restore (void) __asm__ ("__restore") attribute_hidden;
  74. /* If ACT is not NULL, change the action for SIG to *ACT.
  75. If OACT is not NULL, put the old action for SIG in *OACT. */
  76. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  77. {
  78. int result;
  79. struct old_kernel_sigaction kact, koact;
  80. if (act) {
  81. kact.k_sa_handler = act->sa_handler;
  82. kact.sa_mask = act->sa_mask.__val[0];
  83. kact.sa_flags = act->sa_flags;
  84. # ifdef HAVE_SA_RESTORER
  85. # if _MIPS_SIM == _ABIO32
  86. kact.sa_restorer = act->sa_restorer;
  87. # else
  88. kact.sa_restorer = &restore_rt;
  89. # endif
  90. # endif
  91. }
  92. result = __syscall_sigaction(sig, act ? &kact : NULL,
  93. oact ? &koact : NULL);
  94. if (result < 0) {
  95. __set_errno(-result);
  96. return -1;
  97. }
  98. if (oact) {
  99. oact->sa_handler = koact.k_sa_handler;
  100. oact->sa_mask.__val[0] = koact.sa_mask;
  101. oact->sa_flags = koact.sa_flags;
  102. # ifdef HAVE_SA_RESTORER
  103. oact->sa_restorer = koact.sa_restorer;
  104. # endif
  105. }
  106. return result;
  107. }
  108. #endif
  109. #ifndef LIBC_SIGACTION
  110. /* libc_hidden_proto(sigaction) */
  111. weak_alias(__libc_sigaction,sigaction)
  112. libc_hidden_weak(sigaction)
  113. #endif
  114. /* NOTE: Please think twice before making any changes to the bits of
  115. code below. GDB needs some intimate knowledge about it to
  116. recognize them as signal trampolines, and make backtraces through
  117. signal handlers work right. Important are both the names
  118. (__restore_rt) and the exact instruction sequence.
  119. If you ever feel the need to make any changes, please notify the
  120. appropriate GDB maintainer. */
  121. #define RESTORE(name, syscall) RESTORE2 (name, syscall)
  122. #define RESTORE2(name, syscall) \
  123. __asm__ ( \
  124. ".align 4\n" \
  125. "__" #name ":\n" \
  126. " li $2, " #syscall "\n" \
  127. " syscall\n" \
  128. );
  129. /* The return code for realtime-signals. */
  130. #if _MIPS_SIM != _ABIO32
  131. # ifdef __NR_rt_sigreturn
  132. RESTORE (restore_rt, __NR_rt_sigreturn)
  133. # endif
  134. # ifdef __NR_sigreturn
  135. RESTORE (restore, __NR_sigreturn)
  136. # endif
  137. #endif