signal.h revision 8778d64d5c78a42d5389767adcf232bfe323e0f8
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 <asm/sigcontext.h> 33#include <bits/pthread_types.h> 34#include <bits/timespec.h> 35#include <limits.h> 36#include <sys/cdefs.h> 37#include <sys/types.h> 38 39#if defined(__LP64__) || defined(__mips__) 40/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one, 41 * so we need to expose our own and translate behind the scenes. */ 42# define sigaction __kernel_sigaction 43# include <linux/signal.h> 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. */ 48# include <linux/signal.h> 49#endif 50 51#include <sys/ucontext.h> 52#define __BIONIC_HAVE_UCONTEXT_T 53 54__BEGIN_DECLS 55 56#if defined(__clang__) 57#pragma clang diagnostic push 58#pragma clang diagnostic ignored "-Wnullability-completeness" 59#endif 60 61typedef int sig_atomic_t; 62 63/* The arm and x86 kernel header files don't define _NSIG. */ 64#ifndef _KERNEL__NSIG 65#define _KERNEL__NSIG 64 66#endif 67 68/* Userspace's NSIG is the kernel's _NSIG + 1. */ 69#define _NSIG (_KERNEL__NSIG + 1) 70#define NSIG _NSIG 71 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 */ 75#define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2) 76 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()) 80int __libc_current_sigrtmin(void) __INTRODUCED_IN(21); 81int __libc_current_sigrtmax(void) __INTRODUCED_IN(21); 82 83extern const char* const sys_siglist[_NSIG]; 84extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */ 85 86typedef __sighandler_t sig_t; /* BSD compatibility. */ 87typedef __sighandler_t sighandler_t; /* glibc compatibility. */ 88 89#define si_timerid si_tid /* glibc compatibility. */ 90 91#if defined(__LP64__) 92 93struct 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}; 102 103#elif defined(__mips__) 104 105struct 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 114#endif 115 116int sigaction(int, const struct sigaction*, struct sigaction*); 117 118int siginterrupt(int, int); 119 120#if __ANDROID_API__ >= 21 121sighandler_t signal(int, sighandler_t); 122int sigaddset(sigset_t*, int); 123int sigdelset(sigset_t*, int); 124int sigemptyset(sigset_t*); 125int sigfillset(sigset_t*); 126int sigismember(const sigset_t*, int); 127#else 128// Implemented as static inlines before 21. 129#endif 130 131int sigpending(sigset_t* _Nonnull); 132int sigprocmask(int, const sigset_t*, sigset_t*); 133int sigsuspend(const sigset_t* _Nonnull); 134int sigwait(const sigset_t* _Nonnull, int* _Nonnull); 135 136int sighold(int) 137 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) 138 __INTRODUCED_IN_FUTURE; 139int sigignore(int) 140 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE; 141int sigpause(int) 142 __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN_FUTURE; 143int sigrelse(int) 144 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead"))) 145 __INTRODUCED_IN_FUTURE; 146sighandler_t sigset(int, sighandler_t) 147 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE; 148 149int raise(int); 150int kill(pid_t, int); 151int killpg(int, int); 152 153int sigaltstack(const stack_t*, stack_t*); 154 155void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17); 156void psignal(int, const char*) __INTRODUCED_IN(17); 157 158int pthread_kill(pthread_t, int); 159int pthread_sigmask(int, const sigset_t*, sigset_t*); 160 161int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23); 162int sigtimedwait(const sigset_t* _Nonnull, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23); 163int sigwaitinfo(const sigset_t* _Nonnull, siginfo_t*) __INTRODUCED_IN(23); 164 165#if defined(__clang__) 166#pragma clang diagnostic pop 167#endif 168 169__END_DECLS 170 171#include <android/legacy_signal_inlines.h> 172 173#endif /* _SIGNAL_H_ */ 174