11 #ifndef _ASM_UACCESS_H
12 #define _ASM_UACCESS_H
18 #include <linux/kernel.h>
20 #include <asm/errno.h>
23 #define VERIFY_WRITE 1
32 #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
34 #define KERNEL_XDS MAKE_MM_SEG(0xBFFFFFFF)
35 #define KERNEL_DS MAKE_MM_SEG(0x9FFFFFFF)
36 #define USER_DS MAKE_MM_SEG(TASK_SIZE)
38 #define get_ds() (KERNEL_DS)
39 #define get_fs() (current_thread_info()->addr_limit)
40 #define set_fs(x) (current_thread_info()->addr_limit = (x))
41 #define __kernel_ds_p() (current_thread_info()->addr_limit.seg == 0x9FFFFFFF)
43 #define segment_eq(a, b) ((a).seg == (b).seg)
45 #define __addr_ok(addr) \
46 ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
51 static inline int ___range_ok(
unsigned long addr,
unsigned int size)
62 :
"1"(
addr),
"ir"(size),
70 #define __range_ok(addr, size) ___range_ok((unsigned long)(addr), (u32)(size))
72 #define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0)
73 #define __access_ok(addr, size) (__range_ok((addr), (size)) == 0)
75 static inline int verify_area(
int type,
const void *
addr,
unsigned long size)
102 #define put_user(x, ptr) __put_user_check((x), (ptr), sizeof(*(ptr)))
103 #define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
110 #define __put_user(x, ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr)))
111 #define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
119 #define put_user_ret(x, ptr, ret) \
120 ({ if (put_user((x), (ptr))) return (ret); })
121 #define get_user_ret(x, ptr, ret) \
122 ({ if (get_user((x), (ptr))) return (ret); })
123 #define __put_user_ret(x, ptr, ret) \
124 ({ if (__put_user((x), (ptr))) return (ret); })
125 #define __get_user_ret(x, ptr, ret) \
126 ({ if (__get_user((x), (ptr))) return (ret); })
129 #define __m(x) (*(struct __large_struct *)(x))
131 #define __get_user_nocheck(x, ptr, size) \
133 unsigned long __gu_addr; \
135 __gu_addr = (unsigned long) (ptr); \
138 unsigned char __gu_val; \
139 __get_user_asm("bu"); \
140 (x) = *(__force __typeof__(*(ptr))*) &__gu_val; \
144 unsigned short __gu_val; \
145 __get_user_asm("hu"); \
146 (x) = *(__force __typeof__(*(ptr))*) &__gu_val; \
150 unsigned int __gu_val; \
151 __get_user_asm(""); \
152 (x) = *(__force __typeof__(*(ptr))*) &__gu_val; \
156 __get_user_unknown(); \
162 #define __get_user_check(x, ptr, size) \
164 const __typeof__(ptr) __guc_ptr = (ptr); \
166 if (likely(__access_ok((unsigned long) __guc_ptr, (size)))) \
167 _e = __get_user_nocheck((x), __guc_ptr, (size)); \
170 (x) = (__typeof__(x))0; \
175 #define __get_user_asm(INSN) \
179 " mov"INSN" %2,%1\n" \
182 " .section .fixup,\"ax\"\n" \
187 " .section __ex_table,\"a\"\n" \
191 : "=&r" (__gu_err), "=&r" (__gu_val) \
192 : "m" (__m(__gu_addr)), "i" (-EFAULT)); \
197 #define __put_user_nocheck(x, ptr, size) \
200 __typeof__(*(ptr)) val; \
203 unsigned long __pu_addr; \
205 __pu_val.val = (x); \
206 __pu_addr = (unsigned long) (ptr); \
208 case 1: __put_user_asm("bu"); break; \
209 case 2: __put_user_asm("hu"); break; \
210 case 4: __put_user_asm("" ); break; \
211 case 8: __put_user_asm8(); break; \
212 default: __pu_err = __put_user_unknown(); break; \
217 #define __put_user_check(x, ptr, size) \
220 __typeof__(*(ptr)) val; \
223 unsigned long __pu_addr; \
225 __pu_val.val = (x); \
226 __pu_addr = (unsigned long) (ptr); \
227 if (likely(__access_ok(__pu_addr, size))) { \
229 case 1: __put_user_asm("bu"); break; \
230 case 2: __put_user_asm("hu"); break; \
231 case 4: __put_user_asm("" ); break; \
232 case 8: __put_user_asm8(); break; \
233 default: __pu_err = __put_user_unknown(); break; \
237 __pu_err = -EFAULT; \
242 #define __put_user_asm(INSN) \
246 " mov"INSN" %1,%2\n" \
249 " .section .fixup,\"ax\"\n" \
254 " .section __ex_table,\"a\"\n" \
259 : "r" (__pu_val.val), "m" (__m(__pu_addr)), \
264 #define __put_user_asm8() \
271 " .section .fixup,\"ax\" \n" \
276 " .section __ex_table,\"a\"\n" \
282 : "r" (__pu_val.bits[0]), "r" (__pu_val.bits[1]), \
283 "m" (__m(__pu_addr)), "m" (__m(__pu_addr+4)), \
295 #define __copy_user(to, from, size) \
299 const void *__from = from; \
302 "0: movbu (%0),%3;\n" \
303 "1: movbu %3,(%1);\n" \
309 " .section .fixup,\"ax\"\n" \
312 " .section __ex_table,\"a\"\n" \
317 : "=a"(__from), "=a"(__to), "=r"(size), "=&r"(w)\
318 : "0"(__from), "1"(__to), "2"(size) \
323 #define __copy_user_zeroing(to, from, size) \
327 const void *__from = from; \
330 "0: movbu (%0),%3;\n" \
331 "1: movbu %3,(%1);\n" \
337 " .section .fixup,\"ax\"\n" \
341 "4: movbu %3,(%1);\n" \
348 " .section __ex_table,\"a\"\n" \
353 : "=a"(__from), "=a"(__to), "=r"(size), "=&r"(w)\
354 : "0"(__from), "1"(__to), "2"(size) \
363 unsigned long __generic_copy_from_user_nocheck(
void *to,
const void *
from,
371 unsigned long __generic_copy_to_user_nocheck(
void *to,
const void *
from,
380 #error "don't use - these macros don't increment to & from pointers"
382 #define __constant_copy_user(to, from, size) \
386 "0: movbu (%1),d3;\n" \
387 "1: movbu d3,(%2);\n" \
391 ".section .fixup,\"ax\"\n" \
394 ".section __ex_table,\"a\"\n" \
400 : "d"(size), "d"(to), "d"(from) \
405 #define __constant_copy_user_zeroing(to, from, size) \
409 "0: movbu (%1),d3;\n" \
410 "1: movbu d3,(%2);\n" \
414 ".section .fixup,\"ax\"\n" \
417 ".section __ex_table,\"a\"\n" \
423 : "d"(size), "d"(to), "d"(from) \
428 unsigned long __constant_copy_to_user(
void *to,
const void *
from,
432 __constant_copy_user(to, from, n);
437 unsigned long __constant_copy_from_user(
void *to,
const void *from,
441 __constant_copy_user_zeroing(to, from, n);
446 unsigned long __constant_copy_to_user_nocheck(
void *to,
const void *from,
449 __constant_copy_user(to, from, n);
454 unsigned long __constant_copy_from_user_nocheck(
void *to,
const void *from,
457 __constant_copy_user_zeroing(to, from, n);
467 #define __copy_to_user_inatomic(to, from, n) \
468 __generic_copy_to_user_nocheck((to), (from), (n))
469 #define __copy_from_user_inatomic(to, from, n) \
470 __generic_copy_from_user_nocheck((to), (from), (n))
472 #define __copy_to_user(to, from, n) \
475 __copy_to_user_inatomic((to), (from), (n)); \
478 #define __copy_from_user(to, from, n) \
481 __copy_from_user_inatomic((to), (from), (n)); \
485 #define copy_to_user(to, from, n) __generic_copy_to_user((to), (from), (n))
486 #define copy_from_user(to, from, n) __generic_copy_from_user((to), (from), (n))
491 #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
492 extern unsigned long clear_user(
void __user *
mem,
unsigned long len);
493 extern unsigned long __clear_user(
void __user *
mem,
unsigned long len);