blob: 9d3badccfddab49adafe6e1de169cdf0460d6a63 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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#ifndef _SIGNAL_H_
29#define _SIGNAL_H_
30
Elliott Hughesda73f652012-11-30 16:40:55 -080031#include <errno.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080032#include <sys/cdefs.h>
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020033#include <limits.h> /* For LONG_BIT */
34#include <string.h> /* For memset() */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#include <sys/types.h>
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020036#include <asm/signal.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020038#define __ARCH_SI_UID_T __kernel_uid32_t
39#include <asm/siginfo.h>
40#undef __ARCH_SI_UID_T
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080041
42__BEGIN_DECLS
43
David 'Digit' Turnerc124baa2012-07-12 19:06:15 +020044typedef int sig_atomic_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020046/* _NSIG is used by the SIGRTMAX definition under <asm/signal.h>, however
47 * its definition is part of a #if __KERNEL__ .. #endif block in the original
48 * kernel headers and is thus not part of our cleaned-up versions.
49 *
50 * Looking at the current kernel sources, it is defined as 64 for all
51 * architectures except for the 'mips' one which set it to 128.
52 */
53#ifndef _NSIG
54# define _NSIG 64
55#endif
56
Elliott Hughesda73f652012-11-30 16:40:55 -080057extern const char* const sys_siglist[];
58extern const char* const sys_signame[];
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059
Elliott Hughesda73f652012-11-30 16:40:55 -080060static __inline__ int sigismember(sigset_t* set, int signum) {
61 if (set == NULL || signum < 1 || signum >= 8*sizeof(sigset_t)) {
62 errno = EINVAL;
63 return -1;
64 }
65 unsigned long* local_set = (unsigned long*) set;
66 signum--;
67 return (int) ((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080068}
69
Elliott Hughesda73f652012-11-30 16:40:55 -080070static __inline__ int sigaddset(sigset_t* set, int signum) {
71 if (set == NULL || signum < 1 || signum >= 8*sizeof(sigset_t)) {
72 errno = EINVAL;
73 return -1;
74 }
75 unsigned long* local_set = (unsigned long*) set;
76 signum--;
77 local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT);
78 return 0;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079}
80
Elliott Hughesda73f652012-11-30 16:40:55 -080081static __inline__ int sigdelset(sigset_t* set, int signum) {
82 if (set == NULL || signum < 1 || signum >= 8*sizeof(sigset_t)) {
83 errno = EINVAL;
84 return -1;
85 }
86 unsigned long* local_set = (unsigned long*) set;
87 signum--;
88 local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT));
89 return 0;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080090}
91
Elliott Hughesda73f652012-11-30 16:40:55 -080092static __inline__ int sigemptyset(sigset_t* set) {
93 if (set == NULL) {
94 errno = EINVAL;
95 return -1;
96 }
97 memset(set, 0, sizeof *set);
98 return 0;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080099}
100
Elliott Hughesda73f652012-11-30 16:40:55 -0800101static __inline__ int sigfillset(sigset_t* set) {
102 if (set == NULL) {
103 errno = EINVAL;
104 return -1;
105 }
106 memset(set, ~0, sizeof *set);
107 return 0;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800108}
109
110
111/* compatibility types */
112typedef void (*sig_t)(int);
113typedef sig_t sighandler_t;
114
115/* differentiater between sysv and bsd behaviour 8*/
116extern __sighandler_t sysv_signal(int, __sighandler_t);
117extern __sighandler_t bsd_signal(int, __sighandler_t);
118
119/* the default is bsd */
120static __inline__ __sighandler_t signal(int s, __sighandler_t f)
121{
122 return bsd_signal(s,f);
123}
124
125/* the syscall itself */
126extern __sighandler_t __signal(int, __sighandler_t, int);
127
128extern int sigprocmask(int, const sigset_t *, sigset_t *);
129extern int sigaction(int, const struct sigaction *, struct sigaction *);
130
131extern int sigpending(sigset_t *);
132extern int sigsuspend(const sigset_t *);
133extern int sigwait(const sigset_t *set, int *sig);
134extern int siginterrupt(int sig, int flag);
135
136extern int raise(int);
137extern int kill(pid_t, int);
Colin Cross8c59d962010-01-13 16:39:26 -0800138extern int killpg(int pgrp, int sig);
David 'Digit' Turnerbb5581a2010-10-09 17:56:55 +0200139extern int sigaltstack(const stack_t *ss, stack_t *oss);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800140
Irina Tirdeab5f053b2012-09-08 09:17:54 +0300141extern void psiginfo(const siginfo_t* si, const char* message);
142extern void psignal(int signal_number, const char* message);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800143
144__END_DECLS
145
146#endif /* _SIGNAL_H_ */