sigaction.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* POSIX.1 sigaction call for Linux/SPARC64.
  2. Copyright (C) 1997-2017 Free Software Foundation, Inc.
  3. Contributed by Miguel de Icaza <miguel@nuclecu.unam.mx> and
  4. Jakub Jelinek <jj@ultra.linux.cz>.
  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. #include <string.h>
  17. #include <syscall.h>
  18. #include <sysdep.h>
  19. #include <sys/signal.h>
  20. #include <errno.h>
  21. #include <bits/kernel_sigaction.h>
  22. /* SPARC 64bit userland requires a kernel that has rt signals anyway. */
  23. static void __rt_sigreturn_stub (void);
  24. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  25. {
  26. int ret;
  27. struct kernel_sigaction kact, koact;
  28. unsigned long stub = ((unsigned long) &__rt_sigreturn_stub) - 8;
  29. if (act) {
  30. kact.k_sa_handler = act->sa_handler;
  31. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
  32. kact.sa_flags = act->sa_flags;
  33. kact.sa_restorer = NULL;
  34. }
  35. /* XXX The size argument hopefully will have to be changed to the
  36. real size of the user-level sigset_t. */
  37. ret = INLINE_SYSCALL (rt_sigaction, 5, sig,
  38. act ? &kact : 0,
  39. oact ? &koact : 0, stub, _NSIG / 8);
  40. if (oact && ret >= 0) {
  41. oact->sa_handler = koact.k_sa_handler;
  42. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
  43. oact->sa_flags = koact.sa_flags;
  44. oact->sa_restorer = koact.sa_restorer;
  45. }
  46. return ret;
  47. }
  48. #ifndef LIBC_SIGACTION
  49. # ifndef __UCLIBC_HAS_THREADS__
  50. strong_alias(__libc_sigaction,sigaction)
  51. libc_hidden_def(sigaction)
  52. # else
  53. weak_alias(__libc_sigaction,sigaction)
  54. libc_hidden_weak(sigaction)
  55. # endif
  56. #endif
  57. static void
  58. __rt_sigreturn_stub (void)
  59. {
  60. __asm__ ("mov %0, %%g1\n\t"
  61. "ta 0x6d\n\t"
  62. : /* no outputs */
  63. : "i" (__NR_rt_sigreturn));
  64. }