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 | */ |
| 28 | #ifndef _SIGNAL_H_ |
| 29 | #define _SIGNAL_H_ |
| 30 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 31 | #include <errno.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 32 | #include <sys/cdefs.h> |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 33 | #include <limits.h> /* For LONG_BIT */ |
| 34 | #include <string.h> /* For memset() */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | #include <sys/types.h> |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 36 | #include <asm/signal.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 38 | #define __ARCH_SI_UID_T __kernel_uid32_t |
| 39 | #include <asm/siginfo.h> |
| 40 | #undef __ARCH_SI_UID_T |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 41 | |
| 42 | __BEGIN_DECLS |
| 43 | |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame] | 44 | typedef int sig_atomic_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | |
David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 46 | /* _NSIG is used by the SIGRTMAX definition under <asm/signal.h>, however |
| 47 | * its definition is part of a #if __KERNEL__ .. #endif block in the original |
| 48 | * kernel headers and is thus not part of our cleaned-up versions. |
| 49 | * |
| 50 | * Looking at the current kernel sources, it is defined as 64 for all |
| 51 | * architectures except for the 'mips' one which set it to 128. |
| 52 | */ |
| 53 | #ifndef _NSIG |
| 54 | # define _NSIG 64 |
| 55 | #endif |
| 56 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 57 | extern const char* const sys_siglist[]; |
| 58 | extern const char* const sys_signame[]; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | |
Kito Cheng | f373b11 | 2013-01-20 00:15:15 +0800 | [diff] [blame] | 60 | static __inline__ int sigismember(const sigset_t* set, int signum) { |
Elliott Hughes | fb5e5cb | 2013-01-07 13:58:49 -0800 | [diff] [blame] | 61 | int bit = signum - 1; // Signal numbers start at 1, but bit positions start at 0. |
Erik Gilling | 156ccf4 | 2013-05-29 16:26:23 -0700 | [diff] [blame] | 62 | const unsigned long* local_set = (const unsigned long*) set; |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 63 | if (set == NULL || bit < 0 || bit >= (int) (8*sizeof(sigset_t))) { |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 64 | errno = EINVAL; |
| 65 | return -1; |
| 66 | } |
Elliott Hughes | fb5e5cb | 2013-01-07 13:58:49 -0800 | [diff] [blame] | 67 | return (int) ((local_set[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 70 | static __inline__ int sigaddset(sigset_t* set, int signum) { |
Elliott Hughes | fb5e5cb | 2013-01-07 13:58:49 -0800 | [diff] [blame] | 71 | int bit = signum - 1; // Signal numbers start at 1, but bit positions start at 0. |
Erik Gilling | 156ccf4 | 2013-05-29 16:26:23 -0700 | [diff] [blame] | 72 | unsigned long* local_set = (unsigned long*) set; |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 73 | if (set == NULL || bit < 0 || bit >= (int) (8*sizeof(sigset_t))) { |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 74 | errno = EINVAL; |
| 75 | return -1; |
| 76 | } |
Elliott Hughes | fb5e5cb | 2013-01-07 13:58:49 -0800 | [diff] [blame] | 77 | local_set[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 78 | return 0; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 81 | static __inline__ int sigdelset(sigset_t* set, int signum) { |
Elliott Hughes | fb5e5cb | 2013-01-07 13:58:49 -0800 | [diff] [blame] | 82 | int bit = signum - 1; // Signal numbers start at 1, but bit positions start at 0. |
Erik Gilling | 156ccf4 | 2013-05-29 16:26:23 -0700 | [diff] [blame] | 83 | unsigned long* local_set = (unsigned long*) set; |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 84 | if (set == NULL || bit < 0 || bit >= (int) (8*sizeof(sigset_t))) { |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 85 | errno = EINVAL; |
| 86 | return -1; |
| 87 | } |
Elliott Hughes | fb5e5cb | 2013-01-07 13:58:49 -0800 | [diff] [blame] | 88 | local_set[bit / LONG_BIT] &= ~(1UL << (bit % LONG_BIT)); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 89 | return 0; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 92 | static __inline__ int sigemptyset(sigset_t* set) { |
| 93 | if (set == NULL) { |
| 94 | errno = EINVAL; |
| 95 | return -1; |
| 96 | } |
| 97 | memset(set, 0, sizeof *set); |
| 98 | return 0; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 101 | static __inline__ int sigfillset(sigset_t* set) { |
| 102 | if (set == NULL) { |
| 103 | errno = EINVAL; |
| 104 | return -1; |
| 105 | } |
| 106 | memset(set, ~0, sizeof *set); |
| 107 | return 0; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
| 111 | /* compatibility types */ |
| 112 | typedef void (*sig_t)(int); |
| 113 | typedef sig_t sighandler_t; |
| 114 | |
| 115 | /* differentiater between sysv and bsd behaviour 8*/ |
| 116 | extern __sighandler_t sysv_signal(int, __sighandler_t); |
| 117 | extern __sighandler_t bsd_signal(int, __sighandler_t); |
| 118 | |
| 119 | /* the default is bsd */ |
| 120 | static __inline__ __sighandler_t signal(int s, __sighandler_t f) |
| 121 | { |
| 122 | return bsd_signal(s,f); |
| 123 | } |
| 124 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 125 | extern int sigaction(int, const struct sigaction*, struct sigaction*); |
| 126 | extern int siginterrupt(int, int); |
| 127 | extern int sigpending(sigset_t*) __nonnull((1)); |
| 128 | extern int sigprocmask(int, const sigset_t*, sigset_t*); |
| 129 | extern int sigsuspend(const sigset_t*) __nonnull((1)); |
| 130 | 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] | 131 | |
| 132 | extern int raise(int); |
| 133 | extern int kill(pid_t, int); |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 134 | extern int killpg(int, int); |
| 135 | extern int sigaltstack(const stack_t*, stack_t*); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 136 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 137 | extern void psiginfo(const siginfo_t*, const char*); |
| 138 | extern void psignal(int, const char*); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 139 | |
| 140 | __END_DECLS |
| 141 | |
| 142 | #endif /* _SIGNAL_H_ */ |