The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 28 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _SIGNAL_H_ |
| 30 | #define _SIGNAL_H_ |
| 31 | |
Raghu Gandham | 93e7b9f | 2014-06-25 17:58:48 -0700 | [diff] [blame] | 32 | #include <asm/sigcontext.h> |
Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 33 | #include <errno.h> |
| 34 | #include <limits.h> |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame^] | 35 | #include <linux/time.h> |
Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 36 | #include <machine/pthread_types.h> |
| 37 | #include <string.h> |
| 38 | #include <sys/cdefs.h> |
| 39 | #include <sys/types.h> |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 40 | |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 41 | #if defined(__LP64__) || defined(__mips__) |
| 42 | /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one, |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 43 | * so we need to expose our own and translate behind the scenes. */ |
| 44 | # define sigaction __kernel_sigaction |
Elliott Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 45 | # include <linux/signal.h> |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 46 | # 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 Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 50 | # include <linux/signal.h> |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 51 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 52 | |
Elliott Hughes | 26a8eb5 | 2014-09-12 20:04:40 -0700 | [diff] [blame] | 53 | #include <sys/ucontext.h> |
| 54 | #define __BIONIC_HAVE_UCONTEXT_T |
| 55 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 56 | __BEGIN_DECLS |
| 57 | |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame] | 58 | typedef int sig_atomic_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 60 | /* The arm and x86 kernel header files don't define _NSIG. */ |
| 61 | #ifndef _KERNEL__NSIG |
| 62 | #define _KERNEL__NSIG 64 |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 63 | #endif |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 64 | |
| 65 | /* Userspace's NSIG is the kernel's _NSIG + 1. */ |
| 66 | #define _NSIG (_KERNEL__NSIG + 1) |
| 67 | #define NSIG _NSIG |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 68 | |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 69 | /* 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()) |
| 72 | extern int __libc_current_sigrtmin(void); |
| 73 | extern int __libc_current_sigrtmax(void); |
| 74 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 75 | extern const char* const sys_siglist[]; |
Elliott Hughes | 671e236 | 2014-02-12 19:04:27 -0800 | [diff] [blame] | 76 | extern const char* const sys_signame[]; /* BSD compatibility. */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 77 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 78 | typedef __sighandler_t sig_t; /* BSD compatibility. */ |
| 79 | typedef __sighandler_t sighandler_t; /* glibc compatibility. */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 | |
Elliott Hughes | a0cd9bc | 2014-03-07 15:41:25 -0800 | [diff] [blame] | 81 | #define si_timerid si_tid /* glibc compatibility. */ |
| 82 | |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 83 | #if defined(__LP64__) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 85 | struct sigaction { |
| 86 | unsigned int sa_flags; |
| 87 | union { |
| 88 | sighandler_t sa_handler; |
| 89 | void (*sa_sigaction)(int, struct siginfo*, void*); |
| 90 | }; |
| 91 | sigset_t sa_mask; |
| 92 | void (*sa_restorer)(void); |
| 93 | }; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 | |
Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame] | 95 | #elif defined(__mips__) |
| 96 | |
| 97 | struct sigaction { |
| 98 | unsigned int sa_flags; |
| 99 | union { |
| 100 | sighandler_t sa_handler; |
| 101 | void (*sa_sigaction) (int, struct siginfo*, void*); |
| 102 | }; |
| 103 | sigset_t sa_mask; |
| 104 | }; |
| 105 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 106 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 107 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 108 | extern int sigaction(int, const struct sigaction*, struct sigaction*); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 109 | |
| 110 | extern sighandler_t signal(int, sighandler_t); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 111 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 112 | extern int siginterrupt(int, int); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 113 | |
| 114 | extern int sigaddset(sigset_t*, int); |
| 115 | extern int sigdelset(sigset_t*, int); |
| 116 | extern int sigemptyset(sigset_t*); |
| 117 | extern int sigfillset(sigset_t*); |
| 118 | extern int sigismember(const sigset_t*, int); |
| 119 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 120 | extern int sigpending(sigset_t*) __nonnull((1)); |
| 121 | extern int sigprocmask(int, const sigset_t*, sigset_t*); |
| 122 | extern int sigsuspend(const sigset_t*) __nonnull((1)); |
| 123 | extern int sigwait(const sigset_t*, int*) __nonnull((1, 2)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 124 | |
| 125 | extern int raise(int); |
| 126 | extern int kill(pid_t, int); |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 127 | extern int killpg(int, int); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 128 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 129 | extern int sigaltstack(const stack_t*, stack_t*); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 130 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 131 | extern void psiginfo(const siginfo_t*, const char*); |
| 132 | extern void psignal(int, const char*); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 133 | |
Dan Albert | 75ef63d | 2014-11-21 00:18:07 -0800 | [diff] [blame] | 134 | extern int pthread_kill(pthread_t, int); |
| 135 | extern int pthread_sigmask(int, const sigset_t*, sigset_t*); |
| 136 | |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame^] | 137 | extern int sigqueue(pid_t, int, const union sigval); |
| 138 | extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*); |
| 139 | extern int sigwaitinfo(const sigset_t*, siginfo_t*); |
| 140 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 141 | __END_DECLS |
| 142 | |
| 143 | #endif /* _SIGNAL_H_ */ |