sigaction.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. extern void __default_rt_sa_restorer(void);
  12. //libc_hidden_proto(__default_rt_sa_restorer);
  13. #define SA_RESTORER 0x04000000
  14. /* If @act is not NULL, change the action for @sig to @act.
  15. If @oact is not NULL, put the old action for @sig in @oact. */
  16. int
  17. __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  18. {
  19. struct sigaction kact;
  20. /* !act means caller only wants to know @oact
  21. * Hence only otherwise, do SA_RESTORER stuff
  22. *
  23. * For the normal/default cases (user not providing SA_RESTORER) use
  24. * a real sigreturn stub to avoid kernel synthesizing one on user stack
  25. * at runtime, which needs PTE permissions update (hence TLB entry
  26. * update) and costly cache line flushes for code modification
  27. */
  28. if (act && !(act->sa_flags & SA_RESTORER)) {
  29. memcpy(&kact, act, sizeof(kact));
  30. kact.sa_restorer = __default_rt_sa_restorer;
  31. kact.sa_flags |= SA_RESTORER;
  32. act = &kact;
  33. }
  34. return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
  35. }
  36. #ifndef LIBC_SIGACTION
  37. weak_alias(__libc_sigaction,sigaction)
  38. libc_hidden_weak(sigaction)
  39. #endif