sigaction.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 __default_rt_sa_restorer(void)
  15. {
  16. INTERNAL_SYSCALL_NCS(__NR_rt_sigreturn, , 0);
  17. }
  18. #define SA_RESTORER 0x04000000
  19. /* If @act is not NULL, change the action for @sig to @act.
  20. If @oact is not NULL, put the old action for @sig in @oact. */
  21. int
  22. __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  23. {
  24. struct sigaction kact;
  25. /*
  26. * SA_RESTORER is only relevant for act != NULL case
  27. * (!act means caller only wants to know @oact)
  28. */
  29. if (act && !(act->sa_flags & SA_RESTORER)) {
  30. kact.sa_restorer = __default_rt_sa_restorer;
  31. kact.sa_flags = act->sa_flags | SA_RESTORER;
  32. kact.sa_handler = act->sa_handler;
  33. kact.sa_mask = act->sa_mask;
  34. act = &kact;
  35. }
  36. return INLINE_SYSCALL(rt_sigaction, 4,
  37. sig, act, oact, sizeof(act->sa_mask));
  38. }
  39. #ifndef LIBC_SIGACTION
  40. # ifndef __UCLIBC_HAS_THREADS__
  41. strong_alias(__libc_sigaction,sigaction)
  42. libc_hidden_def(sigaction)
  43. # else
  44. weak_alias(__libc_sigaction,sigaction)
  45. libc_hidden_weak(sigaction)
  46. # endif
  47. #endif