blob: 6cbc795b7c5877b68fa39384fd2b4fa88343c9b0 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_SIGNAL_H
2#define _ASM_X86_SIGNAL_H
Thomas Gleixner33185c52007-10-23 22:37:24 +02003
4#ifndef __ASSEMBLY__
5#include <linux/types.h>
6#include <linux/time.h>
7#include <linux/compiler.h>
8
9/* Avoid too many header ordering problems. */
10struct siginfo;
11
Thomas Gleixner96a388d2007-10-11 11:20:03 +020012#ifdef __KERNEL__
Thomas Gleixner33185c52007-10-23 22:37:24 +020013#include <linux/linkage.h>
14
15/* Most things should be clean enough to redefine this at will, if care
16 is taken to make libc match. */
17
18#define _NSIG 64
19
20#ifdef __i386__
21# define _NSIG_BPW 32
Thomas Gleixner96a388d2007-10-11 11:20:03 +020022#else
Thomas Gleixner33185c52007-10-23 22:37:24 +020023# define _NSIG_BPW 64
24#endif
25
26#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
27
28typedef unsigned long old_sigset_t; /* at least 32 bits */
29
30typedef struct {
31 unsigned long sig[_NSIG_WORDS];
32} sigset_t;
33
34#else
35/* Here we must cater to libcs that poke about in kernel headers. */
36
37#define NSIG 32
38typedef unsigned long sigset_t;
39
40#endif /* __KERNEL__ */
41#endif /* __ASSEMBLY__ */
42
43#define SIGHUP 1
44#define SIGINT 2
45#define SIGQUIT 3
46#define SIGILL 4
47#define SIGTRAP 5
48#define SIGABRT 6
49#define SIGIOT 6
50#define SIGBUS 7
51#define SIGFPE 8
52#define SIGKILL 9
53#define SIGUSR1 10
54#define SIGSEGV 11
55#define SIGUSR2 12
56#define SIGPIPE 13
57#define SIGALRM 14
58#define SIGTERM 15
59#define SIGSTKFLT 16
60#define SIGCHLD 17
61#define SIGCONT 18
62#define SIGSTOP 19
63#define SIGTSTP 20
64#define SIGTTIN 21
65#define SIGTTOU 22
66#define SIGURG 23
67#define SIGXCPU 24
68#define SIGXFSZ 25
69#define SIGVTALRM 26
70#define SIGPROF 27
71#define SIGWINCH 28
72#define SIGIO 29
73#define SIGPOLL SIGIO
74/*
75#define SIGLOST 29
76*/
77#define SIGPWR 30
78#define SIGSYS 31
79#define SIGUNUSED 31
80
81/* These should not be considered constants from userland. */
82#define SIGRTMIN 32
83#define SIGRTMAX _NSIG
84
85/*
86 * SA_FLAGS values:
87 *
88 * SA_ONSTACK indicates that a registered stack_t will be used.
89 * SA_RESTART flag to get restarting signals (which were the default long ago)
90 * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
91 * SA_RESETHAND clears the handler when the signal is delivered.
92 * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
93 * SA_NODEFER prevents the current signal from being masked in the handler.
94 *
95 * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
96 * Unix names RESETHAND and NODEFER respectively.
97 */
98#define SA_NOCLDSTOP 0x00000001u
99#define SA_NOCLDWAIT 0x00000002u
100#define SA_SIGINFO 0x00000004u
101#define SA_ONSTACK 0x08000000u
102#define SA_RESTART 0x10000000u
103#define SA_NODEFER 0x40000000u
104#define SA_RESETHAND 0x80000000u
105
106#define SA_NOMASK SA_NODEFER
107#define SA_ONESHOT SA_RESETHAND
108
109#define SA_RESTORER 0x04000000
110
111/*
112 * sigaltstack controls
113 */
114#define SS_ONSTACK 1
115#define SS_DISABLE 2
116
117#define MINSIGSTKSZ 2048
118#define SIGSTKSZ 8192
119
Arnd Bergmann63b852a2009-05-13 22:56:24 +0000120#include <asm-generic/signal-defs.h>
Thomas Gleixner33185c52007-10-23 22:37:24 +0200121
122#ifndef __ASSEMBLY__
123
Jaswinder Singh7b5b50f2008-12-15 22:24:48 +0530124# ifdef __KERNEL__
125extern void do_notify_resume(struct pt_regs *, void *, __u32);
126# endif /* __KERNEL__ */
127
Ben Hutchings556ba702012-11-25 22:24:19 -0500128#define __ARCH_HAS_SA_RESTORER
129
Thomas Gleixner33185c52007-10-23 22:37:24 +0200130#ifdef __i386__
131# ifdef __KERNEL__
132struct old_sigaction {
133 __sighandler_t sa_handler;
134 old_sigset_t sa_mask;
135 unsigned long sa_flags;
136 __sigrestore_t sa_restorer;
137};
138
139struct sigaction {
140 __sighandler_t sa_handler;
141 unsigned long sa_flags;
142 __sigrestore_t sa_restorer;
143 sigset_t sa_mask; /* mask last for extensibility */
144};
145
146struct k_sigaction {
147 struct sigaction sa;
148};
Jaswinder Singhb994b6c2008-07-21 21:37:52 +0530149
Thomas Gleixner33185c52007-10-23 22:37:24 +0200150# else /* __KERNEL__ */
151/* Here we must cater to libcs that poke about in kernel headers. */
152
153struct sigaction {
154 union {
155 __sighandler_t _sa_handler;
156 void (*_sa_sigaction)(int, struct siginfo *, void *);
157 } _u;
158 sigset_t sa_mask;
159 unsigned long sa_flags;
160 void (*sa_restorer)(void);
161};
162
163#define sa_handler _u._sa_handler
164#define sa_sigaction _u._sa_sigaction
165
166# endif /* ! __KERNEL__ */
167#else /* __i386__ */
168
169struct sigaction {
170 __sighandler_t sa_handler;
171 unsigned long sa_flags;
172 __sigrestore_t sa_restorer;
173 sigset_t sa_mask; /* mask last for extensibility */
174};
175
176struct k_sigaction {
177 struct sigaction sa;
178};
179
180#endif /* !__i386__ */
181
182typedef struct sigaltstack {
183 void __user *ss_sp;
184 int ss_flags;
185 size_t ss_size;
186} stack_t;
187
188#ifdef __KERNEL__
189#include <asm/sigcontext.h>
190
Herton Ronaldo Krzesinski723edb52008-07-14 17:40:23 -0300191#ifdef __i386__
Thomas Gleixner33185c52007-10-23 22:37:24 +0200192
193#define __HAVE_ARCH_SIG_BITOPS
194
Joe Perches9551b122008-03-23 01:03:28 -0700195#define sigaddset(set,sig) \
Herton Ronaldo Krzesinski723edb52008-07-14 17:40:23 -0300196 (__builtin_constant_p(sig) \
Joe Perches9551b122008-03-23 01:03:28 -0700197 ? __const_sigaddset((set), (sig)) \
198 : __gen_sigaddset((set), (sig)))
Thomas Gleixner33185c52007-10-23 22:37:24 +0200199
Joe Perches9551b122008-03-23 01:03:28 -0700200static inline void __gen_sigaddset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200201{
Joe Perches9551b122008-03-23 01:03:28 -0700202 asm("btsl %1,%0" : "+m"(*set) : "Ir"(_sig - 1) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +0200203}
204
Joe Perches9551b122008-03-23 01:03:28 -0700205static inline void __const_sigaddset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200206{
207 unsigned long sig = _sig - 1;
208 set->sig[sig / _NSIG_BPW] |= 1 << (sig % _NSIG_BPW);
209}
210
Joe Perches9551b122008-03-23 01:03:28 -0700211#define sigdelset(set, sig) \
212 (__builtin_constant_p(sig) \
213 ? __const_sigdelset((set), (sig)) \
214 : __gen_sigdelset((set), (sig)))
Thomas Gleixner33185c52007-10-23 22:37:24 +0200215
216
Joe Perches9551b122008-03-23 01:03:28 -0700217static inline void __gen_sigdelset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200218{
Joe Perches9551b122008-03-23 01:03:28 -0700219 asm("btrl %1,%0" : "+m"(*set) : "Ir"(_sig - 1) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +0200220}
221
Joe Perches9551b122008-03-23 01:03:28 -0700222static inline void __const_sigdelset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200223{
224 unsigned long sig = _sig - 1;
225 set->sig[sig / _NSIG_BPW] &= ~(1 << (sig % _NSIG_BPW));
226}
227
Joe Perches9551b122008-03-23 01:03:28 -0700228static inline int __const_sigismember(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200229{
230 unsigned long sig = _sig - 1;
231 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
232}
233
Joe Perches9551b122008-03-23 01:03:28 -0700234static inline int __gen_sigismember(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200235{
236 int ret;
Joe Perches9551b122008-03-23 01:03:28 -0700237 asm("btl %2,%1\n\tsbbl %0,%0"
238 : "=r"(ret) : "m"(*set), "Ir"(_sig-1) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +0200239 return ret;
240}
241
Joe Perches9551b122008-03-23 01:03:28 -0700242#define sigismember(set, sig) \
243 (__builtin_constant_p(sig) \
244 ? __const_sigismember((set), (sig)) \
245 : __gen_sigismember((set), (sig)))
Thomas Gleixner33185c52007-10-23 22:37:24 +0200246
Joe Perches9551b122008-03-23 01:03:28 -0700247static inline int sigfindinword(unsigned long word)
Thomas Gleixner33185c52007-10-23 22:37:24 +0200248{
Joe Perches9551b122008-03-23 01:03:28 -0700249 asm("bsfl %1,%0" : "=r"(word) : "rm"(word) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +0200250 return word;
251}
252
253struct pt_regs;
254
Thomas Gleixner33185c52007-10-23 22:37:24 +0200255#else /* __i386__ */
256
257#undef __HAVE_ARCH_SIG_BITOPS
258
Roland McGrathe1f28772008-01-30 13:30:50 +0100259#endif /* !__i386__ */
260
Thomas Gleixner33185c52007-10-23 22:37:24 +0200261#define ptrace_signal_deliver(regs, cookie) do { } while (0)
262
Thomas Gleixner33185c52007-10-23 22:37:24 +0200263#endif /* __KERNEL__ */
264#endif /* __ASSEMBLY__ */
265
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700266#endif /* _ASM_X86_SIGNAL_H */