blob: 3c2344f48136d98351f92b6e9d678e29c052658c [file] [log] [blame]
Jeff Dikef8aaeace2006-01-08 01:01:32 -08001#ifndef _ASM_GENERIC_FUTEX_H
2#define _ASM_GENERIC_FUTEX_H
3
Jeff Dikef8aaeace2006-01-08 01:01:32 -08004#include <linux/futex.h>
Jeff Dike730f4122008-04-30 00:54:49 -07005#include <linux/uaccess.h>
Jeff Dikef8aaeace2006-01-08 01:01:32 -08006#include <asm/errno.h>
Jeff Dikef8aaeace2006-01-08 01:01:32 -08007
8static inline int
9futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
10{
11 int op = (encoded_op >> 28) & 7;
12 int cmp = (encoded_op >> 24) & 15;
13 int oparg = (encoded_op << 8) >> 20;
14 int cmparg = (encoded_op << 20) >> 20;
15 int oldval = 0, ret;
16 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
17 oparg = 1 << oparg;
18
19 if (! access_ok (VERIFY_WRITE, uaddr, sizeof(int)))
20 return -EFAULT;
21
Peter Zijlstraa8663742006-12-06 20:32:20 -080022 pagefault_disable();
Jeff Dikef8aaeace2006-01-08 01:01:32 -080023
24 switch (op) {
25 case FUTEX_OP_SET:
26 case FUTEX_OP_ADD:
27 case FUTEX_OP_OR:
28 case FUTEX_OP_ANDN:
29 case FUTEX_OP_XOR:
30 default:
31 ret = -ENOSYS;
32 }
33
Peter Zijlstraa8663742006-12-06 20:32:20 -080034 pagefault_enable();
Jeff Dikef8aaeace2006-01-08 01:01:32 -080035
36 if (!ret) {
37 switch (cmp) {
38 case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
39 case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
40 case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
41 case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
42 case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
43 case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
44 default: ret = -ENOSYS;
45 }
46 }
47 return ret;
48}
49
Ingo Molnare9056f12006-03-27 01:16:21 -080050static inline int
Ingo Molnar8f17d3a2006-03-27 01:16:27 -080051futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
Ingo Molnare9056f12006-03-27 01:16:21 -080052{
53 return -ENOSYS;
54}
55
Jeff Dikef8aaeace2006-01-08 01:01:32 -080056#endif