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 | |
| 31 | #include <sys/cdefs.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 32 | #include <sys/types.h> |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame^] | 33 | #include <machine/signal.h> |
| 34 | #include <machine/ucontext.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame^] | 36 | #include <limits.h> /* For LONG_BIT */ |
| 37 | #include <string.h> /* For memset() */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 | |
| 39 | __BEGIN_DECLS |
| 40 | |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame^] | 41 | /* Previous versions of <signal.h> didn't define 'struct sigcontext'. This |
| 42 | * has led client code to redefine the structure, sometimes in a custom and |
| 43 | * incompatible way. |
David 'Digit' Turner | 5c8c00a | 2010-12-20 15:58:06 +0100 | [diff] [blame] | 44 | * |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame^] | 45 | * The __BIONIC_HAVE_STRUCT_SIGCONTEXT macro is defined in <sys/cdefs.h> |
| 46 | * to indicate that <signal.h> does indeed define the structure. For |
| 47 | * maximum source compatibility, client code should follow these guidelines: |
| 48 | * |
| 49 | * - If client code is guaranteed to build against a recent NDK/platform |
| 50 | * version, just include <signal.h> as usual, and use the |
| 51 | * 'struct sigcontext'. |
| 52 | * |
| 53 | * - If client code wants to build against older NDK/platform versions, |
| 54 | * and only uses 'struct sigcontext' without accessing _any_ |
| 55 | * of its fields, just always include <asm/sigcontext.h> on Android |
| 56 | * to ensure maximum portability (i.e. to old platform/NDK releases). |
| 57 | * As in: |
| 58 | * |
| 59 | * #include <signal.h> |
| 60 | * #ifdef __BIONIC__ |
| 61 | * #include <asm/sigcontext.h> |
| 62 | * #endif |
| 63 | * |
| 64 | * - Otherwise, if the client has a custom sigcontext definition and wants to |
| 65 | * keep it to minimize source changes, use a macro trick as below to avoid |
| 66 | * naming conflicts: |
| 67 | * |
| 68 | * #include <signal.h> |
| 69 | * #ifdef __BIONIC__ |
| 70 | * # include <asm/sigcontext.h> |
| 71 | * # ifdef __BIONIC_HAVE_STRUCT_SIGCONTEXT |
| 72 | * # undef sigcontext |
| 73 | * # define sigcontext my_custom_sigcontext |
| 74 | * # endif |
| 75 | * #endif |
David 'Digit' Turner | 5c8c00a | 2010-12-20 15:58:06 +0100 | [diff] [blame] | 76 | */ |
David 'Digit' Turner | c124baa | 2012-07-12 19:06:15 +0200 | [diff] [blame^] | 77 | |
| 78 | /* Similarly, previous versions of the C library didn't define ucontext_t |
| 79 | * and mcontext_t in <signal.h>, or <sys/ucontext.h>. Client code can check |
| 80 | * against the macro __BIONIC_HAVE_UCONTEXT_T to determine if it does. |
| 81 | * |
| 82 | * Beware, that does _not_ mean that <ucontext.h> and related functions are |
| 83 | * available. |
| 84 | */ |
| 85 | |
| 86 | typedef int sig_atomic_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | |
| 88 | extern const char * const sys_siglist[]; |
Thorsten Glaser | 81569aa | 2009-12-01 15:12:01 +0100 | [diff] [blame] | 89 | extern const char * const sys_signame[]; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 | |
| 91 | static __inline__ int sigismember(sigset_t *set, int signum) |
| 92 | { |
| 93 | unsigned long *local_set = (unsigned long *)set; |
| 94 | signum--; |
| 95 | return (int)((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | static __inline__ int sigaddset(sigset_t *set, int signum) |
| 100 | { |
| 101 | unsigned long *local_set = (unsigned long *)set; |
| 102 | signum--; |
| 103 | local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | static __inline__ int sigdelset(sigset_t *set, int signum) |
| 109 | { |
| 110 | unsigned long *local_set = (unsigned long *)set; |
| 111 | signum--; |
| 112 | local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT)); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | static __inline__ int sigemptyset(sigset_t *set) |
| 118 | { |
| 119 | memset(set, 0, sizeof *set); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static __inline__ int sigfillset(sigset_t *set) |
| 124 | { |
| 125 | memset(set, ~0, sizeof *set); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /* compatibility types */ |
| 131 | typedef void (*sig_t)(int); |
| 132 | typedef sig_t sighandler_t; |
| 133 | |
| 134 | /* differentiater between sysv and bsd behaviour 8*/ |
| 135 | extern __sighandler_t sysv_signal(int, __sighandler_t); |
| 136 | extern __sighandler_t bsd_signal(int, __sighandler_t); |
| 137 | |
| 138 | /* the default is bsd */ |
| 139 | static __inline__ __sighandler_t signal(int s, __sighandler_t f) |
| 140 | { |
| 141 | return bsd_signal(s,f); |
| 142 | } |
| 143 | |
| 144 | /* the syscall itself */ |
| 145 | extern __sighandler_t __signal(int, __sighandler_t, int); |
| 146 | |
| 147 | extern int sigprocmask(int, const sigset_t *, sigset_t *); |
| 148 | extern int sigaction(int, const struct sigaction *, struct sigaction *); |
| 149 | |
| 150 | extern int sigpending(sigset_t *); |
| 151 | extern int sigsuspend(const sigset_t *); |
| 152 | extern int sigwait(const sigset_t *set, int *sig); |
| 153 | extern int siginterrupt(int sig, int flag); |
| 154 | |
| 155 | extern int raise(int); |
| 156 | extern int kill(pid_t, int); |
Colin Cross | 8c59d96 | 2010-01-13 16:39:26 -0800 | [diff] [blame] | 157 | extern int killpg(int pgrp, int sig); |
David 'Digit' Turner | bb5581a | 2010-10-09 17:56:55 +0200 | [diff] [blame] | 158 | extern int sigaltstack(const stack_t *ss, stack_t *oss); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 159 | |
Irina Tirdea | b5f053b | 2012-09-08 09:17:54 +0300 | [diff] [blame] | 160 | extern void psiginfo(const siginfo_t* si, const char* message); |
| 161 | extern void psignal(int signal_number, const char* message); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 162 | |
| 163 | __END_DECLS |
| 164 | |
| 165 | #endif /* _SIGNAL_H_ */ |