sigaction.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA.
  15. Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
  16. */
  17. #include <errno.h>
  18. #include <signal.h>
  19. #include <string.h>
  20. #include <sys/syscall.h>
  21. #include <bits/kernel_sigaction.h>
  22. #define SA_RESTORER 0x04000000
  23. #if defined __NR_rt_sigaction
  24. libc_hidden_proto(memcpy)
  25. /* If ACT is not NULL, change the action for SIG to *ACT.
  26. If OACT is not NULL, put the old action for SIG in *OACT. */
  27. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  28. {
  29. int result;
  30. struct kernel_sigaction kact, koact;
  31. if (act) {
  32. kact.k_sa_handler = act->sa_handler;
  33. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  34. kact.sa_flags = act->sa_flags;
  35. # ifdef HAVE_SA_RESTORER
  36. # if _MIPS_SIM == _ABIO32
  37. kact.sa_restorer = act->sa_restorer;
  38. # else
  39. kact.sa_restorer = &restore_rt;
  40. # endif
  41. # endif
  42. }
  43. /* XXX The size argument hopefully will have to be changed to the
  44. real size of the user-level sigset_t. */
  45. result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
  46. oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
  47. if (oact && result >= 0) {
  48. oact->sa_handler = koact.k_sa_handler;
  49. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
  50. oact->sa_flags = koact.sa_flags;
  51. # ifdef HAVE_SA_RESTORER
  52. oact->sa_restorer = koact.sa_restorer;
  53. # endif
  54. }
  55. return result;
  56. }
  57. #else
  58. extern void restore (void) asm ("__restore") attribute_hidden;
  59. /* If ACT is not NULL, change the action for SIG to *ACT.
  60. If OACT is not NULL, put the old action for SIG in *OACT. */
  61. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  62. {
  63. int result;
  64. struct old_kernel_sigaction kact, koact;
  65. if (act) {
  66. kact.k_sa_handler = act->sa_handler;
  67. kact.sa_mask = act->sa_mask.__val[0];
  68. kact.sa_flags = act->sa_flags;
  69. # ifdef HAVE_SA_RESTORER
  70. # if _MIPS_SIM == _ABIO32
  71. kact.sa_restorer = act->sa_restorer;
  72. # else
  73. kact.sa_restorer = &restore_rt;
  74. # endif
  75. # endif
  76. }
  77. result = __syscall_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
  78. oact ? __ptrvalue (&koact) : NULL);
  79. if (result < 0) {
  80. __set_errno(-result);
  81. return -1;
  82. }
  83. if (oact) {
  84. oact->sa_handler = koact.k_sa_handler;
  85. oact->sa_mask.__val[0] = koact.sa_mask;
  86. oact->sa_flags = koact.sa_flags;
  87. # ifdef HAVE_SA_RESTORER
  88. oact->sa_restorer = koact.sa_restorer;
  89. # endif
  90. }
  91. return result;
  92. }
  93. #endif
  94. #ifndef LIBC_SIGACTION
  95. libc_hidden_proto(sigaction)
  96. strong_alias(__libc_sigaction,sigaction)
  97. libc_hidden_def(sigaction)
  98. #endif