sigaction.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <errno.h>
  7. #include <signal.h>
  8. #include <string.h>
  9. #include <sys/syscall.h>
  10. #include <bits/kernel_sigaction.h>
  11. /*
  12. * Default sigretrun stub if user doesn't specify SA_RESTORER
  13. */
  14. static void attribute_optimize("Os") __attribute_noinline__
  15. __default_rt_sa_restorer(void)
  16. {
  17. INTERNAL_SYSCALL_NCS(__NR_rt_sigreturn, , 0);
  18. }
  19. #define SA_RESTORER 0x04000000
  20. /* If @act is not NULL, change the action for @sig to @act.
  21. If @oact is not NULL, put the old action for @sig in @oact. */
  22. int
  23. __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  24. {
  25. struct sigaction kact;
  26. /*
  27. * SA_RESTORER is only relevant for act != NULL case
  28. * (!act means caller only wants to know @oact)
  29. */
  30. if (act && !(act->sa_flags & SA_RESTORER)) {
  31. kact.sa_restorer = __default_rt_sa_restorer;
  32. kact.sa_flags = act->sa_flags | SA_RESTORER;
  33. kact.sa_handler = act->sa_handler;
  34. kact.sa_mask = act->sa_mask;
  35. act = &kact;
  36. }
  37. return INLINE_SYSCALL(rt_sigaction, 4,
  38. sig, act, oact, sizeof(act->sa_mask));
  39. }
  40. #ifndef LIBC_SIGACTION
  41. # ifndef __UCLIBC_HAS_THREADS__
  42. strong_alias(__libc_sigaction,sigaction)
  43. libc_hidden_def(sigaction)
  44. # else
  45. weak_alias(__libc_sigaction,sigaction)
  46. libc_hidden_weak(sigaction)
  47. # endif
  48. #endif