signal.h revision 61fb3fc770566c7bafe7af8fb93590bcad387fbb
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__)
39/* For 64-bit, 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#  define __ARCH_SI_UID_T __kernel_uid32_t /* TODO: remove this when we switch to uapi. */
48#  include <linux/signal.h>
49#  undef __ARCH_SI_UID_T
50#endif
51
52__BEGIN_DECLS
53
54typedef int sig_atomic_t;
55
56/* _NSIG is used by the SIGRTMAX definition under <asm/signal.h>, however
57 * its definition is part of a #if __KERNEL__ .. #endif block in the original
58 * kernel headers and is thus not part of our cleaned-up versions.
59 *
60 * Looking at the current kernel sources, it is defined as 64 for all
61 * architectures except for the 'mips' one which set it to 128.
62 */
63#ifndef _NSIG
64#  define _NSIG  64
65#endif
66
67extern const char* const sys_siglist[];
68extern const char* const sys_signame[];
69
70typedef __sighandler_t sig_t; /* BSD compatibility. */
71typedef __sighandler_t sighandler_t; /* glibc compatibility. */
72
73#if __LP64__
74
75struct sigaction {
76  unsigned int sa_flags;
77  union {
78    sighandler_t sa_handler;
79    void (*sa_sigaction)(int, struct siginfo*, void*);
80  };
81  sigset_t sa_mask;
82  void (*sa_restorer)(void);
83};
84
85#endif
86
87extern int sigaction(int, const struct sigaction*, struct sigaction*);
88
89extern sighandler_t signal(int, sighandler_t);
90extern sighandler_t bsd_signal(int, sighandler_t);
91extern sighandler_t sysv_signal(int, sighandler_t);
92
93extern int siginterrupt(int, int);
94
95extern int sigaddset(sigset_t*, int);
96extern int sigdelset(sigset_t*, int);
97extern int sigemptyset(sigset_t*);
98extern int sigfillset(sigset_t*);
99extern int sigismember(const sigset_t*, int);
100
101extern int sigpending(sigset_t*) __nonnull((1));
102extern int sigprocmask(int, const sigset_t*, sigset_t*);
103extern int sigsuspend(const sigset_t*) __nonnull((1));
104extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
105
106extern int raise(int);
107extern int kill(pid_t, int);
108extern int killpg(int, int);
109
110extern int sigaltstack(const stack_t*, stack_t*);
111
112extern void psiginfo(const siginfo_t*, const char*);
113extern void psignal(int, const char*);
114
115__END_DECLS
116
117#endif /* _SIGNAL_H_ */
118