1 #ifndef _ASMARM_UACCESS_H
2 #define _ASMARM_UACCESS_H
5 * User space memory access functions
7 #include <linux/sched.h>
10 #define VERIFY_WRITE 1
13 * The exception table consists of pairs of addresses: the first is the
14 * address of an instruction that is allowed to fault, and the second is
15 * the address at which the program should continue. No registers are
16 * modified, so it is entirely up to the continuation code to figure out
19 * All the routines below use bits of fixup code that are out of line
20 * with the main instruction path. This means when everything is well,
21 * we don't even have to jump over them. Further, they do not intrude
22 * on our cache or tlb entries.
25 struct exception_table_entry
27 unsigned long insn
, fixup
;
30 /* Returns 0 if exception not found and fixup otherwise. */
31 extern unsigned long search_exception_table(unsigned long);
33 #include <asm/proc/uaccess.h>
35 extern inline int verify_area(int type
, const void * addr
, unsigned long size
)
37 return access_ok(type
,addr
,size
) ? 0 : -EFAULT
;
41 * Single-value transfer routines. They automatically use the right
42 * size if we just have the right pointer type.
44 * The "__xxx" versions of the user access functions do not verify the
45 * address space - it must have been done previously with a separate
48 * The "xxx_ret" versions return constant specified in the third
49 * argument if something bad happens.
51 #define get_user(x,p) __get_user_check((x),(p),sizeof(*(p)))
52 #define __get_user(x,p) __get_user_nocheck((x),(p),sizeof(*(p)))
53 #define get_user_ret(x,p,r) ({ if (get_user(x,p)) return r; })
54 #define __get_user_ret(x,p,r) ({ if (__get_user(x,p)) return r; })
56 #define put_user(x,p) __put_user_check((__typeof(*(p)))(x),(p),sizeof(*(p)))
57 #define __put_user(x,p) __put_user_nocheck((__typeof(*(p)))(x),(p),sizeof(*(p)))
58 #define put_user_ret(x,p,r) ({ if (put_user(x,p)) return r; })
59 #define __put_user_ret(x,p,r) ({ if (__put_user(x,p)) return r; })
61 static __inline__
unsigned long copy_from_user(void *to
, const void *from
, unsigned long n
)
63 char *end
= (char *)to
+ n
;
64 if (access_ok(VERIFY_READ
, from
, n
)) {
65 __do_copy_from_user(to
, from
, n
);
66 if (n
) memset(end
- n
, 0, n
);
71 static __inline__
unsigned long __copy_from_user(void *to
, const void *from
, unsigned long n
)
73 __do_copy_from_user(to
, from
, n
);
77 #define copy_from_user_ret(t,f,n,r) \
78 ({ if (copy_from_user(t,f,n)) return r; })
80 static __inline__
unsigned long copy_to_user(void *to
, const void *from
, unsigned long n
)
82 if (access_ok(VERIFY_WRITE
, to
, n
))
83 __do_copy_to_user(to
, from
, n
);
87 static __inline__
unsigned long __copy_to_user(void *to
, const void *from
, unsigned long n
)
89 __do_copy_to_user(to
, from
, n
);
93 #define copy_to_user_ret(t,f,n,r) \
94 ({ if (copy_to_user(t,f,n)) return r; })
96 static __inline__
unsigned long clear_user (void *to
, unsigned long n
)
98 if (access_ok(VERIFY_WRITE
, to
, n
))
99 __do_clear_user(to
, n
);
103 static __inline__
unsigned long __clear_user (void *to
, unsigned long n
)
105 __do_clear_user(to
, n
);
109 static __inline__
long strncpy_from_user (char *dst
, const char *src
, long count
)
112 if (access_ok(VERIFY_READ
, src
, 1))
113 __do_strncpy_from_user(dst
, src
, count
, res
);
117 static __inline__
long __strncpy_from_user (char *dst
, const char *src
, long count
)
120 __do_strncpy_from_user(dst
, src
, count
, res
);
124 extern __inline__
long strlen_user (const char *s
)
126 unsigned long res
= 0;
129 __do_strlen_user (s
, res
);
135 * These are the work horses of the get/put_user functions
137 #define __get_user_check(x,ptr,size) \
139 long __gu_err = -EFAULT, __gu_val = 0; \
140 const __typeof__(*(ptr)) *__gu_addr = (ptr); \
141 if (access_ok(VERIFY_READ,__gu_addr,size)) \
142 __get_user_size(__gu_val,__gu_addr,(size),__gu_err); \
143 (x) = (__typeof__(*(ptr)))__gu_val; \
147 #define __get_user_nocheck(x,ptr,size) \
149 long __gu_err = 0, __gu_val = 0; \
150 __get_user_size(__gu_val,(ptr),(size),__gu_err); \
151 (x) = (__typeof__(*(ptr)))__gu_val; \
155 #define __put_user_check(x,ptr,size) \
157 long __pu_err = -EFAULT; \
158 __typeof__(*(ptr)) *__pu_addr = (ptr); \
159 if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
160 __put_user_size((x),__pu_addr,(size),__pu_err); \
164 #define __put_user_nocheck(x,ptr,size) \
167 __put_user_size((x),(ptr),(size),__pu_err); \
171 extern long __get_user_bad(void);
173 #define __get_user_size(x,ptr,size,retval) \
177 case 1: __get_user_asm_byte(x,ptr,retval); break; \
178 case 2: __get_user_asm_half(x,ptr,retval); break; \
179 case 4: __get_user_asm_word(x,ptr,retval); break; \
180 default: (x) = __get_user_bad(); \
184 extern long __put_user_bad(void);
186 #define __put_user_size(x,ptr,size,retval) \
190 case 1: __put_user_asm_byte(x,ptr,retval); break; \
191 case 2: __put_user_asm_half(x,ptr,retval); break; \
192 case 4: __put_user_asm_word(x,ptr,retval); break; \
193 default: __put_user_bad(); \
197 #endif /* _ASMARM_UACCESS_H */