1 /* 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 */ 28 29 #ifndef _SIGNAL_H_ 30 #define _SIGNAL_H_ 31 32 #include <sys/cdefs.h> 33 #include <sys/types.h> 34 35 #include <asm/sigcontext.h> 36 #include <bits/pthread_types.h> 37 #include <bits/signal_types.h> 38 #include <bits/timespec.h> 39 #include <limits.h> 40 41 #include <sys/ucontext.h> 42 #define __BIONIC_HAVE_UCONTEXT_T 43 44 __BEGIN_DECLS 45 46 /* 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 */ 49 #define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2) 50 51 /* 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()) 54 int __libc_current_sigrtmin(void); 55 int __libc_current_sigrtmax(void); 56 57 extern const char* _Nonnull const sys_siglist[_NSIG]; 58 extern const char* _Nonnull const sys_signame[_NSIG]; /* BSD compatibility. */ 59 60 #define si_timerid si_tid /* glibc compatibility. */ 61 62 int sigaction(int __signal, const struct sigaction* _Nullable __new_action, struct sigaction* _Nullable __old_action); 63 64 #if __BIONIC_AVAILABILITY_GUARD(28) 65 int sigaction64(int __signal, const struct sigaction64* _Nullable __new_action, struct sigaction64* _Nullable __old_action) __INTRODUCED_IN(28); 66 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 67 68 69 int siginterrupt(int __signal, int __flag); 70 71 sighandler_t _Nonnull signal(int __signal, sighandler_t _Nullable __handler); 72 int sigaddset(sigset_t* _Nonnull __set, int __signal); 73 74 #if __BIONIC_AVAILABILITY_GUARD(28) 75 int sigaddset64(sigset64_t* _Nonnull __set, int __signal) __INTRODUCED_IN(28); 76 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 77 78 int sigdelset(sigset_t* _Nonnull __set, int __signal); 79 80 #if __BIONIC_AVAILABILITY_GUARD(28) 81 int sigdelset64(sigset64_t* _Nonnull __set, int __signal) __INTRODUCED_IN(28); 82 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 83 84 int sigemptyset(sigset_t* _Nonnull __set); 85 86 #if __BIONIC_AVAILABILITY_GUARD(28) 87 int sigemptyset64(sigset64_t* _Nonnull __set) __INTRODUCED_IN(28); 88 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 89 90 int sigfillset(sigset_t* _Nonnull __set); 91 92 #if __BIONIC_AVAILABILITY_GUARD(28) 93 int sigfillset64(sigset64_t* _Nonnull __set) __INTRODUCED_IN(28); 94 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 95 96 int sigismember(const sigset_t* _Nonnull __set, int __signal); 97 98 #if __BIONIC_AVAILABILITY_GUARD(28) 99 int sigismember64(const sigset64_t* _Nonnull __set, int __signal) __INTRODUCED_IN(28); 100 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 101 102 103 int sigpending(sigset_t* _Nonnull __set); 104 105 #if __BIONIC_AVAILABILITY_GUARD(28) 106 int sigpending64(sigset64_t* _Nonnull __set) __INTRODUCED_IN(28); 107 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 108 109 int sigprocmask(int __how, const sigset_t* _Nullable __new_set, sigset_t* _Nullable __old_set); 110 111 #if __BIONIC_AVAILABILITY_GUARD(28) 112 int sigprocmask64(int __how, const sigset64_t* _Nullable __new_set, sigset64_t* _Nullable __old_set) __INTRODUCED_IN(28); 113 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 114 115 int sigsuspend(const sigset_t* _Nonnull __mask); 116 117 #if __BIONIC_AVAILABILITY_GUARD(28) 118 int sigsuspend64(const sigset64_t* _Nonnull __mask) __INTRODUCED_IN(28); 119 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 120 121 int sigwait(const sigset_t* _Nonnull __set, int* _Nonnull __signal); 122 123 #if __BIONIC_AVAILABILITY_GUARD(28) 124 int 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) 130 int sighold(int __signal) 131 __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead"))) 132 __INTRODUCED_IN(26); 133 int sigignore(int __signal) 134 __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26); 135 int sigpause(int __signal) 136 __attribute__((__deprecated__("use sigsuspend() instead"))) __INTRODUCED_IN(26); 137 int sigrelse(int __signal) 138 __attribute__((__deprecated__("use sigprocmask() or pthread_sigmask() instead"))) 139 __INTRODUCED_IN(26); 140 sighandler_t _Nonnull sigset(int __signal, sighandler_t _Nullable __handler) 141 __attribute__((__deprecated__("use sigaction() instead"))) __INTRODUCED_IN(26); 142 #endif /* __BIONIC_AVAILABILITY_GUARD(26) */ 143 144 145 int raise(int __signal); 146 int kill(pid_t __pid, int __signal); 147 int killpg(int __pgrp, int __signal); 148 int tgkill(int __tgid, int __tid, int __signal); 149 150 int sigaltstack(const stack_t* _Nullable __new_signal_stack, stack_t* _Nullable __old_signal_stack); 151 152 void psiginfo(const siginfo_t* _Nonnull __info, const char* _Nullable __msg); 153 void psignal(int __signal, const char* _Nullable __msg); 154 155 int pthread_kill(pthread_t __pthread, int __signal); 156 #if defined(__USE_GNU) 157 158 #if __BIONIC_AVAILABILITY_GUARD(29) 159 int pthread_sigqueue(pthread_t __pthread, int __signal, const union sigval __value) __INTRODUCED_IN(29); 160 #endif /* __BIONIC_AVAILABILITY_GUARD(29) */ 161 162 #endif 163 164 int pthread_sigmask(int __how, const sigset_t* _Nullable __new_set, sigset_t* _Nullable __old_set); 165 166 #if __BIONIC_AVAILABILITY_GUARD(28) 167 int 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) 173 int sigqueue(pid_t __pid, int __signal, const union sigval __value) __INTRODUCED_IN(23); 174 int sigtimedwait(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(23); 175 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ 176 177 178 #if __BIONIC_AVAILABILITY_GUARD(28) 179 int sigtimedwait64(const sigset64_t* _Nonnull __set, siginfo_t* _Nullable __info, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(28); 180 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 181 182 183 #if __BIONIC_AVAILABILITY_GUARD(23) 184 int sigwaitinfo(const sigset_t* _Nonnull __set, siginfo_t* _Nullable __info) __INTRODUCED_IN(23); 185 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ 186 187 188 #if __BIONIC_AVAILABILITY_GUARD(28) 189 int sigwaitinfo64(const sigset64_t* _Nonnull __set, siginfo_t* _Nullable __info) __INTRODUCED_IN(28); 190 #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ 191 192 193 /** 194 * Buffer size suitable for any call to sig2str(). 195 */ 196 #define SIG2STR_MAX 32 197 198 /** 199 * [sig2str(3)](https://man7.org/linux/man-pages/man3/sig2str.3.html) 200 * 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 */ 208 209 #if __BIONIC_AVAILABILITY_GUARD(36) 210 int sig2str(int __signal, char* _Nonnull __buf) __INTRODUCED_IN(36); 211 212 /** 213 * [str2sig(3)](https://man7.org/linux/man-pages/man3/str2sig.3.html) 214 * 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 */ 221 int str2sig(const char* _Nonnull __name, int* _Nonnull __signal) __INTRODUCED_IN(36); 222 #endif /* __BIONIC_AVAILABILITY_GUARD(36) */ 223 224 225 __END_DECLS 226 227 #endif 228