sigset.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* __sig_atomic_t, __sigset_t, and related definitions. Linux version.
  2. Copyright (C) 1991, 1992, 1994, 1996, 1997 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _SIGSET_H_types
  17. # define _SIGSET_H_types 1
  18. typedef int __sig_atomic_t;
  19. /* A 'sigset_t' has a bit for each signal.
  20. * glibc has space for 1024 signals (!), but most arches supported
  21. * by Linux have 64 signals, and only MIPS has 128.
  22. * There seems to be some historical baggage in sparc[64]
  23. * where they might have (or had in the past) 32 signals only,
  24. * I hope it's irrelevant now.
  25. * Signal 0 does not exist, so we have signals 1..64, not 0..63.
  26. * In uclibc, kernel and userspace sigset_t is always the same.
  27. * BTW, struct sigaction is also the same on kernel and userspace side.
  28. */
  29. #if defined(__mips__)
  30. # define _SIGSET_NWORDS (128 / (8 * sizeof (unsigned long)))
  31. #else
  32. # define _SIGSET_NWORDS (64 / (8 * sizeof (unsigned long)))
  33. #endif
  34. typedef struct {
  35. unsigned long __val[_SIGSET_NWORDS];
  36. } __sigset_t;
  37. #endif
  38. /* We only want to define these functions if <signal.h> was actually
  39. included; otherwise we were included just to define the types. Since we
  40. are namespace-clean, it wouldn't hurt to define extra macros. But
  41. trouble can be caused by functions being defined (e.g., any global
  42. register vars declared later will cause compilation errors). */
  43. #if !defined _SIGSET_H_fns && defined _SIGNAL_H
  44. # define _SIGSET_H_fns 1
  45. # ifndef _EXTERN_INLINE
  46. # define _EXTERN_INLINE extern __inline
  47. # endif
  48. /* Return a mask that includes the bit for SIG only. */
  49. /* Unsigned cast ensures shift/mask insns are used. */
  50. # define __sigmask(sig) \
  51. (((unsigned long) 1) << ((unsigned)((sig) - 1) % (8 * sizeof (unsigned long))))
  52. /* Return the word index for SIG. */
  53. # define __sigword(sig) ((unsigned)((sig) - 1) / (8 * sizeof (unsigned long)))
  54. /* gcc 4.3.1 is not clever enough to optimize for _SIGSET_NWORDS == 1 and 2,
  55. * which are about the only values which can be there */
  56. # if defined __GNUC__ && __GNUC__ >= 2
  57. # define __sigemptyset(set) \
  58. (__extension__ ({ \
  59. sigset_t *__set = (set); \
  60. if (_SIGSET_NWORDS <= 2) { \
  61. __set->__val[0] = 0; \
  62. if (_SIGSET_NWORDS == 2) \
  63. __set->__val[1] = 0; \
  64. } else { \
  65. int __cnt = _SIGSET_NWORDS; \
  66. while (--__cnt >= 0) __set->__val[__cnt] = 0; \
  67. } \
  68. 0; \
  69. }))
  70. # define __sigfillset(set) \
  71. (__extension__ ({ \
  72. sigset_t *__set = (set); \
  73. if (_SIGSET_NWORDS <= 2) { \
  74. __set->__val[0] = ~0UL; \
  75. if (_SIGSET_NWORDS == 2) \
  76. __set->__val[1] = ~0UL; \
  77. } else { \
  78. int __cnt = _SIGSET_NWORDS; \
  79. while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
  80. } \
  81. 0; \
  82. }))
  83. # ifdef __USE_GNU
  84. /* The POSIX does not specify for handling the whole signal set in one
  85. command. This is often wanted and so we define three more functions
  86. here. */
  87. # define __sigisemptyset(set) \
  88. (__extension__ ({ \
  89. long __ret; \
  90. const sigset_t *__set = (set); \
  91. if (_SIGSET_NWORDS == 1) { \
  92. __ret = __set->__val[0]; \
  93. } else if (_SIGSET_NWORDS == 2) { \
  94. __ret = __set->__val[0] | __set->__val[1]; \
  95. } else { \
  96. int __cnt = _SIGSET_NWORDS; \
  97. __ret = __set->__val[--__cnt]; \
  98. while (!__ret && --__cnt >= 0) \
  99. __ret = __set->__val[__cnt]; \
  100. } \
  101. __ret == 0; \
  102. }))
  103. # define __sigandset(dest, left, right) \
  104. (__extension__ ({ \
  105. sigset_t *__dest = (dest); \
  106. const sigset_t *__left = (left); \
  107. const sigset_t *__right = (right); \
  108. if (_SIGSET_NWORDS <= 2) { \
  109. __dest->__val[0] = __left->__val[0] & __right->__val[0];\
  110. if (_SIGSET_NWORDS == 2) \
  111. __dest->__val[1] = __left->__val[1] & __right->__val[1];\
  112. } else { \
  113. int __cnt = _SIGSET_NWORDS; \
  114. while (--__cnt >= 0) \
  115. __dest->__val[__cnt] = (__left->__val[__cnt] \
  116. & __right->__val[__cnt]); \
  117. } \
  118. 0; \
  119. }))
  120. # define __sigorset(dest, left, right) \
  121. (__extension__ ({ \
  122. sigset_t *__dest = (dest); \
  123. const sigset_t *__left = (left); \
  124. const sigset_t *__right = (right); \
  125. if (_SIGSET_NWORDS <= 2) { \
  126. __dest->__val[0] = __left->__val[0] | __right->__val[0];\
  127. if (_SIGSET_NWORDS == 2) \
  128. __dest->__val[1] = __left->__val[1] | __right->__val[1];\
  129. } else { \
  130. int __cnt = _SIGSET_NWORDS; \
  131. while (--__cnt >= 0) \
  132. __dest->__val[__cnt] = (__left->__val[__cnt] \
  133. | __right->__val[__cnt]); \
  134. } \
  135. 0; \
  136. }))
  137. # endif
  138. # endif
  139. /* These functions needn't check for a bogus signal number -- error
  140. checking is done in the non __ versions. */
  141. extern int __sigismember (__const __sigset_t *, int);
  142. libc_hidden_proto(__sigismember)
  143. extern int __sigaddset (__sigset_t *, int);
  144. libc_hidden_proto(__sigaddset)
  145. extern int __sigdelset (__sigset_t *, int);
  146. libc_hidden_proto(__sigdelset)
  147. # ifdef __USE_EXTERN_INLINES
  148. # define __SIGSETFN(NAME, BODY, CONST) \
  149. _EXTERN_INLINE int \
  150. NAME (CONST __sigset_t *__set, int __sig) \
  151. { \
  152. unsigned long __mask = __sigmask (__sig); \
  153. unsigned long __word = __sigword (__sig); \
  154. return BODY; \
  155. }
  156. __SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
  157. __SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
  158. __SIGSETFN (__sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  159. # undef __SIGSETFN
  160. # endif
  161. #endif /* ! _SIGSET_H_fns. */