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) \
27 __asm__ __volatile__( \
28 "1: ldrex %1, [%3]\n" \
30 "2: strex %2, %0, [%3]\n" \
34 __futex_atomic_ex_table("%5") \
35 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
36 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
40 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
41 u32 oldval
, u32 newval
)
46 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
50 /* Prefetching cannot fault */
52 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
55 " ite eq @ explicit IT needed for the 2b label\n"
56 "2: strexeq %0, %3, [%4]\n"
60 __futex_atomic_ex_table("%5")
61 : "=&r" (ret
), "=&r" (val
)
62 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
70 #else /* !SMP, we can work around lack of atomic ops by disabling preemption */
72 #include <linux/preempt.h>
73 #include <asm/domain.h>
75 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \
76 __asm__ __volatile__( \
77 "1: " TUSER(ldr) " %1, [%3]\n" \
79 "2: " TUSER(str) " %0, [%3]\n" \
81 __futex_atomic_ex_table("%5") \
82 : "=&r" (ret), "=&r" (oldval), "=&r" (tmp) \
83 : "r" (uaddr), "r" (oparg), "Ir" (-EFAULT) \
87 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
88 u32 oldval
, u32 newval
)
93 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
96 __asm__
__volatile__("@futex_atomic_cmpxchg_inatomic\n"
97 "1: " TUSER(ldr
) " %1, [%4]\n"
99 " it eq @ explicit IT needed for the 2b label\n"
100 "2: " TUSER(streq
) " %3, [%4]\n"
101 __futex_atomic_ex_table("%5")
102 : "+r" (ret
), "=&r" (val
)
103 : "r" (oldval
), "r" (newval
), "r" (uaddr
), "Ir" (-EFAULT
)
113 futex_atomic_op_inuser (int encoded_op
, u32 __user
*uaddr
)
115 int op
= (encoded_op
>> 28) & 7;
116 int cmp
= (encoded_op
>> 24) & 15;
117 int oparg
= (encoded_op
<< 8) >> 20;
118 int cmparg
= (encoded_op
<< 20) >> 20;
119 int oldval
= 0, ret
, tmp
;
121 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
124 if (!access_ok(VERIFY_WRITE
, uaddr
, sizeof(u32
)))
127 pagefault_disable(); /* implies preempt_disable() */
131 __futex_atomic_op("mov %0, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
134 __futex_atomic_op("add %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
137 __futex_atomic_op("orr %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
140 __futex_atomic_op("and %0, %1, %4", ret
, oldval
, tmp
, uaddr
, ~oparg
);
143 __futex_atomic_op("eor %0, %1, %4", ret
, oldval
, tmp
, uaddr
, oparg
);
149 pagefault_enable(); /* subsumes preempt_enable() */
153 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
154 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
155 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
156 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
157 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
158 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
159 default: ret
= -ENOSYS
;
165 #endif /* __KERNEL__ */
166 #endif /* _ASM_ARM_FUTEX_H */