initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / asm-arm26 / uaccess.h
blob3818aa939831d60ffe8823ae96f7e10caa134c29
1 #ifndef _ASMARM_UACCESS_H
2 #define _ASMARM_UACCESS_H
4 /*
5 * User space memory access functions
6 */
7 #include <linux/sched.h>
8 #include <asm/errno.h>
10 #define VERIFY_READ 0
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
18 * what to do.
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 static inline int verify_area(int type, const void * addr, unsigned long size)
45 return access_ok(type, addr, size) ? 0 : -EFAULT;
49 * Single-value transfer routines. They automatically use the right
50 * size if we just have the right pointer type. Note that the functions
51 * which read from user space (*get_*) need to take care not to leak
52 * kernel data even if the calling code is buggy and fails to check
53 * the return value. This means zeroing out the destination variable
54 * or buffer on error. Normally this is done out of line by the
55 * fixup code, but there are a few places where it intrudes on the
56 * main code path. When we only write to user space, there is no
57 * problem.
59 * The "__xxx" versions of the user access functions do not verify the
60 * address space - it must have been done previously with a separate
61 * "access_ok()" call.
63 * The "xxx_error" versions set the third argument to EFAULT if an
64 * error occurs, and leave it unchanged on success. Note that these
65 * versions are void (ie, don't return a value as such).
68 extern int __get_user_1(void *);
69 extern int __get_user_2(void *);
70 extern int __get_user_4(void *);
71 extern int __get_user_8(void *);
72 extern int __get_user_bad(void);
74 #define __get_user_x(__r1,__p,__e,__s,__i...) \
75 __asm__ __volatile__ ("bl __get_user_" #__s \
76 : "=&r" (__e), "=r" (__r1) \
77 : "0" (__p) \
78 : __i)
80 #define get_user(x,p) \
81 ({ \
82 const register typeof(*(p)) *__p asm("r0") = (p); \
83 register typeof(*(p)) __r1 asm("r1"); \
84 register int __e asm("r0"); \
85 switch (sizeof(*(p))) { \
86 case 1: \
87 __get_user_x(__r1, __p, __e, 1, "lr"); \
88 break; \
89 case 2: \
90 __get_user_x(__r1, __p, __e, 2, "r2", "lr"); \
91 break; \
92 case 4: \
93 __get_user_x(__r1, __p, __e, 4, "lr"); \
94 break; \
95 case 8: \
96 __get_user_x(__r1, __p, __e, 8, "lr"); \
97 break; \
98 default: __e = __get_user_bad(); break; \
99 } \
100 x = __r1; \
101 __e; \
105 #define __get_user(x,ptr) \
106 ({ \
107 long __gu_err = 0; \
108 __get_user_err((x),(ptr),__gu_err); \
109 __gu_err; \
112 #define __get_user_error(x,ptr,err) \
113 ({ \
114 __get_user_err((x),(ptr),err); \
115 (void) 0; \
118 #define __get_user_err(x,ptr,err) \
119 do { \
120 unsigned long __gu_addr = (unsigned long)(ptr); \
121 unsigned long __gu_val; \
122 switch (sizeof(*(ptr))) { \
123 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
124 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
125 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
126 default: (__gu_val) = __get_user_bad(); \
128 (x) = (__typeof__(*(ptr)))__gu_val; \
129 } while (0)
131 extern int __put_user_1(void *, unsigned int);
132 extern int __put_user_2(void *, unsigned int);
133 extern int __put_user_4(void *, unsigned int);
134 extern int __put_user_8(void *, unsigned long long);
135 extern int __put_user_bad(void);
137 #define __put_user_x(__r1,__p,__e,__s,__i...) \
138 __asm__ __volatile__ ("bl __put_user_" #__s \
139 : "=&r" (__e) \
140 : "0" (__p), "r" (__r1) \
141 : __i)
143 #define put_user(x,p) \
144 ({ \
145 const register typeof(*(p)) __r1 asm("r1") = (x); \
146 const register typeof(*(p)) *__p asm("r0") = (p); \
147 register int __e asm("r0"); \
148 switch (sizeof(*(p))) { \
149 case 1: \
150 __put_user_x(__r1, __p, __e, 1, "r2", "lr"); \
151 break; \
152 case 2: \
153 __put_user_x(__r1, __p, __e, 2, "r2", "lr"); \
154 break; \
155 case 4: \
156 __put_user_x(__r1, __p, __e, 4, "r2", "lr"); \
157 break; \
158 case 8: \
159 __put_user_x(__r1, __p, __e, 8, "ip", "lr"); \
160 break; \
161 default: __e = __put_user_bad(); break; \
163 __e; \
166 #define __put_user(x,ptr) \
167 ({ \
168 long __pu_err = 0; \
169 __put_user_err((x),(ptr),__pu_err); \
170 __pu_err; \
173 #define __put_user_error(x,ptr,err) \
174 ({ \
175 __put_user_err((x),(ptr),err); \
176 (void) 0; \
179 #define __put_user_err(x,ptr,err) \
180 do { \
181 unsigned long __pu_addr = (unsigned long)(ptr); \
182 __typeof__(*(ptr)) __pu_val = (x); \
183 switch (sizeof(*(ptr))) { \
184 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
185 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
186 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
187 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
188 default: __put_user_bad(); \
190 } while (0)
192 static __inline__ unsigned long copy_from_user(void *to, const void *from, unsigned long n)
194 if (access_ok(VERIFY_READ, from, n))
195 __do_copy_from_user(to, from, n);
196 else /* security hole - plug it */
197 memzero(to, n);
198 return n;
201 static __inline__ unsigned long __copy_from_user(void *to, const void *from, unsigned long n)
203 __do_copy_from_user(to, from, n);
204 return n;
207 static __inline__ unsigned long copy_to_user(void *to, const void *from, unsigned long n)
209 if (access_ok(VERIFY_WRITE, to, n))
210 __do_copy_to_user(to, from, n);
211 return n;
214 static __inline__ unsigned long __copy_to_user(void *to, const void *from, unsigned long n)
216 __do_copy_to_user(to, from, n);
217 return n;
220 #define __copy_to_user_inatomic __copy_to_user
221 #define __copy_from_user_inatomic __copy_from_user
223 static __inline__ unsigned long clear_user (void *to, unsigned long n)
225 if (access_ok(VERIFY_WRITE, to, n))
226 __do_clear_user(to, n);
227 return n;
230 static __inline__ unsigned long __clear_user (void *to, unsigned long n)
232 __do_clear_user(to, n);
233 return n;
236 static __inline__ long strncpy_from_user (char *dst, const char *src, long count)
238 long res = -EFAULT;
239 if (access_ok(VERIFY_READ, src, 1))
240 __do_strncpy_from_user(dst, src, count, res);
241 return res;
244 static __inline__ long __strncpy_from_user (char *dst, const char *src, long count)
246 long res;
247 __do_strncpy_from_user(dst, src, count, res);
248 return res;
251 #define strlen_user(s) strnlen_user(s, ~0UL >> 1)
253 static inline long strnlen_user(const char *s, long n)
255 unsigned long res = 0;
257 if (__addr_ok(s))
258 __do_strnlen_user(s, n, res);
260 return res;
263 #endif /* _ASMARM_UACCESS_H */