signal.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /* Copyright (C) 1991-2003, 2004, 2007, 2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.14 Signal handling <signal.h>
  16. */
  17. #ifndef _SIGNAL_H
  18. #if !defined __need_sig_atomic_t && !defined __need_sigset_t
  19. # define _SIGNAL_H
  20. #endif
  21. #include <features.h>
  22. __BEGIN_DECLS
  23. #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */
  24. /* An integral type that can be modified atomically, without the
  25. possibility of a signal arriving in the middle of the operation. */
  26. #if defined __need_sig_atomic_t || defined _SIGNAL_H
  27. # ifndef __sig_atomic_t_defined
  28. # define __sig_atomic_t_defined
  29. __BEGIN_NAMESPACE_STD
  30. typedef __sig_atomic_t sig_atomic_t;
  31. __END_NAMESPACE_STD
  32. # endif
  33. # undef __need_sig_atomic_t
  34. #endif
  35. #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
  36. # ifndef __sigset_t_defined
  37. # define __sigset_t_defined
  38. typedef __sigset_t sigset_t;
  39. # endif
  40. # undef __need_sigset_t
  41. #endif
  42. #ifdef _SIGNAL_H
  43. #include <bits/types.h>
  44. #include <bits/signum.h>
  45. /* Fake signal functions. */
  46. #define SIG_ERR ((__sighandler_t) -1) /* Error return. */
  47. #define SIG_DFL ((__sighandler_t) 0) /* Default action. */
  48. #define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
  49. #ifdef __USE_UNIX98
  50. # define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
  51. #endif
  52. /* Biggest signal number + 1 (including real-time signals). */
  53. #ifndef _NSIG /* if arch has not defined it in bits/signum.h... */
  54. # define _NSIG 65
  55. #endif
  56. #ifdef __USE_MISC
  57. # define NSIG _NSIG
  58. #endif
  59. /* Real-time signal range */
  60. #define SIGRTMIN (__libc_current_sigrtmin())
  61. #define SIGRTMAX (__libc_current_sigrtmax())
  62. /* These are the hard limits of the kernel. These values should not be
  63. used directly at user level. */
  64. #ifndef __SIGRTMIN /* if arch has not defined it in bits/signum.h... */
  65. # define __SIGRTMIN 32
  66. #endif
  67. #define __SIGRTMAX (_NSIG - 1)
  68. #if defined __USE_XOPEN || defined __USE_XOPEN2K
  69. # ifndef __pid_t_defined
  70. typedef __pid_t pid_t;
  71. # define __pid_t_defined
  72. # endif
  73. #endif
  74. #ifdef __USE_XOPEN
  75. # ifndef __uid_t_defined
  76. typedef __uid_t uid_t;
  77. # define __uid_t_defined
  78. # endif
  79. #endif /* Unix98 */
  80. #if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
  81. /* We need `struct timespec' later on. */
  82. # define __need_timespec
  83. # include <time.h>
  84. #endif
  85. #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
  86. /* Get the `siginfo_t' type plus the needed symbols. */
  87. # include <bits/siginfo.h>
  88. #endif
  89. /* Type of a signal handler. */
  90. typedef void (*__sighandler_t) (int);
  91. #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
  92. /* The X/Open definition of `signal' specifies the SVID semantic. Use
  93. the additional function `sysv_signal' when X/Open compatibility is
  94. requested. */
  95. extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
  96. __THROW;
  97. # ifdef __USE_GNU
  98. extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
  99. __THROW;
  100. # endif
  101. #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */
  102. /* Set the handler for the signal SIG to HANDLER, returning the old
  103. handler, or SIG_ERR on error.
  104. By default `signal' has the BSD semantic. */
  105. __BEGIN_NAMESPACE_STD
  106. #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
  107. extern __sighandler_t signal (int __sig, __sighandler_t __handler)
  108. __THROW;
  109. libc_hidden_proto(signal)
  110. #else
  111. /* Make sure the used `signal' implementation is the SVID version. */
  112. # ifdef __REDIRECT_NTH
  113. extern __sighandler_t __REDIRECT_NTH (signal,
  114. (int __sig, __sighandler_t __handler),
  115. __sysv_signal);
  116. # else
  117. # define signal __sysv_signal
  118. # endif
  119. #endif
  120. __END_NAMESPACE_STD
  121. #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__
  122. /* The X/Open definition of `signal' conflicts with the BSD version.
  123. So they defined another function `bsd_signal'. */
  124. extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
  125. __THROW;
  126. #endif
  127. /* Send signal SIG to process number PID. If PID is zero,
  128. send SIG to all processes in the current process's process group.
  129. If PID is < -1, send SIG to all processes in process group - PID. */
  130. #ifdef __USE_POSIX
  131. extern int kill (__pid_t __pid, int __sig) __THROW;
  132. libc_hidden_proto(kill)
  133. #endif
  134. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  135. /* Send SIG to all processes in process group PGRP.
  136. If PGRP is zero, send SIG to all processes in
  137. the current process's process group. */
  138. extern int killpg (__pid_t __pgrp, int __sig) __THROW;
  139. #endif
  140. __BEGIN_NAMESPACE_STD
  141. /* Raise signal SIG, i.e., send SIG to yourself. */
  142. extern int raise (int __sig) __THROW;
  143. libc_hidden_proto(raise)
  144. __END_NAMESPACE_STD
  145. #if 0 /*def __USE_SVID*/
  146. /* SVID names for the same things. */
  147. extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
  148. __THROW;
  149. extern int gsignal (int __sig) __THROW;
  150. #endif /* Use SVID. */
  151. /* glibc guards the next two wrong with __USE_XOPEN2K */
  152. #if defined __USE_MISC || defined __USE_XOPEN2K8
  153. /* Print a message describing the meaning of the given signal number. */
  154. extern void psignal (int __sig, const char *__s);
  155. #endif /* Use misc or POSIX 2008. */
  156. #if 0 /*def __USE_XOPEN2K8*/
  157. /* Print a message describing the meaning of the given signal information. */
  158. extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
  159. #endif /* POSIX 2008. */
  160. #ifdef __UCLIBC_SUSV4_LEGACY__
  161. /* The `sigpause' function has two different interfaces. The original
  162. BSD definition defines the argument as a mask of the signal, while
  163. the more modern interface in X/Open defines it as the signal
  164. number. We go with the BSD version unless the user explicitly
  165. selects the X/Open version.
  166. This function is a cancellation point and therefore not marked with
  167. __THROW. */
  168. /*extern int __sigpause (int __sig_or_mask, int __is_sig);*/
  169. #ifdef __FAVOR_BSD
  170. /* Set the mask of blocked signals to MASK,
  171. wait for a signal to arrive, and then restore the mask. */
  172. /*extern int sigpause (int __mask) __THROW __attribute_deprecated__;
  173. # define sigpause(mask) __sigpause ((mask), 0)*/
  174. /* uClibc note: BSD sigpause is available as __bsd_sigpause.
  175. * It is intentionally not prototyped */
  176. #else
  177. # ifdef __USE_XOPEN
  178. /* Remove a signal from the signal mask and suspend the process. */
  179. extern int sigpause(int __sig);
  180. /*# define sigpause(sig) __sigpause ((sig), 1)*/
  181. # endif
  182. #endif
  183. #endif /* __UCLIBC_SUSV4_LEGACY__ */
  184. #if 0 /*def __USE_BSD*/
  185. /* None of the following functions should be used anymore. They are here
  186. only for compatibility. A single word (`int') is not guaranteed to be
  187. enough to hold a complete signal mask and therefore these functions
  188. simply do not work in many situations. Use `sigprocmask' instead. */
  189. /* Compute mask for signal SIG. */
  190. # define sigmask(sig) __sigmask(sig)
  191. /* Block signals in MASK, returning the old mask. */
  192. extern int sigblock (int __mask) __THROW __attribute_deprecated__;
  193. /* Set the mask of blocked signals to MASK, returning the old mask. */
  194. extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
  195. /* Return currently selected signal mask. */
  196. extern int siggetmask (void) __THROW __attribute_deprecated__;
  197. #endif /* Use BSD. */
  198. #ifdef __USE_GNU
  199. typedef __sighandler_t sighandler_t;
  200. #endif
  201. /* 4.4 BSD uses the name `sig_t' for this. */
  202. #ifdef __USE_BSD
  203. typedef __sighandler_t sig_t;
  204. #endif
  205. #ifdef __USE_POSIX
  206. /* Clear all signals from SET. */
  207. extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
  208. /* Set all signals in SET. */
  209. extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
  210. /* Add SIGNO to SET. */
  211. extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  212. libc_hidden_proto(sigaddset)
  213. /* Remove SIGNO from SET. */
  214. extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
  215. libc_hidden_proto(sigdelset)
  216. /* Return 1 if SIGNO is in SET, 0 if not. */
  217. extern int sigismember (const sigset_t *__set, int __signo)
  218. __THROW __nonnull ((1));
  219. # ifdef __USE_GNU
  220. /* Return non-empty value is SET is not empty. */
  221. extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
  222. /* Build new signal set by combining the two inputs set using logical AND. */
  223. extern int sigandset (sigset_t *__set, const sigset_t *__left,
  224. const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  225. /* Build new signal set by combining the two inputs set using logical OR. */
  226. extern int sigorset (sigset_t *__set, const sigset_t *__left,
  227. const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
  228. # endif /* GNU */
  229. /* Get the system-specific definitions of `struct sigaction'
  230. and the `SA_*' and `SIG_*'. constants. */
  231. # include <bits/sigaction.h>
  232. /* Get and/or change the set of blocked signals. */
  233. extern int sigprocmask (int __how, const sigset_t *__restrict __set,
  234. sigset_t *__restrict __oset) __THROW;
  235. libc_hidden_proto(sigprocmask)
  236. /* Change the set of blocked signals to SET,
  237. wait until a signal arrives, and restore the set of blocked signals.
  238. This function is a cancellation point and therefore not marked with
  239. __THROW. */
  240. extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
  241. #ifdef _LIBC
  242. extern __typeof(sigsuspend) __sigsuspend_nocancel attribute_hidden;
  243. libc_hidden_proto(sigsuspend)
  244. #endif
  245. /* Get and/or set the action for signal SIG. */
  246. extern int sigaction (int __sig, const struct sigaction *__restrict __act,
  247. struct sigaction *__restrict __oact) __THROW;
  248. #ifdef _LIBC
  249. # if 0 /* this is in headers */
  250. /* In uclibc, userspace struct sigaction is identical to
  251. * "new" struct kernel_sigaction (one from the Linux 2.1.68 kernel).
  252. * See sigaction.h
  253. */
  254. struct old_kernel_sigaction;
  255. extern int __syscall_sigaction(int, const struct old_kernel_sigaction *,
  256. struct old_kernel_sigaction *) attribute_hidden;
  257. # else /* this is how the function is built */
  258. extern __typeof(sigaction) __syscall_sigaction attribute_hidden;
  259. # endif
  260. # define __need_size_t
  261. # include <stddef.h>
  262. /* candidate for attribute_hidden, if NPTL would behave */
  263. extern int __syscall_rt_sigaction(int, const struct sigaction *,
  264. struct sigaction *, size_t)
  265. # ifndef __UCLIBC_HAS_THREADS_NATIVE__
  266. attribute_hidden
  267. # endif
  268. ;
  269. extern __typeof(sigaction) __libc_sigaction;
  270. libc_hidden_proto(sigaction)
  271. # ifdef __mips__
  272. # define _KERNEL_NSIG_WORDS (_NSIG / _MIPS_SZLONG)
  273. typedef struct {
  274. unsigned long sig[_KERNEL_NSIG_WORDS];
  275. } kernel_sigset_t;
  276. # define __SYSCALL_SIGSET_T_SIZE (sizeof(kernel_sigset_t))
  277. # else
  278. # define __SYSCALL_SIGSET_T_SIZE (_NSIG / 8)
  279. # endif
  280. #endif
  281. /* Put in SET all signals that are blocked and waiting to be delivered. */
  282. extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
  283. /* Select any of pending signals from SET or wait for any to arrive.
  284. This function is a cancellation point and therefore not marked with
  285. __THROW. */
  286. extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
  287. __nonnull ((1, 2));
  288. # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
  289. /* Select any of pending signals from SET and place information in INFO.
  290. This function is a cancellation point and therefore not marked with
  291. __THROW. */
  292. extern int sigwaitinfo (const sigset_t *__restrict __set,
  293. siginfo_t *__restrict __info) __nonnull ((1));
  294. #ifdef _LIBC
  295. extern __typeof(sigwaitinfo) __sigwaitinfo attribute_hidden;
  296. #endif
  297. /* Select any of pending signals from SET and place information in INFO.
  298. Wait the time specified by TIMEOUT if no signal is pending.
  299. This function is a cancellation point and therefore not marked with
  300. __THROW. */
  301. extern int sigtimedwait (const sigset_t *__restrict __set,
  302. siginfo_t *__restrict __info,
  303. const struct timespec *__restrict __timeout)
  304. __nonnull ((1));
  305. #ifdef _LIBC
  306. extern __typeof(sigtimedwait) __sigtimedwait_nocancel attribute_hidden;
  307. libc_hidden_proto(sigtimedwait)
  308. #endif
  309. /* Send signal SIG to the process PID. Associate data in VAL with the
  310. signal. */
  311. extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
  312. __THROW;
  313. # endif /* Use POSIX 199306. */
  314. #endif /* Use POSIX. */
  315. #ifdef __USE_BSD
  316. # ifdef __UCLIBC_HAS_SYS_SIGLIST__
  317. /* Names of the signals. This variable exists only for compatibility.
  318. Use `strsignal' instead (see <string.h>). */
  319. # define _sys_siglist sys_siglist
  320. extern const char *const sys_siglist[_NSIG];
  321. # endif
  322. #ifndef __UCLIBC_STRICT_HEADERS__
  323. /* Structure passed to `sigvec'. */
  324. struct sigvec
  325. {
  326. __sighandler_t sv_handler; /* Signal handler. */
  327. int sv_mask; /* Mask of signals to be blocked. */
  328. int sv_flags; /* Flags (see below). */
  329. # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
  330. };
  331. /* Bits in `sv_flags'. */
  332. # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
  333. # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
  334. # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
  335. #endif
  336. #if 0
  337. /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
  338. of VEC. The signals in `sv_mask' will be blocked while the handler runs.
  339. If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
  340. reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
  341. it is filled in with the old information for SIG. */
  342. extern int sigvec (int __sig, const struct sigvec *__vec,
  343. struct sigvec *__ovec) __THROW;
  344. #endif
  345. /* Get machine-dependent `struct sigcontext' and signal subcodes. */
  346. # include <bits/sigcontext.h>
  347. #if 0
  348. /* Restore the state saved in SCP. */
  349. extern int sigreturn (struct sigcontext *__scp) __THROW;
  350. #endif
  351. #endif /* use BSD. */
  352. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  353. # define __need_size_t
  354. # include <stddef.h>
  355. # ifdef __UCLIBC_SUSV4_LEGACY__
  356. /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
  357. (causing them to fail with EINTR); if INTERRUPT is zero, make system
  358. calls be restarted after signal SIG. */
  359. extern int siginterrupt (int __sig, int __interrupt) __THROW;
  360. # endif
  361. # include <bits/sigstack.h>
  362. # ifdef __USE_XOPEN
  363. /* This will define `ucontext_t' and `mcontext_t'. */
  364. /* SuSv4 obsoleted include/ucontext.h */
  365. # include <sys/ucontext.h>
  366. # endif
  367. # if 0
  368. /* Run signals handlers on the stack specified by SS (if not NULL).
  369. If OSS is not NULL, it is filled in with the old signal stack status.
  370. This interface is obsolete and on many platform not implemented. */
  371. extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
  372. __THROW __attribute_deprecated__;
  373. # endif
  374. /* Alternate signal handler stack interface.
  375. This interface should always be preferred over `sigstack'. */
  376. extern int sigaltstack (const struct sigaltstack *__restrict __ss,
  377. struct sigaltstack *__restrict __oss) __THROW;
  378. #endif /* use BSD or X/Open Unix. */
  379. #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__
  380. /* Simplified interface for signal management. */
  381. /* Add SIG to the calling process' signal mask. */
  382. extern int sighold (int __sig) __THROW;
  383. /* Remove SIG from the calling process' signal mask. */
  384. extern int sigrelse (int __sig) __THROW;
  385. /* Set the disposition of SIG to SIG_IGN. */
  386. extern int sigignore (int __sig) __THROW;
  387. /* Set the disposition of SIG. */
  388. extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
  389. #endif
  390. #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
  391. /* Some of the functions for handling signals in threaded programs must
  392. be defined here. */
  393. # include <bits/pthreadtypes.h>
  394. # include <bits/sigthread.h>
  395. #endif
  396. /* The following functions are used internally in the C library and in
  397. other code which need deep insights. */
  398. /* Return number of available real-time signal with highest priority. */
  399. extern int __libc_current_sigrtmin (void) __THROW;
  400. /* Return number of available real-time signal with lowest priority. */
  401. extern int __libc_current_sigrtmax (void) __THROW;
  402. #ifdef _LIBC
  403. extern sigset_t _sigintr attribute_hidden;
  404. /* simplified version without parameter checking */
  405. # include <string.h>
  406. # undef __sigemptyset
  407. # define __sigemptyset(ss) (memset(ss, '\0', sizeof(sigset_t)), 0)
  408. #endif
  409. #endif /* signal.h */
  410. __END_DECLS
  411. #endif /* not signal.h */