• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 #include <sys/cdefs.h>
32 
33 #include <limits.h>
34 #include <linux/signal.h>
35 #include <sys/types.h>
36 
37 /**
38  * The highest kernel-supported signal number, plus one.
39  *
40  * In theory this is useful for declaring an array with an entry for each signal.
41  * In practice, that's less useful than it seems because of the real-time
42  * signals and the reserved signals,
43  * and the sig2str() and str2sig() functions cover the most common use case
44  * of translating between signal numbers and signal names.
45  *
46  * Note also that although sigset_t and sigset64_t are the same type on LP64,
47  * on ILP32 only sigset64_t is large enough to refer to the upper 32 signals.
48  * NSIG does _not_ tell you anything about what can be used with sigset_t.
49  *
50  * See the
51  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
52  * documentation.
53  */
54 #define NSIG 65
55 /** A traditional alternative name for NSIG. */
56 #define _NSIG 65
57 
58 /*
59  * We rewrite the kernel's _NSIG to _KERNEL__NSIG
60  * (because the kernel values are off by one from the userspace values),
61  * but the kernel <asm/signal.h> headers define SIGRTMAX in terms of
62  * _KERNEL__NSIG (or _NSIG, in the original kernel source),
63  * so we need to provide a definition here.
64  * (Ideally our uapi header rewriter would just hard-code _KERNEL__NSIG to 64.)
65  */
66 #ifndef _KERNEL__NSIG
67 #define _KERNEL__NSIG 64
68 #endif
69 
70 typedef int sig_atomic_t;
71 
72 typedef __sighandler_t sig_t; /* BSD compatibility. */
73 typedef __sighandler_t sighandler_t; /* glibc compatibility. */
74 
75 #if defined(__LP64__)
76 /**
77  * The kernel LP64 sigset_t is large enough to support all signals;
78  * this typedef is just for source compatibility with code that uses
79  * real-time signals on ILP32.
80  *
81  * See the
82  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
83  * documentation.
84  */
85 typedef sigset_t sigset64_t;
86 #else
87 /**
88  * The ILP32 sigset_t is only 32 bits, so we need a 64-bit sigset64_t
89  * and associated functions to be able to support the real-time signals.
90  *
91  * See the
92  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
93  * documentation.
94  */
95 typedef struct { unsigned long __bits[64/(8*sizeof(long))]; } sigset64_t;
96 #endif
97 
98 /* The kernel's struct sigaction doesn't match the POSIX one,
99  * so we define struct sigaction ourselves. */
100 
101 #if defined(__LP64__)
102 
103 #define __SIGACTION_BODY \
104   int sa_flags; \
105   union { \
106     sighandler_t sa_handler; \
107     void (*sa_sigaction)(int, struct siginfo*, void*); \
108   }; \
109   sigset_t sa_mask; \
110   void (*sa_restorer)(void); \
111 
112 /**
113  * Used with sigaction().
114  *
115  * On LP64, this supports all signals including real-time signals.
116  * On ILP32, this only supports the first 32 signals.
117  *
118  * See the
119  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
120  * documentation.
121  */
122 struct sigaction { __SIGACTION_BODY };
123 /**
124  * Used with sigaction64().
125  *
126  * On LP64, a synonym for struct sigaction for source compatibility with ILP32.
127  * On ILP32, this is needed to support all signals including real-time signals
128  * because struct sigaction only supports the first 32 signals.
129  *
130  * See the
131  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
132  * documentation.
133  */
134 struct sigaction64 { __SIGACTION_BODY };
135 
136 #undef __SIGACTION_BODY
137 
138 #else
139 
140 /* The arm32 kernel headers pollute the namespace with these,
141  * but our header scrubber doesn't know how to remove #defines. */
142 #undef sa_handler
143 #undef sa_sigaction
144 
145 /**
146  * Used with sigaction().
147  *
148  * On LP64, this supports all signals including real-time signals.
149  * On ILP32, this only supports the first 32 signals.
150  *
151  * See the
152  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
153  * documentation.
154  */
155 struct sigaction {
156   union {
157     sighandler_t sa_handler;
158     void (*sa_sigaction)(int, struct siginfo*, void*);
159   };
160   sigset_t sa_mask;
161   int sa_flags;
162   void (*sa_restorer)(void);
163 };
164 
165 /**
166  * Used with sigaction64().
167  *
168  * On LP64, a synonym for struct sigaction for source compatibility with ILP32.
169  * On ILP32, this is needed to support all signals including real-time signals
170  * because struct sigaction only supports the first 32 signals.
171  *
172  * See the
173  * (32-bit ABI bugs)[https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md#is-too-small-for-real_time-signals]
174  * documentation.
175  */
176 struct sigaction64 {
177   union {
178     sighandler_t sa_handler;
179     void (*sa_sigaction)(int, struct siginfo*, void*);
180   };
181   int sa_flags;
182   void (*sa_restorer)(void);
183   sigset64_t sa_mask;
184 };
185 
186 #endif
187