futex.h 1.2 KB
Newer Older
J
Jeff Dike 已提交
1 2 3 4
#ifndef _ASM_GENERIC_FUTEX_H
#define _ASM_GENERIC_FUTEX_H

#include <linux/futex.h>
5
#include <linux/uaccess.h>
J
Jeff Dike 已提交
6 7 8
#include <asm/errno.h>

static inline int
9
futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
J
Jeff Dike 已提交
10 11 12 13 14 15 16 17 18
{
	int op = (encoded_op >> 28) & 7;
	int cmp = (encoded_op >> 24) & 15;
	int oparg = (encoded_op << 8) >> 20;
	int cmparg = (encoded_op << 20) >> 20;
	int oldval = 0, ret;
	if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
		oparg = 1 << oparg;

19
	if (! access_ok (VERIFY_WRITE, uaddr, sizeof(u32)))
J
Jeff Dike 已提交
20 21
		return -EFAULT;

22
	pagefault_disable();
J
Jeff Dike 已提交
23 24 25 26 27 28 29 30 31 32 33

	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;
	}

34
	pagefault_enable();
J
Jeff Dike 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

	if (!ret) {
		switch (cmp) {
		case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
		case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
		case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
		case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
		case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
		case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
		default: ret = -ENOSYS;
		}
	}
	return ret;
}

50
static inline int
51 52
futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
			      u32 oldval, u32 newval)
53 54 55 56
{
	return -ENOSYS;
}

J
Jeff Dike 已提交
57
#endif