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)
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)
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
31 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
32 extern pthread_t main_thread
;
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
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. */
56 #define sigmask(SIG) \
59 sigemptyset (&_mask); \
60 sigaddset (&_mask, SIG); \
63 #else /* ! defined (__GNUC__) */
64 extern sigset_t
sys_sigmask ();
65 #define sigmask(SIG) (sys_sigmask (SIG))
66 #endif /* ! defined (__GNUC__) */
69 #define sigpause(MASK) sigsuspend (&(MASK))
71 #define sigblock(SIG) sys_sigblock (SIG)
72 #define sigunblock(SIG) sys_sigunblock (SIG)
74 #define sigsetmask(SIG) sys_sigsetmask (SIG)
76 #define sighold(SIG) ONLY_USED_IN_BSD_4_1
77 #define sigrelse(SIG) ONLY_USED_IN_BSD_4_1
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) */
95 extern SIGMASKTYPE sigprocmask_set
;
98 #define sigblock(sig) \
99 (sigprocmask_set = SIGEMPTYMASK | (sig), \
100 sigprocmask (SIG_BLOCK, &sigprocmask_set, NULL))
104 #define sigunblock(sig) \
105 (sigprocmask_set = SIGFULLMASK & ~(sig), \
106 sigprocmask (SIG_SETMASK, &sigprocmask_set, NULL))
113 #define sigunblock(sig)
119 #define sigunblock(SIG) \
120 { SIGMASKTYPE omask = sigblock (SIGEMPTYMASK); sigsetmask (omask & ~SIG); }
123 #endif /* ! defined (USG) */
124 #endif /* ! defined (USG5_4) */
125 #endif /* ! defined (POSIX_SIGNALS) */
128 #define SIGMASKTYPE int
132 #define SIGEMPTYMASK (0)
136 #define SIGFULLMASK (0xffffffff)
140 #define sigmask(no) (1L << ((no) - 1))
144 #define sigunblock(SIG) \
145 { SIGMASKTYPE omask = sigblock (SIGFULLMASK); sigsetmask (omask & ~SIG); }
149 #define sigfree() sigsetmask (SIGEMPTYMASK)
150 #endif /* not BSD4_1 */
152 #if defined (SIGINFO) && defined (BROKEN_SIGINFO)
155 #if defined (SIGIO) && defined (BROKEN_SIGIO)
157 # if defined (__Lynx__)
158 # undef SIGPOLL /* Defined as SIGIO on LynxOS */
161 #if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
164 #if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
167 #if defined (SIGURG) && defined (BROKEN_SIGURG)
170 #if defined (SIGAIO) && defined (BROKEN_SIGAIO)
173 #if defined (SIGPTY) && defined (BROKEN_SIGPTY)
178 #if NSIG < NSIG_MINIMUM
182 # define NSIG NSIG_MINIMUM
186 #define SIGIO SIGTINT
187 /* sigfree is in sysdep.c */
190 /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
191 Must do that using the killpg call. */
193 #define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
196 #define EMACS_KILLPG(gid, signo) (kill (gid, signo))
198 #define EMACS_KILLPG(gid, signo) (kill (-(gid), (signo)))
202 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
207 #define SIGCHLD SIGCLD
209 #endif /* ! defined (SIGCLD) */
212 #ifndef HAVE_STRSIGNAL
213 /* strsignal is in sysdep.c */
217 #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
218 #define SIGNAL_THREAD_CHECK(signo) \
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. */ \
228 sigemptyset (&new_mask); \
229 sigaddset (&new_mask, signo); \
230 pthread_sigmask (SIG_BLOCK, &new_mask, 0); \
231 pthread_kill (main_thread, signo); \
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) */