Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

372 linhas
12KB

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