15 #ifndef _CRIS_UACCESS_H
16 #define _CRIS_UACCESS_H
19 #include <linux/sched.h>
20 #include <linux/errno.h>
21 #include <asm/processor.h>
25 #define VERIFY_WRITE 1
35 #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
43 #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
44 #define USER_DS MAKE_MM_SEG(TASK_SIZE)
46 #define get_ds() (KERNEL_DS)
47 #define get_fs() (current_thread_info()->addr_limit)
48 #define set_fs(x) (current_thread_info()->addr_limit = (x))
50 #define segment_eq(a,b) ((a).seg == (b).seg)
52 #define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
53 #define __user_ok(addr,size) (((size) <= TASK_SIZE)&&((addr) <= TASK_SIZE-(size)))
54 #define __access_ok(addr,size) (__kernel_ok || __user_ok((addr),(size)))
55 #define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
57 #include <arch/uaccess.h>
95 #define get_user(x,ptr) \
96 __get_user_check((x),(ptr),sizeof(*(ptr)))
97 #define put_user(x,ptr) \
98 __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
100 #define __get_user(x,ptr) \
101 __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
102 #define __put_user(x,ptr) \
103 __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
107 #define __put_user_size(x,ptr,size,retval) \
111 case 1: __put_user_asm(x,ptr,retval,"move.b"); break; \
112 case 2: __put_user_asm(x,ptr,retval,"move.w"); break; \
113 case 4: __put_user_asm(x,ptr,retval,"move.d"); break; \
114 case 8: __put_user_asm_64(x,ptr,retval); break; \
115 default: __put_user_bad(); \
119 #define __get_user_size(x,ptr,size,retval) \
123 case 1: __get_user_asm(x,ptr,retval,"move.b"); break; \
124 case 2: __get_user_asm(x,ptr,retval,"move.w"); break; \
125 case 4: __get_user_asm(x,ptr,retval,"move.d"); break; \
126 case 8: __get_user_asm_64(x,ptr,retval); break; \
127 default: (x) = __get_user_bad(); \
131 #define __put_user_nocheck(x,ptr,size) \
134 __put_user_size((x),(ptr),(size),__pu_err); \
138 #define __put_user_check(x,ptr,size) \
140 long __pu_err = -EFAULT; \
141 __typeof__(*(ptr)) *__pu_addr = (ptr); \
142 if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
143 __put_user_size((x),__pu_addr,(size),__pu_err); \
148 #define __m(x) (*(struct __large_struct *)(x))
152 #define __get_user_nocheck(x,ptr,size) \
154 long __gu_err, __gu_val; \
155 __get_user_size(__gu_val,(ptr),(size),__gu_err); \
156 (x) = (__typeof__(*(ptr)))__gu_val; \
160 #define __get_user_check(x,ptr,size) \
162 long __gu_err = -EFAULT, __gu_val = 0; \
163 const __typeof__(*(ptr)) *__gu_addr = (ptr); \
164 if (access_ok(VERIFY_READ,__gu_addr,size)) \
165 __get_user_size(__gu_val,__gu_addr,(size),__gu_err); \
166 (x) = (__typeof__(*(ptr)))__gu_val; \
175 extern unsigned long __copy_user(
void __user *to,
const void *
from,
unsigned long n);
179 static inline unsigned long
180 __generic_copy_to_user(
void __user *to,
const void *
from,
unsigned long n)
187 static inline unsigned long
188 __generic_copy_from_user(
void *to,
const void __user *from,
unsigned long n)
195 static inline unsigned long
196 __generic_clear_user(
void __user *to,
unsigned long n)
222 static inline unsigned long
223 __constant_copy_from_user(
void *to,
const void __user *from,
unsigned long n)
225 unsigned long ret = 0;
265 ret = __generic_copy_from_user(to, from, n);
272 static inline unsigned long
273 __constant_copy_to_user(
void __user *to,
const void *from,
unsigned long n)
275 unsigned long ret = 0;
315 ret = __generic_copy_to_user(to, from, n);
322 static inline unsigned long
323 __constant_clear_user(
void __user *to,
unsigned long n)
325 unsigned long ret = 0;
347 ret = __generic_clear_user(to, n);
353 #define clear_user(to, n) \
354 (__builtin_constant_p(n) ? \
355 __constant_clear_user(to, n) : \
356 __generic_clear_user(to, n))
358 #define copy_from_user(to, from, n) \
359 (__builtin_constant_p(n) ? \
360 __constant_copy_from_user(to, from, n) : \
361 __generic_copy_from_user(to, from, n))
363 #define copy_to_user(to, from, n) \
364 (__builtin_constant_p(n) ? \
365 __constant_copy_to_user(to, from, n) : \
366 __generic_copy_to_user(to, from, n))
372 static inline unsigned long
373 __generic_copy_from_user_nocheck(
void *to,
const void __user *from,
379 static inline unsigned long
380 __generic_copy_to_user_nocheck(
void __user *to,
const void *from,
386 static inline unsigned long
387 __generic_clear_user_nocheck(
void __user *to,
unsigned long n)
394 #define __copy_to_user(to,from,n) __generic_copy_to_user_nocheck((to),(from),(n))
395 #define __copy_from_user(to,from,n) __generic_copy_from_user_nocheck((to),(from),(n))
396 #define __copy_to_user_inatomic __copy_to_user
397 #define __copy_from_user_inatomic __copy_from_user
398 #define __clear_user(to,n) __generic_clear_user_nocheck((to),(n))
400 #define strlen_user(str) strnlen_user((str), 0x7ffffffe)