1 #ifndef _ASM_ARM_FUTEX_H
2 #define _ASM_ARM_FUTEX_H
6 #include <linux/futex.h>
7 #include <linux/uaccess.h>
10 #define __futex_atomic_ex_table(err_reg) \
12 " .pushsection __ex_table,\"a\"\n" \
14 " .long 1b, 4f, 2b, 4f\n" \
16 " .pushsection .text.fixup,\"ax\"\n" \
18 "4: mov %0, " err_reg "\n" \
24 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
26 unsigned int __ua_flags; \
29 __ua_flags = uaccess_save_and_enable(); \
30 __asm__ __volatile__( \
31 "1: ldrex %1, [%3]\n" \
33 "2: strex %2, %0, [%3]\n" \
37 __futex_atomic_ex_table("%5") \
38 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
39 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
41 uaccess_restore(__ua_flags); \
45 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
46 u32 oldval
, u32 newval
)
48 unsigned int __ua_flags
;
52 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
56 /* Prefetching cannot fault */
58 __ua_flags
= uaccess_save_and_enable();
59 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
62 " ite eq @ explicit IT needed for the 2b label\n"
63 "2: strexeq %0, %3, [%4]\n"
67 __futex_atomic_ex_table("%5")
68 : "=&r" (ret
), "=&r" (val
)
69 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
71 uaccess_restore(__ua_flags
);
78 #else /* !SMP, we can work around lack of atomic ops by disabling preemption */
80 #include <linux/preempt.h>
81 #include <asm/domain.h>
83 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
85 unsigned int __ua_flags = uaccess_save_and_enable(); \
86 __asm__ __volatile__( \
87 "1: " TUSER(ldr) " %1, [%3]\n" \
89 "2: " TUSER(str) " %0, [%3]\n" \
91 __futex_atomic_ex_table("%5") \
92 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
93 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
95 uaccess_restore(__ua_flags); \
99 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
100 u32 oldval
, u32 newval
)
102 unsigned int __ua_flags
;
106 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
110 __ua_flags
= uaccess_save_and_enable();
111 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
112 "1: " TUSER(ldr
) " %1, [%4]\n"
114 " it eq @ explicit IT needed for the 2b label\n"
115 "2: " TUSER(streq
) " %3, [%4]\n"
116 __futex_atomic_ex_table("%5")
117 : "+r" (ret
), "=&r" (val
)
118 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
120 uaccess_restore(__ua_flags
);
131 futex_atomic_op_inuser (int encoded_op
, u32 __user
*uaddr
)
133 int op
= (encoded_op
>> 28) & 7;
134 int cmp
= (encoded_op
>> 24) & 15;
135 int oparg
= (encoded_op
<< 8) >> 20;
136 int cmparg
= (encoded_op
<< 20) >> 20;
137 int oldval
= 0, ret
, tmp
;
139 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
142 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
152 __futex_atomic_op("mov %0, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
155 __futex_atomic_op("add %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
158 __futex_atomic_op("orr %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
161 __futex_atomic_op("and %0, %1, %4", ret
, oldval
, tmp
, uaddr
, ~oparg
);
164 __futex_atomic_op("eor %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
177 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
178 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
179 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
180 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
181 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
182 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
183 default: ret
= -ENOSYS
;
189 #endif /* __KERNEL__ */
190 #endif /* _ASM_ARM_FUTEX_H */