1 #ifndef _ASMARM_UACCESS_H
2 #define _ASMARM_UACCESS_H
5 * User space memory access functions
7 #include <linux/sched.h>
11 #define VERIFY_WRITE 1
14 * The exception table consists of pairs of addresses: the first is the
15 * address of an instruction that is allowed to fault, and the second is
16 * the address at which the program should continue. No registers are
17 * modified, so it is entirely up to the continuation code to figure out
20 * All the routines below use bits of fixup code that are out of line
21 * with the main instruction path. This means when everything is well,
22 * we don't even have to jump over them. Further, they do not intrude
23 * on our cache or tlb entries.
26 struct exception_table_entry
28 unsigned long insn, fixup;
31 /* Returns 0 if exception not found and fixup otherwise. */
32 extern unsigned long search_exception_table(unsigned long);
33 extern int fixup_exception(struct pt_regs *regs);
35 #define get_ds() (KERNEL_DS)
36 #define get_fs() (current_thread_info()->addr_limit)
37 #define segment_eq(a,b) ((a) == (b))
39 #include <asm/uaccess-asm.h>
41 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
43 /* this function will go away soon - use access_ok() instead */
44 static inline int __deprecated verify_area(int type, const void * addr, unsigned long size)
46 return access_ok(type, addr, size) ? 0 : -EFAULT;
50 * Single-value transfer routines. They automatically use the right
51 * size if we just have the right pointer type. Note that the functions
52 * which read from user space (*get_*) need to take care not to leak
53 * kernel data even if the calling code is buggy and fails to check
54 * the return value. This means zeroing out the destination variable
55 * or buffer on error. Normally this is done out of line by the
56 * fixup code, but there are a few places where it intrudes on the
57 * main code path. When we only write to user space, there is no
60 * The "__xxx" versions of the user access functions do not verify the
61 * address space - it must have been done previously with a separate
64 * The "xxx_error" versions set the third argument to EFAULT if an
65 * error occurs, and leave it unchanged on success. Note that these
66 * versions are void (ie, don't return a value as such).
69 extern int __get_user_1(void *);
70 extern int __get_user_2(void *);
71 extern int __get_user_4(void *);
72 extern int __get_user_8(void *);
73 extern int __get_user_bad(void);
75 #define __get_user_x(__r1,__p,__e,__s,__i...) \
76 __asm__ __volatile__ ("bl __get_user_" #__s \
77 : "=&r" (__e), "=r" (__r1) \
81 #define get_user(x,p) \
83 const register typeof(*(p)) *__p asm("r0") = (p); \
84 register typeof(*(p)) __r1 asm("r1"); \
85 register int __e asm("r0"); \
86 switch (sizeof(*(p))) { \
88 __get_user_x(__r1, __p, __e, 1, "lr"); \
91 __get_user_x(__r1, __p, __e, 2, "r2", "lr"); \
94 __get_user_x(__r1, __p, __e, 4, "lr"); \
97 __get_user_x(__r1, __p, __e, 8, "lr"); \
99 default: __e = __get_user_bad(); break; \
106 #define __get_user(x,ptr) \
109 __get_user_err((x),(ptr),__gu_err); \
113 #define __get_user_error(x,ptr,err) \
115 __get_user_err((x),(ptr),err); \
119 #define __get_user_err(x,ptr,err) \
121 unsigned long __gu_addr = (unsigned long)(ptr); \
122 unsigned long __gu_val; \
123 switch (sizeof(*(ptr))) { \
124 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
125 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
126 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
127 default: (__gu_val) = __get_user_bad(); \
129 (x) = (__typeof__(*(ptr)))__gu_val; \
132 extern int __put_user_1(void *, unsigned int);
133 extern int __put_user_2(void *, unsigned int);
134 extern int __put_user_4(void *, unsigned int);
135 extern int __put_user_8(void *, unsigned long long);
136 extern int __put_user_bad(void);
138 #define __put_user_x(__r1,__p,__e,__s) \
139 __asm__ __volatile__ ( \
140 __asmeq("%0", "r0") __asmeq("%2", "r1") \
141 "bl __put_user_" #__s \
143 : "0" (__p), "r" (__r1) \
146 #define put_user(x,p) \
148 const register typeof(*(p)) __r1 asm("r1") = (x); \
149 const register typeof(*(p)) *__p asm("r0") = (p); \
150 register int __e asm("r0"); \
151 switch (sizeof(*(__p))) { \
153 __put_user_x(__r1, __p, __e, 1); \
156 __put_user_x(__r1, __p, __e, 2); \
159 __put_user_x(__r1, __p, __e, 4); \
162 __put_user_x(__r1, __p, __e, 8); \
164 default: __e = __put_user_bad(); break; \
170 /********************* OLD METHOD *******************/
171 #define __put_user_x(__r1,__p,__e,__s,__i...) \
172 __asm__ __volatile__ ("bl __put_user_" #__s \
174 : "0" (__p), "r" (__r1) \
177 #define put_user(x,p) \
179 const register typeof(*(p)) __r1 asm("r1") = (x); \
180 const register typeof(*(p)) *__p asm("r0") = (p); \
181 register int __e asm("r0"); \
182 switch (sizeof(*(p))) { \
184 __put_user_x(__r1, __p, __e, 1, "r2", "lr"); \
187 __put_user_x(__r1, __p, __e, 2, "r2", "lr"); \
190 __put_user_x(__r1, __p, __e, 4, "r2", "lr"); \
193 __put_user_x(__r1, __p, __e, 8, "r2", "ip", "lr"); \
195 default: __e = __put_user_bad(); break; \
199 /*************************************************/
202 #define __put_user(x,ptr) \
205 __put_user_err((x),(ptr),__pu_err); \
209 #define __put_user_error(x,ptr,err) \
211 __put_user_err((x),(ptr),err); \
215 #define __put_user_err(x,ptr,err) \
217 unsigned long __pu_addr = (unsigned long)(ptr); \
218 __typeof__(*(ptr)) __pu_val = (x); \
219 switch (sizeof(*(ptr))) { \
220 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
221 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
222 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
223 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
224 default: __put_user_bad(); \
228 static __inline__ unsigned long copy_from_user(void *to, const void *from, unsigned long n)
230 if (access_ok(VERIFY_READ, from, n))
231 __do_copy_from_user(to, from, n);
232 else /* security hole - plug it */
237 static __inline__ unsigned long __copy_from_user(void *to, const void *from, unsigned long n)
239 __do_copy_from_user(to, from, n);
243 static __inline__ unsigned long copy_to_user(void *to, const void *from, unsigned long n)
245 if (access_ok(VERIFY_WRITE, to, n))
246 __do_copy_to_user(to, from, n);
250 static __inline__ unsigned long __copy_to_user(void *to, const void *from, unsigned long n)
252 __do_copy_to_user(to, from, n);
256 #define __copy_to_user_inatomic __copy_to_user
257 #define __copy_from_user_inatomic __copy_from_user
259 static __inline__ unsigned long clear_user (void *to, unsigned long n)
261 if (access_ok(VERIFY_WRITE, to, n))
262 __do_clear_user(to, n);
266 static __inline__ unsigned long __clear_user (void *to, unsigned long n)
268 __do_clear_user(to, n);
272 static __inline__ long strncpy_from_user (char *dst, const char *src, long count)
275 if (access_ok(VERIFY_READ, src, 1))
276 __do_strncpy_from_user(dst, src, count, res);
280 static __inline__ long __strncpy_from_user (char *dst, const char *src, long count)
283 __do_strncpy_from_user(dst, src, count, res);
287 #define strlen_user(s) strnlen_user(s, ~0UL >> 1)
289 static inline long strnlen_user(const char *s, long n)
291 unsigned long res = 0;
294 __do_strnlen_user(s, n, res);
299 #endif /* _ASMARM_UACCESS_H */