blob: ffce1fa3c8181fd56e927e5b36d93c6fc69f5cd5 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughesc7e9b232013-10-16 22:27:54 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _SIGNAL_H_
30#define _SIGNAL_H_
31
Josh Gao16016df2016-11-07 18:27:16 -080032#include <sys/cdefs.h>
33#include <sys/types.h>
34
Raghu Gandham93e7b9f2014-06-25 17:58:48 -070035#include <asm/sigcontext.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080036#include <bits/pthread_types.h>
37#include <bits/timespec.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080038#include <limits.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070039
Elliott Hughesd8482b62013-11-20 12:51:52 -080040#if defined(__LP64__) || defined(__mips__)
41/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
Elliott Hughesc7e9b232013-10-16 22:27:54 -070042 * so we need to expose our own and translate behind the scenes. */
43# define sigaction __kernel_sigaction
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080044# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070045# 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. */
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080049# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070050#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051
Elliott Hughes26a8eb52014-09-12 20:04:40 -070052#include <sys/ucontext.h>
53#define __BIONIC_HAVE_UCONTEXT_T
54
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055__BEGIN_DECLS
56
Elliott Hughes5470c182016-07-22 11:36:17 -070057#if defined(__clang__)
58#pragma clang diagnostic push
59#pragma clang diagnostic ignored "-Wnullability-completeness"
60#endif
61
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020062typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080063
Elliott Hughes199346a2014-02-11 20:01:11 -080064/* The arm and x86 kernel header files don't define _NSIG. */
65#ifndef _KERNEL__NSIG
66#define _KERNEL__NSIG 64
Elliott Hughesd8482b62013-11-20 12:51:52 -080067#endif
Elliott Hughes199346a2014-02-11 20:01:11 -080068
69/* Userspace's NSIG is the kernel's _NSIG + 1. */
70#define _NSIG (_KERNEL__NSIG + 1)
71#define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020072
Greg Hackmann5375bf62016-02-29 12:35:33 -080073/* 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 */
Elliott Hughes5470c182016-07-22 11:36:17 -070076#define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2)
Greg Hackmann5375bf62016-02-29 12:35:33 -080077
Elliott Hughes0990d4f2014-04-30 09:45:40 -070078/* 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())
Elliott Hughes5470c182016-07-22 11:36:17 -070081int __libc_current_sigrtmin(void) __INTRODUCED_IN(21);
82int __libc_current_sigrtmax(void) __INTRODUCED_IN(21);
Elliott Hughes0990d4f2014-04-30 09:45:40 -070083
Elliott Hughes5470c182016-07-22 11:36:17 -070084extern const char* const sys_siglist[_NSIG];
85extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086
Elliott Hughesc7e9b232013-10-16 22:27:54 -070087typedef __sighandler_t sig_t; /* BSD compatibility. */
88typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080089
Elliott Hughesa0cd9bc2014-03-07 15:41:25 -080090#define si_timerid si_tid /* glibc compatibility. */
91
Elliott Hughesd8482b62013-11-20 12:51:52 -080092#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093
Elliott Hughesc7e9b232013-10-16 22:27:54 -070094struct 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};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800103
Elliott Hughesd8482b62013-11-20 12:51:52 -0800104#elif defined(__mips__)
105
106struct 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
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700115#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800116
Elliott Hughes5470c182016-07-22 11:36:17 -0700117int sigaction(int, const struct sigaction*, struct sigaction*);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700118
Elliott Hughes5470c182016-07-22 11:36:17 -0700119int siginterrupt(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700120
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800121#if __ANDROID_API__ >= __ANDROID_API_L__
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700122sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21);
123int sigaddset(sigset_t*, int) __INTRODUCED_IN(21);
124int sigdelset(sigset_t*, int) __INTRODUCED_IN(21);
125int sigemptyset(sigset_t*) __INTRODUCED_IN(21);
126int sigfillset(sigset_t*) __INTRODUCED_IN(21);
127int sigismember(const sigset_t*, int) __INTRODUCED_IN(21);
Josh Gao8778d642016-07-22 15:26:36 -0700128#else
129// Implemented as static inlines before 21.
130#endif
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700131
Elliott Hughes5470c182016-07-22 11:36:17 -0700132int sigpending(sigset_t* _Nonnull);
133int sigprocmask(int, const sigset_t*, sigset_t*);
134int sigsuspend(const sigset_t* _Nonnull);
135int sigwait(const sigset_t* _Nonnull, int* _Nonnull);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800136
Elliott Hughes5470c182016-07-22 11:36:17 -0700137int sighold(int)
Josh Gao34c599a2016-04-29 13:45:25 -0700138 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
139 __INTRODUCED_IN_FUTURE;
Elliott Hughes5470c182016-07-22 11:36:17 -0700140int sigignore(int)
Josh Gao34c599a2016-04-29 13:45:25 -0700141 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE;
Elliott Hughes5470c182016-07-22 11:36:17 -0700142int sigpause(int)
Josh Gao34c599a2016-04-29 13:45:25 -0700143 __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN_FUTURE;
Elliott Hughes5470c182016-07-22 11:36:17 -0700144int sigrelse(int)
Josh Gao34c599a2016-04-29 13:45:25 -0700145 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
146 __INTRODUCED_IN_FUTURE;
Elliott Hughes5470c182016-07-22 11:36:17 -0700147sighandler_t sigset(int, sighandler_t)
Josh Gao34c599a2016-04-29 13:45:25 -0700148 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE;
Greg Hackmann5375bf62016-02-29 12:35:33 -0800149
Elliott Hughes5470c182016-07-22 11:36:17 -0700150int raise(int);
151int kill(pid_t, int);
152int killpg(int, int);
Josh Gaod3cfd262017-01-05 13:22:26 -0800153int tgkill(int tgid, int tid, int sig) __INTRODUCED_IN_32(16);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700154
Elliott Hughes5470c182016-07-22 11:36:17 -0700155int sigaltstack(const stack_t*, stack_t*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800156
Elliott Hughes5470c182016-07-22 11:36:17 -0700157void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17);
158void psignal(int, const char*) __INTRODUCED_IN(17);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800159
Elliott Hughes5470c182016-07-22 11:36:17 -0700160int pthread_kill(pthread_t, int);
161int pthread_sigmask(int, const sigset_t*, sigset_t*);
Dan Albert75ef63d2014-11-21 00:18:07 -0800162
Elliott Hughes5470c182016-07-22 11:36:17 -0700163int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23);
164int sigtimedwait(const sigset_t* _Nonnull, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23);
165int sigwaitinfo(const sigset_t* _Nonnull, siginfo_t*) __INTRODUCED_IN(23);
166
167#if defined(__clang__)
168#pragma clang diagnostic pop
169#endif
Yabin Cui63481602014-12-01 17:41:04 -0800170
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800171__END_DECLS
172
Josh Gaob8e1b7052016-04-13 17:18:20 -0700173#include <android/legacy_signal_inlines.h>
174
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800175#endif /* _SIGNAL_H_ */