Go to the documentation of this file.
8 #ifndef _ASMARM_UACCESS_H
9 #define _ASMARM_UACCESS_H
14 #include <linux/string.h>
16 #include <asm/errno.h>
17 #include <asm/memory.h>
20 #include <asm/compiler.h>
23 #define VERIFY_WRITE 1
55 #define KERNEL_DS 0x00000000
56 #define get_ds() (KERNEL_DS)
60 #define USER_DS TASK_SIZE
61 #define get_fs() (current_thread_info()->addr_limit)
69 #define segment_eq(a,b) ((a) == (b))
71 #define __addr_ok(addr) ({ \
73 __asm__("cmp %2, %0; movlo %0, #0" \
75 : "0" (current_thread_info()->addr_limit), "r" (addr) \
80 #define __range_ok(addr,size) ({ \
81 unsigned long flag, roksum; \
82 __chk_user_ptr(addr); \
83 __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \
84 : "=&r" (flag), "=&r" (roksum) \
85 : "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \
104 #define __GUP_CLOBBER_1 "lr", "cc"
105 #ifdef CONFIG_CPU_USE_DOMAINS
106 #define __GUP_CLOBBER_2 "ip", "lr", "cc"
108 #define __GUP_CLOBBER_2 "lr", "cc"
110 #define __GUP_CLOBBER_4 "lr", "cc"
112 #define __get_user_x(__r2,__p,__e,__l,__s) \
113 __asm__ __volatile__ ( \
114 __asmeq("%0", "r0") __asmeq("%1", "r2") \
115 __asmeq("%3", "r1") \
116 "bl __get_user_" #__s \
117 : "=&r" (__e), "=r" (__r2) \
118 : "0" (__p), "r" (__l) \
119 : __GUP_CLOBBER_##__s)
121 #define __get_user_check(x,p) \
123 unsigned long __limit = current_thread_info()->addr_limit - 1; \
124 register const typeof(*(p)) __user *__p asm("r0") = (p);\
125 register unsigned long __r2 asm("r2"); \
126 register unsigned long __l asm("r1") = __limit; \
127 register int __e asm("r0"); \
128 switch (sizeof(*(__p))) { \
130 __get_user_x(__r2, __p, __e, __l, 1); \
133 __get_user_x(__r2, __p, __e, __l, 2); \
136 __get_user_x(__r2, __p, __e, __l, 4); \
138 default: __e = __get_user_bad(); break; \
140 x = (typeof(*(p))) __r2; \
144 #define get_user(x,p) \
147 __get_user_check(x,p); \
155 #define __put_user_x(__r2,__p,__e,__l,__s) \
156 __asm__ __volatile__ ( \
157 __asmeq("%0", "r0") __asmeq("%2", "r2") \
158 __asmeq("%3", "r1") \
159 "bl __put_user_" #__s \
161 : "0" (__p), "r" (__r2), "r" (__l) \
164 #define __put_user_check(x,p) \
166 unsigned long __limit = current_thread_info()->addr_limit - 1; \
167 register const typeof(*(p)) __r2 asm("r2") = (x); \
168 register const typeof(*(p)) __user *__p asm("r0") = (p);\
169 register unsigned long __l asm("r1") = __limit; \
170 register int __e asm("r0"); \
171 switch (sizeof(*(__p))) { \
173 __put_user_x(__r2, __p, __e, __l, 1); \
176 __put_user_x(__r2, __p, __e, __l, 2); \
179 __put_user_x(__r2, __p, __e, __l, 4); \
182 __put_user_x(__r2, __p, __e, __l, 8); \
184 default: __e = __put_user_bad(); break; \
189 #define put_user(x,p) \
192 __put_user_check(x,p); \
200 #define USER_DS KERNEL_DS
202 #define segment_eq(a,b) (1)
203 #define __addr_ok(addr) ((void)(addr),1)
204 #define __range_ok(addr,size) ((void)(addr),0)
205 #define get_fs() (KERNEL_DS)
211 #define get_user(x,p) __get_user(x,p)
212 #define put_user(x,p) __put_user(x,p)
216 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
218 #define user_addr_max() \
219 (segment_eq(get_fs(), USER_DS) ? TASK_SIZE : ~0UL)
230 #define __get_user(x,ptr) \
233 __get_user_err((x),(ptr),__gu_err); \
237 #define __get_user_error(x,ptr,err) \
239 __get_user_err((x),(ptr),err); \
243 #define __get_user_err(x,ptr,err) \
245 unsigned long __gu_addr = (unsigned long)(ptr); \
246 unsigned long __gu_val; \
247 __chk_user_ptr(ptr); \
249 switch (sizeof(*(ptr))) { \
250 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
251 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
252 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
253 default: (__gu_val) = __get_user_bad(); \
255 (x) = (__typeof__(*(ptr)))__gu_val; \
258 #define __get_user_asm_byte(x,addr,err) \
259 __asm__ __volatile__( \
260 "1: " TUSER(ldrb) " %1,[%2],#0\n" \
262 " .pushsection .fixup,\"ax\"\n" \
268 " .pushsection __ex_table,\"a\"\n" \
272 : "+r" (err), "=&r" (x) \
273 : "r" (addr), "i" (-EFAULT) \
277 #define __get_user_asm_half(x,__gu_addr,err) \
279 unsigned long __b1, __b2; \
280 __get_user_asm_byte(__b1, __gu_addr, err); \
281 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
282 (x) = __b1 | (__b2 << 8); \
285 #define __get_user_asm_half(x,__gu_addr,err) \
287 unsigned long __b1, __b2; \
288 __get_user_asm_byte(__b1, __gu_addr, err); \
289 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
290 (x) = (__b1 << 8) | __b2; \
294 #define __get_user_asm_word(x,addr,err) \
295 __asm__ __volatile__( \
296 "1: " TUSER(ldr) " %1,[%2],#0\n" \
298 " .pushsection .fixup,\"ax\"\n" \
304 " .pushsection __ex_table,\"a\"\n" \
308 : "+r" (err), "=&r" (x) \
309 : "r" (addr), "i" (-EFAULT) \
312 #define __put_user(x,ptr) \
315 __put_user_err((x),(ptr),__pu_err); \
319 #define __put_user_error(x,ptr,err) \
321 __put_user_err((x),(ptr),err); \
325 #define __put_user_err(x,ptr,err) \
327 unsigned long __pu_addr = (unsigned long)(ptr); \
328 __typeof__(*(ptr)) __pu_val = (x); \
329 __chk_user_ptr(ptr); \
331 switch (sizeof(*(ptr))) { \
332 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
333 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
334 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
335 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
336 default: __put_user_bad(); \
340 #define __put_user_asm_byte(x,__pu_addr,err) \
341 __asm__ __volatile__( \
342 "1: " TUSER(strb) " %1,[%2],#0\n" \
344 " .pushsection .fixup,\"ax\"\n" \
349 " .pushsection __ex_table,\"a\"\n" \
354 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
358 #define __put_user_asm_half(x,__pu_addr,err) \
360 unsigned long __temp = (unsigned long)(x); \
361 __put_user_asm_byte(__temp, __pu_addr, err); \
362 __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \
365 #define __put_user_asm_half(x,__pu_addr,err) \
367 unsigned long __temp = (unsigned long)(x); \
368 __put_user_asm_byte(__temp >> 8, __pu_addr, err); \
369 __put_user_asm_byte(__temp, __pu_addr + 1, err); \
373 #define __put_user_asm_word(x,__pu_addr,err) \
374 __asm__ __volatile__( \
375 "1: " TUSER(str) " %1,[%2],#0\n" \
377 " .pushsection .fixup,\"ax\"\n" \
382 " .pushsection __ex_table,\"a\"\n" \
387 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
391 #define __reg_oper0 "%R2"
392 #define __reg_oper1 "%Q2"
394 #define __reg_oper0 "%Q2"
395 #define __reg_oper1 "%R2"
398 #define __put_user_asm_dword(x,__pu_addr,err) \
399 __asm__ __volatile__( \
400 ARM( "1: " TUSER(str) " " __reg_oper1 ", [%1], #4\n" ) \
401 ARM( "2: " TUSER(str) " " __reg_oper0 ", [%1]\n" ) \
402 THUMB( "1: " TUSER(str) " " __reg_oper1 ", [%1]\n" ) \
403 THUMB( "2: " TUSER(str) " " __reg_oper0 ", [%1, #4]\n" ) \
405 " .pushsection .fixup,\"ax\"\n" \
410 " .pushsection __ex_table,\"a\"\n" \
415 : "+r" (err), "+r" (__pu_addr) \
416 : "r" (x), "i" (-EFAULT) \
423 extern unsigned long __must_check __copy_to_user_std(
void __user *to,
const void *
from,
unsigned long n);
425 extern unsigned long __must_check __clear_user_std(
void __user *
addr,
unsigned long n);
427 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
428 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
429 #define __clear_user(addr,n) (memset((void __force *)addr, 0, n), 0)
448 #define __copy_to_user_inatomic __copy_to_user
449 #define __copy_from_user_inatomic __copy_from_user