1 #ifndef _ASM_ARM_FUTEX_H
2 #define _ASM_ARM_FUTEX_H
6 #if defined(CONFIG_CPU_USE_DOMAINS) && defined(CONFIG_SMP)
7 /* ARM doesn't provide unprivileged exclusive memory accessors */
8 #include <asm-generic/futex.h>
11 #include <linux/futex.h>
12 #include <linux/uaccess.h>
13 #include <asm/errno.h>
15 #define __futex_atomic_ex_table(err_reg) \
17 " .pushsection __ex_table,\"a\"\n" \
19 " .long 1b, 4f, 2b, 4f\n" \
21 " .pushsection .fixup,\"ax\"\n" \
22 "4: mov %0, " err_reg "\n" \
28 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
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) \
43 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
44 u32 oldval
, u32 newval
)
49 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
53 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
56 " ite eq @ explicit IT needed for the 2b label\n"
57 "2: strexeq %0, %3, [%4]\n"
61 __futex_atomic_ex_table("%5")
62 : "=&r" (ret
), "=&r" (val
)
63 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
71 #else /* !SMP, we can work around lack of atomic ops by disabling preemption */
73 #include <linux/preempt.h>
74 #include <asm/domain.h>
76 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
77 __asm__ __volatile__( \
78 "1: " T(ldr) " %1, [%3]\n" \
80 "2: " T(str) " %0, [%3]\n" \
82 __futex_atomic_ex_table("%5") \
83 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
84 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
88 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
89 u32 oldval
, u32 newval
)
94 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
97 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
98 "1: " T(ldr
) " %1, [%4]\n"
100 " it eq @ explicit IT needed for the 2b label\n"
101 "2: " T(streq
) " %3, [%4]\n"
102 __futex_atomic_ex_table("%5")
103 : "+r" (ret
), "=&r" (val
)
104 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
114 futex_atomic_op_inuser (int encoded_op
, u32 __user
*uaddr
)
116 int op
= (encoded_op
>> 28) & 7;
117 int cmp
= (encoded_op
>> 24) & 15;
118 int oparg
= (encoded_op
<< 8) >> 20;
119 int cmparg
= (encoded_op
<< 20) >> 20;
120 int oldval
= 0, ret
, tmp
;
122 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
125 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
128 pagefault_disable(); /* implies preempt_disable() */
132 __futex_atomic_op("mov %0, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
135 __futex_atomic_op("add %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
138 __futex_atomic_op("orr %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
141 __futex_atomic_op("and %0, %1, %4", ret
, oldval
, tmp
, uaddr
, ~oparg
);
144 __futex_atomic_op("eor %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
150 pagefault_enable(); /* subsumes preempt_enable() */
154 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
155 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
156 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
157 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
158 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
159 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
160 default: ret
= -ENOSYS
;
166 #endif /* !(CPU_USE_DOMAINS && SMP) */
167 #endif /* __KERNEL__ */
168 #endif /* _ASM_ARM_FUTEX_H */