sigaction.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. extern void __default_sa_restorer(void);
  24. extern void __default_rt_sa_restorer(void);
  25. #if defined __NR_rt_sigaction
  26. /* If ACT is not NULL, change the action for SIG to *ACT.
  27. If OACT is not NULL, put the old action for SIG in *OACT. */
  28. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  29. {
  30. int result;
  31. struct kernel_sigaction kact, koact;
  32. if (act) {
  33. kact.k_sa_handler = act->sa_handler;
  34. memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  35. kact.sa_flags = act->sa_flags;
  36. # ifdef HAVE_SA_RESTORER
  37. if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK)) {
  38. kact.sa_restorer = act->sa_restorer;
  39. } else {
  40. if (kact.sa_flags & SA_SIGINFO) {
  41. kact.sa_restorer = __default_rt_sa_restorer;
  42. } else {
  43. kact.sa_restorer = __default_sa_restorer;
  44. kact.sa_flags |= SA_RESTORER;
  45. }
  46. }
  47. # endif
  48. }
  49. /* XXX The size argument hopefully will have to be changed to the
  50. real size of the user-level sigset_t. */
  51. result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
  52. oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
  53. if (oact && result >= 0) {
  54. oact->sa_handler = koact.k_sa_handler;
  55. memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
  56. oact->sa_flags = koact.sa_flags;
  57. # ifdef HAVE_SA_RESTORER
  58. oact->sa_restorer = koact.sa_restorer;
  59. # endif
  60. }
  61. return result;
  62. }
  63. #else
  64. /* If ACT is not NULL, change the action for SIG to *ACT.
  65. If OACT is not NULL, put the old action for SIG in *OACT. */
  66. int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  67. {
  68. int result;
  69. struct old_kernel_sigaction kact, koact;
  70. if (act) {
  71. kact.k_sa_handler = act->sa_handler;
  72. kact.sa_mask = act->sa_mask.__val[0];
  73. kact.sa_flags = act->sa_flags;
  74. # ifdef HAVE_SA_RESTORER
  75. /* See the comments above for why we test SA_ONSTACK. */
  76. if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK)) {
  77. kact.sa_restorer = act->sa_restorer;
  78. } else {
  79. kact.sa_restorer = __default_sa_restorer;
  80. kact.sa_flags |= SA_RESTORER;
  81. }
  82. # endif
  83. }
  84. result = __syscall_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
  85. oact ? __ptrvalue (&koact) : NULL);
  86. if (oact && result >= 0) {
  87. oact->sa_handler = koact.k_sa_handler;
  88. oact->sa_mask.__val[0] = koact.sa_mask;
  89. oact->sa_flags = koact.sa_flags;
  90. # ifdef HAVE_SA_RESTORER
  91. oact->sa_restorer = koact.sa_restorer;
  92. # endif
  93. }
  94. return result;
  95. }
  96. #endif
  97. weak_alias(__libc_sigaction, sigaction)