| 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 |  | 
| Raghu Gandham | 93e7b9f | 2014-06-25 17:58:48 -0700 | [diff] [blame] | 32 | #include <asm/sigcontext.h> | 
| Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 33 | #include <bits/pthread_types.h> | 
|  | 34 | #include <bits/timespec.h> | 
| Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 35 | #include <limits.h> | 
| Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 36 | #include <sys/cdefs.h> | 
|  | 37 | #include <sys/types.h> | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 38 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 39 | #if defined(__LP64__) || defined(__mips__) | 
|  | 40 | /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one, | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 41 | * so we need to expose our own and translate behind the scenes. */ | 
|  | 42 | #  define sigaction __kernel_sigaction | 
| Elliott Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 43 | #  include <linux/signal.h> | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 44 | #  undef sigaction | 
|  | 45 | #else | 
|  | 46 | /* For 32-bit, we're stuck with the definitions we already shipped, | 
|  | 47 | * even though they contain a sigset_t that's too small. */ | 
| Elliott Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 48 | #  include <linux/signal.h> | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 49 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 50 |  | 
| Elliott Hughes | 26a8eb5 | 2014-09-12 20:04:40 -0700 | [diff] [blame] | 51 | #include <sys/ucontext.h> | 
|  | 52 | #define __BIONIC_HAVE_UCONTEXT_T | 
|  | 53 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 54 | __BEGIN_DECLS | 
|  | 55 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 56 | #if defined(__clang__) | 
|  | 57 | #pragma clang diagnostic push | 
|  | 58 | #pragma clang diagnostic ignored "-Wnullability-completeness" | 
|  | 59 | #endif | 
|  | 60 |  | 
| David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame] | 61 | typedef int sig_atomic_t; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 62 |  | 
| Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 63 | /* The arm and x86 kernel header files don't define _NSIG. */ | 
|  | 64 | #ifndef _KERNEL__NSIG | 
|  | 65 | #define _KERNEL__NSIG 64 | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 66 | #endif | 
| Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 67 |  | 
|  | 68 | /* Userspace's NSIG is the kernel's _NSIG + 1. */ | 
|  | 69 | #define _NSIG (_KERNEL__NSIG + 1) | 
|  | 70 | #define NSIG _NSIG | 
| David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 71 |  | 
| Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 72 | /* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since | 
|  | 73 | * SIG_HOLD is only used by the deprecated SysV signal API. | 
|  | 74 | */ | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 75 | #define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2) | 
| Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 76 |  | 
| Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 77 | /* We take a few real-time signals for ourselves. May as well use the same names as glibc. */ | 
|  | 78 | #define SIGRTMIN (__libc_current_sigrtmin()) | 
|  | 79 | #define SIGRTMAX (__libc_current_sigrtmax()) | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 80 | int __libc_current_sigrtmin(void) __INTRODUCED_IN(21); | 
|  | 81 | int __libc_current_sigrtmax(void) __INTRODUCED_IN(21); | 
| Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 82 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 83 | extern const char* const sys_siglist[_NSIG]; | 
|  | 84 | extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */ | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 85 |  | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 86 | typedef __sighandler_t sig_t; /* BSD compatibility. */ | 
|  | 87 | typedef __sighandler_t sighandler_t; /* glibc compatibility. */ | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 88 |  | 
| Elliott Hughes | a0cd9bc | 2014-03-07 15:41:25 -0800 | [diff] [blame] | 89 | #define si_timerid si_tid /* glibc compatibility. */ | 
|  | 90 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 91 | #if defined(__LP64__) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 |  | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 93 | struct sigaction { | 
|  | 94 | unsigned int sa_flags; | 
|  | 95 | union { | 
|  | 96 | sighandler_t sa_handler; | 
|  | 97 | void (*sa_sigaction)(int, struct siginfo*, void*); | 
|  | 98 | }; | 
|  | 99 | sigset_t sa_mask; | 
|  | 100 | void (*sa_restorer)(void); | 
|  | 101 | }; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 102 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 103 | #elif defined(__mips__) | 
|  | 104 |  | 
|  | 105 | struct sigaction { | 
|  | 106 | unsigned int sa_flags; | 
|  | 107 | union { | 
|  | 108 | sighandler_t sa_handler; | 
|  | 109 | void (*sa_sigaction) (int, struct siginfo*, void*); | 
|  | 110 | }; | 
|  | 111 | sigset_t sa_mask; | 
|  | 112 | }; | 
|  | 113 |  | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 114 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 115 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 116 | int sigaction(int, const struct sigaction*, struct sigaction*); | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 117 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 118 | int siginterrupt(int, int); | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 119 |  | 
| Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 120 | #if __ANDROID_API__ >= 21 | 
| Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 121 | sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21); | 
|  | 122 | int sigaddset(sigset_t*, int) __INTRODUCED_IN(21); | 
|  | 123 | int sigdelset(sigset_t*, int) __INTRODUCED_IN(21); | 
|  | 124 | int sigemptyset(sigset_t*) __INTRODUCED_IN(21); | 
|  | 125 | int sigfillset(sigset_t*) __INTRODUCED_IN(21); | 
|  | 126 | int sigismember(const sigset_t*, int) __INTRODUCED_IN(21); | 
| Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 127 | #else | 
|  | 128 | // Implemented as static inlines before 21. | 
|  | 129 | #endif | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 130 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 131 | int sigpending(sigset_t* _Nonnull); | 
|  | 132 | int sigprocmask(int, const sigset_t*, sigset_t*); | 
|  | 133 | int sigsuspend(const sigset_t* _Nonnull); | 
|  | 134 | int sigwait(const sigset_t* _Nonnull, int* _Nonnull); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 135 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 136 | int sighold(int) | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 137 | __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) | 
|  | 138 | __INTRODUCED_IN_FUTURE; | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 139 | int sigignore(int) | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 140 | __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE; | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 141 | int sigpause(int) | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 142 | __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN_FUTURE; | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 143 | int sigrelse(int) | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 144 | __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) | 
|  | 145 | __INTRODUCED_IN_FUTURE; | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 146 | sighandler_t sigset(int, sighandler_t) | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 147 | __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE; | 
| Greg Hackmann | 5375bf6 | 2016-02-29 12:35:33 -0800 | [diff] [blame] | 148 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 149 | int raise(int); | 
|  | 150 | int kill(pid_t, int); | 
|  | 151 | int killpg(int, int); | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 152 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 153 | int sigaltstack(const stack_t*, stack_t*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 154 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 155 | void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17); | 
|  | 156 | void psignal(int, const char*) __INTRODUCED_IN(17); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 157 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 158 | int pthread_kill(pthread_t, int); | 
|  | 159 | int pthread_sigmask(int, const sigset_t*, sigset_t*); | 
| Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 160 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 161 | int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23); | 
|  | 162 | int sigtimedwait(const sigset_t* _Nonnull, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23); | 
|  | 163 | int sigwaitinfo(const sigset_t* _Nonnull, siginfo_t*) __INTRODUCED_IN(23); | 
|  | 164 |  | 
|  | 165 | #if defined(__clang__) | 
|  | 166 | #pragma clang diagnostic pop | 
|  | 167 | #endif | 
| Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 168 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 169 | __END_DECLS | 
|  | 170 |  | 
| Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 171 | #include <android/legacy_signal_inlines.h> | 
|  | 172 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 173 | #endif /* _SIGNAL_H_ */ |