2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2006-01-08 01:01:32 -08:00
|
|
|
#ifndef _ASM_GENERIC_FUTEX_H
|
|
|
|
|
#define _ASM_GENERIC_FUTEX_H
|
|
|
|
|
|
|
|
|
|
#include <linux/futex.h>
|
2008-04-30 00:54:49 -07:00
|
|
|
#include <linux/uaccess.h>
|
2006-01-08 01:01:32 -08:00
|
|
|
#include <asm/errno.h>
|
|
|
|
|
|
2014-11-06 15:19:34 +08:00
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
|
/*
|
|
|
|
|
* The following implementation only for uniprocessor machines.
|
2015-05-11 17:52:13 +02:00
|
|
|
* It relies on preempt_disable() ensuring mutual exclusion.
|
2014-11-06 15:19:34 +08:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-24 09:31:05 +02:00
|
|
|
* arch_futex_atomic_op_inuser() - Atomic arithmetic operation with constant
|
2014-11-06 15:19:34 +08:00
|
|
|
* argument and comparison of the previous
|
|
|
|
|
* futex value with another constant.
|
|
|
|
|
*
|
|
|
|
|
* @encoded_op: encoded operation to execute
|
|
|
|
|
* @uaddr: pointer to user space address
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* 0 - On success
|
|
|
|
|
* <0 - On error
|
|
|
|
|
*/
|
|
|
|
|
static inline int
|
2017-08-24 09:31:05 +02:00
|
|
|
arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
|
2014-11-06 15:19:34 +08:00
|
|
|
{
|
|
|
|
|
int oldval, ret;
|
|
|
|
|
u32 tmp;
|
|
|
|
|
|
2015-05-11 17:52:13 +02:00
|
|
|
preempt_disable();
|
2014-11-06 15:19:34 +08:00
|
|
|
pagefault_disable();
|
|
|
|
|
|
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
if (unlikely(get_user(oldval, uaddr) != 0))
|
|
|
|
|
goto out_pagefault_enable;
|
|
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
tmp = oldval;
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case FUTEX_OP_SET:
|
|
|
|
|
tmp = oparg;
|
|
|
|
|
break;
|
|
|
|
|
case FUTEX_OP_ADD:
|
|
|
|
|
tmp += oparg;
|
|
|
|
|
break;
|
|
|
|
|
case FUTEX_OP_OR:
|
|
|
|
|
tmp |= oparg;
|
|
|
|
|
break;
|
|
|
|
|
case FUTEX_OP_ANDN:
|
|
|
|
|
tmp &= ~oparg;
|
|
|
|
|
break;
|
|
|
|
|
case FUTEX_OP_XOR:
|
|
|
|
|
tmp ^= oparg;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ret = -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0))
|
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
|
|
|
|
|
out_pagefault_enable:
|
|
|
|
|
pagefault_enable();
|
2015-05-11 17:52:13 +02:00
|
|
|
preempt_enable();
|
2014-11-06 15:19:34 +08:00
|
|
|
|
2017-08-24 09:31:05 +02:00
|
|
|
if (ret == 0)
|
|
|
|
|
*oval = oldval;
|
|
|
|
|
|
2014-11-06 15:19:34 +08:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* futex_atomic_cmpxchg_inatomic() - Compare and exchange the content of the
|
|
|
|
|
* uaddr with newval if the current value is
|
|
|
|
|
* oldval.
|
|
|
|
|
* @uval: pointer to store content of @uaddr
|
|
|
|
|
* @uaddr: pointer to user space address
|
|
|
|
|
* @oldval: old value
|
|
|
|
|
* @newval: new value to store to @uaddr
|
|
|
|
|
*
|
|
|
|
|
* Return:
|
|
|
|
|
* 0 - On success
|
|
|
|
|
* <0 - On error
|
|
|
|
|
*/
|
|
|
|
|
static inline int
|
|
|
|
|
futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
|
|
|
|
|
u32 oldval, u32 newval)
|
|
|
|
|
{
|
|
|
|
|
u32 val;
|
|
|
|
|
|
2015-05-11 17:52:14 +02:00
|
|
|
preempt_disable();
|
2016-04-14 15:36:03 +02:00
|
|
|
if (unlikely(get_user(val, uaddr) != 0)) {
|
|
|
|
|
preempt_enable();
|
2014-11-06 15:19:34 +08:00
|
|
|
return -EFAULT;
|
2016-04-14 15:36:03 +02:00
|
|
|
}
|
2014-11-06 15:19:34 +08:00
|
|
|
|
2016-04-14 15:36:03 +02:00
|
|
|
if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) {
|
|
|
|
|
preempt_enable();
|
2014-11-06 15:19:34 +08:00
|
|
|
return -EFAULT;
|
2016-04-14 15:36:03 +02:00
|
|
|
}
|
2014-11-06 15:19:34 +08:00
|
|
|
|
|
|
|
|
*uval = val;
|
2015-05-11 17:52:14 +02:00
|
|
|
preempt_enable();
|
2014-11-06 15:19:34 +08:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
2006-01-08 01:01:32 -08:00
|
|
|
static inline int
|
2017-08-24 09:31:05 +02:00
|
|
|
arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
|
2006-01-08 01:01:32 -08:00
|
|
|
{
|
|
|
|
|
int oldval = 0, ret;
|
|
|
|
|
|
2006-12-06 20:32:20 -08:00
|
|
|
pagefault_disable();
|
2006-01-08 01:01:32 -08:00
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case FUTEX_OP_SET:
|
|
|
|
|
case FUTEX_OP_ADD:
|
|
|
|
|
case FUTEX_OP_OR:
|
|
|
|
|
case FUTEX_OP_ANDN:
|
|
|
|
|
case FUTEX_OP_XOR:
|
|
|
|
|
default:
|
|
|
|
|
ret = -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-06 20:32:20 -08:00
|
|
|
pagefault_enable();
|
2006-01-08 01:01:32 -08:00
|
|
|
|
2017-08-24 09:31:05 +02:00
|
|
|
if (!ret)
|
|
|
|
|
*oval = oldval;
|
|
|
|
|
|
2006-01-08 01:01:32 -08:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-27 01:16:21 -08:00
|
|
|
static inline int
|
2011-03-10 18:50:58 -08:00
|
|
|
futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
|
|
|
|
|
u32 oldval, u32 newval)
|
2006-03-27 01:16:21 -08:00
|
|
|
{
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:19:34 +08:00
|
|
|
#endif /* CONFIG_SMP */
|
2006-01-08 01:01:32 -08:00
|
|
|
#endif
|