blob: 38dcbde3f9f017589e39a3ddce886b2e903a0b1c [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 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 */
Elliott Hughesc7e9b232013-10-16 22:27:54 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _SIGNAL_H_
30#define _SIGNAL_H_
31
Josh Gao16016df2016-11-07 18:27:16 -080032#include <sys/cdefs.h>
33#include <sys/types.h>
34
Raghu Gandham93e7b9f2014-06-25 17:58:48 -070035#include <asm/sigcontext.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080036#include <bits/pthread_types.h>
Elliott Hughes23415fc2018-02-13 19:09:04 -080037#include <bits/signal_types.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080038#include <bits/timespec.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080039#include <limits.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070040
Elliott Hughes26a8eb52014-09-12 20:04:40 -070041#include <sys/ucontext.h>
42#define __BIONIC_HAVE_UCONTEXT_T
43
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044__BEGIN_DECLS
45
Greg Hackmann5375bf62016-02-29 12:35:33 -080046/* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since
47 * SIG_HOLD is only used by the deprecated SysV signal API.
48 */
Elliott Hughes5470c182016-07-22 11:36:17 -070049#define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2)
Greg Hackmann5375bf62016-02-29 12:35:33 -080050
Elliott Hughes0990d4f2014-04-30 09:45:40 -070051/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
52#define SIGRTMIN (__libc_current_sigrtmin())
53#define SIGRTMAX (__libc_current_sigrtmax())
Elliott Hughes655e4302023-06-16 12:39:33 -070054int __libc_current_sigrtmin(void);
55int __libc_current_sigrtmax(void);
Elliott Hughes0990d4f2014-04-30 09:45:40 -070056
zijunzhao38c53442023-02-09 20:28:18 +000057extern const char* _Nonnull const sys_siglist[_NSIG];
58extern const char* _Nonnull const sys_signame[_NSIG]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059
Elliott Hughesa0cd9bc2014-03-07 15:41:25 -080060#define si_timerid si_tid /* glibc compatibility. */
61
zijunzhao38c53442023-02-09 20:28:18 +000062int sigaction(int __signal, const struct sigaction* _Nullable __new_action, struct sigaction* _Nullable __old_action);
Dan Albert02ce4012024-10-25 19:13:49 +000063
64#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +000065int sigaction64(int __signal, const struct sigaction64* _Nullable __new_action, struct sigaction64* _Nullable __old_action) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +000066#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
67
Elliott Hughesc7e9b232013-10-16 22:27:54 -070068
Elliott Hughesfaa74342017-08-11 17:34:44 -070069int siginterrupt(int __signal, int __flag);
Elliott Hughesc7e9b232013-10-16 22:27:54 -070070
Elliott Hughes655e4302023-06-16 12:39:33 -070071sighandler_t _Nonnull signal(int __signal, sighandler_t _Nullable __handler);
72int sigaddset(sigset_t* _Nonnull __set, int __signal);
Dan Albert02ce4012024-10-25 19:13:49 +000073
74#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +000075int sigaddset64(sigset64_t* _Nonnull __set, int __signal) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +000076#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
77
Elliott Hughes655e4302023-06-16 12:39:33 -070078int sigdelset(sigset_t* _Nonnull __set, int __signal);
Dan Albert02ce4012024-10-25 19:13:49 +000079
80#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +000081int sigdelset64(sigset64_t* _Nonnull __set, int __signal) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +000082#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
83
Elliott Hughes655e4302023-06-16 12:39:33 -070084int sigemptyset(sigset_t* _Nonnull __set);
Dan Albert02ce4012024-10-25 19:13:49 +000085
86#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +000087int sigemptyset64(sigset64_t* _Nonnull __set) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +000088#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
89
Elliott Hughes655e4302023-06-16 12:39:33 -070090int sigfillset(sigset_t* _Nonnull __set);
Dan Albert02ce4012024-10-25 19:13:49 +000091
92#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +000093int sigfillset64(sigset64_t* _Nonnull __set) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +000094#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
95
Elliott Hughes655e4302023-06-16 12:39:33 -070096int sigismember(const sigset_t* _Nonnull __set, int __signal);
Dan Albert02ce4012024-10-25 19:13:49 +000097
98#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +000099int sigismember64(const sigset64_t* _Nonnull __set, int __signal) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +0000100#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
101
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700102
zijunzhao38c53442023-02-09 20:28:18 +0000103int sigpending(sigset_t* _Nonnull __set);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800104
Dan Albert02ce4012024-10-25 19:13:49 +0000105#if __BIONIC_AVAILABILITY_GUARD(28)
106int sigpending64(sigset64_t* _Nonnull __set) __INTRODUCED_IN(28);
107#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
108
109int sigprocmask(int __how, const sigset_t* _Nullable __new_set, sigset_t* _Nullable __old_set);
110
111#if __BIONIC_AVAILABILITY_GUARD(28)
112int sigprocmask64(int __how, const sigset64_t* _Nullable __new_set, sigset64_t* _Nullable __old_set) __INTRODUCED_IN(28);
113#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
114
115int sigsuspend(const sigset_t* _Nonnull __mask);
116
117#if __BIONIC_AVAILABILITY_GUARD(28)
118int sigsuspend64(const sigset64_t* _Nonnull __mask) __INTRODUCED_IN(28);
119#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
120
121int sigwait(const sigset_t* _Nonnull __set, int* _Nonnull __signal);
122
123#if __BIONIC_AVAILABILITY_GUARD(28)
124int sigwait64(const sigset64_t* _Nonnull __set, int* _Nonnull __signal) __INTRODUCED_IN(28);
125#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
126
127
128
129#if __BIONIC_AVAILABILITY_GUARD(26)
Elliott Hughesfaa74342017-08-11 17:34:44 -0700130int sighold(int __signal)
Elliott Hughesa1b5ca22024-04-22 20:10:53 +0000131 __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead")))
Josh Gao2e8e5e62017-04-20 12:58:31 -0700132 __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700133int sigignore(int __signal)
Elliott Hughesa1b5ca22024-04-22 20:10:53 +0000134 __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700135int sigpause(int __signal)
Elliott Hughesa1b5ca22024-04-22 20:10:53 +0000136 __attribute__((__deprecated__("use sigsuspend() instead"))) __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700137int sigrelse(int __signal)
Elliott Hughesa1b5ca22024-04-22 20:10:53 +0000138 __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead")))
Josh Gao2e8e5e62017-04-20 12:58:31 -0700139 __INTRODUCED_IN(26);
zijunzhao38c53442023-02-09 20:28:18 +0000140sighandler_t _Nonnull sigset(int __signal, sighandler_t _Nullable __handler)
Elliott Hughesa1b5ca22024-04-22 20:10:53 +0000141 __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26);
Dan Albert02ce4012024-10-25 19:13:49 +0000142#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
143
Greg Hackmann5375bf62016-02-29 12:35:33 -0800144
Elliott Hughesfaa74342017-08-11 17:34:44 -0700145int raise(int __signal);
146int kill(pid_t __pid, int __signal);
147int killpg(int __pgrp, int __signal);
Elliott Hughesf106a392019-10-03 16:09:04 -0700148int tgkill(int __tgid, int __tid, int __signal);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700149
zijunzhao38c53442023-02-09 20:28:18 +0000150int sigaltstack(const stack_t* _Nullable __new_signal_stack, stack_t* _Nullable __old_signal_stack);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800151
Elliott Hughes655e4302023-06-16 12:39:33 -0700152void psiginfo(const siginfo_t* _Nonnull __info, const char* _Nullable __msg);
153void psignal(int __signal, const char* _Nullable __msg);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800154
Elliott Hughesfaa74342017-08-11 17:34:44 -0700155int pthread_kill(pthread_t __pthread, int __signal);
Josh Gao726b63f2018-08-27 16:00:58 -0700156#if defined(__USE_GNU)
Dan Albert02ce4012024-10-25 19:13:49 +0000157
158#if __BIONIC_AVAILABILITY_GUARD(29)
Elliott Hughesc0f46562018-11-09 15:38:52 -0800159int pthread_sigqueue(pthread_t __pthread, int __signal, const union sigval __value) __INTRODUCED_IN(29);
Dan Albert02ce4012024-10-25 19:13:49 +0000160#endif /* __BIONIC_AVAILABILITY_GUARD(29) */
161
Josh Gao726b63f2018-08-27 16:00:58 -0700162#endif
163
zijunzhao38c53442023-02-09 20:28:18 +0000164int pthread_sigmask(int __how, const sigset_t* _Nullable __new_set, sigset_t* _Nullable __old_set);
Dan Albert75ef63d2014-11-21 00:18:07 -0800165
Dan Albert02ce4012024-10-25 19:13:49 +0000166#if __BIONIC_AVAILABILITY_GUARD(28)
167int pthread_sigmask64(int __how, const sigset64_t* _Nullable __new_set, sigset64_t* _Nullable __old_set) __INTRODUCED_IN(28);
168#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
169
170
171
172#if __BIONIC_AVAILABILITY_GUARD(23)
Elliott Hughesfaa74342017-08-11 17:34:44 -0700173int sigqueue(pid_t __pid, int __signal, const union sigval __value) __INTRODUCED_IN(23);
zijunzhao38c53442023-02-09 20:28:18 +0000174int sigtimedwait(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(23);
Dan Albert02ce4012024-10-25 19:13:49 +0000175#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
176
177
178#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +0000179int sigtimedwait64(const sigset64_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +0000180#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
181
182
183#if __BIONIC_AVAILABILITY_GUARD(23)
zijunzhao38c53442023-02-09 20:28:18 +0000184int sigwaitinfo(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info) __INTRODUCED_IN(23);
Dan Albert02ce4012024-10-25 19:13:49 +0000185#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
186
187
188#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao38c53442023-02-09 20:28:18 +0000189int sigwaitinfo64(const sigset64_t* _Nonnull __set, siginfo_t* _Nullable __info) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +0000190#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
191
Yabin Cui63481602014-12-01 17:41:04 -0800192
Elliott Hughes07d52092024-08-09 13:47:14 +0000193/**
194 * Buffer size suitable for any call to sig2str().
195 */
196#define SIG2STR_MAX 32
197
198/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000199 * [sig2str(3)](https://man7.org/linux/man-pages/man3/sig2str.3.html)
Elliott Hughes07d52092024-08-09 13:47:14 +0000200 * converts the integer corresponding to SIGSEGV (say) into a string
201 * like "SEGV" (not including the "SIG" used in the constants).
202 * SIG2STR_MAX is a safe size to use for the buffer.
203 *
204 * Returns 0 on success, and returns -1 _without_ setting errno otherwise.
205 *
206 * Available since API level 36.
207 */
Dan Albert02ce4012024-10-25 19:13:49 +0000208
209#if __BIONIC_AVAILABILITY_GUARD(36)
Elliott Hughes07d52092024-08-09 13:47:14 +0000210int sig2str(int __signal, char* _Nonnull __buf) __INTRODUCED_IN(36);
211
212/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000213 * [str2sig(3)](https://man7.org/linux/man-pages/man3/str2sig.3.html)
Elliott Hughes07d52092024-08-09 13:47:14 +0000214 * converts a string like "SEGV" (not including the "SIG" used in the constants)
215 * into the integer corresponding to SIGSEGV.
216 *
217 * Returns 0 on success, and returns -1 _without_ setting errno otherwise.
218 *
219 * Available since API level 36.
220 */
221int str2sig(const char* _Nonnull __name, int* _Nonnull __signal) __INTRODUCED_IN(36);
Dan Albert02ce4012024-10-25 19:13:49 +0000222#endif /* __BIONIC_AVAILABILITY_GUARD(36) */
223
Elliott Hughes07d52092024-08-09 13:47:14 +0000224
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800225__END_DECLS
226
Elliott Hughes3e235912018-02-01 14:21:51 -0800227#endif