signal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* sys/signal.h */
  2. #ifndef _SYS_SIGNAL_H
  3. #define _SYS_SIGNAL_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "_ansi.h"
  8. #include <sys/features.h>
  9. #include <sys/types.h>
  10. /* #ifndef __STRICT_ANSI__*/
  11. /* Cygwin defines it's own sigset_t in include/cygwin/signal.h */
  12. #ifndef __CYGWIN__
  13. typedef unsigned long sigset_t;
  14. #endif
  15. #if defined(__rtems__)
  16. #if defined(_POSIX_REALTIME_SIGNALS)
  17. /* sigev_notify values
  18. NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
  19. #define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */
  20. /* when the event of interest occurs. */
  21. #define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */
  22. /* value, shall be delivered when the event of */
  23. /* interest occurs. */
  24. #define SIGEV_THREAD 3 /* A notification function shall be called to */
  25. /* perform notification. */
  26. /* Signal Generation and Delivery, P1003.1b-1993, p. 63
  27. NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
  28. sigev_notify_attributes to the sigevent structure. */
  29. union sigval {
  30. int sival_int; /* Integer signal value */
  31. void *sival_ptr; /* Pointer signal value */
  32. };
  33. struct sigevent {
  34. int sigev_notify; /* Notification type */
  35. int sigev_signo; /* Signal number */
  36. union sigval sigev_value; /* Signal value */
  37. #if defined(_POSIX_THREADS)
  38. void (*sigev_notify_function)( union sigval );
  39. /* Notification function */
  40. pthread_attr_t *sigev_notify_attributes; /* Notification Attributes */
  41. #endif
  42. };
  43. /* Signal Actions, P1003.1b-1993, p. 64 */
  44. /* si_code values, p. 66 */
  45. #define SI_USER 1 /* Sent by a user. kill(), abort(), etc */
  46. #define SI_QUEUE 2 /* Sent by sigqueue() */
  47. #define SI_TIMER 3 /* Sent by expiration of a timer_settime() timer */
  48. #define SI_ASYNCIO 4 /* Indicates completion of asycnhronous IO */
  49. #define SI_MESGQ 5 /* Indicates arrival of a message at an empty queue */
  50. typedef struct {
  51. int si_signo; /* Signal number */
  52. int si_code; /* Cause of the signal */
  53. union sigval si_value; /* Signal value */
  54. } siginfo_t;
  55. #endif
  56. /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */
  57. #define SA_NOCLDSTOP 0x1 /* Do not generate SIGCHLD when children stop */
  58. #define SA_SIGINFO 0x2 /* Invoke the signal catching function with */
  59. /* three arguments instead of one. */
  60. #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
  61. #define SA_ONSTACK 0x4 /* Signal delivery will be on a separate stack. */
  62. #endif
  63. /* struct sigaction notes from POSIX:
  64. *
  65. * (1) Routines stored in sa_handler should take a single int as
  66. * their argument although the POSIX standard does not require this.
  67. * This is not longer true since at least POSIX.1-2008
  68. * (2) The fields sa_handler and sa_sigaction may overlap, and a conforming
  69. * application should not use both simultaneously.
  70. */
  71. typedef void (*_sig_func_ptr)(int);
  72. struct sigaction {
  73. int sa_flags; /* Special flags to affect behavior of signal */
  74. sigset_t sa_mask; /* Additional set of signals to be blocked */
  75. /* during execution of signal-catching */
  76. /* function. */
  77. union {
  78. _sig_func_ptr _handler; /* SIG_DFL, SIG_IGN, or pointer to a function */
  79. #if defined(_POSIX_REALTIME_SIGNALS)
  80. void (*_sigaction)( int, siginfo_t *, void * );
  81. #endif
  82. } _signal_handlers;
  83. };
  84. #define sa_handler _signal_handlers._handler
  85. #if defined(_POSIX_REALTIME_SIGNALS)
  86. #define sa_sigaction _signal_handlers._sigaction
  87. #endif
  88. #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
  89. /*
  90. * Minimum and default signal stack constants. Allow for target overrides
  91. * from <sys/features.h>.
  92. */
  93. #ifndef MINSIGSTKSZ
  94. #define MINSIGSTKSZ 2048
  95. #endif
  96. #ifndef SIGSTKSZ
  97. #define SIGSTKSZ 8192
  98. #endif
  99. /*
  100. * Possible values for ss_flags in stack_t below.
  101. */
  102. #define SS_ONSTACK 0x1
  103. #define SS_DISABLE 0x2
  104. /*
  105. * Structure used in sigaltstack call.
  106. */
  107. typedef struct sigaltstack {
  108. void *ss_sp; /* Stack base or pointer. */
  109. int ss_flags; /* Flags. */
  110. size_t ss_size; /* Stack size. */
  111. } stack_t;
  112. #endif
  113. #elif defined(__CYGWIN__)
  114. #include <cygwin/signal.h>
  115. #else
  116. #define SA_NOCLDSTOP 1 /* only value supported now for sa_flags */
  117. typedef void (*_sig_func_ptr)(int);
  118. struct sigaction
  119. {
  120. _sig_func_ptr sa_handler;
  121. sigset_t sa_mask;
  122. int sa_flags;
  123. };
  124. #endif /* defined(__rtems__) */
  125. #define SIG_SETMASK 0 /* set mask with sigprocmask() */
  126. #define SIG_BLOCK 1 /* set of signals to block */
  127. #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
  128. /* These depend upon the type of sigset_t, which right now
  129. is always a long.. They're in the POSIX namespace, but
  130. are not ANSI. */
  131. #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
  132. #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
  133. #define sigemptyset(what) (*(what) = 0, 0)
  134. #define sigfillset(what) (*(what) = ~(0), 0)
  135. #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
  136. int _EXFUN(sigprocmask, (int how, const sigset_t *set, sigset_t *oset));
  137. #if defined(_POSIX_THREADS)
  138. int _EXFUN(pthread_sigmask, (int how, const sigset_t *set, sigset_t *oset));
  139. #endif
  140. #if defined(__CYGWIN__) || defined(__rtems__)
  141. #undef sigaddset
  142. #undef sigdelset
  143. #undef sigemptyset
  144. #undef sigfillset
  145. #undef sigismember
  146. #ifdef _COMPILING_NEWLIB
  147. int _EXFUN(_kill, (pid_t, int));
  148. #endif /* _COMPILING_NEWLIB */
  149. #endif /* __CYGWIN__ || __rtems__ */
  150. #if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__)
  151. int _EXFUN(kill, (pid_t, int));
  152. #endif /* __CYGWIN__ || __rtems__ || __SPU__ */
  153. #if defined(__CYGWIN__) || defined(__rtems__)
  154. int _EXFUN(killpg, (pid_t, int));
  155. int _EXFUN(sigaction, (int, const struct sigaction *, struct sigaction *));
  156. int _EXFUN(sigaddset, (sigset_t *, const int));
  157. int _EXFUN(sigdelset, (sigset_t *, const int));
  158. int _EXFUN(sigismember, (const sigset_t *, int));
  159. int _EXFUN(sigfillset, (sigset_t *));
  160. int _EXFUN(sigemptyset, (sigset_t *));
  161. int _EXFUN(sigpending, (sigset_t *));
  162. int _EXFUN(sigsuspend, (const sigset_t *));
  163. int _EXFUN(sigpause, (int));
  164. #ifdef __rtems__
  165. #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
  166. int _EXFUN(sigaltstack, (const stack_t *__restrict, stack_t *__restrict));
  167. #endif
  168. #endif
  169. #if defined(_POSIX_THREADS)
  170. #ifdef __CYGWIN__
  171. # ifndef _CYGWIN_TYPES_H
  172. # error You need the winsup sources or a cygwin installation to compile the cygwin version of newlib.
  173. # endif
  174. #endif
  175. int _EXFUN(pthread_kill, (pthread_t thread, int sig));
  176. #endif
  177. #if defined(_POSIX_REALTIME_SIGNALS)
  178. /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
  179. NOTE: P1003.1c/D10, p. 39 adds sigwait(). */
  180. int _EXFUN(sigwaitinfo, (const sigset_t *set, siginfo_t *info));
  181. int _EXFUN(sigtimedwait,
  182. (const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
  183. );
  184. int _EXFUN(sigwait, (const sigset_t *set, int *sig));
  185. /* 3.3.9 Queue a Signal to a Process, P1003.1b-1993, p. 78 */
  186. int _EXFUN(sigqueue, (pid_t pid, int signo, const union sigval value));
  187. #endif /* defined(_POSIX_REALTIME_SIGNALS) */
  188. #endif /* defined(__CYGWIN__) || defined(__rtems__) */
  189. /* #endif __STRICT_ANSI__ */
  190. #if defined(___AM29K__)
  191. /* These all need to be defined for ANSI C, but I don't think they are
  192. meaningful. */
  193. #define SIGABRT 1
  194. #define SIGFPE 1
  195. #define SIGILL 1
  196. #define SIGINT 1
  197. #define SIGSEGV 1
  198. #define SIGTERM 1
  199. /* These need to be defined for POSIX, and some others do too. */
  200. #define SIGHUP 1
  201. #define SIGQUIT 1
  202. #define NSIG 2
  203. #elif defined(__GO32__)
  204. #define SIGINT 1
  205. #define SIGKILL 2
  206. #define SIGPIPE 3
  207. #define SIGFPE 4
  208. #define SIGHUP 5
  209. #define SIGTERM 6
  210. #define SIGSEGV 7
  211. #define SIGTSTP 8
  212. #define SIGQUIT 9
  213. #define SIGTRAP 10
  214. #define SIGILL 11
  215. #define SIGEMT 12
  216. #define SIGALRM 13
  217. #define SIGBUS 14
  218. #define SIGLOST 15
  219. #define SIGSTOP 16
  220. #define SIGABRT 17
  221. #define SIGUSR1 18
  222. #define SIGUSR2 19
  223. #define NSIG 20
  224. #elif !defined(SIGTRAP)
  225. #define SIGHUP 1 /* hangup */
  226. #define SIGINT 2 /* interrupt */
  227. #define SIGQUIT 3 /* quit */
  228. #define SIGILL 4 /* illegal instruction (not reset when caught) */
  229. #define SIGTRAP 5 /* trace trap (not reset when caught) */
  230. #define SIGIOT 6 /* IOT instruction */
  231. #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
  232. #define SIGEMT 7 /* EMT instruction */
  233. #define SIGFPE 8 /* floating point exception */
  234. #define SIGKILL 9 /* kill (cannot be caught or ignored) */
  235. #define SIGBUS 10 /* bus error */
  236. #define SIGSEGV 11 /* segmentation violation */
  237. #define SIGSYS 12 /* bad argument to system call */
  238. #define SIGPIPE 13 /* write on a pipe with no one to read it */
  239. #define SIGALRM 14 /* alarm clock */
  240. #define SIGTERM 15 /* software termination signal from kill */
  241. #if defined(__rtems__)
  242. #define SIGURG 16 /* urgent condition on IO channel */
  243. #define SIGSTOP 17 /* sendable stop signal not from tty */
  244. #define SIGTSTP 18 /* stop signal from tty */
  245. #define SIGCONT 19 /* continue a stopped process */
  246. #define SIGCHLD 20 /* to parent on child stop or exit */
  247. #define SIGCLD 20 /* System V name for SIGCHLD */
  248. #define SIGTTIN 21 /* to readers pgrp upon background tty read */
  249. #define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
  250. #define SIGIO 23 /* input/output possible signal */
  251. #define SIGPOLL SIGIO /* System V name for SIGIO */
  252. #define SIGWINCH 24 /* window changed */
  253. #define SIGUSR1 25 /* user defined signal 1 */
  254. #define SIGUSR2 26 /* user defined signal 2 */
  255. /* Real-Time Signals Range, P1003.1b-1993, p. 61
  256. NOTE: By P1003.1b-1993, this should be at least RTSIG_MAX
  257. (which is a minimum of 8) signals.
  258. */
  259. #define SIGRTMIN 27
  260. #define SIGRTMAX 31
  261. #define __SIGFIRSTNOTRT SIGHUP
  262. #define __SIGLASTNOTRT SIGUSR2
  263. #define NSIG 32 /* signal 0 implied */
  264. #elif defined(__svr4__)
  265. /* svr4 specifics. different signals above 15, and sigaction. */
  266. #define SIGUSR1 16
  267. #define SIGUSR2 17
  268. #define SIGCLD 18
  269. #define SIGPWR 19
  270. #define SIGWINCH 20
  271. #define SIGPOLL 22 /* 20 for x.out binaries!!!! */
  272. #define SIGSTOP 23 /* sendable stop signal not from tty */
  273. #define SIGTSTP 24 /* stop signal from tty */
  274. #define SIGCONT 25 /* continue a stopped process */
  275. #define SIGTTIN 26 /* to readers pgrp upon background tty read */
  276. #define SIGTTOU 27 /* like TTIN for output if (tp->t_local&LTOSTOP) */
  277. #define NSIG 28
  278. #else
  279. #define SIGURG 16 /* urgent condition on IO channel */
  280. #define SIGSTOP 17 /* sendable stop signal not from tty */
  281. #define SIGTSTP 18 /* stop signal from tty */
  282. #define SIGCONT 19 /* continue a stopped process */
  283. #define SIGCHLD 20 /* to parent on child stop or exit */
  284. #define SIGCLD 20 /* System V name for SIGCHLD */
  285. #define SIGTTIN 21 /* to readers pgrp upon background tty read */
  286. #define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
  287. #define SIGIO 23 /* input/output possible signal */
  288. #define SIGPOLL SIGIO /* System V name for SIGIO */
  289. #define SIGXCPU 24 /* exceeded CPU time limit */
  290. #define SIGXFSZ 25 /* exceeded file size limit */
  291. #define SIGVTALRM 26 /* virtual time alarm */
  292. #define SIGPROF 27 /* profiling time alarm */
  293. #define SIGWINCH 28 /* window changed */
  294. #define SIGLOST 29 /* resource lost (eg, record-lock lost) */
  295. #define SIGUSR1 30 /* user defined signal 1 */
  296. #define SIGUSR2 31 /* user defined signal 2 */
  297. #define NSIG 32 /* signal 0 implied */
  298. #endif
  299. #endif
  300. #ifdef __cplusplus
  301. }
  302. #endif
  303. #ifndef _SIGNAL_H_
  304. /* Some applications take advantage of the fact that <sys/signal.h>
  305. * and <signal.h> are equivalent in glibc. Allow for that here. */
  306. #include <signal.h>
  307. #endif
  308. #endif /* _SYS_SIGNAL_H */