diff options
Diffstat (limited to 'include/asm-sh/uaccess_32.h')
-rw-r--r-- | include/asm-sh/uaccess_32.h | 344 |
1 files changed, 52 insertions, 292 deletions
diff --git a/include/asm-sh/uaccess_32.h b/include/asm-sh/uaccess_32.h index 1e41fda74bd3..892fd6dea9db 100644 --- a/include/asm-sh/uaccess_32.h +++ b/include/asm-sh/uaccess_32.h | |||
@@ -1,9 +1,8 @@ | |||
1 | /* $Id: uaccess.h,v 1.11 2003/10/13 07:21:20 lethal Exp $ | 1 | /* |
2 | * | ||
3 | * User space memory access functions | 2 | * User space memory access functions |
4 | * | 3 | * |
5 | * Copyright (C) 1999, 2002 Niibe Yutaka | 4 | * Copyright (C) 1999, 2002 Niibe Yutaka |
6 | * Copyright (C) 2003 Paul Mundt | 5 | * Copyright (C) 2003 - 2008 Paul Mundt |
7 | * | 6 | * |
8 | * Based on: | 7 | * Based on: |
9 | * MIPS implementation version 1.15 by | 8 | * MIPS implementation version 1.15 by |
@@ -13,115 +12,6 @@ | |||
13 | #ifndef __ASM_SH_UACCESS_32_H | 12 | #ifndef __ASM_SH_UACCESS_32_H |
14 | #define __ASM_SH_UACCESS_32_H | 13 | #define __ASM_SH_UACCESS_32_H |
15 | 14 | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/sched.h> | ||
18 | |||
19 | #define VERIFY_READ 0 | ||
20 | #define VERIFY_WRITE 1 | ||
21 | |||
22 | /* | ||
23 | * The fs value determines whether argument validity checking should be | ||
24 | * performed or not. If get_fs() == USER_DS, checking is performed, with | ||
25 | * get_fs() == KERNEL_DS, checking is bypassed. | ||
26 | * | ||
27 | * For historical reasons (Data Segment Register?), these macros are misnamed. | ||
28 | */ | ||
29 | |||
30 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) | ||
31 | |||
32 | #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFFUL) | ||
33 | #define USER_DS MAKE_MM_SEG(PAGE_OFFSET) | ||
34 | |||
35 | #define segment_eq(a,b) ((a).seg == (b).seg) | ||
36 | |||
37 | #define get_ds() (KERNEL_DS) | ||
38 | |||
39 | #if !defined(CONFIG_MMU) | ||
40 | /* NOMMU is always true */ | ||
41 | #define __addr_ok(addr) (1) | ||
42 | |||
43 | static inline mm_segment_t get_fs(void) | ||
44 | { | ||
45 | return USER_DS; | ||
46 | } | ||
47 | |||
48 | static inline void set_fs(mm_segment_t s) | ||
49 | { | ||
50 | } | ||
51 | |||
52 | /* | ||
53 | * __access_ok: Check if address with size is OK or not. | ||
54 | * | ||
55 | * If we don't have an MMU (or if its disabled) the only thing we really have | ||
56 | * to look out for is if the address resides somewhere outside of what | ||
57 | * available RAM we have. | ||
58 | */ | ||
59 | static inline int __access_ok(unsigned long addr, unsigned long size) | ||
60 | { | ||
61 | return 1; | ||
62 | } | ||
63 | #else /* CONFIG_MMU */ | ||
64 | #define __addr_ok(addr) \ | ||
65 | ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg)) | ||
66 | |||
67 | #define get_fs() (current_thread_info()->addr_limit) | ||
68 | #define set_fs(x) (current_thread_info()->addr_limit = (x)) | ||
69 | |||
70 | /* | ||
71 | * __access_ok: Check if address with size is OK or not. | ||
72 | * | ||
73 | * Uhhuh, this needs 33-bit arithmetic. We have a carry.. | ||
74 | * | ||
75 | * sum := addr + size; carry? --> flag = true; | ||
76 | * if (sum >= addr_limit) flag = true; | ||
77 | */ | ||
78 | static inline int __access_ok(unsigned long addr, unsigned long size) | ||
79 | { | ||
80 | unsigned long flag, sum; | ||
81 | |||
82 | __asm__("clrt\n\t" | ||
83 | "addc %3, %1\n\t" | ||
84 | "movt %0\n\t" | ||
85 | "cmp/hi %4, %1\n\t" | ||
86 | "rotcl %0" | ||
87 | :"=&r" (flag), "=r" (sum) | ||
88 | :"1" (addr), "r" (size), | ||
89 | "r" (current_thread_info()->addr_limit.seg) | ||
90 | :"t"); | ||
91 | return flag == 0; | ||
92 | } | ||
93 | #endif /* CONFIG_MMU */ | ||
94 | |||
95 | #define access_ok(type, addr, size) \ | ||
96 | (__chk_user_ptr(addr), \ | ||
97 | __access_ok((unsigned long __force)(addr), (size))) | ||
98 | |||
99 | /* | ||
100 | * Uh, these should become the main single-value transfer routines ... | ||
101 | * They automatically use the right size if we just have the right | ||
102 | * pointer type ... | ||
103 | * | ||
104 | * As SuperH uses the same address space for kernel and user data, we | ||
105 | * can just do these as direct assignments. | ||
106 | * | ||
107 | * Careful to not | ||
108 | * (a) re-use the arguments for side effects (sizeof is ok) | ||
109 | * (b) require any knowledge of processes at this stage | ||
110 | */ | ||
111 | #define put_user(x,ptr) __put_user_check((x), (ptr), sizeof(*(ptr))) | ||
112 | #define get_user(x,ptr) __get_user_check((x), (ptr), sizeof(*(ptr))) | ||
113 | |||
114 | /* | ||
115 | * The "__xxx" versions do not do address space checking, useful when | ||
116 | * doing multiple accesses to the same area (the user has to do the | ||
117 | * checks by hand with "access_ok()") | ||
118 | */ | ||
119 | #define __put_user(x,ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr))) | ||
120 | #define __get_user(x,ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr))) | ||
121 | |||
122 | struct __large_struct { unsigned long buf[100]; }; | ||
123 | #define __m(x) (*(struct __large_struct __user *)(x)) | ||
124 | |||
125 | #define __get_user_size(x,ptr,size,retval) \ | 15 | #define __get_user_size(x,ptr,size,retval) \ |
126 | do { \ | 16 | do { \ |
127 | retval = 0; \ | 17 | retval = 0; \ |
@@ -141,28 +31,7 @@ do { \ | |||
141 | } \ | 31 | } \ |
142 | } while (0) | 32 | } while (0) |
143 | 33 | ||
144 | #define __get_user_nocheck(x,ptr,size) \ | 34 | #ifdef CONFIG_MMU |
145 | ({ \ | ||
146 | long __gu_err; \ | ||
147 | unsigned long __gu_val; \ | ||
148 | const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ | ||
149 | __chk_user_ptr(ptr); \ | ||
150 | __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ | ||
151 | (x) = (__typeof__(*(ptr)))__gu_val; \ | ||
152 | __gu_err; \ | ||
153 | }) | ||
154 | |||
155 | #define __get_user_check(x,ptr,size) \ | ||
156 | ({ \ | ||
157 | long __gu_err = -EFAULT; \ | ||
158 | unsigned long __gu_val = 0; \ | ||
159 | const __typeof__(*(ptr)) *__gu_addr = (ptr); \ | ||
160 | if (likely(access_ok(VERIFY_READ, __gu_addr, (size)))) \ | ||
161 | __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ | ||
162 | (x) = (__typeof__(*(ptr)))__gu_val; \ | ||
163 | __gu_err; \ | ||
164 | }) | ||
165 | |||
166 | #define __get_user_asm(x, addr, err, insn) \ | 35 | #define __get_user_asm(x, addr, err, insn) \ |
167 | ({ \ | 36 | ({ \ |
168 | __asm__ __volatile__( \ | 37 | __asm__ __volatile__( \ |
@@ -183,6 +52,16 @@ __asm__ __volatile__( \ | |||
183 | ".previous" \ | 52 | ".previous" \ |
184 | :"=&r" (err), "=&r" (x) \ | 53 | :"=&r" (err), "=&r" (x) \ |
185 | :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) | 54 | :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) |
55 | #else | ||
56 | #define __get_user_asm(x, addr, err, insn) \ | ||
57 | do { \ | ||
58 | __asm__ __volatile__ ( \ | ||
59 | "mov." insn " %1, %0\n\t" \ | ||
60 | : "=&r" (x) \ | ||
61 | : "m" (__m(addr)) \ | ||
62 | ); \ | ||
63 | } while (0) | ||
64 | #endif /* CONFIG_MMU */ | ||
186 | 65 | ||
187 | extern void __get_user_unknown(void); | 66 | extern void __get_user_unknown(void); |
188 | 67 | ||
@@ -197,7 +76,8 @@ do { \ | |||
197 | __put_user_asm(x, ptr, retval, "w"); \ | 76 | __put_user_asm(x, ptr, retval, "w"); \ |
198 | break; \ | 77 | break; \ |
199 | case 4: \ | 78 | case 4: \ |
200 | __put_user_asm(x, ptr, retval, "l"); \ | 79 | __put_user_asm((u32)x, ptr, \ |
80 | retval, "l"); \ | ||
201 | break; \ | 81 | break; \ |
202 | case 8: \ | 82 | case 8: \ |
203 | __put_user_u64(x, ptr, retval); \ | 83 | __put_user_u64(x, ptr, retval); \ |
@@ -207,45 +87,41 @@ do { \ | |||
207 | } \ | 87 | } \ |
208 | } while (0) | 88 | } while (0) |
209 | 89 | ||
210 | #define __put_user_nocheck(x,ptr,size) \ | 90 | #ifdef CONFIG_MMU |
211 | ({ \ | 91 | #define __put_user_asm(x, addr, err, insn) \ |
212 | long __pu_err; \ | 92 | do { \ |
213 | __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ | 93 | __asm__ __volatile__ ( \ |
214 | __chk_user_ptr(ptr); \ | 94 | "1:\n\t" \ |
215 | __put_user_size((x), __pu_addr, (size), __pu_err); \ | 95 | "mov." insn " %1, %2\n\t" \ |
216 | __pu_err; \ | 96 | "2:\n" \ |
217 | }) | 97 | ".section .fixup,\"ax\"\n" \ |
218 | 98 | "3:\n\t" \ | |
219 | #define __put_user_check(x,ptr,size) \ | 99 | "mov.l 4f, %0\n\t" \ |
220 | ({ \ | 100 | "jmp @%0\n\t" \ |
221 | long __pu_err = -EFAULT; \ | 101 | " mov %3, %0\n\t" \ |
222 | __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ | 102 | ".balign 4\n" \ |
223 | if (likely(access_ok(VERIFY_WRITE, __pu_addr, size))) \ | 103 | "4: .long 2b\n\t" \ |
224 | __put_user_size((x), __pu_addr, (size), \ | 104 | ".previous\n" \ |
225 | __pu_err); \ | 105 | ".section __ex_table,\"a\"\n\t" \ |
226 | __pu_err; \ | 106 | ".long 1b, 3b\n\t" \ |
227 | }) | 107 | ".previous" \ |
228 | 108 | : "=&r" (err) \ | |
229 | #define __put_user_asm(x, addr, err, insn) \ | 109 | : "r" (x), "m" (__m(addr)), "i" (-EFAULT), \ |
230 | ({ \ | 110 | "0" (err) \ |
231 | __asm__ __volatile__( \ | 111 | : "memory" \ |
232 | "1:\n\t" \ | 112 | ); \ |
233 | "mov." insn " %1, %2\n\t" \ | 113 | } while (0) |
234 | "2:\n" \ | 114 | #else |
235 | ".section .fixup,\"ax\"\n" \ | 115 | #define __put_user_asm(x, addr, err, insn) \ |
236 | "3:\n\t" \ | 116 | do { \ |
237 | "mov.l 4f, %0\n\t" \ | 117 | __asm__ __volatile__ ( \ |
238 | "jmp @%0\n\t" \ | 118 | "mov." insn " %0, %1\n\t" \ |
239 | " mov %3, %0\n\t" \ | 119 | : /* no outputs */ \ |
240 | ".balign 4\n" \ | 120 | : "r" (x), "m" (__m(addr)) \ |
241 | "4: .long 2b\n\t" \ | 121 | : "memory" \ |
242 | ".previous\n" \ | 122 | ); \ |
243 | ".section __ex_table,\"a\"\n\t" \ | 123 | } while (0) |
244 | ".long 1b, 3b\n\t" \ | 124 | #endif /* CONFIG_MMU */ |
245 | ".previous" \ | ||
246 | :"=&r" (err) \ | ||
247 | :"r" (x), "m" (__m(addr)), "i" (-EFAULT), "0" (err) \ | ||
248 | :"memory"); }) | ||
249 | 125 | ||
250 | #if defined(CONFIG_CPU_LITTLE_ENDIAN) | 126 | #if defined(CONFIG_CPU_LITTLE_ENDIAN) |
251 | #define __put_user_u64(val,addr,retval) \ | 127 | #define __put_user_u64(val,addr,retval) \ |
@@ -295,40 +171,7 @@ __asm__ __volatile__( \ | |||
295 | 171 | ||
296 | extern void __put_user_unknown(void); | 172 | extern void __put_user_unknown(void); |
297 | 173 | ||
298 | /* Generic arbitrary sized copy. */ | 174 | static inline int |
299 | /* Return the number of bytes NOT copied */ | ||
300 | __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n); | ||
301 | |||
302 | |||
303 | static __always_inline unsigned long | ||
304 | __copy_from_user(void *to, const void __user *from, unsigned long n) | ||
305 | { | ||
306 | return __copy_user(to, (__force void *)from, n); | ||
307 | } | ||
308 | |||
309 | static __always_inline unsigned long __must_check | ||
310 | __copy_to_user(void __user *to, const void *from, unsigned long n) | ||
311 | { | ||
312 | return __copy_user((__force void *)to, from, n); | ||
313 | } | ||
314 | |||
315 | #define __copy_to_user_inatomic __copy_to_user | ||
316 | #define __copy_from_user_inatomic __copy_from_user | ||
317 | |||
318 | /* | ||
319 | * Clear the area and return remaining number of bytes | ||
320 | * (on failure. Usually it's 0.) | ||
321 | */ | ||
322 | extern __kernel_size_t __clear_user(void *addr, __kernel_size_t size); | ||
323 | |||
324 | #define clear_user(addr,n) ({ \ | ||
325 | void * __cl_addr = (addr); \ | ||
326 | unsigned long __cl_size = (n); \ | ||
327 | if (__cl_size && __access_ok(((unsigned long)(__cl_addr)), __cl_size)) \ | ||
328 | __cl_size = __clear_user(__cl_addr, __cl_size); \ | ||
329 | __cl_size; }) | ||
330 | |||
331 | static __inline__ int | ||
332 | __strncpy_from_user(unsigned long __dest, unsigned long __user __src, int __count) | 175 | __strncpy_from_user(unsigned long __dest, unsigned long __user __src, int __count) |
333 | { | 176 | { |
334 | __kernel_size_t res; | 177 | __kernel_size_t res; |
@@ -367,37 +210,11 @@ __strncpy_from_user(unsigned long __dest, unsigned long __user __src, int __coun | |||
367 | return res; | 210 | return res; |
368 | } | 211 | } |
369 | 212 | ||
370 | /** | ||
371 | * strncpy_from_user: - Copy a NUL terminated string from userspace. | ||
372 | * @dst: Destination address, in kernel space. This buffer must be at | ||
373 | * least @count bytes long. | ||
374 | * @src: Source address, in user space. | ||
375 | * @count: Maximum number of bytes to copy, including the trailing NUL. | ||
376 | * | ||
377 | * Copies a NUL-terminated string from userspace to kernel space. | ||
378 | * | ||
379 | * On success, returns the length of the string (not including the trailing | ||
380 | * NUL). | ||
381 | * | ||
382 | * If access to userspace fails, returns -EFAULT (some data may have been | ||
383 | * copied). | ||
384 | * | ||
385 | * If @count is smaller than the length of the string, copies @count bytes | ||
386 | * and returns @count. | ||
387 | */ | ||
388 | #define strncpy_from_user(dest,src,count) ({ \ | ||
389 | unsigned long __sfu_src = (unsigned long) (src); \ | ||
390 | int __sfu_count = (int) (count); \ | ||
391 | long __sfu_res = -EFAULT; \ | ||
392 | if(__access_ok(__sfu_src, __sfu_count)) { \ | ||
393 | __sfu_res = __strncpy_from_user((unsigned long) (dest), __sfu_src, __sfu_count); \ | ||
394 | } __sfu_res; }) | ||
395 | |||
396 | /* | 213 | /* |
397 | * Return the size of a string (including the ending 0 even when we have | 214 | * Return the size of a string (including the ending 0 even when we have |
398 | * exceeded the maximum string length). | 215 | * exceeded the maximum string length). |
399 | */ | 216 | */ |
400 | static __inline__ long __strnlen_user(const char __user *__s, long __n) | 217 | static inline long __strnlen_user(const char __user *__s, long __n) |
401 | { | 218 | { |
402 | unsigned long res; | 219 | unsigned long res; |
403 | unsigned long __dummy; | 220 | unsigned long __dummy; |
@@ -429,61 +246,4 @@ static __inline__ long __strnlen_user(const char __user *__s, long __n) | |||
429 | return res; | 246 | return res; |
430 | } | 247 | } |
431 | 248 | ||
432 | /** | ||
433 | * strnlen_user: - Get the size of a string in user space. | ||
434 | * @s: The string to measure. | ||
435 | * @n: The maximum valid length | ||
436 | * | ||
437 | * Context: User context only. This function may sleep. | ||
438 | * | ||
439 | * Get the size of a NUL-terminated string in user space. | ||
440 | * | ||
441 | * Returns the size of the string INCLUDING the terminating NUL. | ||
442 | * On exception, returns 0. | ||
443 | * If the string is too long, returns a value greater than @n. | ||
444 | */ | ||
445 | static __inline__ long strnlen_user(const char __user *s, long n) | ||
446 | { | ||
447 | if (!__addr_ok(s)) | ||
448 | return 0; | ||
449 | else | ||
450 | return __strnlen_user(s, n); | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * strlen_user: - Get the size of a string in user space. | ||
455 | * @str: The string to measure. | ||
456 | * | ||
457 | * Context: User context only. This function may sleep. | ||
458 | * | ||
459 | * Get the size of a NUL-terminated string in user space. | ||
460 | * | ||
461 | * Returns the size of the string INCLUDING the terminating NUL. | ||
462 | * On exception, returns 0. | ||
463 | * | ||
464 | * If there is a limit on the length of a valid string, you may wish to | ||
465 | * consider using strnlen_user() instead. | ||
466 | */ | ||
467 | #define strlen_user(str) strnlen_user(str, ~0UL >> 1) | ||
468 | |||
469 | /* | ||
470 | * The exception table consists of pairs of addresses: the first is the | ||
471 | * address of an instruction that is allowed to fault, and the second is | ||
472 | * the address at which the program should continue. No registers are | ||
473 | * modified, so it is entirely up to the continuation code to figure out | ||
474 | * what to do. | ||
475 | * | ||
476 | * All the routines below use bits of fixup code that are out of line | ||
477 | * with the main instruction path. This means when everything is well, | ||
478 | * we don't even have to jump over them. Further, they do not intrude | ||
479 | * on our cache or tlb entries. | ||
480 | */ | ||
481 | |||
482 | struct exception_table_entry | ||
483 | { | ||
484 | unsigned long insn, fixup; | ||
485 | }; | ||
486 | |||
487 | extern int fixup_exception(struct pt_regs *regs); | ||
488 | |||
489 | #endif /* __ASM_SH_UACCESS_32_H */ | 249 | #endif /* __ASM_SH_UACCESS_32_H */ |