1 #ifndef __SCORE_UACCESS_H
2 #define __SCORE_UACCESS_H
4 #include <linux/kernel.h>
5 #include <linux/errno.h>
11 #define get_ds() (KERNEL_DS)
12 #define get_fs() (current_thread_info()->addr_limit)
13 #define segment_eq(a, b) ((a).seg == (b).seg)
28 #define __ua_size(size) \
29 ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size))
51 #define __access_ok(addr, size) \
52 (((long)((get_fs().seg) & \
53 ((addr) | ((addr) + (size)) | \
54 __ua_size(size)))) == 0)
56 #define access_ok(type, addr, size) \
57 likely(__access_ok((unsigned long)(addr), (size)))
75 #define put_user(x, ptr) __put_user_check((x), (ptr), sizeof(*(ptr)))
94 #define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
115 #define __put_user(x, ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr)))
137 #define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
140 #define __m(x) (*(struct __large_struct __user *)(x))
148 #define __get_user_common(val, size, ptr) \
152 __get_user_asm(val, "lb", ptr); \
155 __get_user_asm(val, "lh", ptr); \
158 __get_user_asm(val, "lw", ptr); \
161 if ((copy_from_user((void *)&val, ptr, 8)) == 0) \
164 __gu_err = -EFAULT; \
167 __get_user_unknown(); \
172 #define __get_user_nocheck(x, ptr, size) \
175 __get_user_common((x), size, ptr); \
179 #define __get_user_check(x, ptr, size) \
181 long __gu_err = -EFAULT; \
182 const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
184 if (likely(access_ok(VERIFY_READ, __gu_ptr, size))) \
185 __get_user_common((x), size, __gu_ptr); \
190 #define __get_user_asm(val, insn, addr) \
194 __asm__ __volatile__( \
195 "1:" insn " %1, %3\n" \
197 ".section .fixup,\"ax\"\n" \
201 ".section __ex_table,\"a\"\n" \
204 : "=r" (__gu_err), "=r" (__gu_tmp) \
205 : "0" (0), "o" (__m(addr)), "i" (-EFAULT)); \
207 (val) = (__typeof__(*(addr))) __gu_tmp; \
214 #define __put_user_nocheck(val, ptr, size) \
216 __typeof__(*(ptr)) __pu_val; \
222 __put_user_asm("sb", ptr); \
225 __put_user_asm("sh", ptr); \
228 __put_user_asm("sw", ptr); \
231 if ((__copy_to_user((void *)ptr, &__pu_val, 8)) == 0) \
234 __pu_err = -EFAULT; \
237 __put_user_unknown(); \
244 #define __put_user_check(val, ptr, size) \
246 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
247 __typeof__(*(ptr)) __pu_val = (val); \
248 long __pu_err = -EFAULT; \
250 if (likely(access_ok(VERIFY_WRITE, __pu_addr, size))) { \
253 __put_user_asm("sb", __pu_addr); \
256 __put_user_asm("sh", __pu_addr); \
259 __put_user_asm("sw", __pu_addr); \
262 if ((__copy_to_user((void *)__pu_addr, &__pu_val, 8)) == 0)\
265 __pu_err = -EFAULT; \
268 __put_user_unknown(); \
275 #define __put_user_asm(insn, ptr) \
276 __asm__ __volatile__( \
277 "1:" insn " %2, %3\n" \
279 ".section .fixup,\"ax\"\n" \
283 ".section __ex_table,\"a\"\n" \
287 : "0" (0), "r" (__pu_val), "o" (__m(ptr)), \
293 static inline unsigned long
308 static inline unsigned long
309 copy_to_user(
void *to,
const void *from,
unsigned long len)
323 #define __copy_from_user(to, from, len) \
324 __copy_tofrom_user((to), (from), (len))
326 #define __copy_to_user(to, from, len) \
327 __copy_tofrom_user((to), (from), (len))
329 static inline unsigned long
335 static inline unsigned long
341 #define __copy_in_user(to, from, len) __copy_from_user(to, from, len)
343 static inline unsigned long
344 copy_in_user(
void *to,
const void *from,
unsigned long len)
402 static inline long strlen_user(
const char __user *src)