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/timespec.h> 38 #include <limits.h> 39 40 #if defined(__LP64__) || defined(__mips__) 41 /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one, 42 * so we need to expose our own and translate behind the scenes. */ 43 # define sigaction __kernel_sigaction 44 # include <linux/signal.h> 45 # undef sigaction 46 #else 47 /* For 32-bit, we're stuck with the definitions we already shipped, 48 * even though they contain a sigset_t that's too small. */ 49 # include <linux/signal.h> 50 #endif 51 52 #include <sys/ucontext.h> 53 #define __BIONIC_HAVE_UCONTEXT_T 54 55 __BEGIN_DECLS 56 57 #if defined(__clang__) 58 #pragma clang diagnostic push 59 #pragma clang diagnostic ignored "-Wnullability-completeness" 60 #endif 61 62 typedef int sig_atomic_t; 63 64 /* The arm and x86 kernel header files don't define _NSIG. */ 65 #ifndef _KERNEL__NSIG 66 #define _KERNEL__NSIG 64 67 #endif 68 69 /* Userspace's NSIG is the kernel's _NSIG + 1. */ 70 #define _NSIG (_KERNEL__NSIG + 1) 71 #define NSIG _NSIG 72 73 /* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since 74 * SIG_HOLD is only used by the deprecated SysV signal API. 75 */ 76 #define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2) 77 78 /* We take a few real-time signals for ourselves. May as well use the same names as glibc. */ 79 #define SIGRTMIN (__libc_current_sigrtmin()) 80 #define SIGRTMAX (__libc_current_sigrtmax()) 81 int __libc_current_sigrtmin(void) __INTRODUCED_IN(21); 82 int __libc_current_sigrtmax(void) __INTRODUCED_IN(21); 83 84 extern const char* const sys_siglist[_NSIG]; 85 extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */ 86 87 typedef __sighandler_t sig_t; /* BSD compatibility. */ 88 typedef __sighandler_t sighandler_t; /* glibc compatibility. */ 89 90 #define si_timerid si_tid /* glibc compatibility. */ 91 92 #if defined(__LP64__) 93 94 struct sigaction { 95 unsigned int sa_flags; 96 union { 97 sighandler_t sa_handler; 98 void (*sa_sigaction)(int, struct siginfo*, void*); 99 }; 100 sigset_t sa_mask; 101 void (*sa_restorer)(void); 102 }; 103 104 #elif defined(__mips__) 105 106 struct sigaction { 107 unsigned int sa_flags; 108 union { 109 sighandler_t sa_handler; 110 void (*sa_sigaction) (int, struct siginfo*, void*); 111 }; 112 sigset_t sa_mask; 113 }; 114 115 #endif 116 117 int sigaction(int, const struct sigaction*, struct sigaction*); 118 119 int siginterrupt(int, int); 120 121 #if __ANDROID_API__ >= __ANDROID_API_L__ 122 sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21); 123 int sigaddset(sigset_t*, int) __INTRODUCED_IN(21); 124 int sigdelset(sigset_t*, int) __INTRODUCED_IN(21); 125 int sigemptyset(sigset_t*) __INTRODUCED_IN(21); 126 int sigfillset(sigset_t*) __INTRODUCED_IN(21); 127 int sigismember(const sigset_t*, int) __INTRODUCED_IN(21); 128 #else 129 // Implemented as static inlines before 21. 130 #endif 131 132 int sigpending(sigset_t* _Nonnull); 133 int sigprocmask(int, const sigset_t*, sigset_t*); 134 int sigsuspend(const sigset_t* _Nonnull); 135 int sigwait(const sigset_t* _Nonnull, int* _Nonnull); 136 137 int sighold(int) 138 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) 139 __INTRODUCED_IN(26); 140 int sigignore(int) 141 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN(26); 142 int sigpause(int) 143 __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN(26); 144 int sigrelse(int) 145 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) 146 __INTRODUCED_IN(26); 147 sighandler_t sigset(int, sighandler_t) 148 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN(26); 149 150 int raise(int); 151 int kill(pid_t, int); 152 int killpg(int, int); 153 int tgkill(int tgid, int tid, int sig) __INTRODUCED_IN_32(16); 154 155 int sigaltstack(const stack_t*, stack_t*); 156 157 void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17); 158 void psignal(int, const char*) __INTRODUCED_IN(17); 159 160 int pthread_kill(pthread_t, int); 161 int pthread_sigmask(int, const sigset_t*, sigset_t*); 162 163 int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23); 164 int sigtimedwait(const sigset_t* _Nonnull, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23); 165 int sigwaitinfo(const sigset_t* _Nonnull, siginfo_t*) __INTRODUCED_IN(23); 166 167 #if defined(__clang__) 168 #pragma clang diagnostic pop 169 #endif 170 171 __END_DECLS 172 173 #include <android/legacy_signal_inlines.h> 174 175 #endif /* _SIGNAL_H_ */ 176