sigaction.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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
  30. __libc_sigaction (int sig, __const struct sigaction *act, struct sigaction *oact)
  31. {
  32. int ret;
  33. struct old_kernel_sigaction kact, koact;
  34. unsigned long stub = 0;
  35. int saved_errno = errno;
  36. if (act)
  37. {
  38. kact.k_sa_handler = act->sa_handler;
  39. memcpy (&kact.sa_mask, &act->sa_mask, sizeof(sigset_t));
  40. if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO)!= 0)
  41. stub = (unsigned long) &__rt_sigreturn_stub;
  42. else
  43. stub = (unsigned long) &__sigreturn_stub;
  44. stub -= 8;
  45. kact.sa_restorer = NULL;
  46. }
  47. /* XXX The size argument hopefully will have to be changed to the real size of the user-level sigset_t. */
  48. ret = rt_sigaction(sig,
  49. (int)(act ? &kact : NULL),
  50. (int)(oact ? &koact : NULL),
  51. stub,
  52. _NSIG / 8);
  53. if (ret >= 0 || errno != ENOSYS)
  54. {
  55. if (oact && ret >= 0)
  56. {
  57. oact->sa_handler = koact.k_sa_handler;
  58. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
  59. oact->sa_flags = koact.sa_flags;
  60. oact->sa_restorer = koact.sa_restorer;
  61. }
  62. return ret;
  63. }
  64. __set_errno (saved_errno);
  65. return -1;
  66. }
  67. #ifndef LIBC_SIGACTION
  68. weak_alias(__libc_sigaction,sigaction)
  69. libc_hidden_weak(sigaction)
  70. #endif
  71. static void
  72. __rt_sigreturn_stub (void)
  73. {
  74. __asm__ ("mov %0, %%g1\n\t"
  75. "ta 0x10\n\t"
  76. : /* no outputs */
  77. : "i" (__NR_rt_sigreturn));
  78. }
  79. static void
  80. __sigreturn_stub (void)
  81. {
  82. __asm__ ("mov %0, %%g1\n\t"
  83. "ta 0x10\n\t"
  84. : /* no outputs */
  85. : "i" (__NR_sigreturn));
  86. }