]>
Commit | Line | Data |
---|---|---|
f8aaeace JD |
1 | #ifndef _ASM_GENERIC_FUTEX_H |
2 | #define _ASM_GENERIC_FUTEX_H | |
3 | ||
f8aaeace | 4 | #include <linux/futex.h> |
730f412c | 5 | #include <linux/uaccess.h> |
f8aaeace | 6 | #include <asm/errno.h> |
f8aaeace | 7 | |
00f634bc LFT |
8 | #ifndef CONFIG_SMP |
9 | /* | |
10 | * The following implementation only for uniprocessor machines. | |
f3dae07e | 11 | * It relies on preempt_disable() ensuring mutual exclusion. |
00f634bc LFT |
12 | * |
13 | */ | |
14 | ||
15 | /** | |
30d6e0a4 | 16 | * arch_futex_atomic_op_inuser() - Atomic arithmetic operation with constant |
00f634bc LFT |
17 | * argument and comparison of the previous |
18 | * futex value with another constant. | |
19 | * | |
20 | * @encoded_op: encoded operation to execute | |
21 | * @uaddr: pointer to user space address | |
22 | * | |
23 | * Return: | |
24 | * 0 - On success | |
25 | * <0 - On error | |
26 | */ | |
27 | static inline int | |
30d6e0a4 | 28 | arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr) |
00f634bc | 29 | { |
00f634bc LFT |
30 | int oldval, ret; |
31 | u32 tmp; | |
32 | ||
f3dae07e | 33 | preempt_disable(); |
00f634bc LFT |
34 | pagefault_disable(); |
35 | ||
36 | ret = -EFAULT; | |
37 | if (unlikely(get_user(oldval, uaddr) != 0)) | |
38 | goto out_pagefault_enable; | |
39 | ||
40 | ret = 0; | |
41 | tmp = oldval; | |
42 | ||
43 | switch (op) { | |
44 | case FUTEX_OP_SET: | |
45 | tmp = oparg; | |
46 | break; | |
47 | case FUTEX_OP_ADD: | |
48 | tmp += oparg; | |
49 | break; | |
50 | case FUTEX_OP_OR: | |
51 | tmp |= oparg; | |
52 | break; | |
53 | case FUTEX_OP_ANDN: | |
54 | tmp &= ~oparg; | |
55 | break; | |
56 | case FUTEX_OP_XOR: | |
57 | tmp ^= oparg; | |
58 | break; | |
59 | default: | |
60 | ret = -ENOSYS; | |
61 | } | |
62 | ||
63 | if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0)) | |
64 | ret = -EFAULT; | |
65 | ||
66 | out_pagefault_enable: | |
67 | pagefault_enable(); | |
f3dae07e | 68 | preempt_enable(); |
00f634bc | 69 | |
30d6e0a4 JS |
70 | if (ret == 0) |
71 | *oval = oldval; | |
72 | ||
00f634bc LFT |
73 | return ret; |
74 | } | |
75 | ||
76 | /** | |
77 | * futex_atomic_cmpxchg_inatomic() - Compare and exchange the content of the | |
78 | * uaddr with newval if the current value is | |
79 | * oldval. | |
80 | * @uval: pointer to store content of @uaddr | |
81 | * @uaddr: pointer to user space address | |
82 | * @oldval: old value | |
83 | * @newval: new value to store to @uaddr | |
84 | * | |
85 | * Return: | |
86 | * 0 - On success | |
87 | * <0 - On error | |
88 | */ | |
89 | static inline int | |
90 | futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, | |
91 | u32 oldval, u32 newval) | |
92 | { | |
93 | u32 val; | |
94 | ||
d9b9ff8c | 95 | preempt_disable(); |
fba7cd68 RP |
96 | if (unlikely(get_user(val, uaddr) != 0)) { |
97 | preempt_enable(); | |
00f634bc | 98 | return -EFAULT; |
fba7cd68 | 99 | } |
00f634bc | 100 | |
fba7cd68 RP |
101 | if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) { |
102 | preempt_enable(); | |
00f634bc | 103 | return -EFAULT; |
fba7cd68 | 104 | } |
00f634bc LFT |
105 | |
106 | *uval = val; | |
d9b9ff8c | 107 | preempt_enable(); |
00f634bc LFT |
108 | |
109 | return 0; | |
110 | } | |
111 | ||
112 | #else | |
f8aaeace | 113 | static inline int |
30d6e0a4 | 114 | arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr) |
f8aaeace | 115 | { |
f8aaeace | 116 | int oldval = 0, ret; |
f8aaeace | 117 | |
a866374a | 118 | pagefault_disable(); |
f8aaeace JD |
119 | |
120 | switch (op) { | |
121 | case FUTEX_OP_SET: | |
122 | case FUTEX_OP_ADD: | |
123 | case FUTEX_OP_OR: | |
124 | case FUTEX_OP_ANDN: | |
125 | case FUTEX_OP_XOR: | |
126 | default: | |
127 | ret = -ENOSYS; | |
128 | } | |
129 | ||
a866374a | 130 | pagefault_enable(); |
f8aaeace | 131 | |
30d6e0a4 JS |
132 | if (!ret) |
133 | *oval = oldval; | |
134 | ||
f8aaeace JD |
135 | return ret; |
136 | } | |
137 | ||
e9056f13 | 138 | static inline int |
8d7718aa ML |
139 | futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, |
140 | u32 oldval, u32 newval) | |
e9056f13 IM |
141 | { |
142 | return -ENOSYS; | |
143 | } | |
144 | ||
00f634bc | 145 | #endif /* CONFIG_SMP */ |
f8aaeace | 146 | #endif |