syssignal.h 6.62 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* syssignal.h - System-dependent definitions for signals.
2
   Copyright (C) 1993, 1999 Free Software Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
3 4 5 6 7

This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Karl Heuer's avatar
Karl Heuer committed
8
the Free Software Foundation; either version 2, or (at your option)
Jim Blandy's avatar
Jim Blandy committed
9 10 11 12 13 14 15 16 17
any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
18 19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */
Jim Blandy's avatar
Jim Blandy committed
20

21 22
extern void init_signals P_ ((void));

23 24 25 26 27
#ifdef HAVE_GTK_AND_PTHREAD
#include <pthread.h>
extern pthread_t main_thread;
#endif

Jim Blandy's avatar
Jim Blandy committed
28
#ifdef POSIX_SIGNALS
29

Karl Heuer's avatar
Karl Heuer committed
30
/* Don't #include <signal.h>.  That header should always be #included
31 32 33 34
   before "config.h", because some configuration files (like s/hpux.h)
   indicate that SIGIO doesn't work by #undef-ing SIGIO.  If this file
   #includes <signal.h>, then that will re-#define SIGIO and confuse
   things.  */
35

Jim Blandy's avatar
Jim Blandy committed
36 37 38 39
#define SIGMASKTYPE sigset_t

#define SIGEMPTYMASK (empty_mask)
#define SIGFULLMASK (full_mask)
40
extern sigset_t empty_mask, full_mask;
Jim Blandy's avatar
Jim Blandy committed
41

Jim Blandy's avatar
Jim Blandy committed
42
/* POSIX pretty much destroys any possibility of writing sigmask as a
43 44 45 46
   macro in standard C.  We always define our own version because the
   predefined macro in Glibc 2.1 is only provided for compatility for old
   programs that use int as signal mask type.  */
#undef sigmask
Jim Blandy's avatar
Jim Blandy committed
47 48 49 50 51 52 53 54
#ifdef __GNUC__
#define sigmask(SIG) 				\
  ({						\
    sigset_t _mask;				\
    sigemptyset (&_mask);			\
    sigaddset (&_mask, SIG);			\
    _mask;					\
  })
55
#else /* ! defined (__GNUC__) */
56
extern sigset_t sys_sigmask ();
Jim Blandy's avatar
Jim Blandy committed
57
#define sigmask(SIG) (sys_sigmask (SIG))
58
#endif /* ! defined (__GNUC__) */
Jim Blandy's avatar
Jim Blandy committed
59

60 61
#undef sigpause
#define sigpause(MASK)    sigsuspend (&(MASK))
62

63 64
#define sigblock(SIG)    sys_sigblock (SIG)
#define sigunblock(SIG)  sys_sigunblock (SIG)
65
#ifndef sigsetmask
66
#define sigsetmask(SIG)  sys_sigsetmask (SIG)
67
#endif
Jim Blandy's avatar
Jim Blandy committed
68 69
#define sighold(SIG)     ONLY_USED_IN_BSD_4_1
#define sigrelse(SIG)    ONLY_USED_IN_BSD_4_1
70
#undef signal
71
#define signal(SIG,ACT)      sys_signal(SIG,ACT)
Jim Blandy's avatar
Jim Blandy committed
72

73
/* Whether this is what all systems want or not, this is what
74
   appears to be assumed in the source, for example data.c:arith_error.  */
Karl Heuer's avatar
Karl Heuer committed
75
typedef RETSIGTYPE (*signal_handler_t) (/*int*/);
76

77 78 79 80
signal_handler_t sys_signal P_ ((int signal_number, signal_handler_t action));
sigset_t sys_sigblock   P_ ((sigset_t new_mask));
sigset_t sys_sigunblock P_ ((sigset_t new_mask));
sigset_t sys_sigsetmask P_ ((sigset_t new_mask));
Jim Blandy's avatar
Jim Blandy committed
81

82
#define sys_sigdel(MASK,SIG) sigdelset (&MASK,SIG)
Jim Blandy's avatar
Jim Blandy committed
83

84 85 86
#else /* ! defined (POSIX_SIGNALS) */
#ifdef USG5_4

87 88
extern SIGMASKTYPE sigprocmask_set;

89
#ifndef sigblock
90 91 92
#define sigblock(sig)					\
     (sigprocmask_set = SIGEMPTYMASK | (sig),		\
      sigprocmask (SIG_BLOCK, &sigprocmask_set, NULL))
93 94
#endif

95
#ifndef sigunblock
96 97 98
#define sigunblock(sig)						\
     (sigprocmask_set = SIGFULLMASK & ~(sig),			\
      sigprocmask (SIG_SETMASK, &sigprocmask_set, NULL))
99
#endif
100 101 102 103

#else
#ifdef USG

104
#ifndef sigunblock
105
#define sigunblock(sig)
106
#endif
107 108

#else
Jim Blandy's avatar
Jim Blandy committed
109

110
#ifndef sigunblock
Jim Blandy's avatar
Jim Blandy committed
111 112
#define sigunblock(SIG) \
{ SIGMASKTYPE omask = sigblock (SIGEMPTYMASK); sigsetmask (omask & ~SIG); }
113
#endif
Jim Blandy's avatar
Jim Blandy committed
114

