sigaction.c 2.7 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, see
  15. <http://www.gnu.org/licenses/>.
  16. Ported to uClibc from glibc: 090520:
  17. Jan Buchholz, KIP, Uni Heidelberg <jan.buchholz@kip.uni-heidelberg.de>
  18. Austin Foxley, Ceton Corporation <austinf@cetoncorp.com>
  19. */
  20. #include <errno.h>
  21. #include <signal.h>
  22. #include <string.h>
  23. #include <sys/syscall.h>
  24. #include <bits/kernel_sigaction.h>
  25. _syscall5(int, rt_sigaction, int, a, int, b, int, c, int, d, int, e)
  26. static void __rt_sigreturn_stub(void);
  27. static void __sigreturn_stub(void);
  28. int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
  29. {
  30. int ret;
  31. struct sigaction kact, koact;
  32. unsigned long stub = 0;
  33. if (act) {
  34. kact.sa_handler = act->sa_handler;
  35. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
  36. if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0)
  37. stub = (unsigned long) &__rt_sigreturn_stub;
  38. else
  39. stub = (unsigned long) &__sigreturn_stub;
  40. stub -= 8;
  41. kact.sa_restorer = NULL;
  42. }
  43. /* XXX The size argument hopefully will have to be changed to the
  44. * real size of the user-level sigset_t. */
  45. ret = INLINE_SYSCALL (rt_sigaction, 5, sig, act ? &kact : 0,
  46. oact ? &koact : 0, stub, _NSIG / 8);
  47. if (oact && ret >= 0) {
  48. oact->sa_handler = koact.sa_handler;
  49. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
  50. oact->sa_flags = koact.sa_flags;
  51. oact->sa_restorer = koact.sa_restorer;
  52. }
  53. return ret;
  54. }
  55. #ifndef LIBC_SIGACTION
  56. # ifndef __UCLIBC_HAS_THREADS__
  57. strong_alias(__libc_sigaction,sigaction)
  58. libc_hidden_def(sigaction)
  59. # else
  60. weak_alias(__libc_sigaction,sigaction)
  61. libc_hidden_weak(sigaction)
  62. # endif
  63. #endif
  64. static void
  65. __rt_sigreturn_stub(void)
  66. {
  67. __asm__(
  68. "mov %0, %%g1\n\t"
  69. "ta 0x10\n\t"
  70. : /* no outputs */
  71. : "i" (__NR_rt_sigreturn)
  72. );
  73. }
  74. static void
  75. __sigreturn_stub(void)
  76. {
  77. __asm__(
  78. "mov %0, %%g1\n\t"
  79. "ta 0x10\n\t"
  80. : /* no outputs */
  81. : "i" (__NR_sigreturn)
  82. );
  83. }