sigaction.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * sigaction() for Xtensa uClibc
  4. *
  5. * Copyright (C) 2007, 2008 Tensilica Inc.
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <errno.h>
  10. #include <signal.h>
  11. #include <sys/syscall.h>
  12. #include <string.h>
  13. #include <bits/kernel_sigaction.h>
  14. #define SA_RESTORER 0x04000000
  15. extern void __default_sa_restorer (void);
  16. /* Experimentally off - libc_hidden_proto(memcpy) */
  17. int __libc_sigaction (int signum, const struct sigaction *act,
  18. struct sigaction *oldact)
  19. {
  20. struct kernel_sigaction kact, koldact;
  21. int result;
  22. if (act) {
  23. kact.k_sa_handler = act->sa_handler;
  24. memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
  25. kact.sa_flags = act->sa_flags;
  26. if (kact.sa_flags & SA_RESTORER) {
  27. kact.sa_restorer = act->sa_restorer;
  28. } else {
  29. kact.sa_restorer = __default_sa_restorer;
  30. kact.sa_flags |= SA_RESTORER;
  31. }
  32. }
  33. result = __syscall_rt_sigaction(signum, act ? __ptrvalue (&kact) : NULL,
  34. oldact ? __ptrvalue (&koldact) : NULL,
  35. _NSIG / 8);
  36. if (oldact && result >= 0) {
  37. oldact->sa_handler = koldact.k_sa_handler;
  38. memcpy(&oldact->sa_mask, &koldact.sa_mask, sizeof(oldact->sa_mask));
  39. oldact->sa_flags = koldact.sa_flags;
  40. oldact->sa_restorer = koldact.sa_restorer;
  41. }
  42. return result;
  43. }
  44. #ifndef LIBC_SIGACTION
  45. libc_hidden_proto (sigaction)
  46. weak_alias (__libc_sigaction, sigaction)
  47. libc_hidden_weak (sigaction)
  48. #endif