115 116 117
#endif /* ! defined (USG) */
#endif /* ! defined (USG5_4) */
#endif /* ! defined (POSIX_SIGNALS) */
Jim Blandy's avatar
Jim Blandy committed
118 119 120 121 122 123

#ifndef SIGMASKTYPE
#define SIGMASKTYPE int
#endif

#ifndef SIGEMPTYMASK
Jim Blandy's avatar
Jim Blandy committed
124 125 126 127 128
#define SIGEMPTYMASK (0)
#endif

#ifndef SIGFULLMASK
#define SIGFULLMASK (0xffffffff)
Jim Blandy's avatar
Jim Blandy committed
129 130 131 132 133 134
#endif

#ifndef sigmask
#define sigmask(no) (1L << ((no) - 1))
#endif

Jim Blandy's avatar
Jim Blandy committed
135 136 137 138 139 140 141
#ifndef sigunblock
#define sigunblock(SIG) \
{ SIGMASKTYPE omask = sigblock (SIGFULLMASK); sigsetmask (omask & ~SIG); }
#endif

#ifndef BSD4_1
#define sigfree() sigsetmask (SIGEMPTYMASK)
Richard M. Stallman's avatar
Richard M. Stallman committed
142
#endif /* not BSD4_1 */
Jim Blandy's avatar
Jim Blandy committed
143

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
#if defined (SIGINFO) && defined (BROKEN_SIGINFO)
#undef SIGINFO
#endif
#if defined (SIGIO) && defined (BROKEN_SIGIO)
#undef SIGIO
#endif
#if defined (SIGPOLL) && defined (BROKEN_SIGPOLL)
#undef SIGPOLL
#endif
#if defined (SIGTSTP) && defined (BROKEN_SIGTSTP)
#undef SIGTSTP
#endif
#if defined (SIGURG) && defined (BROKEN_SIGURG)
#undef SIGURG
#endif
159 160 161 162 163 164 165
#if defined (SIGAIO) && defined (BROKEN_SIGAIO)
#undef SIGAIO
#endif
#if defined (SIGPTY) && defined (BROKEN_SIGPTY)
#undef SIGPTY
#endif

166 167 168 169 170 171 172 173

#if NSIG < NSIG_MINIMUM
# ifdef NSIG
#  undef NSIG
# endif
# define NSIG NSIG_MINIMUM
#endif

Jim Blandy's avatar
Jim Blandy committed
174 175
#ifdef BSD4_1
#define SIGIO SIGTINT
176
/* sigfree is in sysdep.c */
Richard M. Stallman's avatar
Richard M. Stallman committed
177
#endif /* BSD4_1 */
Jim Blandy's avatar
Jim Blandy committed
178 179 180

/* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
   Must do that using the killpg call.  */
181
#ifdef BSD_SYSTEM
Jim Blandy's avatar
Jim Blandy committed
182 183
#define EMACS_KILLPG(gid, signo) (killpg ( (gid), (signo)))
#else
184
#ifdef WINDOWSNT
185
#define EMACS_KILLPG(gid, signo) (kill (gid, signo))
186
#else
Jim Blandy's avatar
Jim Blandy committed
187 188
#define EMACS_KILLPG(gid, signo) (kill   (-(gid), (signo)))
#endif
189
#endif
Jim Blandy's avatar
Jim Blandy committed
190 191 192 193 194 195 196

/* Define SIGCHLD as an alias for SIGCLD.  There are many conditionals
   testing SIGCHLD.  */
#ifndef VMS
#ifdef SIGCLD
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
197 198 199
#endif /* SIGCHLD */
#endif /* ! defined (SIGCLD) */
#endif /* VMS */
200 201 202 203 204

#ifndef HAVE_STRSIGNAL
/* strsignal is in sysdep.c */
char *strsignal ();
#endif
Miles Bader's avatar
Miles Bader committed
205

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
#ifdef HAVE_GTK_AND_PTHREAD
#define SIGNAL_THREAD_CHECK(signo)                                      \
  do {                                                                  \
    if (pthread_self () != main_thread)                                 \
      {                                                                 \
        /* POSIX says any thread can receive the signal.  On GNU/Linux  \
           that is not true, but for other systems (FreeBSD at least)   \
           it is.  So direct the signal to the correct thread and block \
           it from this thread.  */                                     \
        sigset_t new_mask;                                              \
                                                                        \
        sigemptyset (&new_mask);                                        \
        sigaddset (&new_mask, signo);                                   \
        pthread_sigmask (SIG_BLOCK, &new_mask, 0);                      \
        pthread_kill (main_thread, signo);                              \
        return;                                                         \
      }                                                                 \
   } while (0)

#else /* not HAVE_GTK_AND_PTHREAD */
#define SIGNAL_THREAD_CHECK(signo)
#endif /* not HAVE_GTK_AND_PTHREAD */
Miles Bader's avatar
Miles Bader committed
228 229
/* arch-tag: 4580e86a-340d-4574-9e11-a742b6e1a152
   (do not change this comment) */