Merge from trunk
[emacs.git] / src / syssignal.h
blob48eb722935335a0740adebaefbeda79cf90bfe34
1 /* syssignal.h - System-dependent definitions for signals.
2 Copyright (C) 1993, 1999, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 extern void init_signals (void);
22 #if defined (HAVE_GTK_AND_PTHREAD) || defined (HAVE_NS)
23 #include <pthread.h>
24 /* If defined, asynchronous signals delivered to a non-main thread are
25 forwarded to the main thread. */
26 #define FORWARD_SIGNAL_TO_MAIN_THREAD
27 #endif
29 /* Don't #include <signal.h>. That header should always be #included
30 before "config.h", because some configuration files (like s/hpux.h)
31 indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file
32 #includes <signal.h>, then that will re-#define SIGIO and confuse
33 things. */
34 /* XXX This is not correct anymore, there is a BROKEN_SIGIO macro. */
36 #define SIGMASKTYPE sigset_t
38 #define SIGEMPTYMASK (empty_mask)
39 #define SIGFULLMASK (full_mask)
40 extern sigset_t empty_mask, full_mask;
42 /* POSIX pretty much destroys any possibility of writing sigmask as a
43 macro in standard C. We always define our own version because the
44 predefined macro in Glibc 2.1 is only provided for compatility for old
45 programs that use int as signal mask type. */
46 #undef sigmask
47 #ifdef __GNUC__
48 #define sigmask(SIG) \
49 ({ \
50 sigset_t _mask; \
51 sigemptyset (&_mask); \
52 sigaddset (&_mask, SIG); \
53 _mask; \
55 #else /* ! defined (__GNUC__) */
56 extern sigset_t sys_sigmask ();
57 #define sigmask(SIG) (sys_sigmask (SIG))
58 #endif /* ! defined (__GNUC__) */
60 #undef sigpause
61 #define sigpause(MASK) sigsuspend (&(MASK))
63 #define sigblock(SIG) sys_sigblock (SIG)
64 #define sigunblock(SIG) sys_sigunblock (SIG)
65 #ifndef sigsetmask
66 #define sigsetmask(SIG) sys_sigsetmask (SIG)
67 #endif
68 #undef signal
69 #define signal(SIG,ACT) sys_signal(SIG,ACT)
71 /* Whether this is what all systems want or not, this is what
72 appears to be assumed in the source, for example data.c:arith_error. */
73 typedef RETSIGTYPE (*signal_handler_t) (int);
75 signal_handler_t sys_signal (int signal_number, signal_handler_t action);
76 sigset_t sys_sigblock (sigset_t new_mask);
77 sigset_t sys_sigunblock (sigset_t new_mask);
78 sigset_t sys_sigsetmask (sigset_t new_mask);
80 #define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG)
82 #define sigfree() sigsetmask (SIGEMPTYMASK)
84 #if defined (SIGINFO) && defined (BROKEN_SIGINFO)
85 #undef SIGINFO
86 #endif
87 #if defined (SIGIO) && defined (BROKEN_SIGIO)
88 # undef SIGIO
89 #endif
90 #if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
91 #undef SIGPOLL
92 #endif
93 #if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
94 #undef SIGTSTP
95 #endif
96 #if defined (SIGURG) && defined (BROKEN_SIGURG)
97 #undef SIGURG
98 #endif
99 #if defined (SIGAIO) && defined (BROKEN_SIGAIO)
100 #undef SIGAIO
101 #endif
102 #if defined (SIGPTY) && defined (BROKEN_SIGPTY)
103 #undef SIGPTY
104 #endif
107 #if NSIG < NSIG_MINIMUM
108 # ifdef NSIG
109 # undef NSIG
110 # endif
111 # define NSIG NSIG_MINIMUM
112 #endif
114 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
115 Must do that using the killpg call. */
116 #ifdef BSD_SYSTEM
117 #define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
118 #else
119 #ifdef WINDOWSNT
120 #define EMACS_KILLPG(gid, signo) (kill (gid, signo))
121 #else
122 #define EMACS_KILLPG(gid, signo) (kill (-(gid), (signo)))
123 #endif
124 #endif
126 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
127 testing SIGCHLD. */
128 #ifdef SIGCLD
129 #ifndef SIGCHLD
130 #define SIGCHLD SIGCLD
131 #endif /* SIGCHLD */
132 #endif /* ! defined (SIGCLD) */
134 #ifndef HAVE_STRSIGNAL
135 /* strsignal is in sysdep.c */
136 char *strsignal (int);
137 #endif
139 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
140 extern pthread_t main_thread;
141 #define SIGNAL_THREAD_CHECK(signo) \
142 do { \
143 if (!pthread_equal (pthread_self (), main_thread)) \
145 /* POSIX says any thread can receive the signal. On GNU/Linux \
146 that is not true, but for other systems (FreeBSD at least) \
147 it is. So direct the signal to the correct thread and block \
148 it from this thread. */ \
149 sigset_t new_mask; \
151 sigemptyset (&new_mask); \
152 sigaddset (&new_mask, signo); \
153 pthread_sigmask (SIG_BLOCK, &new_mask, 0); \
154 pthread_kill (main_thread, signo); \
155 return; \
157 } while (0)
159 #else /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
160 #define SIGNAL_THREAD_CHECK(signo)
161 #endif /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
162 /* arch-tag: 4580e86a-340d-4574-9e11-a742b6e1a152
163 (do not change this comment) */