The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | */ |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 28 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _SIGNAL_H_ |
| 30 | #define _SIGNAL_H_ |
| 31 | |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 32 | #include <sys/cdefs.h> |
| 33 | #include <sys/types.h> |
| 34 | |
Raghu Gandham | 93e7b9f | 2014-06-25 17:58:48 -0700 | [diff] [blame] | 35 | #include <asm/sigcontext.h> |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 36 | #include <bits/pthread_types.h> |
| 37 | #include <bits/timespec.h> |
Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 38 | #include <limits.h> |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 39 | |
Elliott Hughes | a40640d | 2017-12-13 14:49:21 -0800 | [diff] [blame] | 40 | /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the |
| 41 | * POSIX one, so we need to expose our own and translate behind the scenes. |
| 42 | * For 32-bit, we're stuck with the definitions we already shipped, |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 43 | * even though they contain a sigset_t that's too small. See sigaction64. |
| 44 | */ |
Elliott Hughes | a40640d | 2017-12-13 14:49:21 -0800 | [diff] [blame] | 45 | #define sigaction __kernel_sigaction |
| 46 | #include <linux/signal.h> |
| 47 | #undef sigaction |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 48 | |
Elliott Hughes | 26a8eb5 | 2014-09-12 20:04:40 -0700 | [diff] [blame] | 49 | #include <sys/ucontext.h> |
| 50 | #define __BIONIC_HAVE_UCONTEXT_T |
| 51 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 52 | __BEGIN_DECLS |
| 53 | |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame] | 54 | typedef int sig_atomic_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 55 | |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 56 | /* The arm and x86 kernel header files don't define _NSIG. */ |
| 57 | #ifndef _KERNEL__NSIG |
| 58 | #define _KERNEL__NSIG 64 |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 59 | #endif |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 60 | |
| 61 | /* Userspace's NSIG is the kernel's _NSIG + 1. */ |
| 62 | #define _NSIG (_KERNEL__NSIG + 1) |
| 63 | #define NSIG _NSIG |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 64 | |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 65 | /* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since |
| 66 | * SIG_HOLD is only used by the deprecated SysV signal API. |
| 67 | */ |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 68 | #define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2) |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 69 | |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 70 | /* We take a few real-time signals for ourselves. May as well use the same names as glibc. */ |
| 71 | #define SIGRTMIN (__libc_current_sigrtmin()) |
| 72 | #define SIGRTMAX (__libc_current_sigrtmax()) |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 73 | int __libc_current_sigrtmin(void) __INTRODUCED_IN(21); |
| 74 | int __libc_current_sigrtmax(void) __INTRODUCED_IN(21); |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 75 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 76 | extern const char* const sys_siglist[_NSIG]; |
| 77 | extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 78 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 79 | typedef __sighandler_t sig_t; /* BSD compatibility. */ |
| 80 | typedef __sighandler_t sighandler_t; /* glibc compatibility. */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | |
Elliott Hughes | a0cd9bc | 2014-03-07 15:41:25 -0800 | [diff] [blame] | 82 | #define si_timerid si_tid /* glibc compatibility. */ |
| 83 | |
Goran Jakovljevic | 3796669 | 2018-02-12 09:03:10 +0100 | [diff] [blame^] | 84 | /* sigset_t is already large enough on LP64 and mips, but other LP32's sigset_t |
| 85 | * is just `unsigned long`. |
| 86 | */ |
| 87 | #if defined(__LP64__) || defined(__mips__) |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 88 | typedef sigset_t sigset64_t; |
| 89 | #else |
| 90 | typedef struct { unsigned long __bits[_KERNEL__NSIG/LONG_BIT]; } sigset64_t; |
| 91 | #endif |
| 92 | |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 93 | #if defined(__LP64__) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 | |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 95 | #define __SIGACTION_BODY \ |
| 96 | int sa_flags; \ |
| 97 | union { \ |
| 98 | sighandler_t sa_handler; \ |
| 99 | void (*sa_sigaction)(int, struct siginfo*, void*); \ |
| 100 | }; \ |
| 101 | sigset_t sa_mask; \ |
| 102 | void (*sa_restorer)(void); \ |
| 103 | |
| 104 | struct sigaction { __SIGACTION_BODY }; |
| 105 | struct sigaction64 { __SIGACTION_BODY }; |
| 106 | |
| 107 | #undef __SIGACTION_BODY |
| 108 | |
| 109 | #elif defined(__mips__) |
| 110 | |
| 111 | #define __SIGACTION_BODY \ |
| 112 | int sa_flags; \ |
| 113 | union { \ |
| 114 | sighandler_t sa_handler; \ |
| 115 | void (*sa_sigaction)(int, struct siginfo*, void*); \ |
| 116 | }; \ |
| 117 | sigset_t sa_mask; \ |
| 118 | |
| 119 | struct sigaction { __SIGACTION_BODY }; |
| 120 | struct sigaction64 { __SIGACTION_BODY }; |
| 121 | |
| 122 | #undef __SIGACTION_BODY |
| 123 | |
| 124 | #else |
| 125 | |
| 126 | #undef sa_handler |
| 127 | #undef sa_sigaction |
| 128 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 129 | struct sigaction { |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 130 | union { |
| 131 | sighandler_t sa_handler; |
| 132 | void (*sa_sigaction)(int, struct siginfo*, void*); |
| 133 | }; |
| 134 | sigset_t sa_mask; |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 135 | int sa_flags; |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 136 | void (*sa_restorer)(void); |
| 137 | }; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 138 | |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 139 | /* This matches the kernel's internal structure. */ |
| 140 | struct sigaction64 { |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 141 | union { |
| 142 | sighandler_t sa_handler; |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 143 | void (*sa_sigaction)(int, struct siginfo*, void*); |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 144 | }; |
Elliott Hughes | a40640d | 2017-12-13 14:49:21 -0800 | [diff] [blame] | 145 | int sa_flags; |
| 146 | void (*sa_restorer)(void); |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 147 | sigset64_t sa_mask; |
Elliott Hughes | a40640d | 2017-12-13 14:49:21 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 150 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 151 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 152 | int sigaction(int __signal, const struct sigaction* __new_action, struct sigaction* __old_action); |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 153 | int sigaction64(int __signal, const struct sigaction64* __new_action, struct sigaction64* __old_action) __INTRODUCED_IN(28); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 154 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 155 | int siginterrupt(int __signal, int __flag); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 156 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 157 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 158 | sighandler_t signal(int __signal, sighandler_t __handler) __INTRODUCED_IN(21); |
| 159 | int sigaddset(sigset_t* __set, int __signal) __INTRODUCED_IN(21); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 160 | int sigaddset64(sigset64_t* __set, int __signal) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 161 | int sigdelset(sigset_t* __set, int __signal) __INTRODUCED_IN(21); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 162 | int sigdelset64(sigset64_t* __set, int __signal) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 163 | int sigemptyset(sigset_t* __set) __INTRODUCED_IN(21); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 164 | int sigemptyset64(sigset64_t* __set) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 165 | int sigfillset(sigset_t* __set) __INTRODUCED_IN(21); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 166 | int sigfillset64(sigset64_t* __set) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 167 | int sigismember(const sigset_t* __set, int __signal) __INTRODUCED_IN(21); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 168 | int sigismember64(const sigset64_t* __set, int __signal) __INTRODUCED_IN(28); |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 169 | #else |
| 170 | // Implemented as static inlines before 21. |
| 171 | #endif |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 172 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 173 | int sigpending(sigset_t* __set); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 174 | int sigpending64(sigset64_t* __set) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 175 | int sigprocmask(int __how, const sigset_t* __new_set, sigset_t* __old_set); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 176 | int sigprocmask64(int __how, const sigset64_t* __new_set, sigset64_t* __old_set) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 177 | int sigsuspend(const sigset_t* __mask); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 178 | int sigsuspend64(const sigset64_t* __mask) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 179 | int sigwait(const sigset_t* __set, int* __signal); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 180 | int sigwait64(const sigset64_t* __set, int* __signal) __INTRODUCED_IN(28); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 181 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 182 | int sighold(int __signal) |
Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 183 | __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 184 | __INTRODUCED_IN(26); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 185 | int sigignore(int __signal) |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 186 | __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN(26); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 187 | int sigpause(int __signal) |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 188 | __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN(26); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 189 | int sigrelse(int __signal) |
Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 190 | __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 191 | __INTRODUCED_IN(26); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 192 | sighandler_t sigset(int __signal, sighandler_t __handler) |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 193 | __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN(26); |
Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 194 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 195 | int raise(int __signal); |
| 196 | int kill(pid_t __pid, int __signal); |
| 197 | int killpg(int __pgrp, int __signal); |
| 198 | int tgkill(int __tgid, int __tid, int __signal) __INTRODUCED_IN_32(16); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 199 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 200 | int sigaltstack(const stack_t* __new_signal_stack, stack_t* __old_signal_stack); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 201 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 202 | void psiginfo(const siginfo_t* __info, const char* __msg) __INTRODUCED_IN(17); |
| 203 | void psignal(int __signal, const char* __msg) __INTRODUCED_IN(17); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 204 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 205 | int pthread_kill(pthread_t __pthread, int __signal); |
| 206 | int pthread_sigmask(int __how, const sigset_t* __new_set, sigset_t* __old_set); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 207 | int pthread_sigmask64(int __how, const sigset64_t* __new_set, sigset64_t* __old_set) __INTRODUCED_IN(28); |
Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 208 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 209 | int sigqueue(pid_t __pid, int __signal, const union sigval __value) __INTRODUCED_IN(23); |
| 210 | int sigtimedwait(const sigset_t* __set, siginfo_t* __info, const struct timespec* __timeout) __INTRODUCED_IN(23); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 211 | int sigtimedwait64(const sigset64_t* __set, siginfo_t* __info, const struct timespec* __timeout) __INTRODUCED_IN(28); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 212 | int sigwaitinfo(const sigset_t* __set, siginfo_t* __info) __INTRODUCED_IN(23); |
Elliott Hughes | 5905d6f | 2018-01-30 15:09:51 -0800 | [diff] [blame] | 213 | int sigwaitinfo64(const sigset64_t* __set, siginfo_t* __info) __INTRODUCED_IN(28); |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 214 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 215 | __END_DECLS |
| 216 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 217 | #include <android/legacy_signal_inlines.h> |
| 218 | |
Elliott Hughes | 3e23591 | 2018-02-01 14:21:51 -0800 | [diff] [blame] | 219 | #endif |