xref: /aosp_15_r20/bionic/tests/headers/posix/signal_h.c (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1 /*
2  * Copyright (C) 2017 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 #include <signal.h>
30 
31 #include "header_checks.h"
32 
signal_h()33 static void signal_h() {
34   void (*h)(int);
35   h = SIG_DFL;
36   h = SIG_ERR;
37   h = SIG_HOLD;
38   h = SIG_IGN;
39 
40   TYPE(pthread_t);
41   TYPE(size_t);
42   TYPE(uid_t);
43 
44   TYPE(struct timespec);
45 
46   TYPE(sig_atomic_t);
47   TYPE(pid_t);
48 
49   TYPE(pthread_attr_t);
50 
51   TYPE(struct sigevent);
52   STRUCT_MEMBER(struct sigevent, int, sigev_notify);
53   STRUCT_MEMBER(struct sigevent, int, sigev_signo);
54   STRUCT_MEMBER(struct sigevent, union sigval, sigev_value);
55   STRUCT_MEMBER_FUNCTION_POINTER(struct sigevent, void (*f)(union sigval), sigev_notify_function);
56 #if defined(__BIONIC__)
57   STRUCT_MEMBER(struct sigevent, void*, sigev_notify_attributes);
58 #else
59   STRUCT_MEMBER(struct sigevent, pthread_attr_t*, sigev_notify_attributes);
60 #endif
61 
62   MACRO(SIGEV_NONE);
63   MACRO(SIGEV_SIGNAL);
64   MACRO(SIGEV_THREAD);
65 
66 #if !defined(__GLIBC__)  // Our glibc is too old.
67   MACRO(SIG2STR_MAX);
68 #endif
69 
70   TYPE(union sigval);
71   STRUCT_MEMBER(union sigval, int, sival_int);
72   STRUCT_MEMBER(union sigval, void*, sival_ptr);
73 
74   int i;
75   i = SIGRTMIN;
76   i = SIGRTMAX;
77 
78   MACRO(SIGABRT);
79   MACRO(SIGALRM);
80   MACRO(SIGBUS);
81   MACRO(SIGCHLD);
82   MACRO(SIGCONT);
83   MACRO(SIGFPE);
84   MACRO(SIGHUP);
85   MACRO(SIGILL);
86   MACRO(SIGINT);
87   MACRO(SIGKILL);
88   MACRO(SIGPIPE);
89   MACRO(SIGQUIT);
90   MACRO(SIGSEGV);
91   MACRO(SIGSTOP);
92   MACRO(SIGTERM);
93   MACRO(SIGTSTP);
94   MACRO(SIGTTIN);
95   MACRO(SIGTTOU);
96   MACRO(SIGUSR1);
97   MACRO(SIGUSR2);
98   MACRO(SIGPOLL);
99   MACRO(SIGPROF);
100   MACRO(SIGSYS);
101   MACRO(SIGTRAP);
102   MACRO(SIGURG);
103   MACRO(SIGVTALRM);
104   MACRO(SIGXCPU);
105   MACRO(SIGXFSZ);
106 
107   TYPE(struct sigaction);
108   STRUCT_MEMBER_FUNCTION_POINTER(struct sigaction, void (*f)(int), sa_handler);
109   STRUCT_MEMBER(struct sigaction, sigset_t, sa_mask);
110   STRUCT_MEMBER(struct sigaction, int, sa_flags);
111   STRUCT_MEMBER_FUNCTION_POINTER(struct sigaction, void (*f)(int, siginfo_t*, void*), sa_sigaction);
112 
113   i = SIG_BLOCK;
114   i = SIG_UNBLOCK;
115   i = SIG_SETMASK;
116 
117   MACRO(SA_NOCLDSTOP);
118   MACRO(SA_ONSTACK);
119   MACRO(SA_RESETHAND);
120   MACRO(SA_RESTART);
121   MACRO(SA_SIGINFO);
122   MACRO(SA_NOCLDWAIT);
123   MACRO(SA_NODEFER);
124 
125   MACRO(SS_ONSTACK);
126   MACRO(SS_DISABLE);
127 
128   MACRO(MINSIGSTKSZ);
129   MACRO(SIGSTKSZ);
130 
131   TYPE(mcontext_t);
132 
133   TYPE(ucontext_t);
134   STRUCT_MEMBER(ucontext_t, ucontext_t*, uc_link);
135   STRUCT_MEMBER(ucontext_t, sigset_t, uc_sigmask);
136   STRUCT_MEMBER(ucontext_t, stack_t, uc_stack);
137   STRUCT_MEMBER(ucontext_t, mcontext_t, uc_mcontext);
138 
139   TYPE(stack_t);
140   STRUCT_MEMBER(stack_t, void*, ss_sp);
141   STRUCT_MEMBER(stack_t, size_t, ss_size);
142   STRUCT_MEMBER(stack_t, int, ss_flags);
143 
144   TYPE(siginfo_t);
145   STRUCT_MEMBER(siginfo_t, int, si_signo);
146   STRUCT_MEMBER(siginfo_t, int, si_code);
147   STRUCT_MEMBER(siginfo_t, int, si_errno);
148   STRUCT_MEMBER(siginfo_t, pid_t, si_pid);
149   STRUCT_MEMBER(siginfo_t, uid_t, si_uid);
150   STRUCT_MEMBER(siginfo_t, void*, si_addr);
151   STRUCT_MEMBER(siginfo_t, int, si_status);
152   STRUCT_MEMBER(siginfo_t, long, si_band);
153   STRUCT_MEMBER(siginfo_t, union sigval, si_value);
154 
155   i = ILL_ILLOPC;
156   i = ILL_ILLOPN;
157   i = ILL_ILLADR;
158   i = ILL_ILLTRP;
159   i = ILL_PRVOPC;
160   i = ILL_PRVREG;
161   i = ILL_COPROC;
162   i = ILL_BADSTK;
163 
164   i = FPE_INTDIV;
165   i = FPE_INTOVF;
166   i = FPE_FLTDIV;
167   i = FPE_FLTOVF;
168   i = FPE_FLTUND;
169   i = FPE_FLTRES;
170   i = FPE_FLTINV;
171   i = FPE_FLTSUB;
172 
173   i = SEGV_MAPERR;
174   i = SEGV_ACCERR;
175 
176   i = BUS_ADRALN;
177   i = BUS_ADRERR;
178   i = BUS_OBJERR;
179 
180   i = TRAP_BRKPT;
181   i = TRAP_TRACE;
182 
183   i = CLD_EXITED;
184   i = CLD_KILLED;
185   i = CLD_DUMPED;
186   i = CLD_TRAPPED;
187   i = CLD_STOPPED;
188   i = CLD_CONTINUED;
189 
190   i = POLL_IN;
191   i = POLL_OUT;
192   i = POLL_MSG;
193   i = POLL_ERR;
194   i = POLL_PRI;
195   i = POLL_HUP;
196 
197   i = SI_USER;
198   i = SI_QUEUE;
199   i = SI_TIMER;
200   i = SI_ASYNCIO;
201   i = SI_MESGQ;
202 
203   typedef void (*signal_handler_type)(int);
204 
205   FUNCTION(kill, int (*f)(pid_t, int));
206   FUNCTION(killpg, int (*f)(pid_t, int));
207   FUNCTION(psiginfo, void (*f)(const siginfo_t*, const char*));
208   FUNCTION(psignal, void (*f)(int, const char*));
209   FUNCTION(pthread_kill, int (*f)(pthread_t, int));
210   FUNCTION(pthread_sigmask, int (*f)(int, const sigset_t*, sigset_t*));
211   FUNCTION(raise, int (*f)(int));
212 #if !defined(__GLIBC__)  // Our glibc is too old.
213   FUNCTION(sig2str, int (*f)(int, char*));
214 #endif
215   FUNCTION(sigaction, int (*f)(int, const struct sigaction*, struct sigaction*));
216   FUNCTION(sigaddset, int (*f)(sigset_t*, int));
217   FUNCTION(sigaltstack, int (*f)(const stack_t*, stack_t*));
218   FUNCTION(sigdelset, int (*f)(sigset_t*, int));
219   FUNCTION(sigemptyset, int (*f)(sigset_t*));
220   FUNCTION(sigfillset, int (*f)(sigset_t*));
221   FUNCTION(sighold, int (*f)(int));
222   FUNCTION(sigignore, int (*f)(int));
223   FUNCTION(siginterrupt, int (*f)(int, int));
224   FUNCTION(sigismember, int (*f)(const sigset_t*, int));
225   FUNCTION(signal, signal_handler_type (*f)(int, signal_handler_type));
226   FUNCTION(sigpause, int (*f)(int));
227   FUNCTION(sigpending, int (*f)(sigset_t*));
228   FUNCTION(sigprocmask, int (*f)(int, const sigset_t*, sigset_t*));
229   FUNCTION(sigqueue, int (*f)(pid_t, int, union sigval));
230   FUNCTION(sigrelse, int (*f)(int));
231   FUNCTION(sigset, signal_handler_type (*f)(int, signal_handler_type));
232   FUNCTION(sigsuspend, int (*f)(const sigset_t*));
233   FUNCTION(sigtimedwait, int (*f)(const sigset_t*, siginfo_t*, const struct timespec*));
234   FUNCTION(sigwait, int (*f)(const sigset_t*, int*));
235   FUNCTION(sigwaitinfo, int (*f)(const sigset_t*, siginfo_t*));
236 #if !defined(__GLIBC__)  // Our glibc is too old.
237   FUNCTION(str2sig, int (*f)(const char*, int*));
238 #endif
239 }
240