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 <sys/cdefs.h> 32 33 #include <limits.h> 34 #include <linux/signal.h> 35 #include <sys/types.h> 36 37 /* The arm and x86 kernel header files don't define _NSIG. */ 38 #ifndef _KERNEL__NSIG 39 #define _KERNEL__NSIG 64 40 #endif 41 42 /* Userspace's NSIG is the kernel's _NSIG + 1. */ 43 #define _NSIG (_KERNEL__NSIG + 1) 44 #define NSIG _NSIG 45 46 typedef int sig_atomic_t; 47 48 typedef __sighandler_t sig_t; /* BSD compatibility. */ 49 typedef __sighandler_t sighandler_t; /* glibc compatibility. */ 50 51 /* sigset_t is already large enough on LP64, but LP32's sigset_t 52 * is just `unsigned long`. 53 */ 54 #if defined(__LP64__) 55 typedef sigset_t sigset64_t; 56 #else 57 typedef struct { unsigned long __bits[_KERNEL__NSIG/(8*sizeof(long))]; } sigset64_t; 58 #endif 59 60 /* The kernel's struct sigaction doesn't match the POSIX one. */ 61 62 #if defined(__LP64__) 63 64 /* For 64-bit, that's the only problem, and we only need two structs 65 * for source compatibility with 32-bit. */ 66 67 #define __SIGACTION_BODY \ 68 int sa_flags; \ 69 union { \ 70 sighandler_t sa_handler; \ 71 void (*sa_sigaction)(int, struct siginfo*, void*); \ 72 }; \ 73 sigset_t sa_mask; \ 74 void (*sa_restorer)(void); \ 75 76 struct sigaction { __SIGACTION_BODY }; 77 struct sigaction64 { __SIGACTION_BODY }; 78 79 #undef __SIGACTION_BODY 80 81 #else 82 83 /* For 32-bit, Android's ABIs used a too-small sigset_t that doesn't 84 * support RT signals, so we need two different structs. 85 */ 86 87 /* The arm32 kernel headers also pollute the namespace with these, 88 * but our header scrubber doesn't know how to remove #defines. */ 89 #undef sa_handler 90 #undef sa_sigaction 91 92 struct sigaction { 93 union { 94 sighandler_t sa_handler; 95 void (*sa_sigaction)(int, struct siginfo*, void*); 96 }; 97 sigset_t sa_mask; 98 int sa_flags; 99 void (*sa_restorer)(void); 100 }; 101 102 struct sigaction64 { 103 union { 104 sighandler_t sa_handler; 105 void (*sa_sigaction)(int, struct siginfo*, void*); 106 }; 107 int sa_flags; 108 void (*sa_restorer)(void); 109 sigset64_t sa_mask; 110 }; 111 112 #endif 113