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>
32 #include <limits.h>		/* For LONG_BIT */
33 #include <string.h>		/* For memset() */
34 #include <sys/types.h>
35 #include <asm/signal.h>
36 #include <asm/sigcontext.h>
37 
38 #define __ARCH_SI_UID_T __kernel_uid32_t
39 #include <asm/siginfo.h>
40 #undef __ARCH_SI_UID_T
41 
42 #include <sys/ucontext.h>
43 #define __BIONIC_HAVE_UCONTEXT_T
44 
45 __BEGIN_DECLS
46 
47 typedef int sig_atomic_t;
48 
49 /* _NSIG is used by the SIGRTMAX definition under <asm/signal.h>, however
50  * its definition is part of a #if __KERNEL__ .. #endif block in the original
51  * kernel headers and is thus not part of our cleaned-up versions.
52  *
53  * Looking at the current kernel sources, it is defined as 64 for all
54  * architectures except for the 'mips' one which set it to 128.
55  */
56 #ifndef _NSIG
57 #  define _NSIG  64
58 #endif
59 
60 extern const char * const sys_siglist[];
61 extern const char * const sys_signame[];
62 
sigismember(sigset_t * set,int signum)63 static __inline__ int sigismember(sigset_t *set, int signum)
64 {
65     unsigned long *local_set = (unsigned long *)set;
66     signum--;
67     return (int)((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1);
68 }
69 
70 
sigaddset(sigset_t * set,int signum)71 static __inline__ int sigaddset(sigset_t *set, int signum)
72 {
73     unsigned long *local_set = (unsigned long *)set;
74     signum--;
75     local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT);
76     return 0;
77 }
78 
79 
sigdelset(sigset_t * set,int signum)80 static __inline__ int sigdelset(sigset_t *set, int signum)
81 {
82     unsigned long *local_set = (unsigned long *)set;
83     signum--;
84     local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT));
85     return 0;
86 }
87 
88 
sigemptyset(sigset_t * set)89 static __inline__ int sigemptyset(sigset_t *set)
90 {
91     memset(set, 0, sizeof *set);
92     return 0;
93 }
94 
sigfillset(sigset_t * set)95 static __inline__ int sigfillset(sigset_t *set)
96 {
97     memset(set, ~0, sizeof *set);
98     return 0;
99 }
100 
101 
102 /* compatibility types */
103 typedef void  (*sig_t)(int);
104 typedef sig_t sighandler_t;
105 
106 /* differentiater between sysv and bsd behaviour 8*/
107 extern __sighandler_t sysv_signal(int, __sighandler_t);
108 extern __sighandler_t bsd_signal(int, __sighandler_t);
109 
110 /* the default is bsd */
signal(int s,__sighandler_t f)111 static __inline__ __sighandler_t signal(int s, __sighandler_t f)
112 {
113     return bsd_signal(s,f);
114 }
115 
116 /* the syscall itself */
117 extern __sighandler_t __signal(int, __sighandler_t, int);
118 
119 extern int sigprocmask(int, const sigset_t *, sigset_t *);
120 extern int sigaction(int, const struct sigaction *, struct sigaction *);
121 
122 extern int sigpending(sigset_t *);
123 extern int sigsuspend(const sigset_t *);
124 extern int sigwait(const sigset_t *set, int *sig);
125 extern int siginterrupt(int  sig, int  flag);
126 
127 extern int raise(int);
128 extern int kill(pid_t, int);
129 extern int killpg(int pgrp, int sig);
130 extern int sigaltstack(const stack_t *ss, stack_t *oss);
131 
132 
133 __END_DECLS
134 
135 #endif /* _SIGNAL_H_ */
136