blob: 89888880912f5c58b73ec2aff138b0e66b4452d6 [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>
Dan Albert75ef63d2014-11-21 00:18:07 -080033#include <limits.h>
34#include <machine/pthread_types.h>
Yabin Cuidb499032014-12-09 20:15:48 -080035#include <machine/timespec.h>
Dan Albert75ef63d2014-11-21 00:18:07 -080036#include <string.h>
37#include <sys/cdefs.h>
38#include <sys/types.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
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020057typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080058
Elliott Hughes199346a2014-02-11 20:01:11 -080059/* The arm and x86 kernel header files don't define _NSIG. */
60#ifndef _KERNEL__NSIG
61#define _KERNEL__NSIG 64
Elliott Hughesd8482b62013-11-20 12:51:52 -080062#endif
Elliott Hughes199346a2014-02-11 20:01:11 -080063
64/* Userspace's NSIG is the kernel's _NSIG + 1. */
65#define _NSIG (_KERNEL__NSIG + 1)
66#define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020067
Elliott Hughes0990d4f2014-04-30 09:45:40 -070068/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
69#define SIGRTMIN (__libc_current_sigrtmin())
70#define SIGRTMAX (__libc_current_sigrtmax())
71extern int __libc_current_sigrtmin(void);
72extern int __libc_current_sigrtmax(void);
73
Elliott Hughesda73f652012-11-30 16:40:55 -080074extern const char* const sys_siglist[];
Elliott Hughes671e2362014-02-12 19:04:27 -080075extern const char* const sys_signame[]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080076
Elliott Hughesc7e9b232013-10-16 22:27:54 -070077typedef __sighandler_t sig_t; /* BSD compatibility. */
78typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079
Elliott Hughesa0cd9bc2014-03-07 15:41:25 -080080#define si_timerid si_tid /* glibc compatibility. */
81
Elliott Hughesd8482b62013-11-20 12:51:52 -080082#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080083
Elliott Hughesc7e9b232013-10-16 22:27:54 -070084struct sigaction {
85 unsigned int sa_flags;
86 union {
87 sighandler_t sa_handler;
88 void (*sa_sigaction)(int, struct siginfo*, void*);
89 };
90 sigset_t sa_mask;
91 void (*sa_restorer)(void);
92};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093
Elliott Hughesd8482b62013-11-20 12:51:52 -080094#elif defined(__mips__)
95
96struct sigaction {
97 unsigned int sa_flags;
98 union {
99 sighandler_t sa_handler;
100 void (*sa_sigaction) (int, struct siginfo*, void*);
101 };
102 sigset_t sa_mask;
103};
104
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700105#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800106
Elliott Hughes40d105c2013-10-16 12:53:58 -0700107extern int sigaction(int, const struct sigaction*, struct sigaction*);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700108
109extern sighandler_t signal(int, sighandler_t);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700110
Elliott Hughes40d105c2013-10-16 12:53:58 -0700111extern int siginterrupt(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700112
113extern int sigaddset(sigset_t*, int);
114extern int sigdelset(sigset_t*, int);
115extern int sigemptyset(sigset_t*);
116extern int sigfillset(sigset_t*);
117extern int sigismember(const sigset_t*, int);
118
Elliott Hughes40d105c2013-10-16 12:53:58 -0700119extern int sigpending(sigset_t*) __nonnull((1));
120extern int sigprocmask(int, const sigset_t*, sigset_t*);
121extern int sigsuspend(const sigset_t*) __nonnull((1));
122extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800123
124extern int raise(int);
125extern int kill(pid_t, int);
Elliott Hughes40d105c2013-10-16 12:53:58 -0700126extern int killpg(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700127
Elliott Hughes40d105c2013-10-16 12:53:58 -0700128extern int sigaltstack(const stack_t*, stack_t*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800129
Elliott Hughes40d105c2013-10-16 12:53:58 -0700130extern void psiginfo(const siginfo_t*, const char*);
131extern void psignal(int, const char*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800132
Dan Albert75ef63d2014-11-21 00:18:07 -0800133extern int pthread_kill(pthread_t, int);
134extern int pthread_sigmask(int, const sigset_t*, sigset_t*);
135
Yabin Cui63481602014-12-01 17:41:04 -0800136extern int sigqueue(pid_t, int, const union sigval);
137extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*);
138extern int sigwaitinfo(const sigset_t*, siginfo_t*);
139
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800140__END_DECLS
141
142#endif /* _SIGNAL_H_ */