1 /*        $NetBSD: sigtypes.h,v 1.13 2024/05/12 10:34:56 rillig Exp $ */
2 
3 /*
4  * Copyright (c) 1982, 1986, 1989, 1991, 1993
5  *        The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *        @(#)signal.h        8.4 (Berkeley) 5/4/95
37  */
38 
39 #ifndef   _SYS_SIGTYPES_H_
40 #define   _SYS_SIGTYPES_H_
41 
42 /*
43  * This header file defines various signal-related types.  We also keep
44  * the macros to manipulate sigset_t here, to encapsulate knowledge of
45  * its internals.
46  */
47 
48 #include <sys/featuretest.h>
49 #include <machine/int_types.h>
50 #include <machine/ansi.h>
51 
52 #ifdef    _BSD_SIZE_T_
53 typedef   _BSD_SIZE_T_        size_t;
54 #undef    _BSD_SIZE_T_
55 #endif
56 
57 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
58     defined(_NETBSD_SOURCE)
59 
60 typedef struct {
61           __uint32_t          __bits[4];
62 } sigset_t;
63 
64 /*
65  * Macro for manipulating signal masks.
66  */
67 #define __sigmask(n)                    (1U << (((unsigned int)(n) - 1) & 31))
68 #define   __sigword(n)                  (((unsigned int)(n) - 1) >> 5)
69 #define   __sigaddset(s, n)   ((s)->__bits[__sigword(n)] |= __sigmask(n))
70 #define   __sigdelset(s, n)   ((s)->__bits[__sigword(n)] &= ~__sigmask(n))
71 #define   __sigismember(s, n) (((s)->__bits[__sigword(n)] & __sigmask(n)) != 0)
72 #define   __sigemptyset(s)    ((s)->__bits[0] = 0x00000000, \
73                                          (s)->__bits[1] = 0x00000000, \
74                                          (s)->__bits[2] = 0x00000000, \
75                                          (s)->__bits[3] = 0x00000000)
76 #define __sigsetequal(s1,s2)  ((s1)->__bits[0] == (s2)->__bits[0] && \
77                                          (s1)->__bits[1] == (s2)->__bits[1] && \
78                                          (s1)->__bits[2] == (s2)->__bits[2] && \
79                                          (s1)->__bits[3] == (s2)->__bits[3])
80 #define   __sigfillset(s)               ((s)->__bits[0] = 0xffffffff, \
81                                          (s)->__bits[1] = 0xffffffff, \
82                                          (s)->__bits[2] = 0xffffffff, \
83                                          (s)->__bits[3] = 0xffffffff)
84 #define   __sigplusset(s, t) \
85           do {                                                        \
86                     (t)->__bits[0] |= (s)->__bits[0];       \
87                     (t)->__bits[1] |= (s)->__bits[1];       \
88                     (t)->__bits[2] |= (s)->__bits[2];       \
89                     (t)->__bits[3] |= (s)->__bits[3];       \
90           } while (0)
91 #define   __sigminusset(s, t) \
92           do {                                                        \
93                     (t)->__bits[0] &= ~(s)->__bits[0];      \
94                     (t)->__bits[1] &= ~(s)->__bits[1];      \
95                     (t)->__bits[2] &= ~(s)->__bits[2];      \
96                     (t)->__bits[3] &= ~(s)->__bits[3];      \
97           } while (0)
98 #define   __sigandset(s, t) \
99           do {                                                        \
100                     (t)->__bits[0] &= (s)->__bits[0];       \
101                     (t)->__bits[1] &= (s)->__bits[1];       \
102                     (t)->__bits[2] &= (s)->__bits[2];       \
103                     (t)->__bits[3] &= (s)->__bits[3];       \
104           } while (0)
105 
106 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
107     (_XOPEN_SOURCE - 0) >= 500 || (_POSIX_C_SOURCE - 0) >= 200809L || \
108     defined(_NETBSD_SOURCE)
109 typedef struct
110 #if defined(_NETBSD_SOURCE)
111                sigaltstack
112 #endif /* _NETBSD_SOURCE */
113                                  {
114           void      *ss_sp;                       /* signal stack base */
115           size_t    ss_size;            /* signal stack length */
116           int       ss_flags;           /* SS_DISABLE and/or SS_ONSTACK */
117 } stack_t;
118 
119 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500
120           * || _POSIX_C_SOURCE >= 200809L || _NETBSD_SOURCE
121           */
122 
123 #endif    /* _POSIX_C_SOURCE || _XOPEN_SOURCE || ... */
124 
125 #endif    /* !_SYS_SIGTYPES_H_ */
126