1 /* __sigset_t manipulators. Linux version.
2 Copyright (C) 1991-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #define _SIGSETOPS_H 1
24 #include <libc-pointer-arith.h>
26 /* Return a mask that includes the bit for SIG only. */
27 #define __sigmask(sig) \
28 (1UL << (((sig) - 1) % ULONG_WIDTH))
30 /* Return the word index for SIG. */
31 static inline unsigned long int
34 return (sig
- 1) / ULONG_WIDTH
;
37 /* Linux sig* functions only handle up to __NSIG_WORDS words instead of
38 full _SIGSET_NWORDS sigset size. The signal numbers are 1-based, and
39 bit 0 of a signal mask is for signal 1. */
40 #define __NSIG_WORDS (ALIGN_UP ((_NSIG - 1), ULONG_WIDTH) / ULONG_WIDTH)
41 _Static_assert (__NSIG_WORDS
<= _SIGSET_NWORDS
,
42 "__NSIG_WORDS > _SIGSET_WORDS");
44 /* This macro is used on syscall that takes a sigset_t to specify the expected
45 size in bytes. As for glibc, kernel sigset is implemented as an array of
47 #define __NSIG_BYTES (__NSIG_WORDS * (ULONG_WIDTH / UCHAR_WIDTH))
50 __sigemptyset (sigset_t
*set
)
52 int cnt
= __NSIG_WORDS
;
58 __sigfillset (sigset_t
*set
)
60 int cnt
= __NSIG_WORDS
;
62 set
->__val
[cnt
] = ~0UL;
66 __sigisemptyset (const sigset_t
*set
)
68 int cnt
= __NSIG_WORDS
;
69 int ret
= set
->__val
[--cnt
];
70 while (ret
== 0 && --cnt
>= 0)
71 ret
= set
->__val
[cnt
];
76 __sigandset (sigset_t
*dest
, const sigset_t
*left
, const sigset_t
*right
)
78 int cnt
= __NSIG_WORDS
;
80 dest
->__val
[cnt
] = left
->__val
[cnt
] & right
->__val
[cnt
];
84 __sigorset (sigset_t
*dest
, const sigset_t
*left
, const sigset_t
*right
)
86 int cnt
= __NSIG_WORDS
;
88 dest
->__val
[cnt
] = left
->__val
[cnt
] | right
->__val
[cnt
];
92 __sigismember (const sigset_t
*set
, int sig
)
94 unsigned long int mask
= __sigmask (sig
);
95 unsigned long int word
= __sigword (sig
);
96 return set
->__val
[word
] & mask
? 1 : 0;
100 __sigaddset (sigset_t
*set
, int sig
)
102 unsigned long int mask
= __sigmask (sig
);
103 unsigned long int word
= __sigword (sig
);
104 set
->__val
[word
] |= mask
;
108 __sigdelset (sigset_t
*set
, int sig
)
110 unsigned long int mask
= __sigmask (sig
);
111 unsigned long int word
= __sigword (sig
);
112 set
->__val
[word
] &= ~mask
;
115 #endif /* bits/sigsetops.h */