• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Derived from gdk/platforms/android-14/arch-arm/usr/include/signal.h
3  *
4  * Copyright (C) 2008 The Android Open Source Project
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *  * Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 #ifndef _SIGNAL_PORTABLE_H_
31 #define _SIGNAL_PORTABLE_H_
32 
33 #include <portability.h>
34 #include <sys/cdefs.h>
35 #include <limits.h>             /* For LONG_BIT */
36 #include <string.h>             /* For memset() */
37 #include <signal.h>
38 #include <time.h>
39 #include <sys/types.h>
40 #include <asm/signal_portable.h>
41 #include <asm/sigcontext_portable.h>
42 
43 #define __ARCH_SI_UID_T __kernel_uid32_t
44 #include <asm/siginfo_portable.h>
45 #undef __ARCH_SI_UID_T
46 
47 __BEGIN_DECLS
48 
49 typedef int sig_atomic_t;
50 
51 #if 0
52 /* _NSIG is used by the SIGRTMAX definition under <asm/signal.h>, however
53  * its definition is part of a #if __KERNEL__ .. #endif block in the original
54  * kernel headers and is thus not part of our cleaned-up versions.
55  *
56  * Looking at the current kernel sources, it is defined as 64 for all
57  * architectures except for the 'mips' one which set it to 128.
58  */
59 #ifndef _NSIG_PORTABLE
60 #  define _NSIG_PORTABLE  64
61 #endif
62 #endif
63 
64 extern const char * const sys_siglist[];
65 extern const char * const sys_signame[];
66 
WRAP(sigismember)67 static __inline__ int WRAP(sigismember)(sigset_portable_t *set, int signum)
68 {
69     unsigned long *local_set = (unsigned long *)set;
70     signum--;
71     return (int)((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1);
72 }
73 
74 
WRAP(sigaddset)75 static __inline__ int WRAP(sigaddset)(sigset_portable_t *set, int signum)
76 {
77     unsigned long *local_set = (unsigned long *)set;
78     signum--;
79     local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT);
80     return 0;
81 }
82 
83 
WRAP(sigdelset)84 static __inline__ int WRAP(sigdelset)(sigset_portable_t *set, int signum)
85 {
86     unsigned long *local_set = (unsigned long *)set;
87     signum--;
88     local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT));
89     return 0;
90 }
91 
92 
WRAP(sigemptyset)93 static __inline__ int WRAP(sigemptyset)(sigset_portable_t *set)
94 {
95     memset(set, 0, sizeof *set);
96     return 0;
97 }
98 
WRAP(sigfillset)99 static __inline__ int WRAP(sigfillset)(sigset_portable_t *set)
100 {
101     memset(set, ~0, sizeof *set);
102     return 0;
103 }
104 
105 /* compatibility types */
106 typedef void            (*sig_portable_t)(int);
107 typedef sig_portable_t   sighandler_portable_t;
108 
109 /* Extended compatibility types, for processing a siginfo_t argument */
110 typedef void            (*sig3_portable_t)(int, siginfo_portable_t *, void *);
111 typedef sig3_portable_t   sig3handler_portable_t;
112 
113 /* differentiater between sysv and bsd behaviour 8*/
114 extern __sighandler_t sysv_signal(int, __sighandler_portable_t);
115 extern __sighandler_t bsd_signal(int, __sighandler_portable_t);
116 
117 #if 0
118 /* the default is bsd */
119 static __inline__ __sighandler_portable_t WRAP(signal)(int s, sighandler_portable_t f)
120 {
121     return bsd_signal(s,f);
122 }
123 #endif
124 
125 /* the portable mapped syscall itself */
126 extern __sighandler_portable_t WRAP(__signal)(int, __sighandler_portable_t);
127 
128 extern int WRAP(sigprocmask)(int, const sigset_portable_t *, sigset_portable_t *);
129 
130 extern int WRAP(sigaction)(int, const struct sigaction_portable *,
131                               struct sigaction_portable *);
132 
133 extern int WRAP(sigpending)(sigset_portable_t *);
134 extern int WRAP(sigsuspend)(const sigset_portable_t *);
135 extern int WRAP(sigwait)(const sigset_portable_t *set, int *sig);
136 extern int WRAP(siginterrupt)(int  sig, int  flag);
137 
138 extern int WRAP(raise)(int);
139 extern int WRAP(kill)(pid_t, int);
140 extern int WRAP(killpg)(int pgrp, int sig);
141 extern int WRAP(tkill)(int tid, int portable_signum);
142 extern int WRAP(sigaltstack)(const portable_stack_t *ss, portable_stack_t *oss);
143 extern int WRAP(timer_create)(clockid_t, struct sigevent *, timer_t *);
144 
145 #if 0
146 extern int WRAP(signalfd)(int fd, const sigset_portable_t *portable_sigmask, int flags);
147 #endif
148 
149 extern __hidden int do_signalfd4_portable(int fd, const sigset_portable_t *portable_sigmask,
150                                           int portable_sigsetsize, int flags);
151 
152 extern __hidden int read_signalfd_mapper(int fd, void *buf, size_t count);
153 extern __hidden char *map_portable_signum_to_name(int portable_signum);
154 extern __hidden char *map_mips_signum_to_name(int mips_signum);
155 extern __hidden int signum_pton(int portable_signum);
156 extern __hidden int signum_ntop(int mips_signum);
157 
158 typedef int (*sigmask_fn)(int, const sigset_t *, sigset_t *);
159 typedef int (*rt_sigmask_fn)(int, const sigset_t *, sigset_t *, size_t);
160 typedef int (*sigaction_fn)(int, const struct sigaction *, struct sigaction *);
161 typedef int (*rt_sigaction_fn)(int, const struct sigaction *, struct sigaction *, size_t);
162 
163 
164 extern __hidden int do_sigmask(int portable_how, const sigset_portable_t *portable_sigset,
165                                sigset_portable_t *portable_oldset, sigmask_fn fn,
166                                rt_sigmask_fn rt_fn);
167 
168 
169 /* These functions are called from syscall.c and experimental Bionic linker. */
170 extern int WRAP(__rt_sigaction)(int portable_signum,
171                                 const struct sigaction_portable *act,
172                                 struct sigaction_portable *oldact,
173                                 size_t sigsetsize);
174 
175 extern int WRAP(__rt_sigprocmask)(int portable_how,
176                                   const sigset_portable_t *portable_sigset,
177                                   sigset_portable_t *portable_oldset,
178                                   size_t sigsetsize);
179 
180 extern int WRAP(__rt_sigtimedwait)(const sigset_portable_t *portable_sigset,
181                                    siginfo_portable_t *portable_siginfo,
182                                    const struct timespec *timeout,
183                                    size_t portable_sigsetsize);
184 
185 
186 /* These functions are only called from syscall.c; not experimental Bionic linker. */
187 extern __hidden int WRAP(rt_sigqueueinfo)(pid_t pid, int sig, siginfo_portable_t *uinfo);
188 
189 extern __hidden int WRAP(rt_tgsigqueueinfo)(pid_t tgid, pid_t pid, int sig,
190                                                siginfo_portable_t *uinfo);
191 
192 
193 /* Called by clone when memory and signal handlers aren't compatable. */
194 extern __hidden void signal_disable_mapping(void);
195 
196 __END_DECLS
197 
198 #endif /* _SIGNAL_PORTABLE_H_ */
199