1 #ifndef _ASM_GENERIC_FUTEX_H
2 #define _ASM_GENERIC_FUTEX_H
4 #include <linux/futex.h>
5 #include <linux/uaccess.h>
10 * The following implementation only for uniprocessor machines.
11 * For UP, it's relies on the fact that pagefault_disable() also disables
12 * preemption to ensure mutual exclusion.
17 * futex_atomic_op_inuser() - Atomic arithmetic operation with constant
18 * argument and comparison of the previous
19 * futex value with another constant.
21 * @encoded_op: encoded operation to execute
22 * @uaddr: pointer to user space address
29 futex_atomic_op_inuser(int encoded_op
, u32 __user
*uaddr
)
31 int op
= (encoded_op
>> 28) & 7;
32 int cmp
= (encoded_op
>> 24) & 15;
33 int oparg
= (encoded_op
<< 8) >> 20;
34 int cmparg
= (encoded_op
<< 20) >> 20;
38 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
44 if (unlikely(get_user(oldval
, uaddr
) != 0))
45 goto out_pagefault_enable
;
70 if (ret
== 0 && unlikely(put_user(tmp
, uaddr
) != 0))
78 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
79 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
80 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
81 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
82 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
83 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
84 default: ret
= -ENOSYS
;
91 * futex_atomic_cmpxchg_inatomic() - Compare and exchange the content of the
92 * uaddr with newval if the current value is
94 * @uval: pointer to store content of @uaddr
95 * @uaddr: pointer to user space address
97 * @newval: new value to store to @uaddr
104 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
105 u32 oldval
, u32 newval
)
109 if (unlikely(get_user(val
, uaddr
) != 0))
112 if (val
== oldval
&& unlikely(put_user(newval
, uaddr
) != 0))
122 futex_atomic_op_inuser (int encoded_op
, u32 __user
*uaddr
)
124 int op
= (encoded_op
>> 28) & 7;
125 int cmp
= (encoded_op
>> 24) & 15;
126 int oparg
= (encoded_op
<< 8) >> 20;
127 int cmparg
= (encoded_op
<< 20) >> 20;
129 if (encoded_op
& (FUTEX_OP_OPARG_SHIFT
<< 28))
132 if (! access_ok (VERIFY_WRITE
, uaddr
, sizeof(u32
)))
151 case FUTEX_OP_CMP_EQ
: ret
= (oldval
== cmparg
); break;
152 case FUTEX_OP_CMP_NE
: ret
= (oldval
!= cmparg
); break;
153 case FUTEX_OP_CMP_LT
: ret
= (oldval
< cmparg
); break;
154 case FUTEX_OP_CMP_GE
: ret
= (oldval
>= cmparg
); break;
155 case FUTEX_OP_CMP_LE
: ret
= (oldval
<= cmparg
); break;
156 case FUTEX_OP_CMP_GT
: ret
= (oldval
> cmparg
); break;
157 default: ret
= -ENOSYS
;
164 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
,
165 u32 oldval
, u32 newval
)
170 #endif /* CONFIG_SMP */