Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __ALPHA_UACCESS_H |
3 | #define __ALPHA_UACCESS_H | |
4 | ||
12700c17 | 5 | #include <asm-generic/access_ok.h> |
1da177e4 LT |
6 | /* |
7 | * These are the main single-value transfer routines. They automatically | |
8 | * use the right size if we just have the right pointer type. | |
9 | * | |
10 | * As the alpha uses the same address space for kernel and user | |
11 | * data, we can just do these as direct assignments. (Of course, the | |
12 | * exception handling means that it's no longer "just"...) | |
13 | * | |
14 | * Careful to not | |
15 | * (a) re-use the arguments for side effects (sizeof/typeof is ok) | |
16 | * (b) require any knowledge of processes at this stage | |
17 | */ | |
4fb9bccb | 18 | #define put_user(x, ptr) \ |
d78d834b | 19 | __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr))) |
4fb9bccb | 20 | #define get_user(x, ptr) \ |
d78d834b | 21 | __get_user_check((x), (ptr), sizeof(*(ptr))) |
1da177e4 LT |
22 | |
23 | /* | |
24 | * The "__xxx" versions do not do address space checking, useful when | |
25 | * doing multiple accesses to the same area (the programmer has to do the | |
26 | * checks by hand with "access_ok()") | |
27 | */ | |
4fb9bccb MT |
28 | #define __put_user(x, ptr) \ |
29 | __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr))) | |
30 | #define __get_user(x, ptr) \ | |
31 | __get_user_nocheck((x), (ptr), sizeof(*(ptr))) | |
1da177e4 LT |
32 | |
33 | /* | |
34 | * The "lda %1, 2b-1b(%0)" bits are magic to get the assembler to | |
35 | * encode the bits we need for resolving the exception. See the | |
36 | * more extensive comments with fixup_inline_exception below for | |
37 | * more information. | |
38 | */ | |
ca282f69 AV |
39 | #define EXC(label,cont,res,err) \ |
40 | ".section __ex_table,\"a\"\n" \ | |
41 | " .long "#label"-.\n" \ | |
42 | " lda "#res","#cont"-"#label"("#err")\n" \ | |
43 | ".previous\n" | |
1da177e4 LT |
44 | |
45 | extern void __get_user_unknown(void); | |
46 | ||
4fb9bccb | 47 | #define __get_user_nocheck(x, ptr, size) \ |
1da177e4 LT |
48 | ({ \ |
49 | long __gu_err = 0; \ | |
50 | unsigned long __gu_val; \ | |
51 | __chk_user_ptr(ptr); \ | |
52 | switch (size) { \ | |
53 | case 1: __get_user_8(ptr); break; \ | |
54 | case 2: __get_user_16(ptr); break; \ | |
55 | case 4: __get_user_32(ptr); break; \ | |
56 | case 8: __get_user_64(ptr); break; \ | |
57 | default: __get_user_unknown(); break; \ | |
58 | } \ | |
1ab5786a | 59 | (x) = (__force __typeof__(*(ptr))) __gu_val; \ |
1da177e4 LT |
60 | __gu_err; \ |
61 | }) | |
62 | ||
c9df6025 AV |
63 | #define __get_user_check(x, ptr, size) \ |
64 | ({ \ | |
65 | long __gu_err = -EFAULT; \ | |
66 | unsigned long __gu_val = 0; \ | |
67 | const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ | |
12700c17 | 68 | if (__access_ok(__gu_addr, size)) { \ |
c9df6025 AV |
69 | __gu_err = 0; \ |
70 | switch (size) { \ | |
71 | case 1: __get_user_8(__gu_addr); break; \ | |
72 | case 2: __get_user_16(__gu_addr); break; \ | |
73 | case 4: __get_user_32(__gu_addr); break; \ | |
74 | case 8: __get_user_64(__gu_addr); break; \ | |
75 | default: __get_user_unknown(); break; \ | |
76 | } \ | |
77 | } \ | |
78 | (x) = (__force __typeof__(*(ptr))) __gu_val; \ | |
79 | __gu_err; \ | |
1da177e4 LT |
80 | }) |
81 | ||
82 | struct __large_struct { unsigned long buf[100]; }; | |
83 | #define __m(x) (*(struct __large_struct __user *)(x)) | |
84 | ||
85 | #define __get_user_64(addr) \ | |
86 | __asm__("1: ldq %0,%2\n" \ | |
87 | "2:\n" \ | |
ca282f69 | 88 | EXC(1b,2b,%0,%1) \ |
1da177e4 LT |
89 | : "=r"(__gu_val), "=r"(__gu_err) \ |
90 | : "m"(__m(addr)), "1"(__gu_err)) | |
91 | ||
92 | #define __get_user_32(addr) \ | |
93 | __asm__("1: ldl %0,%2\n" \ | |
94 | "2:\n" \ | |
ca282f69 | 95 | EXC(1b,2b,%0,%1) \ |
1da177e4 LT |
96 | : "=r"(__gu_val), "=r"(__gu_err) \ |
97 | : "m"(__m(addr)), "1"(__gu_err)) | |
98 | ||
1da177e4 LT |
99 | #define __get_user_16(addr) \ |
100 | __asm__("1: ldwu %0,%2\n" \ | |
101 | "2:\n" \ | |
ca282f69 | 102 | EXC(1b,2b,%0,%1) \ |
1da177e4 LT |
103 | : "=r"(__gu_val), "=r"(__gu_err) \ |
104 | : "m"(__m(addr)), "1"(__gu_err)) | |
105 | ||
106 | #define __get_user_8(addr) \ | |
107 | __asm__("1: ldbu %0,%2\n" \ | |
108 | "2:\n" \ | |
ca282f69 | 109 | EXC(1b,2b,%0,%1) \ |
1da177e4 LT |
110 | : "=r"(__gu_val), "=r"(__gu_err) \ |
111 | : "m"(__m(addr)), "1"(__gu_err)) | |
1da177e4 LT |
112 | |
113 | extern void __put_user_unknown(void); | |
114 | ||
4fb9bccb | 115 | #define __put_user_nocheck(x, ptr, size) \ |
1da177e4 LT |
116 | ({ \ |
117 | long __pu_err = 0; \ | |
118 | __chk_user_ptr(ptr); \ | |
119 | switch (size) { \ | |
4fb9bccb MT |
120 | case 1: __put_user_8(x, ptr); break; \ |
121 | case 2: __put_user_16(x, ptr); break; \ | |
122 | case 4: __put_user_32(x, ptr); break; \ | |
123 | case 8: __put_user_64(x, ptr); break; \ | |
1da177e4 LT |
124 | default: __put_user_unknown(); break; \ |
125 | } \ | |
126 | __pu_err; \ | |
127 | }) | |
128 | ||
c9df6025 AV |
129 | #define __put_user_check(x, ptr, size) \ |
130 | ({ \ | |
131 | long __pu_err = -EFAULT; \ | |
132 | __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ | |
12700c17 | 133 | if (__access_ok(__pu_addr, size)) { \ |
c9df6025 AV |
134 | __pu_err = 0; \ |
135 | switch (size) { \ | |
136 | case 1: __put_user_8(x, __pu_addr); break; \ | |
137 | case 2: __put_user_16(x, __pu_addr); break; \ | |
138 | case 4: __put_user_32(x, __pu_addr); break; \ | |
139 | case 8: __put_user_64(x, __pu_addr); break; \ | |
140 | default: __put_user_unknown(); break; \ | |
141 | } \ | |
142 | } \ | |
143 | __pu_err; \ | |
1da177e4 LT |
144 | }) |
145 | ||
146 | /* | |
147 | * The "__put_user_xx()" macros tell gcc they read from memory | |
148 | * instead of writing: this is because they do not write to | |
149 | * any memory gcc knows about, so there are no aliasing issues | |
150 | */ | |
4fb9bccb | 151 | #define __put_user_64(x, addr) \ |
1da177e4 LT |
152 | __asm__ __volatile__("1: stq %r2,%1\n" \ |
153 | "2:\n" \ | |
ca282f69 | 154 | EXC(1b,2b,$31,%0) \ |
1da177e4 LT |
155 | : "=r"(__pu_err) \ |
156 | : "m" (__m(addr)), "rJ" (x), "0"(__pu_err)) | |
157 | ||
4fb9bccb | 158 | #define __put_user_32(x, addr) \ |
1da177e4 LT |
159 | __asm__ __volatile__("1: stl %r2,%1\n" \ |
160 | "2:\n" \ | |
ca282f69 | 161 | EXC(1b,2b,$31,%0) \ |
1da177e4 LT |
162 | : "=r"(__pu_err) \ |
163 | : "m"(__m(addr)), "rJ"(x), "0"(__pu_err)) | |
164 | ||
4fb9bccb | 165 | #define __put_user_16(x, addr) \ |
1da177e4 LT |
166 | __asm__ __volatile__("1: stw %r2,%1\n" \ |
167 | "2:\n" \ | |
ca282f69 | 168 | EXC(1b,2b,$31,%0) \ |
1da177e4 LT |
169 | : "=r"(__pu_err) \ |
170 | : "m"(__m(addr)), "rJ"(x), "0"(__pu_err)) | |
171 | ||
4fb9bccb | 172 | #define __put_user_8(x, addr) \ |
1da177e4 LT |
173 | __asm__ __volatile__("1: stb %r2,%1\n" \ |
174 | "2:\n" \ | |
ca282f69 | 175 | EXC(1b,2b,$31,%0) \ |
1da177e4 LT |
176 | : "=r"(__pu_err) \ |
177 | : "m"(__m(addr)), "rJ"(x), "0"(__pu_err)) | |
1da177e4 LT |
178 | |
179 | /* | |
180 | * Complex access routines | |
181 | */ | |
182 | ||
85250231 | 183 | extern long __copy_user(void *to, const void *from, long len); |
1da177e4 | 184 | |
ec022681 AV |
185 | static inline unsigned long |
186 | raw_copy_from_user(void *to, const void __user *from, unsigned long len) | |
1da177e4 | 187 | { |
ec022681 | 188 | return __copy_user(to, (__force const void *)from, len); |
1da177e4 LT |
189 | } |
190 | ||
ec022681 AV |
191 | static inline unsigned long |
192 | raw_copy_to_user(void __user *to, const void *from, unsigned long len) | |
1da177e4 | 193 | { |
ec022681 | 194 | return __copy_user((__force void *)to, from, len); |
1da177e4 LT |
195 | } |
196 | ||
85250231 | 197 | extern long __clear_user(void __user *to, long len); |
1da177e4 | 198 | |
12700c17 | 199 | static inline long |
1da177e4 LT |
200 | clear_user(void __user *to, long len) |
201 | { | |
12700c17 | 202 | if (__access_ok(to, len)) |
1da177e4 LT |
203 | len = __clear_user(to, len); |
204 | return len; | |
205 | } | |
206 | ||
f2db633d | 207 | extern long strncpy_from_user(char *dest, const char __user *src, long count); |
f2db633d | 208 | extern __must_check long strnlen_user(const char __user *str, long n); |
1da177e4 | 209 | |
b5478c1b | 210 | #include <asm/extable.h> |
1da177e4 LT |
211 | |
212 | #endif /* __ALPHA_UACCESS_H */ |