blob: e326ddb1abe7599496e4cefb1b59adbf44aa03e9 [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 Hughesd8482b62013-11-20 12:51:52 -080047# define __ARCH_SI_UID_T __kernel_uid32_t /* TODO: 64-bit: remove this when we've switch 32-bit to uapi too. */
Elliott Hughes61fb3fc2013-11-07 12:28:46 -080048# include <linux/signal.h>
49# undef __ARCH_SI_UID_T
Elliott Hughesc7e9b232013-10-16 22:27:54 -070050#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052__BEGIN_DECLS
53
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020054typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055
Elliott Hughesd8482b62013-11-20 12:51:52 -080056/* TODO: 64-bit: we should probably #undef the uapi NSIG and add a unit test that NSIG == _NSIG && NSIG >= 64. */
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020057#ifndef _NSIG
Elliott Hughesd8482b62013-11-20 12:51:52 -080058# define _NSIG 64
59#endif
60#ifndef NSIG
61# define NSIG _NSIG
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020062#endif
63
Elliott Hughesda73f652012-11-30 16:40:55 -080064extern const char* const sys_siglist[];
65extern const char* const sys_signame[];
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080066
Elliott Hughesc7e9b232013-10-16 22:27:54 -070067typedef __sighandler_t sig_t; /* BSD compatibility. */
68typedef __sighandler_t sighandler_t; /* glibc compatibility. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069
Elliott Hughesd8482b62013-11-20 12:51:52 -080070#if defined(__LP64__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080071
Elliott Hughesc7e9b232013-10-16 22:27:54 -070072struct sigaction {
73 unsigned int sa_flags;
74 union {
75 sighandler_t sa_handler;
76 void (*sa_sigaction)(int, struct siginfo*, void*);
77 };
78 sigset_t sa_mask;
79 void (*sa_restorer)(void);
80};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080081
Elliott Hughesd8482b62013-11-20 12:51:52 -080082#elif defined(__mips__)
83
84struct 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};
92
Elliott Hughesc7e9b232013-10-16 22:27:54 -070093#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080094
Elliott Hughes40d105c2013-10-16 12:53:58 -070095extern int sigaction(int, const struct sigaction*, struct sigaction*);
Elliott Hughesc7e9b232013-10-16 22:27:54 -070096
97extern sighandler_t signal(int, sighandler_t);
98extern sighandler_t bsd_signal(int, sighandler_t);
99extern sighandler_t sysv_signal(int, sighandler_t);
100
Elliott Hughes40d105c2013-10-16 12:53:58 -0700101extern int siginterrupt(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700102
103extern int sigaddset(sigset_t*, int);
104extern int sigdelset(sigset_t*, int);
105extern int sigemptyset(sigset_t*);
106extern int sigfillset(sigset_t*);
107extern int sigismember(const sigset_t*, int);
108
Elliott Hughes40d105c2013-10-16 12:53:58 -0700109extern int sigpending(sigset_t*) __nonnull((1));
110extern int sigprocmask(int, const sigset_t*, sigset_t*);
111extern int sigsuspend(const sigset_t*) __nonnull((1));
112extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800113
114extern int raise(int);
115extern int kill(pid_t, int);
Elliott Hughes40d105c2013-10-16 12:53:58 -0700116extern int killpg(int, int);
Elliott Hughesc7e9b232013-10-16 22:27:54 -0700117
Elliott Hughes40d105c2013-10-16 12:53:58 -0700118extern int sigaltstack(const stack_t*, stack_t*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800119
Elliott Hughes40d105c2013-10-16 12:53:58 -0700120extern void psiginfo(const siginfo_t*, const char*);
121extern void psignal(int, const char*);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800122
123__END_DECLS
124
125#endif /* _SIGNAL_H_ */