sighandler.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Linuxthreads - a simple clone()-based implementation of Posix */
  2. /* threads for Linux. */
  3. /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
  4. /* */
  5. /* This program is free software; you can redistribute it and/or */
  6. /* modify it under the terms of the GNU Library General Public License */
  7. /* as published by the Free Software Foundation; either version 2 */
  8. /* of the License, or (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU Library General Public License for more details. */
  14. /* Signal handlers */
  15. #include "internals.h"
  16. /* The wrapper around user-provided signal handlers */
  17. void __pthread_sighandler(int signo, SIGCONTEXT ctx)
  18. {
  19. pthread_descr self;
  20. char * in_sighandler;
  21. self = check_thread_self();
  22. /* If we're in a sigwait operation, just record the signal received
  23. and return without calling the user's handler */
  24. if (THREAD_GETMEM(self, p_sigwaiting)) {
  25. THREAD_SETMEM(self, p_sigwaiting, 0);
  26. THREAD_SETMEM(self, p_signal, signo);
  27. return;
  28. }
  29. /* Record that we're in a signal handler and call the user's
  30. handler function */
  31. in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
  32. if (in_sighandler == NULL)
  33. THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
  34. CALL_SIGHANDLER(__sighandler[signo].old, signo, ctx);
  35. if (in_sighandler == NULL)
  36. THREAD_SETMEM(self, p_in_sighandler, NULL);
  37. }
  38. /* The same, this time for real-time signals. */
  39. void __pthread_sighandler_rt(int signo, struct siginfo *si,
  40. struct ucontext *uc)
  41. {
  42. pthread_descr self;
  43. char * in_sighandler;
  44. self = check_thread_self();
  45. /* If we're in a sigwait operation, just record the signal received
  46. and return without calling the user's handler */
  47. if (THREAD_GETMEM(self, p_sigwaiting)) {
  48. THREAD_SETMEM(self, p_sigwaiting, 0);
  49. THREAD_SETMEM(self, p_signal, signo);
  50. return;
  51. }
  52. /* Record that we're in a signal handler and call the user's
  53. handler function */
  54. in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
  55. if (in_sighandler == NULL)
  56. THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
  57. __sighandler[signo].rt(signo, si, uc);
  58. if (in_sighandler == NULL)
  59. THREAD_SETMEM(self, p_in_sighandler, NULL);
  60. }
  61. /* A signal handler that does nothing */
  62. void __pthread_null_sighandler(int sig) { }