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