• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 _BITS_SIGNAL_TYPES_H_
30 #define _BITS_SIGNAL_TYPES_H_
31 
32 #include <limits.h>
33 #include <sys/cdefs.h>
34 #include <sys/types.h>
35 
36 /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the
37  * POSIX one, so we need to expose our own and translate behind the scenes.
38  * For 32-bit, we're stuck with the definitions we already shipped,
39  * even though they contain a sigset_t that's too small. See sigaction64.
40  */
41 #define sigaction __kernel_sigaction
42 #include <linux/signal.h>
43 #undef sigaction
44 
45 /* The arm and x86 kernel header files don't define _NSIG. */
46 #ifndef _KERNEL__NSIG
47 #define _KERNEL__NSIG 64
48 #endif
49 
50 /* Userspace's NSIG is the kernel's _NSIG + 1. */
51 #define _NSIG (_KERNEL__NSIG + 1)
52 #define NSIG _NSIG
53 
54 typedef int sig_atomic_t;
55 
56 typedef __sighandler_t sig_t; /* BSD compatibility. */
57 typedef __sighandler_t sighandler_t; /* glibc compatibility. */
58 
59 /* sigset_t is already large enough on LP64 and mips, but other LP32's sigset_t
60  * is just `unsigned long`.
61  */
62 #if defined(__LP64__) || defined(__mips__)
63 typedef sigset_t sigset64_t;
64 #else
65 typedef struct { unsigned long __bits[_KERNEL__NSIG/LONG_BIT]; } sigset64_t;
66 #endif
67 
68 #if defined(__LP64__)
69 
70 #define __SIGACTION_BODY \
71   int sa_flags; \
72   union { \
73     sighandler_t sa_handler; \
74     void (*sa_sigaction)(int, struct siginfo*, void*); \
75   }; \
76   sigset_t sa_mask; \
77   void (*sa_restorer)(void); \
78 
79 struct sigaction { __SIGACTION_BODY };
80 struct sigaction64 { __SIGACTION_BODY };
81 
82 #undef __SIGACTION_BODY
83 
84 #elif defined(__mips__)
85 
86 #define __SIGACTION_BODY \
87   int sa_flags; \
88   union { \
89     sighandler_t sa_handler; \
90     void (*sa_sigaction)(int, struct siginfo*, void*); \
91   }; \
92   sigset_t sa_mask; \
93 
94 struct sigaction { __SIGACTION_BODY };
95 struct sigaction64 { __SIGACTION_BODY };
96 
97 #undef __SIGACTION_BODY
98 
99 #else
100 
101 #undef sa_handler
102 #undef sa_sigaction
103 
104 struct sigaction {
105   union {
106     sighandler_t sa_handler;
107     void (*sa_sigaction)(int, struct siginfo*, void*);
108   };
109   sigset_t sa_mask;
110   int sa_flags;
111   void (*sa_restorer)(void);
112 };
113 
114 /* This matches the kernel's internal structure. */
115 struct sigaction64 {
116   union {
117     sighandler_t sa_handler;
118     void (*sa_sigaction)(int, struct siginfo*, void*);
119   };
120   int sa_flags;
121   void (*sa_restorer)(void);
122   sigset64_t sa_mask;
123 };
124 
125 #endif
126 
127 #endif
128