blob: 29bef573c83a7163097ed1e81450f97130f1ceed [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>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070037
Elliott Hughesd8482b62013-11-20 12:51:52 -080038#if defined(__LP64__) || defined(__mips__)
39/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
Elliott Hughesc7e9b232013-10-16 22:27:54 -070040 * so we need to expose our own and translate behind the scenes. */
41# define sigaction __kernel_sigaction
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080042# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070043# undef sigaction
44#else
45/* For 32-bit, we're stuck with the definitions we already shipped,
46 * even though they contain a sigset_t that's too small. */
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080047# include <linux/signal.h>
Elliott Hughesc7e9b232013-10-16 22:27:54 -070048#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080050__BEGIN_DECLS
51
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020052typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080053
Elliott Hughes199346a2014-02-11 20:01:11 -080054/* The arm and x86 kernel header files don't define _NSIG. */
55#ifndef _KERNEL__NSIG
56#define _KERNEL__NSIG 64
Elliott Hughesd8482b62013-11-20 12:51:52 -080057#endif
Elliott Hughes199346a2014-02-11 20:01:11 -080058
59/* Userspace's NSIG is the kernel's _NSIG + 1. */
60#define _NSIG (_KERNEL__NSIG + 1)
61#define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020062
Elliott Hughesda73f652012-11-30 16:40:55 -080063extern const char* const sys_siglist[];
Elliott Hughes671e2362014-02-12 19:04:27 -080064extern const char* const sys_signame[]; /* BSD compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065
Elliott Hughesc7e9b232013-10-16 22:27:54 -070066typedef __sighandler_t sig_t; /* BSD compatibility. */
67typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080068
Elliott Hughesd8482b62013-11-20 12:51:52 -080069#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080070
Elliott Hughesc7e9b232013-10-16 22:27:54 -070071struct sigaction {
72 unsigned int sa_flags;
73 union {
74 sighandler_t sa_handler;
75 void (*sa_sigaction)(int, struct siginfo*, void*);
76 };
77 sigset_t sa_mask;
78 void (*sa_restorer)(void);
79};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080080
Elliott Hughesd8482b62013-11-20 12:51:52 -080081#elif defined(__mips__)
82
83struct sigaction {
84 unsigned int sa_flags;
85 union {
86 sighandler_t sa_handler;
87 void (*sa_sigaction) (int, struct siginfo*, void*);
88 };
89 sigset_t sa_mask;
90};
91
Elliott Hughesc7e9b232013-10-16 22:27:54 -070092#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093
Elliott Hughes40d105c2013-10-16 12:53:58 -070094extern int sigaction(int, const struct sigaction*, struct sigaction*);
Elliott Hughesc7e9b232013-10-16 22:27:54 -070095
96extern sighandler_t signal(int, sighandler_t);
97extern sighandler_t bsd_signal(int, sighandler_t);
98extern sighandler_t sysv_signal(int, sighandler_t);
99
Elliott Hughes40d105c2013-10-16 12:53:58 -0700100extern int siginterrupt(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700101
102extern int sigaddset(sigset_t*, int);
103extern int sigdelset(sigset_t*, int);
104extern int sigemptyset(sigset_t*);
105extern int sigfillset(sigset_t*);
106extern int sigismember(const sigset_t*, int);
107
Elliott Hughes40d105c2013-10-16 12:53:58 -0700108extern int sigpending(sigset_t*) __nonnull((1));
109extern int sigprocmask(int, const sigset_t*, sigset_t*);
110extern int sigsuspend(const sigset_t*) __nonnull((1));
111extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800112
113extern int raise(int);
114extern int kill(pid_t, int);
Elliott Hughes40d105c2013-10-16 12:53:58 -0700115extern int killpg(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700116
Elliott Hughes40d105c2013-10-16 12:53:58 -0700117extern int sigaltstack(const stack_t*, stack_t*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800118
Elliott Hughes40d105c2013-10-16 12:53:58 -0700119extern void psiginfo(const siginfo_t*, const char*);
120extern void psignal(int, const char*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800121
122__END_DECLS
123
124#endif /* _SIGNAL_H_ */