blob: 5f9012ff52ed3c879887df556613979fb0e7d184 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_SIGNAL_H
3#define _ASM_X86_SIGNAL_H
Thomas Gleixner33185c52007-10-23 22:37:24 +02004
5#ifndef __ASSEMBLY__
Thomas Gleixner33185c52007-10-23 22:37:24 +02006#include <linux/linkage.h>
7
8/* Most things should be clean enough to redefine this at will, if care
9 is taken to make libc match. */
10
11#define _NSIG 64
12
13#ifdef __i386__
14# define _NSIG_BPW 32
Thomas Gleixner96a388d2007-10-11 11:20:03 +020015#else
Thomas Gleixner33185c52007-10-23 22:37:24 +020016# define _NSIG_BPW 64
17#endif
18
19#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
20
21typedef unsigned long old_sigset_t; /* at least 32 bits */
22
23typedef struct {
24 unsigned long sig[_NSIG_WORDS];
25} sigset_t;
26
Dmitry Safonov68463512016-09-05 16:33:08 +030027/* non-uapi in-kernel SA_FLAGS for those indicates ABI for a signal frame */
28#define SA_IA32_ABI 0x02000000u
29#define SA_X32_ABI 0x01000000u
30
Suresh Siddha050902c2012-07-24 16:05:27 -070031#ifndef CONFIG_COMPAT
32typedef sigset_t compat_sigset_t;
33#endif
34
Thomas Gleixner33185c52007-10-23 22:37:24 +020035#endif /* __ASSEMBLY__ */
David Howellsaf170c52012-12-14 22:37:13 +000036#include <uapi/asm/signal.h>
Thomas Gleixner33185c52007-10-23 22:37:24 +020037#ifndef __ASSEMBLY__
Andy Lutomirski1f484aa2015-07-03 12:44:23 -070038extern void do_signal(struct pt_regs *regs);
Al Viro574c4862012-11-25 22:24:19 -050039
40#define __ARCH_HAS_SA_RESTORER
41
Ingo Molnardecb4c42015-09-05 09:32:43 +020042#include <uapi/asm/sigcontext.h>
Thomas Gleixner33185c52007-10-23 22:37:24 +020043
Herton Ronaldo Krzesinski723edb52008-07-14 17:40:23 -030044#ifdef __i386__
Thomas Gleixner33185c52007-10-23 22:37:24 +020045
46#define __HAVE_ARCH_SIG_BITOPS
47
Joe Perches9551b122008-03-23 01:03:28 -070048#define sigaddset(set,sig) \
Herton Ronaldo Krzesinski723edb52008-07-14 17:40:23 -030049 (__builtin_constant_p(sig) \
Joe Perches9551b122008-03-23 01:03:28 -070050 ? __const_sigaddset((set), (sig)) \
51 : __gen_sigaddset((set), (sig)))
Thomas Gleixner33185c52007-10-23 22:37:24 +020052
Joe Perches9551b122008-03-23 01:03:28 -070053static inline void __gen_sigaddset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +020054{
Joe Perches9551b122008-03-23 01:03:28 -070055 asm("btsl %1,%0" : "+m"(*set) : "Ir"(_sig - 1) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +020056}
57
Joe Perches9551b122008-03-23 01:03:28 -070058static inline void __const_sigaddset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +020059{
60 unsigned long sig = _sig - 1;
61 set->sig[sig / _NSIG_BPW] |= 1 << (sig % _NSIG_BPW);
62}
63
Joe Perches9551b122008-03-23 01:03:28 -070064#define sigdelset(set, sig) \
65 (__builtin_constant_p(sig) \
66 ? __const_sigdelset((set), (sig)) \
67 : __gen_sigdelset((set), (sig)))
Thomas Gleixner33185c52007-10-23 22:37:24 +020068
69
Joe Perches9551b122008-03-23 01:03:28 -070070static inline void __gen_sigdelset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +020071{
Joe Perches9551b122008-03-23 01:03:28 -070072 asm("btrl %1,%0" : "+m"(*set) : "Ir"(_sig - 1) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +020073}
74
Joe Perches9551b122008-03-23 01:03:28 -070075static inline void __const_sigdelset(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +020076{
77 unsigned long sig = _sig - 1;
78 set->sig[sig / _NSIG_BPW] &= ~(1 << (sig % _NSIG_BPW));
79}
80
Joe Perches9551b122008-03-23 01:03:28 -070081static inline int __const_sigismember(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +020082{
83 unsigned long sig = _sig - 1;
84 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
85}
86
Joe Perches9551b122008-03-23 01:03:28 -070087static inline int __gen_sigismember(sigset_t *set, int _sig)
Thomas Gleixner33185c52007-10-23 22:37:24 +020088{
H. Peter Anvin2823d4d2016-06-08 12:38:37 -070089 unsigned char ret;
90 asm("btl %2,%1\n\tsetc %0"
91 : "=qm"(ret) : "m"(*set), "Ir"(_sig-1) : "cc");
Thomas Gleixner33185c52007-10-23 22:37:24 +020092 return ret;
93}
94
Joe Perches9551b122008-03-23 01:03:28 -070095#define sigismember(set, sig) \
96 (__builtin_constant_p(sig) \
97 ? __const_sigismember((set), (sig)) \
98 : __gen_sigismember((set), (sig)))
Thomas Gleixner33185c52007-10-23 22:37:24 +020099
Thomas Gleixner33185c52007-10-23 22:37:24 +0200100struct pt_regs;
101
Thomas Gleixner33185c52007-10-23 22:37:24 +0200102#else /* __i386__ */
103
104#undef __HAVE_ARCH_SIG_BITOPS
105
Roland McGrathe1f28772008-01-30 13:30:50 +0100106#endif /* !__i386__ */
107
Thomas Gleixner33185c52007-10-23 22:37:24 +0200108#endif /* __ASSEMBLY__ */
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700109#endif /* _ASM_X86_SIGNAL_H */