diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-m32r/uaccess.h |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'include/asm-m32r/uaccess.h')
-rw-r--r-- | include/asm-m32r/uaccess.h | 753 |
1 files changed, 753 insertions, 0 deletions
diff --git a/include/asm-m32r/uaccess.h b/include/asm-m32r/uaccess.h new file mode 100644 index 000000000000..bbb8ac4018a0 --- /dev/null +++ b/include/asm-m32r/uaccess.h | |||
@@ -0,0 +1,753 @@ | |||
1 | #ifndef _ASM_M32R_UACCESS_H | ||
2 | #define _ASM_M32R_UACCESS_H | ||
3 | |||
4 | /* | ||
5 | * linux/include/asm-m32r/uaccess.h | ||
6 | * | ||
7 | * M32R version. | ||
8 | * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org> | ||
9 | */ | ||
10 | |||
11 | #undef UACCESS_DEBUG | ||
12 | |||
13 | #ifdef UACCESS_DEBUG | ||
14 | #define UAPRINTK(args...) printk(args) | ||
15 | #else | ||
16 | #define UAPRINTK(args...) | ||
17 | #endif /* UACCESS_DEBUG */ | ||
18 | |||
19 | /* | ||
20 | * User space memory access functions | ||
21 | */ | ||
22 | #include <linux/config.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/thread_info.h> | ||
25 | #include <asm/page.h> | ||
26 | |||
27 | #define VERIFY_READ 0 | ||
28 | #define VERIFY_WRITE 1 | ||
29 | |||
30 | /* | ||
31 | * The fs value determines whether argument validity checking should be | ||
32 | * performed or not. If get_fs() == USER_DS, checking is performed, with | ||
33 | * get_fs() == KERNEL_DS, checking is bypassed. | ||
34 | * | ||
35 | * For historical reasons, these macros are grossly misnamed. | ||
36 | */ | ||
37 | |||
38 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) | ||
39 | |||
40 | #ifdef CONFIG_MMU | ||
41 | #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) | ||
42 | #define USER_DS MAKE_MM_SEG(PAGE_OFFSET) | ||
43 | #else | ||
44 | #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) | ||
45 | #define USER_DS MAKE_MM_SEG(0xFFFFFFFF) | ||
46 | #endif /* CONFIG_MMU */ | ||
47 | |||
48 | #define get_ds() (KERNEL_DS) | ||
49 | #ifdef CONFIG_MMU | ||
50 | #define get_fs() (current_thread_info()->addr_limit) | ||
51 | #define set_fs(x) (current_thread_info()->addr_limit = (x)) | ||
52 | #else | ||
53 | static inline mm_segment_t get_fs(void) | ||
54 | { | ||
55 | return USER_DS; | ||
56 | } | ||
57 | |||
58 | static inline void set_fs(mm_segment_t s) | ||
59 | { | ||
60 | } | ||
61 | #endif /* CONFIG_MMU */ | ||
62 | |||
63 | #define segment_eq(a,b) ((a).seg == (b).seg) | ||
64 | |||
65 | #define __addr_ok(addr) \ | ||
66 | ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg)) | ||
67 | |||
68 | /* | ||
69 | * Test whether a block of memory is a valid user space address. | ||
70 | * Returns 0 if the range is valid, nonzero otherwise. | ||
71 | * | ||
72 | * This is equivalent to the following test: | ||
73 | * (u33)addr + (u33)size >= (u33)current->addr_limit.seg | ||
74 | * | ||
75 | * This needs 33-bit arithmetic. We have a carry... | ||
76 | */ | ||
77 | #define __range_ok(addr,size) ({ \ | ||
78 | unsigned long flag, sum; \ | ||
79 | __chk_user_ptr(addr); \ | ||
80 | asm ( \ | ||
81 | " cmpu %1, %1 ; clear cbit\n" \ | ||
82 | " addx %1, %3 ; set cbit if overflow\n" \ | ||
83 | " subx %0, %0\n" \ | ||
84 | " cmpu %4, %1\n" \ | ||
85 | " subx %0, %5\n" \ | ||
86 | : "=&r"(flag), "=r"(sum) \ | ||
87 | : "1"(addr), "r"((int)(size)), \ | ||
88 | "r"(current_thread_info()->addr_limit.seg), "r"(0) \ | ||
89 | : "cbit" ); \ | ||
90 | flag; }) | ||
91 | |||
92 | /** | ||
93 | * access_ok: - Checks if a user space pointer is valid | ||
94 | * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that | ||
95 | * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe | ||
96 | * to write to a block, it is always safe to read from it. | ||
97 | * @addr: User space pointer to start of block to check | ||
98 | * @size: Size of block to check | ||
99 | * | ||
100 | * Context: User context only. This function may sleep. | ||
101 | * | ||
102 | * Checks if a pointer to a block of memory in user space is valid. | ||
103 | * | ||
104 | * Returns true (nonzero) if the memory block may be valid, false (zero) | ||
105 | * if it is definitely invalid. | ||
106 | * | ||
107 | * Note that, depending on architecture, this function probably just | ||
108 | * checks that the pointer is in the user space range - after calling | ||
109 | * this function, memory access functions may still return -EFAULT. | ||
110 | */ | ||
111 | #ifdef CONFIG_MMU | ||
112 | #define access_ok(type,addr,size) (likely(__range_ok(addr,size) == 0)) | ||
113 | #else | ||
114 | static inline int access_ok(int type, const void *addr, unsigned long size) | ||
115 | { | ||
116 | extern unsigned long memory_start, memory_end; | ||
117 | unsigned long val = (unsigned long)addr; | ||
118 | |||
119 | return ((val >= memory_start) && ((val + size) < memory_end)); | ||
120 | } | ||
121 | #endif /* CONFIG_MMU */ | ||
122 | |||
123 | /** | ||
124 | * verify_area: - Obsolete/deprecated and will go away soon, | ||
125 | * use access_ok() instead. | ||
126 | * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE | ||
127 | * @addr: User space pointer to start of block to check | ||
128 | * @size: Size of block to check | ||
129 | * | ||
130 | * Context: User context only. This function may sleep. | ||
131 | * | ||
132 | * This function has been replaced by access_ok(). | ||
133 | * | ||
134 | * Checks if a pointer to a block of memory in user space is valid. | ||
135 | * | ||
136 | * Returns zero if the memory block may be valid, -EFAULT | ||
137 | * if it is definitely invalid. | ||
138 | * | ||
139 | * See access_ok() for more details. | ||
140 | */ | ||
141 | static inline int __deprecated verify_area(int type, const void __user *addr, | ||
142 | unsigned long size) | ||
143 | { | ||
144 | return access_ok(type, addr, size) ? 0 : -EFAULT; | ||
145 | } | ||
146 | |||
147 | |||
148 | /* | ||
149 | * The exception table consists of pairs of addresses: the first is the | ||
150 | * address of an instruction that is allowed to fault, and the second is | ||
151 | * the address at which the program should continue. No registers are | ||
152 | * modified, so it is entirely up to the continuation code to figure out | ||
153 | * what to do. | ||
154 | * | ||
155 | * All the routines below use bits of fixup code that are out of line | ||
156 | * with the main instruction path. This means when everything is well, | ||
157 | * we don't even have to jump over them. Further, they do not intrude | ||
158 | * on our cache or tlb entries. | ||
159 | */ | ||
160 | |||
161 | struct exception_table_entry | ||
162 | { | ||
163 | unsigned long insn, fixup; | ||
164 | }; | ||
165 | |||
166 | extern int fixup_exception(struct pt_regs *regs); | ||
167 | |||
168 | /* | ||
169 | * These are the main single-value transfer routines. They automatically | ||
170 | * use the right size if we just have the right pointer type. | ||
171 | * | ||
172 | * This gets kind of ugly. We want to return _two_ values in "get_user()" | ||
173 | * and yet we don't want to do any pointers, because that is too much | ||
174 | * of a performance impact. Thus we have a few rather ugly macros here, | ||
175 | * and hide all the uglyness from the user. | ||
176 | * | ||
177 | * The "__xxx" versions of the user access functions are versions that | ||
178 | * do not verify the address space, that must have been done previously | ||
179 | * with a separate "access_ok()" call (this is used when we do multiple | ||
180 | * accesses to the same area of user memory). | ||
181 | */ | ||
182 | |||
183 | extern void __get_user_1(void); | ||
184 | extern void __get_user_2(void); | ||
185 | extern void __get_user_4(void); | ||
186 | |||
187 | #ifndef MODULE | ||
188 | #define __get_user_x(size,ret,x,ptr) \ | ||
189 | __asm__ __volatile__( \ | ||
190 | " mv r0, %0\n" \ | ||
191 | " mv r1, %1\n" \ | ||
192 | " bl __get_user_" #size "\n" \ | ||
193 | " mv %0, r0\n" \ | ||
194 | " mv %1, r1\n" \ | ||
195 | : "=r"(ret), "=r"(x) \ | ||
196 | : "0"(ptr) \ | ||
197 | : "r0", "r1", "r14" ) | ||
198 | #else /* MODULE */ | ||
199 | /* | ||
200 | * Use "jl" instead of "bl" for MODULE | ||
201 | */ | ||
202 | #define __get_user_x(size,ret,x,ptr) \ | ||
203 | __asm__ __volatile__( \ | ||
204 | " mv r0, %0\n" \ | ||
205 | " mv r1, %1\n" \ | ||
206 | " seth lr, #high(__get_user_" #size ")\n" \ | ||
207 | " or3 lr, lr, #low(__get_user_" #size ")\n" \ | ||
208 | " jl lr\n" \ | ||
209 | " mv %0, r0\n" \ | ||
210 | " mv %1, r1\n" \ | ||
211 | : "=r"(ret), "=r"(x) \ | ||
212 | : "0"(ptr) \ | ||
213 | : "r0", "r1", "r14" ) | ||
214 | #endif | ||
215 | |||
216 | /* Careful: we have to cast the result to the type of the pointer for sign | ||
217 | reasons */ | ||
218 | /** | ||
219 | * get_user: - Get a simple variable from user space. | ||
220 | * @x: Variable to store result. | ||
221 | * @ptr: Source address, in user space. | ||
222 | * | ||
223 | * Context: User context only. This function may sleep. | ||
224 | * | ||
225 | * This macro copies a single simple variable from user space to kernel | ||
226 | * space. It supports simple types like char and int, but not larger | ||
227 | * data types like structures or arrays. | ||
228 | * | ||
229 | * @ptr must have pointer-to-simple-variable type, and the result of | ||
230 | * dereferencing @ptr must be assignable to @x without a cast. | ||
231 | * | ||
232 | * Returns zero on success, or -EFAULT on error. | ||
233 | * On error, the variable @x is set to zero. | ||
234 | */ | ||
235 | #define get_user(x,ptr) \ | ||
236 | ({ int __ret_gu,__val_gu; \ | ||
237 | __chk_user_ptr(ptr); \ | ||
238 | switch(sizeof (*(ptr))) { \ | ||
239 | case 1: __get_user_x(1,__ret_gu,__val_gu,ptr); break; \ | ||
240 | case 2: __get_user_x(2,__ret_gu,__val_gu,ptr); break; \ | ||
241 | case 4: __get_user_x(4,__ret_gu,__val_gu,ptr); break; \ | ||
242 | default: __get_user_x(X,__ret_gu,__val_gu,ptr); break; \ | ||
243 | } \ | ||
244 | (x) = (__typeof__(*(ptr)))__val_gu; \ | ||
245 | __ret_gu; \ | ||
246 | }) | ||
247 | |||
248 | extern void __put_user_bad(void); | ||
249 | |||
250 | /** | ||
251 | * put_user: - Write a simple value into user space. | ||
252 | * @x: Value to copy to user space. | ||
253 | * @ptr: Destination address, in user space. | ||
254 | * | ||
255 | * Context: User context only. This function may sleep. | ||
256 | * | ||
257 | * This macro copies a single simple value from kernel space to user | ||
258 | * space. It supports simple types like char and int, but not larger | ||
259 | * data types like structures or arrays. | ||
260 | * | ||
261 | * @ptr must have pointer-to-simple-variable type, and @x must be assignable | ||
262 | * to the result of dereferencing @ptr. | ||
263 | * | ||
264 | * Returns zero on success, or -EFAULT on error. | ||
265 | */ | ||
266 | #define put_user(x,ptr) \ | ||
267 | __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr))) | ||
268 | |||
269 | |||
270 | /** | ||
271 | * __get_user: - Get a simple variable from user space, with less checking. | ||
272 | * @x: Variable to store result. | ||
273 | * @ptr: Source address, in user space. | ||
274 | * | ||
275 | * Context: User context only. This function may sleep. | ||
276 | * | ||
277 | * This macro copies a single simple variable from user space to kernel | ||
278 | * space. It supports simple types like char and int, but not larger | ||
279 | * data types like structures or arrays. | ||
280 | * | ||
281 | * @ptr must have pointer-to-simple-variable type, and the result of | ||
282 | * dereferencing @ptr must be assignable to @x without a cast. | ||
283 | * | ||
284 | * Caller must check the pointer with access_ok() before calling this | ||
285 | * function. | ||
286 | * | ||
287 | * Returns zero on success, or -EFAULT on error. | ||
288 | * On error, the variable @x is set to zero. | ||
289 | */ | ||
290 | #define __get_user(x,ptr) \ | ||
291 | __get_user_nocheck((x),(ptr),sizeof(*(ptr))) | ||
292 | |||
293 | |||
294 | /** | ||
295 | * __put_user: - Write a simple value into user space, with less checking. | ||
296 | * @x: Value to copy to user space. | ||
297 | * @ptr: Destination address, in user space. | ||
298 | * | ||
299 | * Context: User context only. This function may sleep. | ||
300 | * | ||
301 | * This macro copies a single simple value from kernel space to user | ||
302 | * space. It supports simple types like char and int, but not larger | ||
303 | * data types like structures or arrays. | ||
304 | * | ||
305 | * @ptr must have pointer-to-simple-variable type, and @x must be assignable | ||
306 | * to the result of dereferencing @ptr. | ||
307 | * | ||
308 | * Caller must check the pointer with access_ok() before calling this | ||
309 | * function. | ||
310 | * | ||
311 | * Returns zero on success, or -EFAULT on error. | ||
312 | */ | ||
313 | #define __put_user(x,ptr) \ | ||
314 | __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr))) | ||
315 | |||
316 | #define __put_user_nocheck(x,ptr,size) \ | ||
317 | ({ \ | ||
318 | long __pu_err; \ | ||
319 | __put_user_size((x),(ptr),(size),__pu_err); \ | ||
320 | __pu_err; \ | ||
321 | }) | ||
322 | |||
323 | |||
324 | #define __put_user_check(x,ptr,size) \ | ||
325 | ({ \ | ||
326 | long __pu_err = -EFAULT; \ | ||
327 | __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ | ||
328 | might_sleep(); \ | ||
329 | if (access_ok(VERIFY_WRITE,__pu_addr,size)) \ | ||
330 | __put_user_size((x),__pu_addr,(size),__pu_err); \ | ||
331 | __pu_err; \ | ||
332 | }) | ||
333 | |||
334 | #if defined(__LITTLE_ENDIAN__) | ||
335 | #define __put_user_u64(x, addr, err) \ | ||
336 | __asm__ __volatile__( \ | ||
337 | " .fillinsn\n" \ | ||
338 | "1: st %L1,@%2\n" \ | ||
339 | " .fillinsn\n" \ | ||
340 | "2: st %H1,@(4,%2)\n" \ | ||
341 | " .fillinsn\n" \ | ||
342 | "3:\n" \ | ||
343 | ".section .fixup,\"ax\"\n" \ | ||
344 | " .balign 4\n" \ | ||
345 | "4: ldi %0,%3\n" \ | ||
346 | " seth r14,#high(3b)\n" \ | ||
347 | " or3 r14,r14,#low(3b)\n" \ | ||
348 | " jmp r14\n" \ | ||
349 | ".previous\n" \ | ||
350 | ".section __ex_table,\"a\"\n" \ | ||
351 | " .balign 4\n" \ | ||
352 | " .long 1b,4b\n" \ | ||
353 | " .long 2b,4b\n" \ | ||
354 | ".previous" \ | ||
355 | : "=r"(err) \ | ||
356 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err) \ | ||
357 | : "r14", "memory") | ||
358 | |||
359 | #elif defined(__BIG_ENDIAN__) | ||
360 | #define __put_user_u64(x, addr, err) \ | ||
361 | __asm__ __volatile__( \ | ||
362 | " .fillinsn\n" \ | ||
363 | "1: st %H1,@%2\n" \ | ||
364 | " .fillinsn\n" \ | ||
365 | "2: st %L1,@(4,%2)\n" \ | ||
366 | " .fillinsn\n" \ | ||
367 | "3:\n" \ | ||
368 | ".section .fixup,\"ax\"\n" \ | ||
369 | " .balign 4\n" \ | ||
370 | "4: ldi %0,%3\n" \ | ||
371 | " seth r14,#high(3b)\n" \ | ||
372 | " or3 r14,r14,#low(3b)\n" \ | ||
373 | " jmp r14\n" \ | ||
374 | ".previous\n" \ | ||
375 | ".section __ex_table,\"a\"\n" \ | ||
376 | " .balign 4\n" \ | ||
377 | " .long 1b,4b\n" \ | ||
378 | " .long 2b,4b\n" \ | ||
379 | ".previous" \ | ||
380 | : "=r"(err) \ | ||
381 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err) \ | ||
382 | : "r14", "memory") | ||
383 | #else | ||
384 | #error no endian defined | ||
385 | #endif | ||
386 | |||
387 | #define __put_user_size(x,ptr,size,retval) \ | ||
388 | do { \ | ||
389 | retval = 0; \ | ||
390 | __chk_user_ptr(ptr); \ | ||
391 | switch (size) { \ | ||
392 | case 1: __put_user_asm(x,ptr,retval,"b"); break; \ | ||
393 | case 2: __put_user_asm(x,ptr,retval,"h"); break; \ | ||
394 | case 4: __put_user_asm(x,ptr,retval,""); break; \ | ||
395 | case 8: __put_user_u64((__typeof__(*ptr))(x),ptr,retval); break;\ | ||
396 | default: __put_user_bad(); \ | ||
397 | } \ | ||
398 | } while (0) | ||
399 | |||
400 | struct __large_struct { unsigned long buf[100]; }; | ||
401 | #define __m(x) (*(struct __large_struct *)(x)) | ||
402 | |||
403 | /* | ||
404 | * Tell gcc we read from memory instead of writing: this is because | ||
405 | * we do not write to any memory gcc knows about, so there are no | ||
406 | * aliasing issues. | ||
407 | */ | ||
408 | #define __put_user_asm(x, addr, err, itype) \ | ||
409 | __asm__ __volatile__( \ | ||
410 | " .fillinsn\n" \ | ||
411 | "1: st"itype" %1,@%2\n" \ | ||
412 | " .fillinsn\n" \ | ||
413 | "2:\n" \ | ||
414 | ".section .fixup,\"ax\"\n" \ | ||
415 | " .balign 4\n" \ | ||
416 | "3: ldi %0,%3\n" \ | ||
417 | " seth r14,#high(2b)\n" \ | ||
418 | " or3 r14,r14,#low(2b)\n" \ | ||
419 | " jmp r14\n" \ | ||
420 | ".previous\n" \ | ||
421 | ".section __ex_table,\"a\"\n" \ | ||
422 | " .balign 4\n" \ | ||
423 | " .long 1b,3b\n" \ | ||
424 | ".previous" \ | ||
425 | : "=r"(err) \ | ||
426 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err) \ | ||
427 | : "r14", "memory") | ||
428 | |||
429 | #define __get_user_nocheck(x,ptr,size) \ | ||
430 | ({ \ | ||
431 | long __gu_err, __gu_val; \ | ||
432 | __get_user_size(__gu_val,(ptr),(size),__gu_err); \ | ||
433 | (x) = (__typeof__(*(ptr)))__gu_val; \ | ||
434 | __gu_err; \ | ||
435 | }) | ||
436 | |||
437 | extern long __get_user_bad(void); | ||
438 | |||
439 | #define __get_user_size(x,ptr,size,retval) \ | ||
440 | do { \ | ||
441 | retval = 0; \ | ||
442 | __chk_user_ptr(ptr); \ | ||
443 | switch (size) { \ | ||
444 | case 1: __get_user_asm(x,ptr,retval,"ub"); break; \ | ||
445 | case 2: __get_user_asm(x,ptr,retval,"uh"); break; \ | ||
446 | case 4: __get_user_asm(x,ptr,retval,""); break; \ | ||
447 | default: (x) = __get_user_bad(); \ | ||
448 | } \ | ||
449 | } while (0) | ||
450 | |||
451 | #define __get_user_asm(x, addr, err, itype) \ | ||
452 | __asm__ __volatile__( \ | ||
453 | " .fillinsn\n" \ | ||
454 | "1: ld"itype" %1,@%2\n" \ | ||
455 | " .fillinsn\n" \ | ||
456 | "2:\n" \ | ||
457 | ".section .fixup,\"ax\"\n" \ | ||
458 | " .balign 4\n" \ | ||
459 | "3: ldi %0,%3\n" \ | ||
460 | " seth r14,#high(2b)\n" \ | ||
461 | " or3 r14,r14,#low(2b)\n" \ | ||
462 | " jmp r14\n" \ | ||
463 | ".previous\n" \ | ||
464 | ".section __ex_table,\"a\"\n" \ | ||
465 | " .balign 4\n" \ | ||
466 | " .long 1b,3b\n" \ | ||
467 | ".previous" \ | ||
468 | : "=r"(err), "=&r"(x) \ | ||
469 | : "r"(addr), "i"(-EFAULT), "0"(err) \ | ||
470 | : "r14", "memory") | ||
471 | |||
472 | /* | ||
473 | * Here we special-case 1, 2 and 4-byte copy_*_user invocations. On a fault | ||
474 | * we return the initial request size (1, 2 or 4), as copy_*_user should do. | ||
475 | * If a store crosses a page boundary and gets a fault, the m32r will not write | ||
476 | * anything, so this is accurate. | ||
477 | */ | ||
478 | |||
479 | |||
480 | /* | ||
481 | * Copy To/From Userspace | ||
482 | */ | ||
483 | |||
484 | /* Generic arbitrary sized copy. */ | ||
485 | /* Return the number of bytes NOT copied. */ | ||
486 | #define __copy_user(to,from,size) \ | ||
487 | do { \ | ||
488 | unsigned long __dst, __src, __c; \ | ||
489 | __asm__ __volatile__ ( \ | ||
490 | " mv r14, %0\n" \ | ||
491 | " or r14, %1\n" \ | ||
492 | " beq %0, %1, 9f\n" \ | ||
493 | " beqz %2, 9f\n" \ | ||
494 | " and3 r14, r14, #3\n" \ | ||
495 | " bnez r14, 2f\n" \ | ||
496 | " and3 %2, %2, #3\n" \ | ||
497 | " beqz %3, 2f\n" \ | ||
498 | " addi %0, #-4 ; word_copy \n" \ | ||
499 | " .fillinsn\n" \ | ||
500 | "0: ld r14, @%1+\n" \ | ||
501 | " addi %3, #-1\n" \ | ||
502 | " .fillinsn\n" \ | ||
503 | "1: st r14, @+%0\n" \ | ||
504 | " bnez %3, 0b\n" \ | ||
505 | " beqz %2, 9f\n" \ | ||
506 | " addi %0, #4\n" \ | ||
507 | " .fillinsn\n" \ | ||
508 | "2: ldb r14, @%1 ; byte_copy \n" \ | ||
509 | " .fillinsn\n" \ | ||
510 | "3: stb r14, @%0\n" \ | ||
511 | " addi %1, #1\n" \ | ||
512 | " addi %2, #-1\n" \ | ||
513 | " addi %0, #1\n" \ | ||
514 | " bnez %2, 2b\n" \ | ||
515 | " .fillinsn\n" \ | ||
516 | "9:\n" \ | ||
517 | ".section .fixup,\"ax\"\n" \ | ||
518 | " .balign 4\n" \ | ||
519 | "5: addi %3, #1\n" \ | ||
520 | " addi %1, #-4\n" \ | ||
521 | " .fillinsn\n" \ | ||
522 | "6: slli %3, #2\n" \ | ||
523 | " add %2, %3\n" \ | ||
524 | " addi %0, #4\n" \ | ||
525 | " .fillinsn\n" \ | ||
526 | "7: seth r14, #high(9b)\n" \ | ||
527 | " or3 r14, r14, #low(9b)\n" \ | ||
528 | " jmp r14\n" \ | ||
529 | ".previous\n" \ | ||
530 | ".section __ex_table,\"a\"\n" \ | ||
531 | " .balign 4\n" \ | ||
532 | " .long 0b,6b\n" \ | ||
533 | " .long 1b,5b\n" \ | ||
534 | " .long 2b,9b\n" \ | ||
535 | " .long 3b,9b\n" \ | ||
536 | ".previous\n" \ | ||
537 | : "=&r"(__dst), "=&r"(__src), "=&r"(size), "=&r"(__c) \ | ||
538 | : "0"(to), "1"(from), "2"(size), "3"(size / 4) \ | ||
539 | : "r14", "memory"); \ | ||
540 | } while (0) | ||
541 | |||
542 | #define __copy_user_zeroing(to,from,size) \ | ||
543 | do { \ | ||
544 | unsigned long __dst, __src, __c; \ | ||
545 | __asm__ __volatile__ ( \ | ||
546 | " mv r14, %0\n" \ | ||
547 | " or r14, %1\n" \ | ||
548 | " beq %0, %1, 9f\n" \ | ||
549 | " beqz %2, 9f\n" \ | ||
550 | " and3 r14, r14, #3\n" \ | ||
551 | " bnez r14, 2f\n" \ | ||
552 | " and3 %2, %2, #3\n" \ | ||
553 | " beqz %3, 2f\n" \ | ||
554 | " addi %0, #-4 ; word_copy \n" \ | ||
555 | " .fillinsn\n" \ | ||
556 | "0: ld r14, @%1+\n" \ | ||
557 | " addi %3, #-1\n" \ | ||
558 | " .fillinsn\n" \ | ||
559 | "1: st r14, @+%0\n" \ | ||
560 | " bnez %3, 0b\n" \ | ||
561 | " beqz %2, 9f\n" \ | ||
562 | " addi %0, #4\n" \ | ||
563 | " .fillinsn\n" \ | ||
564 | "2: ldb r14, @%1 ; byte_copy \n" \ | ||
565 | " .fillinsn\n" \ | ||
566 | "3: stb r14, @%0\n" \ | ||
567 | " addi %1, #1\n" \ | ||
568 | " addi %2, #-1\n" \ | ||
569 | " addi %0, #1\n" \ | ||
570 | " bnez %2, 2b\n" \ | ||
571 | " .fillinsn\n" \ | ||
572 | "9:\n" \ | ||
573 | ".section .fixup,\"ax\"\n" \ | ||
574 | " .balign 4\n" \ | ||
575 | "5: addi %3, #1\n" \ | ||
576 | " addi %1, #-4\n" \ | ||
577 | " .fillinsn\n" \ | ||
578 | "6: slli %3, #2\n" \ | ||
579 | " add %2, %3\n" \ | ||
580 | " addi %0, #4\n" \ | ||
581 | " .fillinsn\n" \ | ||
582 | "7: ldi r14, #0 ; store zero \n" \ | ||
583 | " .fillinsn\n" \ | ||
584 | "8: addi %2, #-1\n" \ | ||
585 | " stb r14, @%0 ; ACE? \n" \ | ||
586 | " addi %0, #1\n" \ | ||
587 | " bnez %2, 8b\n" \ | ||
588 | " seth r14, #high(9b)\n" \ | ||
589 | " or3 r14, r14, #low(9b)\n" \ | ||
590 | " jmp r14\n" \ | ||
591 | ".previous\n" \ | ||
592 | ".section __ex_table,\"a\"\n" \ | ||
593 | " .balign 4\n" \ | ||
594 | " .long 0b,6b\n" \ | ||
595 | " .long 1b,5b\n" \ | ||
596 | " .long 2b,7b\n" \ | ||
597 | " .long 3b,7b\n" \ | ||
598 | ".previous\n" \ | ||
599 | : "=&r"(__dst), "=&r"(__src), "=&r"(size), "=&r"(__c) \ | ||
600 | : "0"(to), "1"(from), "2"(size), "3"(size / 4) \ | ||
601 | : "r14", "memory"); \ | ||
602 | } while (0) | ||
603 | |||
604 | |||
605 | /* We let the __ versions of copy_from/to_user inline, because they're often | ||
606 | * used in fast paths and have only a small space overhead. | ||
607 | */ | ||
608 | static inline unsigned long __generic_copy_from_user_nocheck(void *to, | ||
609 | const void __user *from, unsigned long n) | ||
610 | { | ||
611 | __copy_user_zeroing(to,from,n); | ||
612 | return n; | ||
613 | } | ||
614 | |||
615 | static inline unsigned long __generic_copy_to_user_nocheck(void __user *to, | ||
616 | const void *from, unsigned long n) | ||
617 | { | ||
618 | __copy_user(to,from,n); | ||
619 | return n; | ||
620 | } | ||
621 | |||
622 | unsigned long __generic_copy_to_user(void *, const void *, unsigned long); | ||
623 | unsigned long __generic_copy_from_user(void *, const void *, unsigned long); | ||
624 | |||
625 | /** | ||
626 | * __copy_to_user: - Copy a block of data into user space, with less checking. | ||
627 | * @to: Destination address, in user space. | ||
628 | * @from: Source address, in kernel space. | ||
629 | * @n: Number of bytes to copy. | ||
630 | * | ||
631 | * Context: User context only. This function may sleep. | ||
632 | * | ||
633 | * Copy data from kernel space to user space. Caller must check | ||
634 | * the specified block with access_ok() before calling this function. | ||
635 | * | ||
636 | * Returns number of bytes that could not be copied. | ||
637 | * On success, this will be zero. | ||
638 | */ | ||
639 | #define __copy_to_user(to,from,n) \ | ||
640 | __generic_copy_to_user_nocheck((to),(from),(n)) | ||
641 | |||
642 | #define __copy_to_user_inatomic __copy_to_user | ||
643 | #define __copy_from_user_inatomic __copy_from_user | ||
644 | |||
645 | /** | ||
646 | * copy_to_user: - Copy a block of data into user space. | ||
647 | * @to: Destination address, in user space. | ||
648 | * @from: Source address, in kernel space. | ||
649 | * @n: Number of bytes to copy. | ||
650 | * | ||
651 | * Context: User context only. This function may sleep. | ||
652 | * | ||
653 | * Copy data from kernel space to user space. | ||
654 | * | ||
655 | * Returns number of bytes that could not be copied. | ||
656 | * On success, this will be zero. | ||
657 | */ | ||
658 | #define copy_to_user(to,from,n) \ | ||
659 | ({ \ | ||
660 | might_sleep(); \ | ||
661 | __generic_copy_to_user((to),(from),(n)); \ | ||
662 | }) | ||
663 | |||
664 | /** | ||
665 | * __copy_from_user: - Copy a block of data from user space, with less checking. * @to: Destination address, in kernel space. | ||
666 | * @from: Source address, in user space. | ||
667 | * @n: Number of bytes to copy. | ||
668 | * | ||
669 | * Context: User context only. This function may sleep. | ||
670 | * | ||
671 | * Copy data from user space to kernel space. Caller must check | ||
672 | * the specified block with access_ok() before calling this function. | ||
673 | * | ||
674 | * Returns number of bytes that could not be copied. | ||
675 | * On success, this will be zero. | ||
676 | * | ||
677 | * If some data could not be copied, this function will pad the copied | ||
678 | * data to the requested size using zero bytes. | ||
679 | */ | ||
680 | #define __copy_from_user(to,from,n) \ | ||
681 | __generic_copy_from_user_nocheck((to),(from),(n)) | ||
682 | |||
683 | /** | ||
684 | * copy_from_user: - Copy a block of data from user space. | ||
685 | * @to: Destination address, in kernel space. | ||
686 | * @from: Source address, in user space. | ||
687 | * @n: Number of bytes to copy. | ||
688 | * | ||
689 | * Context: User context only. This function may sleep. | ||
690 | * | ||
691 | * Copy data from user space to kernel space. | ||
692 | * | ||
693 | * Returns number of bytes that could not be copied. | ||
694 | * On success, this will be zero. | ||
695 | * | ||
696 | * If some data could not be copied, this function will pad the copied | ||
697 | * data to the requested size using zero bytes. | ||
698 | */ | ||
699 | #define copy_from_user(to,from,n) \ | ||
700 | ({ \ | ||
701 | might_sleep(); \ | ||
702 | __generic_copy_from_user((to),(from),(n)); \ | ||
703 | }) | ||
704 | |||
705 | long __must_check strncpy_from_user(char *dst, const char __user *src, | ||
706 | long count); | ||
707 | long __must_check __strncpy_from_user(char *dst, | ||
708 | const char __user *src, long count); | ||
709 | |||
710 | /** | ||
711 | * __clear_user: - Zero a block of memory in user space, with less checking. | ||
712 | * @to: Destination address, in user space. | ||
713 | * @n: Number of bytes to zero. | ||
714 | * | ||
715 | * Zero a block of memory in user space. Caller must check | ||
716 | * the specified block with access_ok() before calling this function. | ||
717 | * | ||
718 | * Returns number of bytes that could not be cleared. | ||
719 | * On success, this will be zero. | ||
720 | */ | ||
721 | unsigned long __clear_user(void __user *mem, unsigned long len); | ||
722 | |||
723 | /** | ||
724 | * clear_user: - Zero a block of memory in user space. | ||
725 | * @to: Destination address, in user space. | ||
726 | * @n: Number of bytes to zero. | ||
727 | * | ||
728 | * Zero a block of memory in user space. Caller must check | ||
729 | * the specified block with access_ok() before calling this function. | ||
730 | * | ||
731 | * Returns number of bytes that could not be cleared. | ||
732 | * On success, this will be zero. | ||
733 | */ | ||
734 | unsigned long clear_user(void __user *mem, unsigned long len); | ||
735 | |||
736 | /** | ||
737 | * strlen_user: - Get the size of a string in user space. | ||
738 | * @str: The string to measure. | ||
739 | * | ||
740 | * Context: User context only. This function may sleep. | ||
741 | * | ||
742 | * Get the size of a NUL-terminated string in user space. | ||
743 | * | ||
744 | * Returns the size of the string INCLUDING the terminating NUL. | ||
745 | * On exception, returns 0. | ||
746 | * | ||
747 | * If there is a limit on the length of a valid string, you may wish to | ||
748 | * consider using strnlen_user() instead. | ||
749 | */ | ||
750 | #define strlen_user(str) strnlen_user(str, ~0UL >> 1) | ||
751 | long strnlen_user(const char __user *str, long n); | ||
752 | |||
753 | #endif /* _ASM_M32R_UACCESS_H */ | ||