blob: 7d15edade8d3aabefa84f935a97a917c2739bad4 [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
Elliott Hughesda73f652012-11-30 16:40:55 -080032#include <errno.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080033#include <sys/cdefs.h>
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020034#include <limits.h> /* For LONG_BIT */
35#include <string.h> /* For memset() */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036#include <sys/types.h>
Chiou-Hao Hsu2415f1f2014-07-02 18:46:28 -070037#if defined(__LP64__)
Raghu Gandham93e7b9f2014-06-25 17:58:48 -070038#include <asm/sigcontext.h>
Chiou-Hao Hsu2415f1f2014-07-02 18:46:28 -070039#endif
Elliott Hughesc7e9b232013-10-16 22:27:54 -070040
Elliott Hughesd8482b62013-11-20 12:51:52 -080041#if defined(__LP64__) || defined(__mips__)
42/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
Elliott Hughesc7e9b232013-10-16 22:27:54 -070043 * so we need to expose our own and translate behind the scenes. */
44# define sigaction __kernel_sigaction
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080045# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070046# undef sigaction
47#else
48/* For 32-bit, we're stuck with the definitions we already shipped,
49 * even though they contain a sigset_t that's too small. */
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080050# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070051#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080053__BEGIN_DECLS
54
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020055typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080056
Elliott Hughes199346a2014-02-11 20:01:11 -080057/* The arm and x86 kernel header files don't define _NSIG. */
58#ifndef _KERNEL__NSIG
59#define _KERNEL__NSIG 64
Elliott Hughesd8482b62013-11-20 12:51:52 -080060#endif
Elliott Hughes199346a2014-02-11 20:01:11 -080061
62/* Userspace's NSIG is the kernel's _NSIG + 1. */
63#define _NSIG (_KERNEL__NSIG + 1)
64#define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020065
Elliott Hughes0990d4f2014-04-30 09:45:40 -070066/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
67#define SIGRTMIN (__libc_current_sigrtmin())
68#define SIGRTMAX (__libc_current_sigrtmax())
69extern int __libc_current_sigrtmin(void);
70extern int __libc_current_sigrtmax(void);
71
Elliott Hughesda73f652012-11-30 16:40:55 -080072extern const char* const sys_siglist[];
Elliott Hughes671e2362014-02-12 19:04:27 -080073extern const char* const sys_signame[]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080074
Elliott Hughesc7e9b232013-10-16 22:27:54 -070075typedef __sighandler_t sig_t; /* BSD compatibility. */
76typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080077
Elliott Hughesa0cd9bc2014-03-07 15:41:25 -080078#define si_timerid si_tid /* glibc compatibility. */
79
Elliott Hughesd8482b62013-11-20 12:51:52 -080080#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080081
Elliott Hughesc7e9b232013-10-16 22:27:54 -070082struct sigaction {
83 unsigned int sa_flags;
84 union {
85 sighandler_t sa_handler;
86 void (*sa_sigaction)(int, struct siginfo*, void*);
87 };
88 sigset_t sa_mask;
89 void (*sa_restorer)(void);
90};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080091
Elliott Hughesd8482b62013-11-20 12:51:52 -080092#elif defined(__mips__)
93
94struct 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};
102
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700103#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800104
Elliott Hughes40d105c2013-10-16 12:53:58 -0700105extern int sigaction(int, const struct sigaction*, struct sigaction*);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700106
107extern sighandler_t signal(int, sighandler_t);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700108
Elliott Hughes40d105c2013-10-16 12:53:58 -0700109extern int siginterrupt(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700110
111extern int sigaddset(sigset_t*, int);
112extern int sigdelset(sigset_t*, int);
113extern int sigemptyset(sigset_t*);
114extern int sigfillset(sigset_t*);
115extern int sigismember(const sigset_t*, int);
116
Elliott Hughes40d105c2013-10-16 12:53:58 -0700117extern int sigpending(sigset_t*) __nonnull((1));
118extern int sigprocmask(int, const sigset_t*, sigset_t*);
119extern int sigsuspend(const sigset_t*) __nonnull((1));
120extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800121
122extern int raise(int);
123extern int kill(pid_t, int);
Elliott Hughes40d105c2013-10-16 12:53:58 -0700124extern int killpg(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700125
Elliott Hughes40d105c2013-10-16 12:53:58 -0700126extern int sigaltstack(const stack_t*, stack_t*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127
Elliott Hughes40d105c2013-10-16 12:53:58 -0700128extern void psiginfo(const siginfo_t*, const char*);
129extern void psignal(int, const char*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130
131__END_DECLS
132
133#endif /* _SIGNAL_H_ */