1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_FUTEX_H
3 #define _ASM_X86_FUTEX_H
7 #include <linux/futex.h>
8 #include <linux/uaccess.h>
11 #include <asm/errno.h>
12 #include <asm/processor.h>
15 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16 asm volatile("\t" ASM_STAC "\n" \
18 "2:\t" ASM_CLAC "\n" \
19 "\t.section .fixup,\"ax\"\n" \
23 _ASM_EXTABLE(1b, 3b) \
24 : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
25 : "i" (-EFAULT), "0" (oparg), "1" (0))
27 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
28 asm volatile("\t" ASM_STAC "\n" \
32 "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
34 "3:\t" ASM_CLAC "\n" \
35 "\t.section .fixup,\"ax\"\n" \
39 _ASM_EXTABLE(1b, 4b) \
40 _ASM_EXTABLE(2b, 4b) \
41 : "=&a" (oldval), "=&r" (ret), \
42 "+m" (*uaddr), "=&r" (tem) \
43 : "r" (oparg), "i" (-EFAULT), "1" (0))
45 static inline int arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
,
48 int oldval
= 0, ret
, tem
;
54 __futex_atomic_op1("xchgl %0, %2", ret
, oldval
, uaddr
, oparg
);
57 __futex_atomic_op1(LOCK_PREFIX
"xaddl %0, %2", ret
, oldval
,
61 __futex_atomic_op2("orl %4, %3", ret
, oldval
, uaddr
, oparg
);
64 __futex_atomic_op2("andl %4, %3", ret
, oldval
, uaddr
, ~oparg
);
67 __futex_atomic_op2("xorl %4, %3", ret
, oldval
, uaddr
, oparg
);
81 static inline int futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
82 u32 oldval
, u32 newval
)
84 return user_atomic_cmpxchg_inatomic(uval
, uaddr
, oldval
, newval
);
88 #endif /* _ASM_X86_FUTEX_H */