Merge master.kernel.org:/home/rmk/linux-2.6-serial
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / asm-mips / uaccess.h
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03, 04 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 */
9 #ifndef _ASM_UACCESS_H
10 #define _ASM_UACCESS_H
11
12 #include <linux/config.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/thread_info.h>
16 #include <asm-generic/uaccess.h>
17
18 /*
19 * The fs value determines whether argument validity checking should be
20 * performed or not. If get_fs() == USER_DS, checking is performed, with
21 * get_fs() == KERNEL_DS, checking is bypassed.
22 *
23 * For historical reasons, these macros are grossly misnamed.
24 */
25 #ifdef CONFIG_32BIT
26
27 #define __UA_LIMIT 0x80000000UL
28
29 #define __UA_ADDR ".word"
30 #define __UA_LA "la"
31 #define __UA_ADDU "addu"
32 #define __UA_t0 "$8"
33 #define __UA_t1 "$9"
34
35 #endif /* CONFIG_32BIT */
36
37 #ifdef CONFIG_64BIT
38
39 #define __UA_LIMIT (- TASK_SIZE)
40
41 #define __UA_ADDR ".dword"
42 #define __UA_LA "dla"
43 #define __UA_ADDU "daddu"
44 #define __UA_t0 "$12"
45 #define __UA_t1 "$13"
46
47 #endif /* CONFIG_64BIT */
48
49 /*
50 * USER_DS is a bitmask that has the bits set that may not be set in a valid
51 * userspace address. Note that we limit 32-bit userspace to 0x7fff8000 but
52 * the arithmetic we're doing only works if the limit is a power of two, so
53 * we use 0x80000000 here on 32-bit kernels. If a process passes an invalid
54 * address in this range it's the process's problem, not ours :-)
55 */
56
57 #define KERNEL_DS ((mm_segment_t) { 0UL })
58 #define USER_DS ((mm_segment_t) { __UA_LIMIT })
59
60 #define VERIFY_READ 0
61 #define VERIFY_WRITE 1
62
63 #define get_ds() (KERNEL_DS)
64 #define get_fs() (current_thread_info()->addr_limit)
65 #define set_fs(x) (current_thread_info()->addr_limit = (x))
66
67 #define segment_eq(a,b) ((a).seg == (b).seg)
68
69
70 /*
71 * Is a address valid? This does a straighforward calculation rather
72 * than tests.
73 *
74 * Address valid if:
75 * - "addr" doesn't have any high-bits set
76 * - AND "size" doesn't have any high-bits set
77 * - AND "addr+size" doesn't have any high-bits set
78 * - OR we are in kernel mode.
79 *
80 * __ua_size() is a trick to avoid runtime checking of positive constant
81 * sizes; for those we already know at compile time that the size is ok.
82 */
83 #define __ua_size(size) \
84 ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size))
85
86 /*
87 * access_ok: - Checks if a user space pointer is valid
88 * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
89 * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
90 * to write to a block, it is always safe to read from it.
91 * @addr: User space pointer to start of block to check
92 * @size: Size of block to check
93 *
94 * Context: User context only. This function may sleep.
95 *
96 * Checks if a pointer to a block of memory in user space is valid.
97 *
98 * Returns true (nonzero) if the memory block may be valid, false (zero)
99 * if it is definitely invalid.
100 *
101 * Note that, depending on architecture, this function probably just
102 * checks that the pointer is in the user space range - after calling
103 * this function, memory access functions may still return -EFAULT.
104 */
105
106 #define __access_mask get_fs().seg
107
108 #define __access_ok(addr, size, mask) \
109 (((signed long)((mask) & ((addr) | ((addr) + (size)) | __ua_size(size)))) == 0)
110
111 #define access_ok(type, addr, size) \
112 likely(__access_ok((unsigned long)(addr), (size),__access_mask))
113
114 /*
115 * put_user: - Write a simple value into user space.
116 * @x: Value to copy to user space.
117 * @ptr: Destination address, in user space.
118 *
119 * Context: User context only. This function may sleep.
120 *
121 * This macro copies a single simple value from kernel space to user
122 * space. It supports simple types like char and int, but not larger
123 * data types like structures or arrays.
124 *
125 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
126 * to the result of dereferencing @ptr.
127 *
128 * Returns zero on success, or -EFAULT on error.
129 */
130 #define put_user(x,ptr) \
131 __put_user_check((x),(ptr),sizeof(*(ptr)))
132
133 /*
134 * get_user: - Get a simple variable from user space.
135 * @x: Variable to store result.
136 * @ptr: Source address, in user space.
137 *
138 * Context: User context only. This function may sleep.
139 *
140 * This macro copies a single simple variable from user space to kernel
141 * space. It supports simple types like char and int, but not larger
142 * data types like structures or arrays.
143 *
144 * @ptr must have pointer-to-simple-variable type, and the result of
145 * dereferencing @ptr must be assignable to @x without a cast.
146 *
147 * Returns zero on success, or -EFAULT on error.
148 * On error, the variable @x is set to zero.
149 */
150 #define get_user(x,ptr) \
151 __get_user_check((x),(ptr),sizeof(*(ptr)))
152
153 /*
154 * __put_user: - Write a simple value into user space, with less checking.
155 * @x: Value to copy to user space.
156 * @ptr: Destination address, in user space.
157 *
158 * Context: User context only. This function may sleep.
159 *
160 * This macro copies a single simple value from kernel space to user
161 * space. It supports simple types like char and int, but not larger
162 * data types like structures or arrays.
163 *
164 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
165 * to the result of dereferencing @ptr.
166 *
167 * Caller must check the pointer with access_ok() before calling this
168 * function.
169 *
170 * Returns zero on success, or -EFAULT on error.
171 */
172 #define __put_user(x,ptr) \
173 __put_user_nocheck((x),(ptr),sizeof(*(ptr)))
174
175 /*
176 * __get_user: - Get a simple variable from user space, with less checking.
177 * @x: Variable to store result.
178 * @ptr: Source address, in user space.
179 *
180 * Context: User context only. This function may sleep.
181 *
182 * This macro copies a single simple variable from user space to kernel
183 * space. It supports simple types like char and int, but not larger
184 * data types like structures or arrays.
185 *
186 * @ptr must have pointer-to-simple-variable type, and the result of
187 * dereferencing @ptr must be assignable to @x without a cast.
188 *
189 * Caller must check the pointer with access_ok() before calling this
190 * function.
191 *
192 * Returns zero on success, or -EFAULT on error.
193 * On error, the variable @x is set to zero.
194 */
195 #define __get_user(x,ptr) \
196 __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
197
198 struct __large_struct { unsigned long buf[100]; };
199 #define __m(x) (*(struct __large_struct __user *)(x))
200
201 /*
202 * Yuck. We need two variants, one for 64bit operation and one
203 * for 32 bit mode and old iron.
204 */
205 #ifdef CONFIG_32BIT
206 #define __GET_USER_DW(val, ptr) __get_user_asm_ll32(val, ptr)
207 #endif
208 #ifdef CONFIG_64BIT
209 #define __GET_USER_DW(val, ptr) __get_user_asm(val, "ld", ptr)
210 #endif
211
212 extern void __get_user_unknown(void);
213
214 #define __get_user_common(val, size, ptr) \
215 do { \
216 switch (size) { \
217 case 1: __get_user_asm(val, "lb", ptr); break; \
218 case 2: __get_user_asm(val, "lh", ptr); break; \
219 case 4: __get_user_asm(val, "lw", ptr); break; \
220 case 8: __GET_USER_DW(val, ptr); break; \
221 default: __get_user_unknown(); break; \
222 } \
223 } while (0)
224
225 #define __get_user_nocheck(x,ptr,size) \
226 ({ \
227 long __gu_err; \
228 \
229 __get_user_common((x), size, ptr); \
230 __gu_err; \
231 })
232
233 #define __get_user_check(x,ptr,size) \
234 ({ \
235 long __gu_err = -EFAULT; \
236 const void __user * __gu_ptr = (ptr); \
237 \
238 if (likely(access_ok(VERIFY_READ, __gu_ptr, size))) \
239 __get_user_common((x), size, __gu_ptr); \
240 \
241 __gu_err; \
242 })
243
244 #define __get_user_asm(val, insn, addr) \
245 { \
246 long __gu_tmp; \
247 \
248 __asm__ __volatile__( \
249 "1: " insn " %1, %3 \n" \
250 "2: \n" \
251 " .section .fixup,\"ax\" \n" \
252 "3: li %0, %4 \n" \
253 " j 2b \n" \
254 " .previous \n" \
255 " .section __ex_table,\"a\" \n" \
256 " "__UA_ADDR "\t1b, 3b \n" \
257 " .previous \n" \
258 : "=r" (__gu_err), "=r" (__gu_tmp) \
259 : "0" (0), "o" (__m(addr)), "i" (-EFAULT)); \
260 \
261 (val) = (__typeof__(val)) __gu_tmp; \
262 }
263
264 /*
265 * Get a long long 64 using 32 bit registers.
266 */
267 #define __get_user_asm_ll32(val, addr) \
268 { \
269 __asm__ __volatile__( \
270 "1: lw %1, (%3) \n" \
271 "2: lw %D1, 4(%3) \n" \
272 " move %0, $0 \n" \
273 "3: .section .fixup,\"ax\" \n" \
274 "4: li %0, %4 \n" \
275 " move %1, $0 \n" \
276 " move %D1, $0 \n" \
277 " j 3b \n" \
278 " .previous \n" \
279 " .section __ex_table,\"a\" \n" \
280 " " __UA_ADDR " 1b, 4b \n" \
281 " " __UA_ADDR " 2b, 4b \n" \
282 " .previous \n" \
283 : "=r" (__gu_err), "=&r" (val) \
284 : "0" (0), "r" (addr), "i" (-EFAULT)); \
285 }
286
287 /*
288 * Yuck. We need two variants, one for 64bit operation and one
289 * for 32 bit mode and old iron.
290 */
291 #ifdef CONFIG_32BIT
292 #define __PUT_USER_DW(ptr) __put_user_asm_ll32(ptr)
293 #endif
294 #ifdef CONFIG_64BIT
295 #define __PUT_USER_DW(ptr) __put_user_asm("sd", ptr)
296 #endif
297
298 #define __put_user_nocheck(x,ptr,size) \
299 ({ \
300 __typeof__(*(ptr)) __pu_val; \
301 long __pu_err = 0; \
302 \
303 __pu_val = (x); \
304 switch (size) { \
305 case 1: __put_user_asm("sb", ptr); break; \
306 case 2: __put_user_asm("sh", ptr); break; \
307 case 4: __put_user_asm("sw", ptr); break; \
308 case 8: __PUT_USER_DW(ptr); break; \
309 default: __put_user_unknown(); break; \
310 } \
311 __pu_err; \
312 })
313
314 #define __put_user_check(x,ptr,size) \
315 ({ \
316 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
317 __typeof__(*(ptr)) __pu_val = (x); \
318 long __pu_err = -EFAULT; \
319 \
320 if (likely(access_ok(VERIFY_WRITE, __pu_addr, size))) { \
321 switch (size) { \
322 case 1: __put_user_asm("sb", __pu_addr); break; \
323 case 2: __put_user_asm("sh", __pu_addr); break; \
324 case 4: __put_user_asm("sw", __pu_addr); break; \
325 case 8: __PUT_USER_DW(__pu_addr); break; \
326 default: __put_user_unknown(); break; \
327 } \
328 } \
329 __pu_err; \
330 })
331
332 #define __put_user_asm(insn, ptr) \
333 { \
334 __asm__ __volatile__( \
335 "1: " insn " %z2, %3 # __put_user_asm\n" \
336 "2: \n" \
337 " .section .fixup,\"ax\" \n" \
338 "3: li %0, %4 \n" \
339 " j 2b \n" \
340 " .previous \n" \
341 " .section __ex_table,\"a\" \n" \
342 " " __UA_ADDR " 1b, 3b \n" \
343 " .previous \n" \
344 : "=r" (__pu_err) \
345 : "0" (0), "Jr" (__pu_val), "o" (__m(ptr)), \
346 "i" (-EFAULT)); \
347 }
348
349 #define __put_user_asm_ll32(ptr) \
350 { \
351 __asm__ __volatile__( \
352 "1: sw %2, (%3) # __put_user_asm_ll32 \n" \
353 "2: sw %D2, 4(%3) \n" \
354 "3: \n" \
355 " .section .fixup,\"ax\" \n" \
356 "4: li %0, %4 \n" \
357 " j 3b \n" \
358 " .previous \n" \
359 " .section __ex_table,\"a\" \n" \
360 " " __UA_ADDR " 1b, 4b \n" \
361 " " __UA_ADDR " 2b, 4b \n" \
362 " .previous" \
363 : "=r" (__pu_err) \
364 : "0" (0), "r" (__pu_val), "r" (ptr), \
365 "i" (-EFAULT)); \
366 }
367
368 extern void __put_user_unknown(void);
369
370 /*
371 * We're generating jump to subroutines which will be outside the range of
372 * jump instructions
373 */
374 #ifdef MODULE
375 #define __MODULE_JAL(destination) \
376 ".set\tnoat\n\t" \
377 __UA_LA "\t$1, " #destination "\n\t" \
378 "jalr\t$1\n\t" \
379 ".set\tat\n\t"
380 #else
381 #define __MODULE_JAL(destination) \
382 "jal\t" #destination "\n\t"
383 #endif
384
385 extern size_t __copy_user(void *__to, const void *__from, size_t __n);
386
387 #define __invoke_copy_to_user(to,from,n) \
388 ({ \
389 register void __user *__cu_to_r __asm__ ("$4"); \
390 register const void *__cu_from_r __asm__ ("$5"); \
391 register long __cu_len_r __asm__ ("$6"); \
392 \
393 __cu_to_r = (to); \
394 __cu_from_r = (from); \
395 __cu_len_r = (n); \
396 __asm__ __volatile__( \
397 __MODULE_JAL(__copy_user) \
398 : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
399 : \
400 : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \
401 "memory"); \
402 __cu_len_r; \
403 })
404
405 /*
406 * __copy_to_user: - Copy a block of data into user space, with less checking.
407 * @to: Destination address, in user space.
408 * @from: Source address, in kernel space.
409 * @n: Number of bytes to copy.
410 *
411 * Context: User context only. This function may sleep.
412 *
413 * Copy data from kernel space to user space. Caller must check
414 * the specified block with access_ok() before calling this function.
415 *
416 * Returns number of bytes that could not be copied.
417 * On success, this will be zero.
418 */
419 #define __copy_to_user(to,from,n) \
420 ({ \
421 void __user *__cu_to; \
422 const void *__cu_from; \
423 long __cu_len; \
424 \
425 might_sleep(); \
426 __cu_to = (to); \
427 __cu_from = (from); \
428 __cu_len = (n); \
429 __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, __cu_len); \
430 __cu_len; \
431 })
432
433 #define __copy_to_user_inatomic __copy_to_user
434 #define __copy_from_user_inatomic __copy_from_user
435
436 /*
437 * copy_to_user: - Copy a block of data into user space.
438 * @to: Destination address, in user space.
439 * @from: Source address, in kernel space.
440 * @n: Number of bytes to copy.
441 *
442 * Context: User context only. This function may sleep.
443 *
444 * Copy data from kernel space to user space.
445 *
446 * Returns number of bytes that could not be copied.
447 * On success, this will be zero.
448 */
449 #define copy_to_user(to,from,n) \
450 ({ \
451 void __user *__cu_to; \
452 const void *__cu_from; \
453 long __cu_len; \
454 \
455 might_sleep(); \
456 __cu_to = (to); \
457 __cu_from = (from); \
458 __cu_len = (n); \
459 if (access_ok(VERIFY_WRITE, __cu_to, __cu_len)) \
460 __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, \
461 __cu_len); \
462 __cu_len; \
463 })
464
465 #define __invoke_copy_from_user(to,from,n) \
466 ({ \
467 register void *__cu_to_r __asm__ ("$4"); \
468 register const void __user *__cu_from_r __asm__ ("$5"); \
469 register long __cu_len_r __asm__ ("$6"); \
470 \
471 __cu_to_r = (to); \
472 __cu_from_r = (from); \
473 __cu_len_r = (n); \
474 __asm__ __volatile__( \
475 ".set\tnoreorder\n\t" \
476 __MODULE_JAL(__copy_user) \
477 ".set\tnoat\n\t" \
478 __UA_ADDU "\t$1, %1, %2\n\t" \
479 ".set\tat\n\t" \
480 ".set\treorder" \
481 : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
482 : \
483 : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \
484 "memory"); \
485 __cu_len_r; \
486 })
487
488 /*
489 * __copy_from_user: - Copy a block of data from user space, with less checking. * @to: Destination address, in kernel space.
490 * @from: Source address, in user space.
491 * @n: Number of bytes to copy.
492 *
493 * Context: User context only. This function may sleep.
494 *
495 * Copy data from user space to kernel space. Caller must check
496 * the specified block with access_ok() before calling this function.
497 *
498 * Returns number of bytes that could not be copied.
499 * On success, this will be zero.
500 *
501 * If some data could not be copied, this function will pad the copied
502 * data to the requested size using zero bytes.
503 */
504 #define __copy_from_user(to,from,n) \
505 ({ \
506 void *__cu_to; \
507 const void __user *__cu_from; \
508 long __cu_len; \
509 \
510 might_sleep(); \
511 __cu_to = (to); \
512 __cu_from = (from); \
513 __cu_len = (n); \
514 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
515 __cu_len); \
516 __cu_len; \
517 })
518
519 /*
520 * copy_from_user: - Copy a block of data from user space.
521 * @to: Destination address, in kernel space.
522 * @from: Source address, in user space.
523 * @n: Number of bytes to copy.
524 *
525 * Context: User context only. This function may sleep.
526 *
527 * Copy data from user space to kernel space.
528 *
529 * Returns number of bytes that could not be copied.
530 * On success, this will be zero.
531 *
532 * If some data could not be copied, this function will pad the copied
533 * data to the requested size using zero bytes.
534 */
535 #define copy_from_user(to,from,n) \
536 ({ \
537 void *__cu_to; \
538 const void __user *__cu_from; \
539 long __cu_len; \
540 \
541 might_sleep(); \
542 __cu_to = (to); \
543 __cu_from = (from); \
544 __cu_len = (n); \
545 if (access_ok(VERIFY_READ, __cu_from, __cu_len)) \
546 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
547 __cu_len); \
548 __cu_len; \
549 })
550
551 #define __copy_in_user(to, from, n) __copy_from_user(to, from, n)
552
553 #define copy_in_user(to,from,n) \
554 ({ \
555 void __user *__cu_to; \
556 const void __user *__cu_from; \
557 long __cu_len; \
558 \
559 might_sleep(); \
560 __cu_to = (to); \
561 __cu_from = (from); \
562 __cu_len = (n); \
563 if (likely(access_ok(VERIFY_READ, __cu_from, __cu_len) && \
564 access_ok(VERIFY_WRITE, __cu_to, __cu_len))) \
565 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
566 __cu_len); \
567 __cu_len; \
568 })
569
570 /*
571 * __clear_user: - Zero a block of memory in user space, with less checking.
572 * @to: Destination address, in user space.
573 * @n: Number of bytes to zero.
574 *
575 * Zero a block of memory in user space. Caller must check
576 * the specified block with access_ok() before calling this function.
577 *
578 * Returns number of bytes that could not be cleared.
579 * On success, this will be zero.
580 */
581 static inline __kernel_size_t
582 __clear_user(void __user *addr, __kernel_size_t size)
583 {
584 __kernel_size_t res;
585
586 might_sleep();
587 __asm__ __volatile__(
588 "move\t$4, %1\n\t"
589 "move\t$5, $0\n\t"
590 "move\t$6, %2\n\t"
591 __MODULE_JAL(__bzero)
592 "move\t%0, $6"
593 : "=r" (res)
594 : "r" (addr), "r" (size)
595 : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
596
597 return res;
598 }
599
600 #define clear_user(addr,n) \
601 ({ \
602 void __user * __cl_addr = (addr); \
603 unsigned long __cl_size = (n); \
604 if (__cl_size && access_ok(VERIFY_WRITE, \
605 ((unsigned long)(__cl_addr)), __cl_size)) \
606 __cl_size = __clear_user(__cl_addr, __cl_size); \
607 __cl_size; \
608 })
609
610 /*
611 * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
612 * @dst: Destination address, in kernel space. This buffer must be at
613 * least @count bytes long.
614 * @src: Source address, in user space.
615 * @count: Maximum number of bytes to copy, including the trailing NUL.
616 *
617 * Copies a NUL-terminated string from userspace to kernel space.
618 * Caller must check the specified block with access_ok() before calling
619 * this function.
620 *
621 * On success, returns the length of the string (not including the trailing
622 * NUL).
623 *
624 * If access to userspace fails, returns -EFAULT (some data may have been
625 * copied).
626 *
627 * If @count is smaller than the length of the string, copies @count bytes
628 * and returns @count.
629 */
630 static inline long
631 __strncpy_from_user(char *__to, const char __user *__from, long __len)
632 {
633 long res;
634
635 might_sleep();
636 __asm__ __volatile__(
637 "move\t$4, %1\n\t"
638 "move\t$5, %2\n\t"
639 "move\t$6, %3\n\t"
640 __MODULE_JAL(__strncpy_from_user_nocheck_asm)
641 "move\t%0, $2"
642 : "=r" (res)
643 : "r" (__to), "r" (__from), "r" (__len)
644 : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
645
646 return res;
647 }
648
649 /*
650 * strncpy_from_user: - Copy a NUL terminated string from userspace.
651 * @dst: Destination address, in kernel space. This buffer must be at
652 * least @count bytes long.
653 * @src: Source address, in user space.
654 * @count: Maximum number of bytes to copy, including the trailing NUL.
655 *
656 * Copies a NUL-terminated string from userspace to kernel space.
657 *
658 * On success, returns the length of the string (not including the trailing
659 * NUL).
660 *
661 * If access to userspace fails, returns -EFAULT (some data may have been
662 * copied).
663 *
664 * If @count is smaller than the length of the string, copies @count bytes
665 * and returns @count.
666 */
667 static inline long
668 strncpy_from_user(char *__to, const char __user *__from, long __len)
669 {
670 long res;
671
672 might_sleep();
673 __asm__ __volatile__(
674 "move\t$4, %1\n\t"
675 "move\t$5, %2\n\t"
676 "move\t$6, %3\n\t"
677 __MODULE_JAL(__strncpy_from_user_asm)
678 "move\t%0, $2"
679 : "=r" (res)
680 : "r" (__to), "r" (__from), "r" (__len)
681 : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
682
683 return res;
684 }
685
686 /* Returns: 0 if bad, string length+1 (memory size) of string if ok */
687 static inline long __strlen_user(const char __user *s)
688 {
689 long res;
690
691 might_sleep();
692 __asm__ __volatile__(
693 "move\t$4, %1\n\t"
694 __MODULE_JAL(__strlen_user_nocheck_asm)
695 "move\t%0, $2"
696 : "=r" (res)
697 : "r" (s)
698 : "$2", "$4", __UA_t0, "$31");
699
700 return res;
701 }
702
703 /*
704 * strlen_user: - Get the size of a string in user space.
705 * @str: The string to measure.
706 *
707 * Context: User context only. This function may sleep.
708 *
709 * Get the size of a NUL-terminated string in user space.
710 *
711 * Returns the size of the string INCLUDING the terminating NUL.
712 * On exception, returns 0.
713 *
714 * If there is a limit on the length of a valid string, you may wish to
715 * consider using strnlen_user() instead.
716 */
717 static inline long strlen_user(const char __user *s)
718 {
719 long res;
720
721 might_sleep();
722 __asm__ __volatile__(
723 "move\t$4, %1\n\t"
724 __MODULE_JAL(__strlen_user_asm)
725 "move\t%0, $2"
726 : "=r" (res)
727 : "r" (s)
728 : "$2", "$4", __UA_t0, "$31");
729
730 return res;
731 }
732
733 /* Returns: 0 if bad, string length+1 (memory size) of string if ok */
734 static inline long __strnlen_user(const char __user *s, long n)
735 {
736 long res;
737
738 might_sleep();
739 __asm__ __volatile__(
740 "move\t$4, %1\n\t"
741 "move\t$5, %2\n\t"
742 __MODULE_JAL(__strnlen_user_nocheck_asm)
743 "move\t%0, $2"
744 : "=r" (res)
745 : "r" (s), "r" (n)
746 : "$2", "$4", "$5", __UA_t0, "$31");
747
748 return res;
749 }
750
751 /*
752 * strlen_user: - Get the size of a string in user space.
753 * @str: The string to measure.
754 *
755 * Context: User context only. This function may sleep.
756 *
757 * Get the size of a NUL-terminated string in user space.
758 *
759 * Returns the size of the string INCLUDING the terminating NUL.
760 * On exception, returns 0.
761 *
762 * If there is a limit on the length of a valid string, you may wish to
763 * consider using strnlen_user() instead.
764 */
765 static inline long strnlen_user(const char __user *s, long n)
766 {
767 long res;
768
769 might_sleep();
770 __asm__ __volatile__(
771 "move\t$4, %1\n\t"
772 "move\t$5, %2\n\t"
773 __MODULE_JAL(__strnlen_user_asm)
774 "move\t%0, $2"
775 : "=r" (res)
776 : "r" (s), "r" (n)
777 : "$2", "$4", "$5", __UA_t0, "$31");
778
779 return res;
780 }
781
782 struct exception_table_entry
783 {
784 unsigned long insn;
785 unsigned long nextinsn;
786 };
787
788 extern int fixup_exception(struct pt_regs *regs);
789
790 #endif /* _ASM_UACCESS_H */