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