aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-arm26/uaccess.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-arm26/uaccess.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-arm26/uaccess.h')
-rw-r--r--include/asm-arm26/uaccess.h299
1 files changed, 299 insertions, 0 deletions
diff --git a/include/asm-arm26/uaccess.h b/include/asm-arm26/uaccess.h
new file mode 100644
index 000000000000..ab9ce38c6aec
--- /dev/null
+++ b/include/asm-arm26/uaccess.h
@@ -0,0 +1,299 @@
1#ifndef _ASMARM_UACCESS_H
2#define _ASMARM_UACCESS_H
3
4/*
5 * User space memory access functions
6 */
7#include <linux/sched.h>
8#include <asm/errno.h>
9
10#define VERIFY_READ 0
11#define VERIFY_WRITE 1
12
13/*
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.
19 *
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.
24 */
25
26struct exception_table_entry
27{
28 unsigned long insn, fixup;
29};
30
31/* Returns 0 if exception not found and fixup otherwise. */
32extern unsigned long search_exception_table(unsigned long);
33extern int fixup_exception(struct pt_regs *regs);
34
35#define get_ds() (KERNEL_DS)
36#define get_fs() (current_thread_info()->addr_limit)
37#define segment_eq(a,b) ((a) == (b))
38
39#include <asm/uaccess-asm.h>
40
41#define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
42
43/* this function will go away soon - use access_ok() instead */
44static inline int __deprecated verify_area(int type, const void * addr, unsigned long size)
45{
46 return access_ok(type, addr, size) ? 0 : -EFAULT;
47}
48
49/*
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
58 * problem.
59 *
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
62 * "access_ok()" call.
63 *
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).
67 */
68
69extern int __get_user_1(void *);
70extern int __get_user_2(void *);
71extern int __get_user_4(void *);
72extern int __get_user_8(void *);
73extern int __get_user_bad(void);
74
75#define __get_user_x(__r1,__p,__e,__s,__i...) \
76 __asm__ __volatile__ ("bl __get_user_" #__s \
77 : "=&r" (__e), "=r" (__r1) \
78 : "0" (__p) \
79 : __i)
80
81#define get_user(x,p) \
82 ({ \
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))) { \
87 case 1: \
88 __get_user_x(__r1, __p, __e, 1, "lr"); \
89 break; \
90 case 2: \
91 __get_user_x(__r1, __p, __e, 2, "r2", "lr"); \
92 break; \
93 case 4: \
94 __get_user_x(__r1, __p, __e, 4, "lr"); \
95 break; \
96 case 8: \
97 __get_user_x(__r1, __p, __e, 8, "lr"); \
98 break; \
99 default: __e = __get_user_bad(); break; \
100 } \
101 x = __r1; \
102 __e; \
103 })
104
105
106#define __get_user(x,ptr) \
107({ \
108 long __gu_err = 0; \
109 __get_user_err((x),(ptr),__gu_err); \
110 __gu_err; \
111})
112
113#define __get_user_error(x,ptr,err) \
114({ \
115 __get_user_err((x),(ptr),err); \
116 (void) 0; \
117})
118
119#define __get_user_err(x,ptr,err) \
120do { \
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(); \
128 } \
129 (x) = (__typeof__(*(ptr)))__gu_val; \
130} while (0)
131
132extern int __put_user_1(void *, unsigned int);
133extern int __put_user_2(void *, unsigned int);
134extern int __put_user_4(void *, unsigned int);
135extern int __put_user_8(void *, unsigned long long);
136extern int __put_user_bad(void);
137
138#define __put_user_x(__r1,__p,__e,__s) \
139 __asm__ __volatile__ ( \
140 __asmeq("%0", "r0") __asmeq("%2", "r1") \
141 "bl __put_user_" #__s \
142 : "=&r" (__e) \
143 : "0" (__p), "r" (__r1) \
144 : "ip", "lr", "cc")
145
146#define put_user(x,p) \
147 ({ \
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))) { \
152 case 1: \
153 __put_user_x(__r1, __p, __e, 1); \
154 break; \
155 case 2: \
156 __put_user_x(__r1, __p, __e, 2); \
157 break; \
158 case 4: \
159 __put_user_x(__r1, __p, __e, 4); \
160 break; \
161 case 8: \
162 __put_user_x(__r1, __p, __e, 8); \
163 break; \
164 default: __e = __put_user_bad(); break; \
165 } \
166 __e; \
167 })
168
169#if 0
170/********************* OLD METHOD *******************/
171#define __put_user_x(__r1,__p,__e,__s,__i...) \
172 __asm__ __volatile__ ("bl __put_user_" #__s \
173 : "=&r" (__e) \
174 : "0" (__p), "r" (__r1) \
175 : __i)
176
177#define put_user(x,p) \
178 ({ \
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))) { \
183 case 1: \
184 __put_user_x(__r1, __p, __e, 1, "r2", "lr"); \
185 break; \
186 case 2: \
187 __put_user_x(__r1, __p, __e, 2, "r2", "lr"); \
188 break; \
189 case 4: \
190 __put_user_x(__r1, __p, __e, 4, "r2", "lr"); \
191 break; \
192 case 8: \
193 __put_user_x(__r1, __p, __e, 8, "r2", "ip", "lr"); \
194 break; \
195 default: __e = __put_user_bad(); break; \
196 } \
197 __e; \
198 })
199/*************************************************/
200#endif
201
202#define __put_user(x,ptr) \
203({ \
204 long __pu_err = 0; \
205 __put_user_err((x),(ptr),__pu_err); \
206 __pu_err; \
207})
208
209#define __put_user_error(x,ptr,err) \
210({ \
211 __put_user_err((x),(ptr),err); \
212 (void) 0; \
213})
214
215#define __put_user_err(x,ptr,err) \
216do { \
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(); \
225 } \
226} while (0)
227
228static __inline__ unsigned long copy_from_user(void *to, const void *from, unsigned long n)
229{
230 if (access_ok(VERIFY_READ, from, n))
231 __do_copy_from_user(to, from, n);
232 else /* security hole - plug it */
233 memzero(to, n);
234 return n;
235}
236
237static __inline__ unsigned long __copy_from_user(void *to, const void *from, unsigned long n)
238{
239 __do_copy_from_user(to, from, n);
240 return n;
241}
242
243static __inline__ unsigned long copy_to_user(void *to, const void *from, unsigned long n)
244{
245 if (access_ok(VERIFY_WRITE, to, n))
246 __do_copy_to_user(to, from, n);
247 return n;
248}
249
250static __inline__ unsigned long __copy_to_user(void *to, const void *from, unsigned long n)
251{
252 __do_copy_to_user(to, from, n);
253 return n;
254}
255
256#define __copy_to_user_inatomic __copy_to_user
257#define __copy_from_user_inatomic __copy_from_user
258
259static __inline__ unsigned long clear_user (void *to, unsigned long n)
260{
261 if (access_ok(VERIFY_WRITE, to, n))
262 __do_clear_user(to, n);
263 return n;
264}
265
266static __inline__ unsigned long __clear_user (void *to, unsigned long n)
267{
268 __do_clear_user(to, n);
269 return n;
270}
271
272static __inline__ long strncpy_from_user (char *dst, const char *src, long count)
273{
274 long res = -EFAULT;
275 if (access_ok(VERIFY_READ, src, 1))
276 __do_strncpy_from_user(dst, src, count, res);
277 return res;
278}
279
280static __inline__ long __strncpy_from_user (char *dst, const char *src, long count)
281{
282 long res;
283 __do_strncpy_from_user(dst, src, count, res);
284 return res;
285}
286
287#define strlen_user(s) strnlen_user(s, ~0UL >> 1)
288
289static inline long strnlen_user(const char *s, long n)
290{
291 unsigned long res = 0;
292
293 if (__addr_ok(s))
294 __do_strnlen_user(s, n, res);
295
296 return res;
297}
298
299#endif /* _ASMARM_UACCESS_H */