16 #ifndef _XTENSA_UACCESS_H
17 #define _XTENSA_UACCESS_H
19 #include <linux/errno.h>
21 #include <linux/prefetch.h>
23 #include <asm/types.h>
26 #define VERIFY_WRITE 1
30 #include <asm/current.h>
31 #include <asm/asm-offsets.h>
32 #include <asm/processor.h>
43 #define get_ds (KERNEL_DS)
55 l32i \ad, \ad, THREAD_CURRENT_DS
70 s32i \av, \at, THREAD_CURRENT_DS
93 #if ((KERNEL_DS != 0) || (USER_DS == 0))
94 # error Assembly macro kernel_ok fails
96 .macro kernel_ok
at,
sp, success
126 bgeu \as, \at, \
error
128 bgeu \aa, \at, \
error
155 kernel_ok \at, \sp, .Laccess_ok_\@
156 user_ok \aa, \as, \at, \
error
162 #include <linux/sched.h>
173 #define KERNEL_DS ((mm_segment_t) { 0 })
174 #define USER_DS ((mm_segment_t) { 1 })
176 #define get_ds() (KERNEL_DS)
177 #define get_fs() (current->thread.current_ds)
178 #define set_fs(val) (current->thread.current_ds = (val))
180 #define segment_eq(a,b) ((a).seg == (b).seg)
182 #define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
183 #define __user_ok(addr,size) (((size) <= TASK_SIZE)&&((addr) <= TASK_SIZE-(size)))
184 #define __access_ok(addr,size) (__kernel_ok || __user_ok((addr),(size)))
185 #define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
201 #define put_user(x,ptr) __put_user_check((x),(ptr),sizeof(*(ptr)))
202 #define get_user(x,ptr) __get_user_check((x),(ptr),sizeof(*(ptr)))
210 #define __put_user(x,ptr) __put_user_nocheck((x),(ptr),sizeof(*(ptr)))
211 #define __get_user(x,ptr) __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
216 #define __put_user_nocheck(x,ptr,size) \
219 __put_user_size((x),(ptr),(size),__pu_err); \
223 #define __put_user_check(x,ptr,size) \
225 long __pu_err = -EFAULT; \
226 __typeof__(*(ptr)) *__pu_addr = (ptr); \
227 if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
228 __put_user_size((x),__pu_addr,(size),__pu_err); \
232 #define __put_user_size(x,ptr,size,retval) \
237 case 1: __put_user_asm(x,ptr,retval,1,"s8i",__cb); break; \
238 case 2: __put_user_asm(x,ptr,retval,2,"s16i",__cb); break; \
239 case 4: __put_user_asm(x,ptr,retval,4,"s32i",__cb); break; \
241 __typeof__(*ptr) __v64 = x; \
242 retval = __copy_to_user(ptr,&__v64,8); \
245 default: __put_user_bad(); \
271 #define __check_align_1 ""
273 #define __check_align_2 \
274 " _bbci.l %3, 0, 1f \n" \
278 #define __check_align_4 \
279 " _bbsi.l %3, 0, 0f \n" \
280 " _bbci.l %3, 1, 1f \n" \
281 "0: movi %0, %4 \n" \
293 #define __put_user_asm(x, addr, err, align, insn, cb) \
294 __asm__ __volatile__( \
295 __check_align_##align \
296 "1: "insn" %2, %3, 0 \n" \
298 " .section .fixup,\"ax\" \n" \
307 " .section __ex_table,\"a\" \n" \
310 :"=r" (err), "=r" (cb) \
311 :"r" ((int)(x)), "r" (addr), "i" (-EFAULT), "0" (err))
313 #define __get_user_nocheck(x,ptr,size) \
315 long __gu_err, __gu_val; \
316 __get_user_size(__gu_val,(ptr),(size),__gu_err); \
317 (x) = (__typeof__(*(ptr)))__gu_val; \
321 #define __get_user_check(x,ptr,size) \
323 long __gu_err = -EFAULT, __gu_val = 0; \
324 const __typeof__(*(ptr)) *__gu_addr = (ptr); \
325 if (access_ok(VERIFY_READ,__gu_addr,size)) \
326 __get_user_size(__gu_val,__gu_addr,(size),__gu_err); \
327 (x) = (__typeof__(*(ptr)))__gu_val; \
333 #define __get_user_size(x,ptr,size,retval) \
338 case 1: __get_user_asm(x,ptr,retval,1,"l8ui",__cb); break; \
339 case 2: __get_user_asm(x,ptr,retval,2,"l16ui",__cb); break; \
340 case 4: __get_user_asm(x,ptr,retval,4,"l32i",__cb); break; \
341 case 8: retval = __copy_from_user(&x,ptr,8); break; \
342 default: (x) = __get_user_bad(); \
351 #define __get_user_asm(x, addr, err, align, insn, cb) \
352 __asm__ __volatile__( \
353 __check_align_##align \
354 "1: "insn" %2, %3, 0 \n" \
356 " .section .fixup,\"ax\" \n" \
366 " .section __ex_table,\"a\" \n" \
369 :"=r" (err), "=r" (cb), "=r" (x) \
370 :"r" (addr), "i" (-EFAULT), "0" (err))
387 #define __copy_user(to,from,size) __xtensa_copy_user(to,from,size)
390 static inline unsigned long
391 __generic_copy_from_user_nocheck(
void *to,
const void *
from,
unsigned long n)
396 static inline unsigned long
397 __generic_copy_to_user_nocheck(
void *to,
const void *
from,
unsigned long n)
402 static inline unsigned long
411 static inline unsigned long
422 #define copy_to_user(to,from,n) __generic_copy_to_user((to),(from),(n))
423 #define copy_from_user(to,from,n) __generic_copy_from_user((to),(from),(n))
424 #define __copy_to_user(to,from,n) __generic_copy_to_user_nocheck((to),(from),(n))
425 #define __copy_from_user(to,from,n) __generic_copy_from_user_nocheck((to),(from),(n))
426 #define __copy_to_user_inatomic __copy_to_user
427 #define __copy_from_user_inatomic __copy_from_user
437 static inline unsigned long
438 __xtensa_clear_user(
void *
addr,
unsigned long size)
440 if ( !
memset(addr, 0, size) )
445 static inline unsigned long
449 return __xtensa_clear_user(addr, size);
450 return size ? -
EFAULT : 0;
453 #define __clear_user __xtensa_clear_user
457 #define __strncpy_from_user __strncpy_user
468 #define strlen_user(str) strnlen_user((str), TASK_SIZE - 1)
479 if ((
unsigned long)str > top)
496 #define fixup_exception(map_reg, fixup_unit, pc) \