sigaction.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* POSIX.1 sigaction call for Linux/SPARC.
  2. Copyright (C) 1997-2000,2002,2003,2005 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx), 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA.
  17. Ported to uClibc from glibc: 090520:
  18. Jan Buchholz, KIP, Uni Heidelberg <jan.buchholz@kip.uni-heidelberg.de>
  19. Austin Foxley, Ceton Corporation <austinf@cetoncorp.com>
  20. */
  21. #include <errno.h>
  22. #include <signal.h>
  23. #include <string.h>
  24. #include <sys/syscall.h>
  25. #include <bits/kernel_sigaction.h>
  26. _syscall5(int, rt_sigaction, int, a, int, b, int, c, int, d, int, e);
  27. static void __rt_sigreturn_stub(void);
  28. static void __sigreturn_stub(void);
  29. int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  30. {
  31. int ret;
  32. struct old_kernel_sigaction kact, koact;
  33. unsigned long stub = 0;
  34. int saved_errno = errno;
  35. if (act) {
  36. kact.k_sa_handler = act->sa_handler;
  37. /* BUG?! kact.sa_mask is a long, but sigset_t is a vector
  38. /* of longs and it may be bigger (in glibc, it _is_ bigger).
  39. /* Should we do this instead?
  40. /* kact.sa_mask = act->sa_mask.__val[0]; */
  41. memcpy(&kact.sa_mask, &act->sa_mask, sizeof(sigset_t));
  42. kact.sa_flags = act->sa_flags;
  43. if (kact.sa_flags & SA_SIGINFO)
  44. stub = (unsigned long) &__rt_sigreturn_stub;
  45. else
  46. stub = (unsigned long) &__sigreturn_stub;
  47. stub -= 8;
  48. kact.sa_restorer = NULL;
  49. }
  50. /* NB: kernel (as of 2.6.25) will return EINVAL
  51. * if _NSIG / 8 does not match kernel's sizeof(sigset_t) */
  52. ret = rt_sigaction(sig,
  53. (int)(act ? &kact : NULL),
  54. (int)(oact ? &koact : NULL),
  55. stub,
  56. _NSIG / 8);
  57. /* BUG?! if ret == -1, we return -1 but do not set errno?! */
  58. if (ret >= 0 || errno != ENOSYS) {
  59. if (oact && ret >= 0) {
  60. oact->sa_handler = koact.k_sa_handler;
  61. /* maybe oact->sa_mask.__val[0] = koact.sa_mask;? */
  62. memcpy(&oact->sa_mask, &koact.sa_mask, sizeof(sigset_t));
  63. oact->sa_flags = koact.sa_flags;
  64. oact->sa_restorer = koact.sa_restorer;
  65. }
  66. return ret;
  67. }
  68. __set_errno(saved_errno);
  69. return -1;
  70. }
  71. #ifndef LIBC_SIGACTION
  72. weak_alias(__libc_sigaction,sigaction)
  73. libc_hidden_weak(sigaction)
  74. #endif
  75. static void
  76. __rt_sigreturn_stub(void)
  77. {
  78. __asm__(
  79. "mov %0, %%g1\n\t"
  80. "ta 0x10\n\t"
  81. : /* no outputs */
  82. : "i" (__NR_rt_sigreturn)
  83. );
  84. }
  85. static void
  86. __sigreturn_stub(void)
  87. {
  88. __asm__(
  89. "mov %0, %%g1\n\t"
  90. "ta 0x10\n\t"
  91. : /* no outputs */
  92. : "i" (__NR_sigreturn)
  93. );
  94. }