sigaction.c 2.7 KB

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