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)
44 * Single-value transfer routines. They automatically use the right
45 * size if we just have the right pointer type. Note that the functions
46 * which read from user space (*get_*) need to take care not to leak
47 * kernel data even if the calling code is buggy and fails to check
48 * the return value. This means zeroing out the destination variable
49 * or buffer on error. Normally this is done out of line by the
50 * fixup code, but there are a few places where it intrudes on the
51 * main code path. When we only write to user space, there is no
54 * The "__xxx" versions of the user access functions do not verify the
55 * address space - it must have been done previously with a separate
58 * The "xxx_error" versions set the third argument to EFAULT if an
59 * error occurs, and leave it unchanged on success. Note that these
60 * versions are void (ie, don't return a value as such).
63 extern int __get_user_1(void *);
64 extern int __get_user_2(void *);
65 extern int __get_user_4(void *);
66 extern int __get_user_8(void *);
67 extern int __get_user_bad(void);
69 #define __get_user_x(__r1,__p,__e,__s,__i...) \
70 __asm__ __volatile__ ("bl __get_user_" #__s \
71 : "=&r" (__e), "=r" (__r1) \
75 #define get_user(x,p) \
77 register const typeof(*(p)) *__p asm("r0") = (p); \
78 register typeof(*(p)) __r1 asm("r1"); \
79 register int __e asm("r0"); \
80 switch (sizeof(*(p))) { \
82 __get_user_x(__r1, __p, __e, 1, "lr"); \
85 __get_user_x(__r1, __p, __e, 2, "r2", "lr"); \
88 __get_user_x(__r1, __p, __e, 4, "lr"); \
91 __get_user_x(__r1, __p, __e, 8, "lr"); \
93 default: __e = __get_user_bad(); break; \
100 #define __get_user(x,ptr) \
103 __get_user_err((x),(ptr),__gu_err); \
107 #define __get_user_error(x,ptr,err) \
109 __get_user_err((x),(ptr),err); \
113 #define __get_user_err(x,ptr,err) \
115 unsigned long __gu_addr = (unsigned long)(ptr); \
116 unsigned long __gu_val; \
117 switch (sizeof(*(ptr))) { \
118 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
119 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
120 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
121 default: (__gu_val) = __get_user_bad(); \
123 (x) = (__typeof__(*(ptr)))__gu_val; \
126 extern int __put_user_1(void *, unsigned int);
127 extern int __put_user_2(void *, unsigned int);
128 extern int __put_user_4(void *, unsigned int);
129 extern int __put_user_8(void *, unsigned long long);
130 extern int __put_user_bad(void);
132 #define __put_user_x(__r1,__p,__e,__s) \
133 __asm__ __volatile__ ( \
134 __asmeq("%0", "r0") __asmeq("%2", "r1") \
135 "bl __put_user_" #__s \
137 : "0" (__p), "r" (__r1) \
140 #define put_user(x,p) \
142 register const typeof(*(p)) __r1 asm("r1") = (x); \
143 register const typeof(*(p)) *__p asm("r0") = (p); \
144 register int __e asm("r0"); \
145 switch (sizeof(*(__p))) { \
147 __put_user_x(__r1, __p, __e, 1); \
150 __put_user_x(__r1, __p, __e, 2); \
153 __put_user_x(__r1, __p, __e, 4); \
156 __put_user_x(__r1, __p, __e, 8); \
158 default: __e = __put_user_bad(); break; \
164 /********************* OLD METHOD *******************/
165 #define __put_user_x(__r1,__p,__e,__s,__i...) \
166 __asm__ __volatile__ ("bl __put_user_" #__s \
168 : "0" (__p), "r" (__r1) \
171 #define put_user(x,p) \
173 register const typeof(*(p)) __r1 asm("r1") = (x); \
174 register const typeof(*(p)) *__p asm("r0") = (p); \
175 register int __e asm("r0"); \
176 switch (sizeof(*(p))) { \
178 __put_user_x(__r1, __p, __e, 1, "r2", "lr"); \
181 __put_user_x(__r1, __p, __e, 2, "r2", "lr"); \
184 __put_user_x(__r1, __p, __e, 4, "r2", "lr"); \
187 __put_user_x(__r1, __p, __e, 8, "r2", "ip", "lr"); \
189 default: __e = __put_user_bad(); break; \
193 /*************************************************/
196 #define __put_user(x,ptr) \
199 __put_user_err((x),(ptr),__pu_err); \
203 #define __put_user_error(x,ptr,err) \
205 __put_user_err((x),(ptr),err); \
209 #define __put_user_err(x,ptr,err) \
211 unsigned long __pu_addr = (unsigned long)(ptr); \
212 __typeof__(*(ptr)) __pu_val = (x); \
213 switch (sizeof(*(ptr))) { \
214 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
215 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
216 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
217 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
218 default: __put_user_bad(); \
222 static __inline__
unsigned long copy_from_user(void *to
, const void *from
, unsigned long n
)
224 if (access_ok(VERIFY_READ
, from
, n
))
225 __do_copy_from_user(to
, from
, n
);
226 else /* security hole - plug it */
231 static __inline__
unsigned long __copy_from_user(void *to
, const void *from
, unsigned long n
)
233 __do_copy_from_user(to
, from
, n
);
237 static __inline__
unsigned long copy_to_user(void *to
, const void *from
, unsigned long n
)
239 if (access_ok(VERIFY_WRITE
, to
, n
))
240 __do_copy_to_user(to
, from
, n
);
244 static __inline__
unsigned long __copy_to_user(void *to
, const void *from
, unsigned long n
)
246 __do_copy_to_user(to
, from
, n
);
250 #define __copy_to_user_inatomic __copy_to_user
251 #define __copy_from_user_inatomic __copy_from_user
253 static __inline__
unsigned long clear_user (void *to
, unsigned long n
)
255 if (access_ok(VERIFY_WRITE
, to
, n
))
256 __do_clear_user(to
, n
);
260 static __inline__
unsigned long __clear_user (void *to
, unsigned long n
)
262 __do_clear_user(to
, n
);
266 static __inline__
long strncpy_from_user (char *dst
, const char *src
, long count
)
269 if (access_ok(VERIFY_READ
, src
, 1))
270 __do_strncpy_from_user(dst
, src
, count
, res
);
274 static __inline__
long __strncpy_from_user (char *dst
, const char *src
, long count
)
277 __do_strncpy_from_user(dst
, src
, count
, res
);
281 #define strlen_user(s) strnlen_user(s, ~0UL >> 1)
283 static inline long strnlen_user(const char *s
, long n
)
285 unsigned long res
= 0;
288 __do_strnlen_user(s
, n
, res
);
293 #endif /* _ASMARM_UACCESS_H */