Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 1 | #ifndef _ASM_GENERIC_FUTEX_H |
| 2 | #define _ASM_GENERIC_FUTEX_H |
| 3 | |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 4 | #include <linux/futex.h> |
Jeff Dike | 730f412 | 2008-04-30 00:54:49 -0700 | [diff] [blame] | 5 | #include <linux/uaccess.h> |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 6 | #include <asm/errno.h> |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 7 | |
| 8 | static inline int |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame^] | 9 | futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 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 | |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame^] | 19 | if (! access_ok (VERIFY_WRITE, uaddr, sizeof(u32))) |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 20 | return -EFAULT; |
| 21 | |
Peter Zijlstra | a866374 | 2006-12-06 20:32:20 -0800 | [diff] [blame] | 22 | pagefault_disable(); |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 23 | |
| 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 Zijlstra | a866374 | 2006-12-06 20:32:20 -0800 | [diff] [blame] | 34 | pagefault_enable(); |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 35 | |
| 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 Molnar | e9056f1 | 2006-03-27 01:16:21 -0800 | [diff] [blame] | 50 | static inline int |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame^] | 51 | futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, |
| 52 | u32 oldval, u32 newval) |
Ingo Molnar | e9056f1 | 2006-03-27 01:16:21 -0800 | [diff] [blame] | 53 | { |
| 54 | return -ENOSYS; |
| 55 | } |
| 56 | |
Jeff Dike | f8aaeace | 2006-01-08 01:01:32 -0800 | [diff] [blame] | 57 | #endif |