* ctype/ctype.h (__ctype_b, __ctype_toupper, __ctype_tolower):
[platform/upstream/glibc.git] / linuxthreads / sighandler.c
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
15 /* Signal handlers */
16
17 #include "internals.h"
18
19
20 /* The wrapper around user-provided signal handlers */
21 void __pthread_sighandler(int signo, SIGCONTEXT ctx)
22 {
23   pthread_descr self;
24   char * in_sighandler;
25   self = thread_self();
26   /* If we're in a sigwait operation, just record the signal received
27      and return without calling the user's handler */
28   if (THREAD_GETMEM(self, p_sigwaiting)) {
29     THREAD_SETMEM(self, p_sigwaiting, 0);
30     THREAD_SETMEM(self, p_signal, signo);
31     return;
32   }
33   /* Record that we're in a signal handler and call the user's
34      handler function */
35   in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
36   if (in_sighandler == NULL)
37     THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
38   CALL_SIGHANDLER(__sighandler[signo].old, signo, ctx);
39   if (in_sighandler == NULL)
40     THREAD_SETMEM(self, p_in_sighandler, NULL);
41 }
42
43 /* The same, this time for real-time signals.  */
44 void __pthread_sighandler_rt(int signo, struct siginfo *si,
45                              struct ucontext *uc)
46 {
47   pthread_descr self;
48   char * in_sighandler;
49   self =  thread_self();
50   /* If we're in a sigwait operation, just record the signal received
51      and return without calling the user's handler */
52   if (THREAD_GETMEM(self, p_sigwaiting)) {
53     THREAD_SETMEM(self, p_sigwaiting, 0);
54     THREAD_SETMEM(self, p_signal, signo);
55     return;
56   }
57   /* Record that we're in a signal handler and call the user's
58      handler function */
59   in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
60   if (in_sighandler == NULL)
61     THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
62   __sighandler[signo].rt(signo, si, uc);
63   if (in_sighandler == NULL)
64     THREAD_SETMEM(self, p_in_sighandler, NULL);
65 }
66
67
68 /* A signal handler that does nothing */
69 void __pthread_null_sighandler(int sig) { }