sigaction.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. libc_hidden_proto(memcpy)
  16. /*
  17. * If act is not NULL, change the action for sig to *act.
  18. * If oact is not NULL, put the old action for sig in *oact.
  19. */
  20. int __libc_sigaction(int signum, const struct sigaction *act,
  21. struct sigaction *oldact)
  22. {
  23. struct kernel_sigaction kact, koact;
  24. int result;
  25. if (act) {
  26. kact.k_sa_handler = act->sa_handler;
  27. memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  28. kact.sa_flags = act->sa_flags;
  29. if (kact.sa_flags & SA_RESTORER)
  30. kact.sa_restorer = act->sa_restorer;
  31. else
  32. kact.sa_restorer = __default_rt_sa_restorer;
  33. kact.sa_flags |= SA_RESTORER;
  34. }
  35. result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
  36. oldact ? __ptrvalue(&koact) : NULL,
  37. _NSIG / 8);
  38. if (oldact && result >= 0) {
  39. oldact->sa_handler = koact.k_sa_handler;
  40. memcpy(&oldact->sa_mask, &koact.sa_mask,
  41. sizeof(oldact->sa_mask));
  42. oldact->sa_flags = koact.sa_flags;
  43. oldact->sa_restorer = koact.sa_restorer;
  44. }
  45. return result;
  46. }
  47. #ifndef LIBC_SIGACTION
  48. libc_hidden_proto(sigaction)
  49. weak_alias(__libc_sigaction, sigaction)
  50. libc_hidden_weak(sigaction)
  51. #endif