blob: 763bae982cea8effe296cb803ababe71a8c76d8e [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
Raghu Gandham93e7b9f2014-06-25 17:58:48 -070032#include <asm/sigcontext.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080033#include <bits/pthread_types.h>
34#include <bits/timespec.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080035#include <limits.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080036#include <sys/cdefs.h>
37#include <sys/types.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070038
Elliott Hughesd8482b62013-11-20 12:51:52 -080039#if defined(__LP64__) || defined(__mips__)
40/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
Elliott Hughesc7e9b232013-10-16 22:27:54 -070041 * so we need to expose our own and translate behind the scenes. */
42# define sigaction __kernel_sigaction
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080043# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070044# 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 Hughes61fb3fc2013-11-07 12:28:46 -080048# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070049#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080050
Elliott Hughes26a8eb52014-09-12 20:04:40 -070051#include <sys/ucontext.h>
52#define __BIONIC_HAVE_UCONTEXT_T
53
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054__BEGIN_DECLS
55
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020056typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
Elliott Hughes199346a2014-02-11 20:01:11 -080058/* The arm and x86 kernel header files don't define _NSIG. */
59#ifndef _KERNEL__NSIG
60#define _KERNEL__NSIG 64
Elliott Hughesd8482b62013-11-20 12:51:52 -080061#endif
Elliott Hughes199346a2014-02-11 20:01:11 -080062
63/* Userspace's NSIG is the kernel's _NSIG + 1. */
64#define _NSIG (_KERNEL__NSIG + 1)
65#define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020066
Greg Hackmann5375bf62016-02-29 12:35:33 -080067/* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since
68 * SIG_HOLD is only used by the deprecated SysV signal API.
69 */
70#define SIG_HOLD ((sighandler_t)(uintptr_t)2)
71
Elliott Hughes0990d4f2014-04-30 09:45:40 -070072/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
73#define SIGRTMIN (__libc_current_sigrtmin())
74#define SIGRTMAX (__libc_current_sigrtmax())
75extern int __libc_current_sigrtmin(void);
76extern int __libc_current_sigrtmax(void);
77
Elliott Hughesda73f652012-11-30 16:40:55 -080078extern const char* const sys_siglist[];
Elliott Hughes671e2362014-02-12 19:04:27 -080079extern const char* const sys_signame[]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080080
Elliott Hughesc7e9b232013-10-16 22:27:54 -070081typedef __sighandler_t sig_t; /* BSD compatibility. */
82typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080083
Elliott Hughesa0cd9bc2014-03-07 15:41:25 -080084#define si_timerid si_tid /* glibc compatibility. */
85
Elliott Hughesd8482b62013-11-20 12:51:52 -080086#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080087
Elliott Hughesc7e9b232013-10-16 22:27:54 -070088struct sigaction {
89 unsigned int sa_flags;
90 union {
91 sighandler_t sa_handler;
92 void (*sa_sigaction)(int, struct siginfo*, void*);
93 };
94 sigset_t sa_mask;
95 void (*sa_restorer)(void);
96};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080097
Elliott Hughesd8482b62013-11-20 12:51:52 -080098#elif defined(__mips__)
99
100struct sigaction {
101 unsigned int sa_flags;
102 union {
103 sighandler_t sa_handler;
104 void (*sa_sigaction) (int, struct siginfo*, void*);
105 };
106 sigset_t sa_mask;
107};
108
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700109#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800110
Elliott Hughes40d105c2013-10-16 12:53:58 -0700111extern int sigaction(int, const struct sigaction*, struct sigaction*);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700112
Dan Alberta6435a12015-08-06 14:32:25 -0700113extern sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700114
Elliott Hughes40d105c2013-10-16 12:53:58 -0700115extern int siginterrupt(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700116
Dan Alberta6435a12015-08-06 14:32:25 -0700117extern int sigaddset(sigset_t*, int) __INTRODUCED_IN(21);
118extern int sigdelset(sigset_t*, int) __INTRODUCED_IN(21);
119extern int sigemptyset(sigset_t*) __INTRODUCED_IN(21);
120extern int sigfillset(sigset_t*) __INTRODUCED_IN(21);
121extern int sigismember(const sigset_t*, int) __INTRODUCED_IN(21);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700122
Elliott Hughes40d105c2013-10-16 12:53:58 -0700123extern int sigpending(sigset_t*) __nonnull((1));
124extern int sigprocmask(int, const sigset_t*, sigset_t*);
125extern int sigsuspend(const sigset_t*) __nonnull((1));
126extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127
Greg Hackmann5375bf62016-02-29 12:35:33 -0800128extern int sighold(int) __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")));
129extern int sigignore(int) __attribute__((deprecated("use sigaction() instead")));
130extern int sigpause(int) __attribute__((deprecated("use sigsuspend() instead")));
131extern int sigrelse(int) __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")));
132extern sighandler_t sigset(int, sighandler_t) __attribute__((deprecated("use sigaction() instead")));
133
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800134extern int raise(int);
135extern int kill(pid_t, int);
Elliott Hughes40d105c2013-10-16 12:53:58 -0700136extern int killpg(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700137
Elliott Hughes40d105c2013-10-16 12:53:58 -0700138extern int sigaltstack(const stack_t*, stack_t*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800139
Elliott Hughes40d105c2013-10-16 12:53:58 -0700140extern void psiginfo(const siginfo_t*, const char*);
141extern void psignal(int, const char*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800142
Dan Albert75ef63d2014-11-21 00:18:07 -0800143extern int pthread_kill(pthread_t, int);
144extern int pthread_sigmask(int, const sigset_t*, sigset_t*);
145
Yabin Cui63481602014-12-01 17:41:04 -0800146extern int sigqueue(pid_t, int, const union sigval);
147extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*);
148extern int sigwaitinfo(const sigset_t*, siginfo_t*);
149
Dan Albert466dbe42015-01-28 18:16:08 -0800150#if __ANDROID_API__ < 21
151#include <android/legacy_signal_inlines.h>
152#endif
153
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800154__END_DECLS
155
156#endif /* _SIGNAL_H_ */