blob: 61bb395fa6f303db378a828f1d887fd924de5911 [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 Hughesa40640d2017-12-13 14:49:21 -080040/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the
41 * POSIX one, so we need to expose our own and translate behind the scenes.
42 * For 32-bit, we're stuck with the definitions we already shipped,
Elliott Hughesc7e9b232013-10-16 22:27:54 -070043 * even though they contain a sigset_t that's too small. */
Elliott Hughesa40640d2017-12-13 14:49:21 -080044#define sigaction __kernel_sigaction
45#include <linux/signal.h>
46#undef sigaction
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047
Elliott Hughes26a8eb52014-09-12 20:04:40 -070048#include <sys/ucontext.h>
49#define __BIONIC_HAVE_UCONTEXT_T
50
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051__BEGIN_DECLS
52
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020053typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054
Elliott Hughes199346a2014-02-11 20:01:11 -080055/* The arm and x86 kernel header files don't define _NSIG. */
56#ifndef _KERNEL__NSIG
57#define _KERNEL__NSIG 64
Elliott Hughesd8482b62013-11-20 12:51:52 -080058#endif
Elliott Hughes199346a2014-02-11 20:01:11 -080059
60/* Userspace's NSIG is the kernel's _NSIG + 1. */
61#define _NSIG (_KERNEL__NSIG + 1)
62#define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020063
Greg Hackmann5375bf62016-02-29 12:35:33 -080064/* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since
65 * SIG_HOLD is only used by the deprecated SysV signal API.
66 */
Elliott Hughes5470c182016-07-22 11:36:17 -070067#define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2)
Greg Hackmann5375bf62016-02-29 12:35:33 -080068
Elliott Hughes0990d4f2014-04-30 09:45:40 -070069/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
70#define SIGRTMIN (__libc_current_sigrtmin())
71#define SIGRTMAX (__libc_current_sigrtmax())
Elliott Hughes5470c182016-07-22 11:36:17 -070072int __libc_current_sigrtmin(void) __INTRODUCED_IN(21);
73int __libc_current_sigrtmax(void) __INTRODUCED_IN(21);
Elliott Hughes0990d4f2014-04-30 09:45:40 -070074
Elliott Hughes5470c182016-07-22 11:36:17 -070075extern const char* const sys_siglist[_NSIG];
76extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080077
Elliott Hughesc7e9b232013-10-16 22:27:54 -070078typedef __sighandler_t sig_t; /* BSD compatibility. */
79typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080080
Elliott Hughesa0cd9bc2014-03-07 15:41:25 -080081#define si_timerid si_tid /* glibc compatibility. */
82
Elliott Hughes5905d6f2018-01-30 15:09:51 -080083/* sigset_t is already large enough on LP64, but LP32's sigset_t is just `unsigned long`. */
84#if defined(__LP64__)
85typedef sigset_t sigset64_t;
86#else
87typedef struct { unsigned long __bits[_KERNEL__NSIG/LONG_BIT]; } sigset64_t;
88#endif
89
Elliott Hughesd8482b62013-11-20 12:51:52 -080090#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080091
Elliott Hughesc7e9b232013-10-16 22:27:54 -070092struct sigaction {
Elliott Hughesa40640d2017-12-13 14:49:21 -080093 int sa_flags;
Elliott Hughesc7e9b232013-10-16 22:27:54 -070094 union {
95 sighandler_t sa_handler;
96 void (*sa_sigaction)(int, struct siginfo*, void*);
97 };
98 sigset_t sa_mask;
99 void (*sa_restorer)(void);
100};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800101
Elliott Hughesd8482b62013-11-20 12:51:52 -0800102#elif defined(__mips__)
103
104struct sigaction {
Elliott Hughesa40640d2017-12-13 14:49:21 -0800105 int sa_flags;
Elliott Hughesd8482b62013-11-20 12:51:52 -0800106 union {
107 sighandler_t sa_handler;
108 void (*sa_sigaction) (int, struct siginfo*, void*);
109 };
110 sigset_t sa_mask;
111};
112
Elliott Hughesa40640d2017-12-13 14:49:21 -0800113#else
114
115struct sigaction {
116 union {
117 sighandler_t _sa_handler;
118 void (*_sa_sigaction)(int, struct siginfo*, void*);
119 } _u;
120 sigset_t sa_mask;
121 int sa_flags;
122 void (*sa_restorer)(void);
123};
124
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700125#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800126
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800127// TODO: sigaction contains a sigset_t that's too small on LP32.
Elliott Hughesfaa74342017-08-11 17:34:44 -0700128int sigaction(int __signal, const struct sigaction* __new_action, struct sigaction* __old_action);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700129
Elliott Hughesfaa74342017-08-11 17:34:44 -0700130int siginterrupt(int __signal, int __flag);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700131
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800132#if __ANDROID_API__ >= __ANDROID_API_L__
Elliott Hughesfaa74342017-08-11 17:34:44 -0700133sighandler_t signal(int __signal, sighandler_t __handler) __INTRODUCED_IN(21);
134int sigaddset(sigset_t* __set, int __signal) __INTRODUCED_IN(21);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800135int sigaddset64(sigset64_t* __set, int __signal) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700136int sigdelset(sigset_t* __set, int __signal) __INTRODUCED_IN(21);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800137int sigdelset64(sigset64_t* __set, int __signal) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700138int sigemptyset(sigset_t* __set) __INTRODUCED_IN(21);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800139int sigemptyset64(sigset64_t* __set) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700140int sigfillset(sigset_t* __set) __INTRODUCED_IN(21);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800141int sigfillset64(sigset64_t* __set) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700142int sigismember(const sigset_t* __set, int __signal) __INTRODUCED_IN(21);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800143int sigismember64(const sigset64_t* __set, int __signal) __INTRODUCED_IN(28);
Josh Gao8778d642016-07-22 15:26:36 -0700144#else
145// Implemented as static inlines before 21.
146#endif
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700147
Elliott Hughesfaa74342017-08-11 17:34:44 -0700148int sigpending(sigset_t* __set);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800149int sigpending64(sigset64_t* __set) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700150int sigprocmask(int __how, const sigset_t* __new_set, sigset_t* __old_set);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800151int sigprocmask64(int __how, const sigset64_t* __new_set, sigset64_t* __old_set) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700152int sigsuspend(const sigset_t* __mask);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800153int sigsuspend64(const sigset64_t* __mask) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700154int sigwait(const sigset_t* __set, int* __signal);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800155int sigwait64(const sigset64_t* __set, int* __signal) __INTRODUCED_IN(28);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800156
Elliott Hughesfaa74342017-08-11 17:34:44 -0700157int sighold(int __signal)
Josh Gao34c599a2016-04-29 13:45:25 -0700158 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
Josh Gao2e8e5e62017-04-20 12:58:31 -0700159 __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700160int sigignore(int __signal)
Josh Gao2e8e5e62017-04-20 12:58:31 -0700161 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700162int sigpause(int __signal)
Josh Gao2e8e5e62017-04-20 12:58:31 -0700163 __attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700164int sigrelse(int __signal)
Josh Gao34c599a2016-04-29 13:45:25 -0700165 __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
Josh Gao2e8e5e62017-04-20 12:58:31 -0700166 __INTRODUCED_IN(26);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700167sighandler_t sigset(int __signal, sighandler_t __handler)
Josh Gao2e8e5e62017-04-20 12:58:31 -0700168 __attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN(26);
Greg Hackmann5375bf62016-02-29 12:35:33 -0800169
Elliott Hughesfaa74342017-08-11 17:34:44 -0700170int raise(int __signal);
171int kill(pid_t __pid, int __signal);
172int killpg(int __pgrp, int __signal);
173int tgkill(int __tgid, int __tid, int __signal) __INTRODUCED_IN_32(16);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700174
Elliott Hughesfaa74342017-08-11 17:34:44 -0700175int sigaltstack(const stack_t* __new_signal_stack, stack_t* __old_signal_stack);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800176
Elliott Hughesfaa74342017-08-11 17:34:44 -0700177void psiginfo(const siginfo_t* __info, const char* __msg) __INTRODUCED_IN(17);
178void psignal(int __signal, const char* __msg) __INTRODUCED_IN(17);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800179
Elliott Hughesfaa74342017-08-11 17:34:44 -0700180int pthread_kill(pthread_t __pthread, int __signal);
181int pthread_sigmask(int __how, const sigset_t* __new_set, sigset_t* __old_set);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800182int pthread_sigmask64(int __how, const sigset64_t* __new_set, sigset64_t* __old_set) __INTRODUCED_IN(28);
Dan Albert75ef63d2014-11-21 00:18:07 -0800183
Elliott Hughesfaa74342017-08-11 17:34:44 -0700184int sigqueue(pid_t __pid, int __signal, const union sigval __value) __INTRODUCED_IN(23);
185int sigtimedwait(const sigset_t* __set, siginfo_t* __info, const struct timespec* __timeout) __INTRODUCED_IN(23);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800186int sigtimedwait64(const sigset64_t* __set, siginfo_t* __info, const struct timespec* __timeout) __INTRODUCED_IN(28);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700187int sigwaitinfo(const sigset_t* __set, siginfo_t* __info) __INTRODUCED_IN(23);
Elliott Hughes5905d6f2018-01-30 15:09:51 -0800188int sigwaitinfo64(const sigset64_t* __set, siginfo_t* __info) __INTRODUCED_IN(28);
Yabin Cui63481602014-12-01 17:41:04 -0800189
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800190__END_DECLS
191
Josh Gaob8e1b7052016-04-13 17:18:20 -0700192#include <android/legacy_signal_inlines.h>
193
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800194#endif /* _SIGNAL_H_ */