Back to index

glibc  2.9
sighandler.c
Go to the documentation of this file.
00001 /* Linuxthreads - a simple clone()-based implementation of Posix        */
00002 /* threads for Linux.                                                   */
00003 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
00004 /*                                                                      */
00005 /* This program is free software; you can redistribute it and/or        */
00006 /* modify it under the terms of the GNU Library General Public License  */
00007 /* as published by the Free Software Foundation; either version 2       */
00008 /* of the License, or (at your option) any later version.               */
00009 /*                                                                      */
00010 /* This program is distributed in the hope that it will be useful,      */
00011 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
00012 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
00013 /* GNU Library General Public License for more details.                 */
00014 
00015 /* Signal handlers */
00016 
00017 #include "internals.h"
00018 
00019 
00020 /* The wrapper around user-provided signal handlers */
00021 void __pthread_sighandler(int signo, SIGCONTEXT ctx)
00022 {
00023   pthread_descr self;
00024   char * in_sighandler;
00025   self = check_thread_self();
00026 
00027   /* If we're in a sigwait operation, just record the signal received
00028      and return without calling the user's handler */
00029   if (THREAD_GETMEM(self, p_sigwaiting)) {
00030     THREAD_SETMEM(self, p_sigwaiting, 0);
00031     THREAD_SETMEM(self, p_signal, signo);
00032     return;
00033   }
00034   /* Record that we're in a signal handler and call the user's
00035      handler function */
00036   in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
00037   if (in_sighandler == NULL)
00038     THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
00039   CALL_SIGHANDLER(__sighandler[signo].old, signo, ctx);
00040   if (in_sighandler == NULL)
00041     THREAD_SETMEM(self, p_in_sighandler, NULL);
00042 }
00043 
00044 /* The same, this time for real-time signals.  */
00045 void __pthread_sighandler_rt(int signo, struct siginfo *si,
00046                           struct ucontext *uc)
00047 {
00048   pthread_descr self;
00049   char * in_sighandler;
00050   self = check_thread_self();
00051 
00052   /* If we're in a sigwait operation, just record the signal received
00053      and return without calling the user's handler */
00054   if (THREAD_GETMEM(self, p_sigwaiting)) {
00055     THREAD_SETMEM(self, p_sigwaiting, 0);
00056     THREAD_SETMEM(self, p_signal, signo);
00057     return;
00058   }
00059   /* Record that we're in a signal handler and call the user's
00060      handler function */
00061   in_sighandler = THREAD_GETMEM(self, p_in_sighandler);
00062   if (in_sighandler == NULL)
00063     THREAD_SETMEM(self, p_in_sighandler, CURRENT_STACK_FRAME);
00064   __sighandler[signo].rt(signo, si, uc);
00065   if (in_sighandler == NULL)
00066     THREAD_SETMEM(self, p_in_sighandler, NULL);
00067 }
00068 
00069 
00070 /* A signal handler that does nothing */
00071 void __pthread_null_sighandler(int sig) { }