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