xref: /linux/arch/parisc/include/asm/futex.h (revision 8d7718aa082aaf30a0b4989e1f04858952f941bc)
1deae26bfSKyle McMartin #ifndef _ASM_PARISC_FUTEX_H
2deae26bfSKyle McMartin #define _ASM_PARISC_FUTEX_H
3deae26bfSKyle McMartin 
4deae26bfSKyle McMartin #ifdef __KERNEL__
5deae26bfSKyle McMartin 
6deae26bfSKyle McMartin #include <linux/futex.h>
7deae26bfSKyle McMartin #include <linux/uaccess.h>
8deae26bfSKyle McMartin #include <asm/errno.h>
9deae26bfSKyle McMartin 
10deae26bfSKyle McMartin static inline int
11*8d7718aaSMichel Lespinasse futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
12deae26bfSKyle McMartin {
13deae26bfSKyle McMartin 	int op = (encoded_op >> 28) & 7;
14deae26bfSKyle McMartin 	int cmp = (encoded_op >> 24) & 15;
15deae26bfSKyle McMartin 	int oparg = (encoded_op << 8) >> 20;
16deae26bfSKyle McMartin 	int cmparg = (encoded_op << 20) >> 20;
17deae26bfSKyle McMartin 	int oldval = 0, ret;
18deae26bfSKyle McMartin 	if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
19deae26bfSKyle McMartin 		oparg = 1 << oparg;
20deae26bfSKyle McMartin 
21*8d7718aaSMichel Lespinasse 	if (! access_ok (VERIFY_WRITE, uaddr, sizeof(u32)))
22deae26bfSKyle McMartin 		return -EFAULT;
23deae26bfSKyle McMartin 
24deae26bfSKyle McMartin 	pagefault_disable();
25deae26bfSKyle McMartin 
26deae26bfSKyle McMartin 	switch (op) {
27deae26bfSKyle McMartin 	case FUTEX_OP_SET:
28deae26bfSKyle McMartin 	case FUTEX_OP_ADD:
29deae26bfSKyle McMartin 	case FUTEX_OP_OR:
30deae26bfSKyle McMartin 	case FUTEX_OP_ANDN:
31deae26bfSKyle McMartin 	case FUTEX_OP_XOR:
32deae26bfSKyle McMartin 	default:
33deae26bfSKyle McMartin 		ret = -ENOSYS;
34deae26bfSKyle McMartin 	}
35deae26bfSKyle McMartin 
36deae26bfSKyle McMartin 	pagefault_enable();
37deae26bfSKyle McMartin 
38deae26bfSKyle McMartin 	if (!ret) {
39deae26bfSKyle McMartin 		switch (cmp) {
40deae26bfSKyle McMartin 		case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
41deae26bfSKyle McMartin 		case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
42deae26bfSKyle McMartin 		case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
43deae26bfSKyle McMartin 		case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
44deae26bfSKyle McMartin 		case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
45deae26bfSKyle McMartin 		case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
46deae26bfSKyle McMartin 		default: ret = -ENOSYS;
47deae26bfSKyle McMartin 		}
48deae26bfSKyle McMartin 	}
49deae26bfSKyle McMartin 	return ret;
50deae26bfSKyle McMartin }
51deae26bfSKyle McMartin 
52deae26bfSKyle McMartin /* Non-atomic version */
53deae26bfSKyle McMartin static inline int
54*8d7718aaSMichel Lespinasse futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
55*8d7718aaSMichel Lespinasse 			      u32 oldval, u32 newval)
56deae26bfSKyle McMartin {
57*8d7718aaSMichel Lespinasse 	u32 val;
58deae26bfSKyle McMartin 
59deae26bfSKyle McMartin 	/* futex.c wants to do a cmpxchg_inatomic on kernel NULL, which is
60deae26bfSKyle McMartin 	 * our gateway page, and causes no end of trouble...
61deae26bfSKyle McMartin 	 */
62deae26bfSKyle McMartin 	if (segment_eq(KERNEL_DS, get_fs()) && !uaddr)
63deae26bfSKyle McMartin 		return -EFAULT;
64deae26bfSKyle McMartin 
65*8d7718aaSMichel Lespinasse 	if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
66deae26bfSKyle McMartin 		return -EFAULT;
67deae26bfSKyle McMartin 
6837a9d912SMichel Lespinasse 	if (get_user(val, uaddr))
6937a9d912SMichel Lespinasse 		return -EFAULT;
7037a9d912SMichel Lespinasse 	if (val == oldval && put_user(newval, uaddr))
7137a9d912SMichel Lespinasse 		return -EFAULT;
7237a9d912SMichel Lespinasse 	*uval = val;
7337a9d912SMichel Lespinasse 	return 0;
74deae26bfSKyle McMartin }
75deae26bfSKyle McMartin 
76deae26bfSKyle McMartin #endif /*__KERNEL__*/
77deae26bfSKyle McMartin #endif /*_ASM_PARISC_FUTEX_H*/
78