Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / include / asm-cris / uaccess.h
blob4689374f2441eb5b18e5ab430fec50c7ab5f1647
1 /*
2 * Authors: Bjorn Wesen (bjornw@axis.com)
3 * Hans-Peter Nilsson (hp@axis.com)
4 <<<<<<< HEAD:include/asm-cris/uaccess.h
6 * $Log: uaccess.h,v $
7 * Revision 1.8 2001/10/29 13:01:48 bjornw
8 * Removed unused variable tmp2 in strnlen_user
10 * Revision 1.7 2001/10/02 12:44:52 hp
11 * Add support for 64-bit put_user/get_user
13 * Revision 1.6 2001/10/01 14:51:17 bjornw
14 * Added register prefixes and removed underscores
16 * Revision 1.5 2000/10/25 03:33:21 hp
17 * - Provide implementation for everything else but get_user and put_user;
18 * copying inline to/from user for constant length 0..16, 20, 24, and
19 * clearing for 0..4, 8, 12, 16, 20, 24, strncpy_from_user and strnlen_user
20 * always inline.
21 * - Constraints for destination addr in get_user cannot be memory, only reg.
22 * - Correct labels for PC at expected fault points.
23 * - Nits with assembly code.
24 * - Don't use statement expressions without value; use "do {} while (0)".
25 * - Return correct values from __generic_... functions.
27 * Revision 1.4 2000/09/12 16:28:25 bjornw
28 * * Removed comments from the get/put user asm code
29 * * Constrains for destination addr in put_user cannot be memory, only reg
31 * Revision 1.3 2000/09/12 14:30:20 bjornw
32 * MAX_ADDR_USER does not exist anymore
34 * Revision 1.2 2000/07/13 15:52:48 bjornw
35 * New user-access functions
37 * Revision 1.1.1.1 2000/07/10 16:32:31 bjornw
38 * CRIS architecture, working draft
42 =======
43 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-cris/uaccess.h
46 /* Asm:s have been tweaked (within the domain of correctness) to give
47 satisfactory results for "gcc version 2.96 20000427 (experimental)".
49 Check regularly...
51 Register $r9 is chosen for temporaries, being a call-clobbered register
52 first in line to be used (notably for local blocks), not colliding with
53 parameter registers. */
55 #ifndef _CRIS_UACCESS_H
56 #define _CRIS_UACCESS_H
58 #ifndef __ASSEMBLY__
59 #include <linux/sched.h>
60 #include <linux/errno.h>
61 #include <asm/processor.h>
62 #include <asm/page.h>
64 #define VERIFY_READ 0
65 #define VERIFY_WRITE 1
68 * The fs value determines whether argument validity checking should be
69 * performed or not. If get_fs() == USER_DS, checking is performed, with
70 * get_fs() == KERNEL_DS, checking is bypassed.
72 * For historical reasons, these macros are grossly misnamed.
75 #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
77 /* addr_limit is the maximum accessible address for the task. we misuse
78 * the KERNEL_DS and USER_DS values to both assign and compare the
79 * addr_limit values through the equally misnamed get/set_fs macros.
80 * (see above)
83 #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
84 #define USER_DS MAKE_MM_SEG(TASK_SIZE)
86 #define get_ds() (KERNEL_DS)
87 #define get_fs() (current_thread_info()->addr_limit)
88 #define set_fs(x) (current_thread_info()->addr_limit = (x))
90 #define segment_eq(a,b) ((a).seg == (b).seg)
92 #define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
93 #define __user_ok(addr,size) (((size) <= TASK_SIZE)&&((addr) <= TASK_SIZE-(size)))
94 #define __access_ok(addr,size) (__kernel_ok || __user_ok((addr),(size)))
95 #define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
97 #include <asm/arch/uaccess.h>
100 * The exception table consists of pairs of addresses: the first is the
101 * address of an instruction that is allowed to fault, and the second is
102 * the address at which the program should continue. No registers are
103 * modified, so it is entirely up to the continuation code to figure out
104 * what to do.
106 * All the routines below use bits of fixup code that are out of line
107 * with the main instruction path. This means when everything is well,
108 * we don't even have to jump over them. Further, they do not intrude
109 * on our cache or tlb entries.
112 struct exception_table_entry
114 unsigned long insn, fixup;
118 * These are the main single-value transfer routines. They automatically
119 * use the right size if we just have the right pointer type.
121 * This gets kind of ugly. We want to return _two_ values in "get_user()"
122 * and yet we don't want to do any pointers, because that is too much
123 * of a performance impact. Thus we have a few rather ugly macros here,
124 * and hide all the ugliness from the user.
126 * The "__xxx" versions of the user access functions are versions that
127 * do not verify the address space, that must have been done previously
128 * with a separate "access_ok()" call (this is used when we do multiple
129 * accesses to the same area of user memory).
131 * As we use the same address space for kernel and user data on
132 * CRIS, we can just do these as direct assignments. (Of course, the
133 * exception handling means that it's no longer "just"...)
135 #define get_user(x,ptr) \
136 __get_user_check((x),(ptr),sizeof(*(ptr)))
137 #define put_user(x,ptr) \
138 __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
140 #define __get_user(x,ptr) \
141 __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
142 #define __put_user(x,ptr) \
143 __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
145 extern long __put_user_bad(void);
147 #define __put_user_size(x,ptr,size,retval) \
148 do { \
149 retval = 0; \
150 switch (size) { \
151 case 1: __put_user_asm(x,ptr,retval,"move.b"); break; \
152 case 2: __put_user_asm(x,ptr,retval,"move.w"); break; \
153 case 4: __put_user_asm(x,ptr,retval,"move.d"); break; \
154 case 8: __put_user_asm_64(x,ptr,retval); break; \
155 default: __put_user_bad(); \
157 } while (0)
159 #define __get_user_size(x,ptr,size,retval) \
160 do { \
161 retval = 0; \
162 switch (size) { \
163 case 1: __get_user_asm(x,ptr,retval,"move.b"); break; \
164 case 2: __get_user_asm(x,ptr,retval,"move.w"); break; \
165 case 4: __get_user_asm(x,ptr,retval,"move.d"); break; \
166 case 8: __get_user_asm_64(x,ptr,retval); break; \
167 default: (x) = __get_user_bad(); \
169 } while (0)
171 #define __put_user_nocheck(x,ptr,size) \
172 ({ \
173 long __pu_err; \
174 __put_user_size((x),(ptr),(size),__pu_err); \
175 __pu_err; \
178 #define __put_user_check(x,ptr,size) \
179 ({ \
180 long __pu_err = -EFAULT; \
181 __typeof__(*(ptr)) *__pu_addr = (ptr); \
182 if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
183 __put_user_size((x),__pu_addr,(size),__pu_err); \
184 __pu_err; \
187 struct __large_struct { unsigned long buf[100]; };
188 #define __m(x) (*(struct __large_struct *)(x))
192 #define __get_user_nocheck(x,ptr,size) \
193 ({ \
194 long __gu_err, __gu_val; \
195 __get_user_size(__gu_val,(ptr),(size),__gu_err); \
196 (x) = (__typeof__(*(ptr)))__gu_val; \
197 __gu_err; \
200 #define __get_user_check(x,ptr,size) \
201 ({ \
202 long __gu_err = -EFAULT, __gu_val = 0; \
203 const __typeof__(*(ptr)) *__gu_addr = (ptr); \
204 if (access_ok(VERIFY_READ,__gu_addr,size)) \
205 __get_user_size(__gu_val,__gu_addr,(size),__gu_err); \
206 (x) = (__typeof__(*(ptr)))__gu_val; \
207 __gu_err; \
210 extern long __get_user_bad(void);
212 /* More complex functions. Most are inline, but some call functions that
213 live in lib/usercopy.c */
215 <<<<<<< HEAD:include/asm-cris/uaccess.h
216 extern unsigned long __copy_user(void *to, const void *from, unsigned long n);
217 extern unsigned long __copy_user_zeroing(void *to, const void *from, unsigned long n);
218 extern unsigned long __do_clear_user(void *to, unsigned long n);
219 =======
220 extern unsigned long __copy_user(void __user *to, const void *from, unsigned long n);
221 extern unsigned long __copy_user_zeroing(void *to, const void __user *from, unsigned long n);
222 extern unsigned long __do_clear_user(void __user *to, unsigned long n);
223 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-cris/uaccess.h
225 static inline unsigned long
226 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
228 if (access_ok(VERIFY_WRITE, to, n))
229 return __copy_user(to,from,n);
230 return n;
233 static inline unsigned long
234 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
236 if (access_ok(VERIFY_READ, from, n))
237 return __copy_user_zeroing(to,from,n);
238 return n;
241 static inline unsigned long
242 __generic_clear_user(void __user *to, unsigned long n)
244 if (access_ok(VERIFY_WRITE, to, n))
245 return __do_clear_user(to,n);
246 return n;
249 static inline long
250 __strncpy_from_user(char *dst, const char __user *src, long count)
252 return __do_strncpy_from_user(dst, src, count);
255 static inline long
256 strncpy_from_user(char *dst, const char __user *src, long count)
258 long res = -EFAULT;
259 if (access_ok(VERIFY_READ, src, 1))
260 res = __do_strncpy_from_user(dst, src, count);
261 return res;
265 <<<<<<< HEAD:include/asm-cris/uaccess.h
266 /* Note that if these expand awfully if made into switch constructs, so
267 =======
268 /* Note that these expand awfully if made into switch constructs, so
269 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-cris/uaccess.h
270 don't do that. */
272 static inline unsigned long
273 __constant_copy_from_user(void *to, const void __user *from, unsigned long n)
275 unsigned long ret = 0;
276 if (n == 0)
278 else if (n == 1)
279 __asm_copy_from_user_1(to, from, ret);
280 else if (n == 2)
281 __asm_copy_from_user_2(to, from, ret);
282 else if (n == 3)
283 __asm_copy_from_user_3(to, from, ret);
284 else if (n == 4)
285 __asm_copy_from_user_4(to, from, ret);
286 else if (n == 5)
287 __asm_copy_from_user_5(to, from, ret);
288 else if (n == 6)
289 __asm_copy_from_user_6(to, from, ret);
290 else if (n == 7)
291 __asm_copy_from_user_7(to, from, ret);
292 else if (n == 8)
293 __asm_copy_from_user_8(to, from, ret);
294 else if (n == 9)
295 __asm_copy_from_user_9(to, from, ret);
296 else if (n == 10)
297 __asm_copy_from_user_10(to, from, ret);
298 else if (n == 11)
299 __asm_copy_from_user_11(to, from, ret);
300 else if (n == 12)
301 __asm_copy_from_user_12(to, from, ret);
302 else if (n == 13)
303 __asm_copy_from_user_13(to, from, ret);
304 else if (n == 14)
305 __asm_copy_from_user_14(to, from, ret);
306 else if (n == 15)
307 __asm_copy_from_user_15(to, from, ret);
308 else if (n == 16)
309 __asm_copy_from_user_16(to, from, ret);
310 else if (n == 20)
311 __asm_copy_from_user_20(to, from, ret);
312 else if (n == 24)
313 __asm_copy_from_user_24(to, from, ret);
314 else
315 ret = __generic_copy_from_user(to, from, n);
317 return ret;
320 /* Ditto, don't make a switch out of this. */
322 static inline unsigned long
323 __constant_copy_to_user(void __user *to, const void *from, unsigned long n)
325 unsigned long ret = 0;
326 if (n == 0)
328 else if (n == 1)
329 __asm_copy_to_user_1(to, from, ret);
330 else if (n == 2)
331 __asm_copy_to_user_2(to, from, ret);
332 else if (n == 3)
333 __asm_copy_to_user_3(to, from, ret);
334 else if (n == 4)
335 __asm_copy_to_user_4(to, from, ret);
336 else if (n == 5)
337 __asm_copy_to_user_5(to, from, ret);
338 else if (n == 6)
339 __asm_copy_to_user_6(to, from, ret);
340 else if (n == 7)
341 __asm_copy_to_user_7(to, from, ret);
342 else if (n == 8)
343 __asm_copy_to_user_8(to, from, ret);
344 else if (n == 9)
345 __asm_copy_to_user_9(to, from, ret);
346 else if (n == 10)
347 __asm_copy_to_user_10(to, from, ret);
348 else if (n == 11)
349 __asm_copy_to_user_11(to, from, ret);
350 else if (n == 12)
351 __asm_copy_to_user_12(to, from, ret);
352 else if (n == 13)
353 __asm_copy_to_user_13(to, from, ret);
354 else if (n == 14)
355 __asm_copy_to_user_14(to, from, ret);
356 else if (n == 15)
357 __asm_copy_to_user_15(to, from, ret);
358 else if (n == 16)
359 __asm_copy_to_user_16(to, from, ret);
360 else if (n == 20)
361 __asm_copy_to_user_20(to, from, ret);
362 else if (n == 24)
363 __asm_copy_to_user_24(to, from, ret);
364 else
365 ret = __generic_copy_to_user(to, from, n);
367 return ret;
370 /* No switch, please. */
372 static inline unsigned long
373 __constant_clear_user(void __user *to, unsigned long n)
375 unsigned long ret = 0;
376 if (n == 0)
378 else if (n == 1)
379 __asm_clear_1(to, ret);
380 else if (n == 2)
381 __asm_clear_2(to, ret);
382 else if (n == 3)
383 __asm_clear_3(to, ret);
384 else if (n == 4)
385 __asm_clear_4(to, ret);
386 else if (n == 8)
387 __asm_clear_8(to, ret);
388 else if (n == 12)
389 __asm_clear_12(to, ret);
390 else if (n == 16)
391 __asm_clear_16(to, ret);
392 else if (n == 20)
393 __asm_clear_20(to, ret);
394 else if (n == 24)
395 __asm_clear_24(to, ret);
396 else
397 ret = __generic_clear_user(to, n);
399 return ret;
403 #define clear_user(to, n) \
404 (__builtin_constant_p(n) ? \
405 __constant_clear_user(to, n) : \
406 __generic_clear_user(to, n))
408 #define copy_from_user(to, from, n) \
409 (__builtin_constant_p(n) ? \
410 __constant_copy_from_user(to, from, n) : \
411 __generic_copy_from_user(to, from, n))
413 #define copy_to_user(to, from, n) \
414 (__builtin_constant_p(n) ? \
415 __constant_copy_to_user(to, from, n) : \
416 __generic_copy_to_user(to, from, n))
418 /* We let the __ versions of copy_from/to_user inline, because they're often
419 * used in fast paths and have only a small space overhead.
422 static inline unsigned long
423 <<<<<<< HEAD:include/asm-cris/uaccess.h
424 __generic_copy_from_user_nocheck(void *to, const void *from, unsigned long n)
425 =======
426 __generic_copy_from_user_nocheck(void *to, const void __user *from,
427 unsigned long n)
428 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-cris/uaccess.h
430 return __copy_user_zeroing(to,from,n);
433 static inline unsigned long
434 <<<<<<< HEAD:include/asm-cris/uaccess.h
435 __generic_copy_to_user_nocheck(void *to, const void *from, unsigned long n)
436 =======
437 __generic_copy_to_user_nocheck(void __user *to, const void *from,
438 unsigned long n)
439 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-cris/uaccess.h
441 return __copy_user(to,from,n);
444 static inline unsigned long
445 <<<<<<< HEAD:include/asm-cris/uaccess.h
446 __generic_clear_user_nocheck(void *to, unsigned long n)
447 =======
448 __generic_clear_user_nocheck(void __user *to, unsigned long n)
449 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-cris/uaccess.h
451 return __do_clear_user(to,n);
454 /* without checking */
456 #define __copy_to_user(to,from,n) __generic_copy_to_user_nocheck((to),(from),(n))
457 #define __copy_from_user(to,from,n) __generic_copy_from_user_nocheck((to),(from),(n))
458 #define __copy_to_user_inatomic __copy_to_user
459 #define __copy_from_user_inatomic __copy_from_user
460 #define __clear_user(to,n) __generic_clear_user_nocheck((to),(n))
462 #define strlen_user(str) strnlen_user((str), 0x7ffffffe)
464 #endif /* __ASSEMBLY__ */
466 #endif /* _CRIS_UACCESS_H */