• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
29 #ifndef _SIGNAL_H_
30 #define _SIGNAL_H_
31 
32 #include <errno.h>
33 #include <sys/cdefs.h>
34 #include <limits.h>		/* For LONG_BIT */
35 #include <string.h>		/* For memset() */
36 #include <sys/types.h>
37 #include <asm/sigcontext.h>
38 
39 #if defined(__LP64__) || defined(__mips__)
40 /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
41  * so we need to expose our own and translate behind the scenes. */
42 #  define sigaction __kernel_sigaction
43 #  include <linux/signal.h>
44 #  undef sigaction
45 #else
46 /* For 32-bit, we're stuck with the definitions we already shipped,
47  * even though they contain a sigset_t that's too small. */
48 #  include <linux/signal.h>
49 #endif
50 
51 __BEGIN_DECLS
52 
53 typedef int sig_atomic_t;
54 
55 /* The arm and x86 kernel header files don't define _NSIG. */
56 #ifndef _KERNEL__NSIG
57 #define _KERNEL__NSIG 64
58 #endif
59 
60 /* Userspace's NSIG is the kernel's _NSIG + 1. */
61 #define _NSIG (_KERNEL__NSIG + 1)
62 #define NSIG _NSIG
63 
64 /* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
65 #define SIGRTMIN (__libc_current_sigrtmin())
66 #define SIGRTMAX (__libc_current_sigrtmax())
67 extern int __libc_current_sigrtmin(void);
68 extern int __libc_current_sigrtmax(void);
69 
70 extern const char* const sys_siglist[];
71 extern const char* const sys_signame[]; /* BSD compatibility. */
72 
73 typedef __sighandler_t sig_t; /* BSD compatibility. */
74 typedef __sighandler_t sighandler_t; /* glibc compatibility. */
75 
76 #define si_timerid si_tid /* glibc compatibility. */
77 
78 #if defined(__LP64__)
79 
80 struct sigaction {
81   unsigned int sa_flags;
82   union {
83     sighandler_t sa_handler;
84     void (*sa_sigaction)(int, struct siginfo*, void*);
85   };
86   sigset_t sa_mask;
87   void (*sa_restorer)(void);
88 };
89 
90 #elif defined(__mips__)
91 
92 struct sigaction {
93   unsigned int sa_flags;
94   union {
95     sighandler_t sa_handler;
96     void (*sa_sigaction) (int, struct siginfo*, void*);
97   };
98   sigset_t sa_mask;
99 };
100 
101 #endif
102 
103 extern int sigaction(int, const struct sigaction*, struct sigaction*);
104 
105 extern sighandler_t signal(int, sighandler_t);
106 
107 extern int siginterrupt(int, int);
108 
109 extern int sigaddset(sigset_t*, int);
110 extern int sigdelset(sigset_t*, int);
111 extern int sigemptyset(sigset_t*);
112 extern int sigfillset(sigset_t*);
113 extern int sigismember(const sigset_t*, int);
114 
115 extern int sigpending(sigset_t*) __nonnull((1));
116 extern int sigprocmask(int, const sigset_t*, sigset_t*);
117 extern int sigsuspend(const sigset_t*) __nonnull((1));
118 extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
119 
120 extern int raise(int);
121 extern int kill(pid_t, int);
122 extern int killpg(int, int);
123 
124 extern int sigaltstack(const stack_t*, stack_t*);
125 
126 extern void psiginfo(const siginfo_t*, const char*);
127 extern void psignal(int, const char*);
128 
129 __END_DECLS
130 
131 #endif /* _SIGNAL_H_ */
132