Switch to recommended form of GPLv3 permissions notice.
[emacs.git] / src / syssignal.h
blob0ab4598b5075f268690e08129e4fa6f501ca4896
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. */
42 /* XXX This is not correct anymore, there is a BROKEN_SIGIO macro. */
44 #define SIGMASKTYPE sigset_t
46 #define SIGEMPTYMASK (empty_mask)
47 #define SIGFULLMASK (full_mask)
48 extern sigset_t empty_mask, full_mask;
50 /* POSIX pretty much destroys any possibility of writing sigmask as a
51 macro in standard C. We always define our own version because the
52 predefined macro in Glibc 2.1 is only provided for compatility for old
53 programs that use int as signal mask type. */
54 #undef sigmask
55 #ifdef __GNUC__
56 #define sigmask(SIG) \
57 ({ \
58 sigset_t _mask; \
59 sigemptyset (&_mask); \
60 sigaddset (&_mask, SIG); \
61 _mask; \
63 #else /* ! defined (__GNUC__) */
64 extern sigset_t sys_sigmask ();
65 #define sigmask(SIG) (sys_sigmask (SIG))
66 #endif /* ! defined (__GNUC__) */
68 #undef sigpause
69 #define sigpause(MASK) sigsuspend (&(MASK))
71 #define sigblock(SIG) sys_sigblock (SIG)
72 #define sigunblock(SIG) sys_sigunblock (SIG)
73 #ifndef sigsetmask
74 #define sigsetmask(SIG) sys_sigsetmask (SIG)
75 #endif
76 #define sighold(SIG) ONLY_USED_IN_BSD_4_1
77 #define sigrelse(SIG) ONLY_USED_IN_BSD_4_1
78 #undef signal
79 #define signal(SIG,ACT) sys_signal(SIG,ACT)
81 /* Whether this is what all systems want or not, this is what
82 appears to be assumed in the source, for example data.c:arith_error. */
83 typedef RETSIGTYPE (*signal_handler_t) (/*int*/);
85 signal_handler_t sys_signal P_ ((int signal_number, signal_handler_t action));
86 sigset_t sys_sigblock P_ ((sigset_t new_mask));
87 sigset_t sys_sigunblock P_ ((sigset_t new_mask));
88 sigset_t sys_sigsetmask P_ ((sigset_t new_mask));
90 #define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG)
92 #else /* ! defined (POSIX_SIGNALS) */
93 #ifdef USG5_4
95 extern SIGMASKTYPE sigprocmask_set;
97 #ifndef sigblock
98 #define sigblock(sig) \
99 (sigprocmask_set = SIGEMPTYMASK | (sig), \
100 sigprocmask (SIG_BLOCK, &sigprocmask_set, NULL))
101 #endif
103 #ifndef sigunblock
104 #define sigunblock(sig) \
105 (sigprocmask_set = SIGFULLMASK & ~(sig), \
106 sigprocmask (SIG_SETMASK, &sigprocmask_set, NULL))
107 #endif
109 #else
110 #ifdef USG
112 #ifndef sigunblock
113 #define sigunblock(sig)
114 #endif
116 #else
118 #ifndef sigunblock
119 #define sigunblock(SIG) \
120 { SIGMASKTYPE omask = sigblock (SIGEMPTYMASK); sigsetmask (omask & ~SIG); }
121 #endif
123 #endif /* ! defined (USG) */
124 #endif /* ! defined (USG5_4) */
125 #endif /* ! defined (POSIX_SIGNALS) */
127 #ifndef SIGMASKTYPE
128 #define SIGMASKTYPE int
129 #endif
131 #ifndef SIGEMPTYMASK
132 #define SIGEMPTYMASK (0)
133 #endif
135 #ifndef SIGFULLMASK
136 #define SIGFULLMASK (0xffffffff)
137 #endif
139 #ifndef sigmask
140 #define sigmask(no) (1L << ((no) - 1))
141 #endif
143 #ifndef sigunblock
144 #define sigunblock(SIG) \
145 { SIGMASKTYPE omask = sigblock (SIGFULLMASK); sigsetmask (omask & ~SIG); }
146 #endif
148 #ifndef BSD4_1
149 #define sigfree() sigsetmask (SIGEMPTYMASK)
150 #endif /* not BSD4_1 */
152 #if defined (SIGINFO) && defined (BROKEN_SIGINFO)
153 #undef SIGINFO
154 #endif
155 #if defined (SIGIO) && defined (BROKEN_SIGIO)
156 # undef SIGIO
157 # if defined (__Lynx__)
158 # undef SIGPOLL /* Defined as SIGIO on LynxOS */
159 # endif
160 #endif
161 #if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
162 #undef SIGPOLL
163 #endif
164 #if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
165 #undef SIGTSTP
166 #endif
167 #if defined (SIGURG) && defined (BROKEN_SIGURG)
168 #undef SIGURG
169 #endif
170 #if defined (SIGAIO) && defined (BROKEN_SIGAIO)
171 #undef SIGAIO
172 #endif
173 #if defined (SIGPTY) && defined (BROKEN_SIGPTY)
174 #undef SIGPTY
175 #endif
178 #if NSIG < NSIG_MINIMUM
179 # ifdef NSIG
180 # undef NSIG
181 # endif
182 # define NSIG NSIG_MINIMUM
183 #endif
185 #ifdef BSD4_1
186 #define SIGIO SIGTINT
187 /* sigfree is in sysdep.c */
188 #endif /* BSD4_1 */
190 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
191 Must do that using the killpg call. */
192 #ifdef BSD_SYSTEM
193 #define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
194 #else
195 #ifdef WINDOWSNT
196 #define EMACS_KILLPG(gid, signo) (kill (gid, signo))
197 #else
198 #define EMACS_KILLPG(gid, signo) (kill (-(gid), (signo)))
199 #endif
200 #endif
202 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
203 testing SIGCHLD. */
204 #ifndef VMS
205 #ifdef SIGCLD
206 #ifndef SIGCHLD
207 #define SIGCHLD SIGCLD
208 #endif /* SIGCHLD */
209 #endif /* ! defined (SIGCLD) */
210 #endif /* VMS */
212 #ifndef HAVE_STRSIGNAL
213 /* strsignal is in sysdep.c */
214 char *strsignal ();
215 #endif
217 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
218 #define SIGNAL_THREAD_CHECK(signo) \
219 do { \
220 if (!pthread_equal (pthread_self (), main_thread)) \
222 /* POSIX says any thread can receive the signal. On GNU/Linux \
223 that is not true, but for other systems (FreeBSD at least) \
224 it is. So direct the signal to the correct thread and block \
225 it from this thread. */ \
226 sigset_t new_mask; \
228 sigemptyset (&new_mask); \
229 sigaddset (&new_mask, signo); \
230 pthread_sigmask (SIG_BLOCK, &new_mask, 0); \
231 pthread_kill (main_thread, signo); \
232 return; \
234 } while (0)
236 #else /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
237 #define SIGNAL_THREAD_CHECK(signo)
238 #endif /* not FORWARD_SIGNAL_TO_MAIN_THREAD */
239 /* arch-tag: 4580e86a-340d-4574-9e11-a742b6e1a152
240 (do not change this comment) */