| 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 |  | 
| Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 32 | #include <errno.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 33 | #include <sys/cdefs.h> | 
| David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 34 | #include <limits.h>		/* For LONG_BIT */ | 
|  | 35 | #include <string.h>		/* For memset() */ | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | #include <sys/types.h> | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 37 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame^] | 38 | #if defined(__LP64__) || defined(__mips__) | 
|  | 39 | /* 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] | 40 | * so we need to expose our own and translate behind the scenes. */ | 
|  | 41 | #  define sigaction __kernel_sigaction | 
| Elliott Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 42 | #  include <linux/signal.h> | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 43 | #  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 Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame^] | 47 | #  define __ARCH_SI_UID_T __kernel_uid32_t /* TODO: 64-bit: remove this when we've switch 32-bit to uapi too. */ | 
| Elliott Hughes | 61fb3fc | 2013-11-07 12:28:46 -0800 | [diff] [blame] | 48 | #  include <linux/signal.h> | 
|  | 49 | #  undef __ARCH_SI_UID_T | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 50 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 52 | __BEGIN_DECLS | 
|  | 53 |  | 
| David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame] | 54 | typedef int sig_atomic_t; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 55 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame^] | 56 | /* TODO: 64-bit: we should probably #undef the uapi NSIG and add a unit test that NSIG == _NSIG && NSIG >= 64. */ | 
| David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 57 | #ifndef _NSIG | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame^] | 58 | #  define _NSIG 64 | 
|  | 59 | #endif | 
|  | 60 | #ifndef NSIG | 
|  | 61 | #  define NSIG _NSIG | 
| David 'Digit' Turner | c1b44ec | 2012-10-17 19:10:11 +0200 | [diff] [blame] | 62 | #endif | 
|  | 63 |  | 
| Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 64 | extern const char* const sys_siglist[]; | 
|  | 65 | extern const char* const sys_signame[]; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 66 |  | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 67 | typedef __sighandler_t sig_t; /* BSD compatibility. */ | 
|  | 68 | typedef __sighandler_t sighandler_t; /* glibc compatibility. */ | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 69 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame^] | 70 | #if defined(__LP64__) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 |  | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 72 | struct 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 Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 |  | 
| Elliott Hughes | d8482b6 | 2013-11-20 12:51:52 -0800 | [diff] [blame^] | 82 | #elif defined(__mips__) | 
|  | 83 |  | 
|  | 84 | struct 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 Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 93 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 |  | 
| Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 95 | extern int sigaction(int, const struct sigaction*, struct sigaction*); | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 96 |  | 
|  | 97 | extern sighandler_t signal(int, sighandler_t); | 
|  | 98 | extern sighandler_t bsd_signal(int, sighandler_t); | 
|  | 99 | extern sighandler_t sysv_signal(int, sighandler_t); | 
|  | 100 |  | 
| Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 101 | extern int siginterrupt(int, int); | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 102 |  | 
|  | 103 | extern int sigaddset(sigset_t*, int); | 
|  | 104 | extern int sigdelset(sigset_t*, int); | 
|  | 105 | extern int sigemptyset(sigset_t*); | 
|  | 106 | extern int sigfillset(sigset_t*); | 
|  | 107 | extern int sigismember(const sigset_t*, int); | 
|  | 108 |  | 
| Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 109 | extern int sigpending(sigset_t*) __nonnull((1)); | 
|  | 110 | extern int sigprocmask(int, const sigset_t*, sigset_t*); | 
|  | 111 | extern int sigsuspend(const sigset_t*) __nonnull((1)); | 
|  | 112 | 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] | 113 |  | 
|  | 114 | extern int raise(int); | 
|  | 115 | extern int kill(pid_t, int); | 
| Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 116 | extern int killpg(int, int); | 
| Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 117 |  | 
| Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 118 | extern int sigaltstack(const stack_t*, stack_t*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 119 |  | 
| Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 120 | extern void psiginfo(const siginfo_t*, const char*); | 
|  | 121 | extern void psignal(int, const char*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 122 |  | 
|  | 123 | __END_DECLS | 
|  | 124 |  | 
|  | 125 | #endif /* _SIGNAL_H_ */ |