sigaction.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. see <http://www.gnu.org/licenses/>.
  14. Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
  15. */
  16. #include <errno.h>
  17. #include <signal.h>
  18. #include <string.h>
  19. #include <sys/syscall.h>
  20. #include <bits/kernel_sigaction.h>
  21. #define SA_RESTORER 0x04000000
  22. #ifdef __NR_rt_sigaction
  23. # if _MIPS_SIM != _ABIO32
  24. # ifdef __NR_rt_sigreturn
  25. static void restore_rt(void) __asm__ ("__restore_rt");
  26. # endif
  27. # ifdef __NR_sigreturn
  28. static void restore(void) __asm__ ("__restore");
  29. # endif
  30. # endif
  31. /* If ACT is not NULL, change the action for SIG to *ACT.
  32. If OACT is not NULL, put the old action for SIG in *OACT. */
  33. int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  34. {
  35. # if _MIPS_SIM != _ABIO32
  36. struct sigaction kact;
  37. if (act) {
  38. memcpy(&kact, act, sizeof(kact));
  39. kact.sa_restorer = &restore_rt;
  40. act = &kact;
  41. }
  42. # endif
  43. /* NB: kernel (as of 2.6.25) will return EINVAL
  44. * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */
  45. return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
  46. }
  47. #else
  48. extern void restore(void) __asm__ ("__restore") attribute_hidden;
  49. /* If ACT is not NULL, change the action for SIG to *ACT.
  50. If OACT is not NULL, put the old action for SIG in *OACT. */
  51. int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  52. {
  53. int result;
  54. struct old_kernel_sigaction kact, koact;
  55. if (act) {
  56. kact.k_sa_handler = act->sa_handler;
  57. kact.sa_mask = act->sa_mask.__val[0];
  58. kact.sa_flags = act->sa_flags;
  59. # if _MIPS_SIM == _ABIO32
  60. kact.sa_restorer = act->sa_restorer;
  61. # else
  62. kact.sa_restorer = &restore_rt;
  63. # endif
  64. }
  65. result = __syscall_sigaction(sig,
  66. act ? &kact : NULL,
  67. oact ? &koact : NULL);
  68. if (result < 0) {
  69. __set_errno(-result);
  70. return -1;
  71. }
  72. if (oact) {
  73. oact->sa_handler = koact.k_sa_handler;
  74. oact->sa_mask.__val[0] = koact.sa_mask;
  75. oact->sa_flags = koact.sa_flags;
  76. oact->sa_restorer = koact.sa_restorer;
  77. }
  78. return result;
  79. }
  80. #endif
  81. #ifndef LIBC_SIGACTION
  82. # ifndef __UCLIBC_HAS_THREADS__
  83. strong_alias(__libc_sigaction,sigaction)
  84. libc_hidden_def(sigaction)
  85. # else
  86. weak_alias(__libc_sigaction,sigaction)
  87. libc_hidden_weak(sigaction)
  88. # endif
  89. #endif
  90. /* NOTE: Please think twice before making any changes to the bits of
  91. code below. GDB needs some intimate knowledge about it to
  92. recognize them as signal trampolines, and make backtraces through
  93. signal handlers work right. Important are both the names
  94. (__restore_rt) and the exact instruction sequence.
  95. If you ever feel the need to make any changes, please notify the
  96. appropriate GDB maintainer. */
  97. #define RESTORE(name, syscall) RESTORE2(name, syscall)
  98. #define RESTORE2(name, syscall) \
  99. __asm__ ( \
  100. ".align 4\n" \
  101. "__" #name ":\n" \
  102. " li $2, " #syscall "\n" \
  103. " syscall\n" \
  104. );
  105. /* The return code for realtime-signals. */
  106. #if _MIPS_SIM != _ABIO32
  107. # ifdef __NR_rt_sigreturn
  108. RESTORE(restore_rt, __NR_rt_sigreturn)
  109. # endif
  110. # ifdef __NR_sigreturn
  111. RESTORE(restore, __NR_sigreturn)
  112. # endif
  113. #endif