This source file includes following definitions.
- arch_futex_atomic_op_inuser
- futex_atomic_cmpxchg_inatomic
- arch_futex_atomic_op_inuser
- futex_atomic_cmpxchg_inatomic
1
2 #ifndef _ASM_GENERIC_FUTEX_H
3 #define _ASM_GENERIC_FUTEX_H
4
5 #include <linux/futex.h>
6 #include <linux/uaccess.h>
7 #include <asm/errno.h>
8
9 #ifndef CONFIG_SMP
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 static inline int
31 arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
32 {
33 int oldval, ret;
34 u32 tmp;
35
36 preempt_disable();
37 pagefault_disable();
38
39 ret = -EFAULT;
40 if (unlikely(get_user(oldval, uaddr) != 0))
41 goto out_pagefault_enable;
42
43 ret = 0;
44 tmp = oldval;
45
46 switch (op) {
47 case FUTEX_OP_SET:
48 tmp = oparg;
49 break;
50 case FUTEX_OP_ADD:
51 tmp += oparg;
52 break;
53 case FUTEX_OP_OR:
54 tmp |= oparg;
55 break;
56 case FUTEX_OP_ANDN:
57 tmp &= ~oparg;
58 break;
59 case FUTEX_OP_XOR:
60 tmp ^= oparg;
61 break;
62 default:
63 ret = -ENOSYS;
64 }
65
66 if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0))
67 ret = -EFAULT;
68
69 out_pagefault_enable:
70 pagefault_enable();
71 preempt_enable();
72
73 if (ret == 0)
74 *oval = oldval;
75
76 return ret;
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 static inline int
95 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
96 u32 oldval, u32 newval)
97 {
98 u32 val;
99
100 preempt_disable();
101 if (unlikely(get_user(val, uaddr) != 0)) {
102 preempt_enable();
103 return -EFAULT;
104 }
105
106 if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) {
107 preempt_enable();
108 return -EFAULT;
109 }
110
111 *uval = val;
112 preempt_enable();
113
114 return 0;
115 }
116
117 #else
118 static inline int
119 arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
120 {
121 return -ENOSYS;
122 }
123
124 static inline int
125 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
126 u32 oldval, u32 newval)
127 {
128 return -ENOSYS;
129 }
130
131 #endif
132 #endif