sigaction.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2004-2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <errno.h>
  9. #include <signal.h>
  10. #include <string.h>
  11. #include <sys/syscall.h>
  12. #include <bits/kernel_sigaction.h>
  13. #define SA_RESTORER 0x04000000
  14. extern void __default_rt_sa_restorer(void);
  15. /* Experimentally off - libc_hidden_proto(memcpy) */
  16. extern __typeof(sigaction) __libc_sigaction;
  17. /*
  18. * If act is not NULL, change the action for sig to *act.
  19. * If oact is not NULL, put the old action for sig in *oact.
  20. */
  21. int __libc_sigaction(int signum, const struct sigaction *act,
  22. struct sigaction *oldact)
  23. {
  24. struct kernel_sigaction kact, koact;
  25. int result;
  26. if (act) {
  27. kact.k_sa_handler = act->sa_handler;
  28. memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  29. kact.sa_flags = act->sa_flags;
  30. if (kact.sa_flags & SA_RESTORER)
  31. kact.sa_restorer = act->sa_restorer;
  32. else
  33. kact.sa_restorer = __default_rt_sa_restorer;
  34. kact.sa_flags |= SA_RESTORER;
  35. }
  36. result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
  37. oldact ? __ptrvalue(&koact) : NULL,
  38. _NSIG / 8);
  39. if (oldact && result >= 0) {
  40. oldact->sa_handler = koact.k_sa_handler;
  41. memcpy(&oldact->sa_mask, &koact.sa_mask,
  42. sizeof(oldact->sa_mask));
  43. oldact->sa_flags = koact.sa_flags;
  44. oldact->sa_restorer = koact.sa_restorer;
  45. }
  46. return result;
  47. }
  48. #ifndef LIBC_SIGACTION
  49. libc_hidden_proto(sigaction)
  50. weak_alias(__libc_sigaction, sigaction)
  51. libc_hidden_weak(sigaction)
  52. #endif