(FORWARD_SIGNAL_TO_MAIN_THREAD): New define.
[emacs.git] / src / syssignal.h
blob13710d3104b75615f0745faeaefe13275b7a451e
1 /* syssignal.h - System-dependent definitions for signals.
2 Copyright (C) 1993, 1999, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 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, or (at your option)
10 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; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 extern void init_signals P_ ((void));
24 #if defined (HAVE_GTK_AND_PTHREAD) || (defined (HAVE_CARBON) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1020)
25 #include <pthread.h>
26 /* If defined, asynchronous signals delivered to a non-main thread are
27 forwarded to the main thread. */
28 #define FORWARD_SIGNAL_TO_MAIN_THREAD
29 #endif
31 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
32 extern pthread_t main_thread;
33 #endif
35 #ifdef POSIX_SIGNALS
37 /* Don't #include <signal.h>. That header should always be #included
38 before "config.h", because some configuration files (like s/hpux.h)
39 indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file
40 #includes <signal.h>, then that will re-#define SIGIO and confuse
41 things. */
43 #define SIGMASKTYPE sigset_t
45 #define SIGEMPTYMASK (empty_mask)
46 #define SIGFULLMASK (full_mask)
47 extern sigset_t empty_mask, full_mask;
49 /* POSIX pretty much destroys any possibility of writing sigmask as a
50 macro in standard C. We always define our own version because the
51 predefined macro in Glibc 2.1 is only provided for compatility for old
52 programs that use int as signal mask type. */
53 #undef sigmask
54 #ifdef __GNUC__
55 #define sigmask(SIG) \
56 ({ \
57 sigset_t _mask; \
58 sigemptyset (&_mask); \
59 sigaddset (&_mask, SIG); \
60 _mask; \
62 #else /* ! defined (__GNUC__) */
63 extern sigset_t sys_sigmask ();
64 #define sigmask(SIG) (sys_sigmask (SIG))
65 #endif /* ! defined (__GNUC__) */
67 #undef sigpause
68 #define sigpause(MASK) sigsuspend (&(MASK))
70 #define sigblock(SIG) sys_sigblock (SIG)
71 #define sigunblock(SIG) sys_sigunblock (SIG)
72 #ifndef sigsetmask
73 #define sigsetmask(SIG) sys_sigsetmask (SIG)
74 #endif
75 #define sighold(SIG) ONLY_USED_IN_BSD_4_1
76 #define sigrelse(SIG) ONLY_USED_IN_BSD_4_1
77 #undef signal
78 #define signal(SIG,ACT) sys_signal(SIG,ACT)
80 /* Whether this is what all systems want or not, this is what
81 appears to be assumed in the source, for example data.c:arith_error. */
82 typedef RETSIGTYPE (*signal_handler_t) (/*int*/);
84 signal_handler_t sys_signal P_ ((int signal_number, signal_handler_t action));
85 sigset_t sys_sigblock P_ ((sigset_t new_mask));
86 sigset_t sys_sigunblock P_ ((sigset_t new_mask));
87 sigset_t sys_sigsetmask P_ ((sigset_t new_mask));
89 #define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG)
91 #else /* ! defined (POSIX_SIGNALS) */
92 #ifdef USG5_4
94 extern SIGMASKTYPE sigprocmask_set;
96 #ifndef sigblock
97 #define sigblock(sig) \
98 (sigprocmask_set = SIGEMPTYMASK | (sig), \
99 sigprocmask (SIG_BLOCK, &sigprocmask_set, NULL))
100 #endif
102 #ifndef sigunblock
103 #define sigunblock(sig) \
104 (sigprocmask_set = SIGFULLMASK & ~(sig), \
105 sigprocmask (SIG_SETMASK, &sigprocmask_set, NULL))
106 #endif
108 #else
109 #ifdef USG
111 #ifndef sigunblock
112 #define sigunblock(sig)
113 #endif
115 #else
117 #ifndef sigunblock
118 #define sigunblock(SIG) \
119 { SIGMASKTYPE omask = sigblock (SIGEMPTYMASK); sigsetmask (omask & ~SIG); }
120 #endif
122 #endif /* ! defined (USG) */
123 #endif /* ! defined (USG5_4) */
124 #endif /* ! defined (POSIX_SIGNALS) */
126 #ifndef SIGMASKTYPE
127 #define SIGMASKTYPE int
128 #endif
130 #ifndef SIGEMPTYMASK
131 #define SIGEMPTYMASK (0)
132 #endif
134 #ifndef SIGFULLMASK
135 #define SIGFULLMASK (0xffffffff)
136 #endif
138 #ifndef sigmask
139 #define sigmask(no) (1L << ((no) - 1))
140 #endif
142 #ifndef sigunblock
143 #define sigunblock(SIG) \
144 { SIGMASKTYPE omask = sigblock (SIGFULLMASK); sigsetmask (omask & ~SIG); }
145 #endif
147 #ifndef BSD4_1
148 #define sigfree() sigsetmask (SIGEMPTYMASK)
149 #endif /* not BSD4_1 */
151 #if defined (SIGINFO) && defined (BROKEN_SIGINFO)
152 #undef SIGINFO
153 #endif
154 #if defined (SIGIO) && defined (BROKEN_SIGIO)
155 # undef SIGIO
156 # if defined (__Lynx__)
157 # undef SIGPOLL /* Defined as SIGIO on LynxOS */
158 # endif
159 #endif
160 #if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
161 #undef SIGPOLL
162 #endif
163 #if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
164 #undef SIGTSTP
165 #endif
166 #if defined (SIGURG) && defined (BROKEN_SIGURG)
167 #undef SIGURG
168 #endif
169 #if defined (SIGAIO) && defined (BROKEN_SIGAIO)
170 #undef SIGAIO
171 #endif
172 #if defined (SIGPTY) && defined (BROKEN_SIGPTY)
173 #undef SIGPTY
174 #endif
177 #if NSIG < NSIG_MINIMUM
178 # ifdef NSIG
179 # undef NSIG
180 # endif
181 # define NSIG NSIG_MINIMUM
182 #endif
184 #ifdef BSD4_1
185 #define SIGIO SIGTINT
186 /* sigfree is in sysdep.c */
187 #endif /* BSD4_1 */
189 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
190 Must do that using the killpg call. */
191 #ifdef BSD_SYSTEM
192 #define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
193 #else
194 #ifdef WINDOWSNT
195 #define EMACS_KILLPG(gid, signo) (kill (gid, signo))
196 #else
197 #define EMACS_KILLPG(gid, signo) (kill (-(gid), (signo)))
198 #endif
199 #endif
201 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
202 testing SIGCHLD. */
203 #ifndef VMS
204 #ifdef SIGCLD
205 #ifndef SIGCHLD
206 #define SIGCHLD SIGCLD
207 #endif /* SIGCHLD */
208 #endif /* ! defined (SIGCLD) */
209 #endif /* VMS */
211 #ifndef HAVE_STRSIGNAL
212 /* strsignal is in sysdep.c */
213 char *strsignal ();
214 #endif
216 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
217 #define SIGNAL_THREAD_CHECK(signo) \
218 do { \
219 if (!pthread_equal (pthread_self (), main_thread)) \
221 /* POSIX says any thread can receive the signal. On GNU/Linux \
222 that is not true, but for other systems (FreeBSD at least) \
223 it is. So direct the signal to the correct thread and block \
224 it from this thread. */ \
225 sigset_t new_mask; \
227 sigemptyset (&new_mask); \
228 sigaddset (&new_mask, signo); \
229 pthread_sigmask (SIG_BLOCK, &new_mask, 0); \
230 pthread_kill (main_thread, signo); \
231 return; \
233 } while (0)
235 #else /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
236 #define SIGNAL_THREAD_CHECK(signo)
237 #endif /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
238 /* arch-tag: 4580e86a-340d-4574-9e11-a742b6e1a152
239 (do not change this comment) */