blob: a4cd7af475e90de4bb57398cfd569e06f15a1135 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Russell King4baa9922008-08-02 10:55:55 +01002 * arch/arm/include/asm/uaccess.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef _ASMARM_UACCESS_H
9#define _ASMARM_UACCESS_H
10
11/*
12 * User space memory access functions
13 */
Russell King87c52572008-11-29 17:35:51 +000014#include <linux/string.h>
15#include <linux/thread_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/errno.h>
17#include <asm/memory.h>
18#include <asm/domain.h>
Catalin Marinas8b592782009-07-24 12:32:57 +010019#include <asm/unified.h>
David Howells9f97da72012-03-28 18:30:01 +010020#include <asm/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Nicolas Pitreafdd3bb2014-02-04 13:23:48 +010022#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Nicolas Pitrec89efa72013-09-17 19:16:38 +010023#include <asm-generic/uaccess-unaligned.h>
24#else
25#define __get_user_unaligned __get_user
26#define __put_user_unaligned __put_user
27#endif
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#define VERIFY_READ 0
30#define VERIFY_WRITE 1
31
32/*
33 * The exception table consists of pairs of addresses: the first is the
34 * address of an instruction that is allowed to fault, and the second is
35 * the address at which the program should continue. No registers are
36 * modified, so it is entirely up to the continuation code to figure out
37 * what to do.
38 *
39 * All the routines below use bits of fixup code that are out of line
40 * with the main instruction path. This means when everything is well,
41 * we don't even have to jump over them. Further, they do not intrude
42 * on our cache or tlb entries.
43 */
44
45struct exception_table_entry
46{
47 unsigned long insn, fixup;
48};
49
50extern int fixup_exception(struct pt_regs *regs);
51
52/*
Russell King9641c7c2006-06-21 20:38:17 +010053 * These two are intentionally not defined anywhere - if the kernel
54 * code generates any references to them, that's a bug.
55 */
56extern int __get_user_bad(void);
57extern int __put_user_bad(void);
58
59/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 * Note that this is actually 0x1,0000,0000
61 */
62#define KERNEL_DS 0x00000000
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define get_ds() (KERNEL_DS)
Russell King9641c7c2006-06-21 20:38:17 +010064
65#ifdef CONFIG_MMU
66
67#define USER_DS TASK_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define get_fs() (current_thread_info()->addr_limit)
69
Russell King9641c7c2006-06-21 20:38:17 +010070static inline void set_fs(mm_segment_t fs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 current_thread_info()->addr_limit = fs;
73 modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
74}
75
76#define segment_eq(a,b) ((a) == (b))
77
78#define __addr_ok(addr) ({ \
79 unsigned long flag; \
80 __asm__("cmp %2, %0; movlo %0, #0" \
81 : "=&r" (flag) \
82 : "0" (current_thread_info()->addr_limit), "r" (addr) \
83 : "cc"); \
84 (flag == 0); })
85
86/* We use 33-bit arithmetic here... */
87#define __range_ok(addr,size) ({ \
Tilman Schmidt16cf5b32007-02-10 01:45:41 -080088 unsigned long flag, roksum; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 __chk_user_ptr(addr); \
90 __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \
Tilman Schmidt16cf5b32007-02-10 01:45:41 -080091 : "=&r" (flag), "=&r" (roksum) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 : "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \
93 : "cc"); \
94 flag; })
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*
97 * Single-value transfer routines. They automatically use the right
98 * size if we just have the right pointer type. Note that the functions
99 * which read from user space (*get_*) need to take care not to leak
100 * kernel data even if the calling code is buggy and fails to check
101 * the return value. This means zeroing out the destination variable
102 * or buffer on error. Normally this is done out of line by the
103 * fixup code, but there are a few places where it intrudes on the
104 * main code path. When we only write to user space, there is no
105 * problem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int __get_user_1(void *);
108extern int __get_user_2(void *);
109extern int __get_user_4(void *);
Daniel Thompsone38361d2014-07-10 20:58:08 +0100110extern int __get_user_lo8(void *);
111extern int __get_user_8(void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Russell King84046632012-09-07 18:22:28 +0100113#define __GUP_CLOBBER_1 "lr", "cc"
114#ifdef CONFIG_CPU_USE_DOMAINS
115#define __GUP_CLOBBER_2 "ip", "lr", "cc"
116#else
117#define __GUP_CLOBBER_2 "lr", "cc"
118#endif
119#define __GUP_CLOBBER_4 "lr", "cc"
Daniel Thompsone38361d2014-07-10 20:58:08 +0100120#define __GUP_CLOBBER_lo8 "lr", "cc"
121#define __GUP_CLOBBER_8 "lr", "cc"
Russell King84046632012-09-07 18:22:28 +0100122
123#define __get_user_x(__r2,__p,__e,__l,__s) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 __asm__ __volatile__ ( \
125 __asmeq("%0", "r0") __asmeq("%1", "r2") \
Russell King84046632012-09-07 18:22:28 +0100126 __asmeq("%3", "r1") \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 "bl __get_user_" #__s \
128 : "=&r" (__e), "=r" (__r2) \
Russell King84046632012-09-07 18:22:28 +0100129 : "0" (__p), "r" (__l) \
130 : __GUP_CLOBBER_##__s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Daniel Thompsone38361d2014-07-10 20:58:08 +0100132/* narrowing a double-word get into a single 32bit word register: */
133#ifdef __ARMEB__
134#define __get_user_xb(__r2, __p, __e, __l, __s) \
135 __get_user_x(__r2, __p, __e, __l, lo8)
136#else
137#define __get_user_xb __get_user_x
138#endif
139
Will Deaconad729072012-09-07 18:24:10 +0100140#define __get_user_check(x,p) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 ({ \
Russell King84046632012-09-07 18:22:28 +0100142 unsigned long __limit = current_thread_info()->addr_limit - 1; \
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100143 register const typeof(*(p)) __user *__p asm("r0") = (p);\
Daniel Thompsone38361d2014-07-10 20:58:08 +0100144 register typeof(x) __r2 asm("r2"); \
Russell King84046632012-09-07 18:22:28 +0100145 register unsigned long __l asm("r1") = __limit; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 register int __e asm("r0"); \
147 switch (sizeof(*(__p))) { \
148 case 1: \
Russell King84046632012-09-07 18:22:28 +0100149 __get_user_x(__r2, __p, __e, __l, 1); \
150 break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 case 2: \
Russell King84046632012-09-07 18:22:28 +0100152 __get_user_x(__r2, __p, __e, __l, 2); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 break; \
154 case 4: \
Russell King84046632012-09-07 18:22:28 +0100155 __get_user_x(__r2, __p, __e, __l, 4); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 break; \
Daniel Thompsone38361d2014-07-10 20:58:08 +0100157 case 8: \
158 if (sizeof((x)) < 8) \
159 __get_user_xb(__r2, __p, __e, __l, 4); \
160 else \
161 __get_user_x(__r2, __p, __e, __l, 8); \
162 break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 default: __e = __get_user_bad(); break; \
164 } \
Russell Kingd2c5b692005-11-18 14:22:03 +0000165 x = (typeof(*(p))) __r2; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 __e; \
167 })
168
Will Deaconad729072012-09-07 18:24:10 +0100169#define get_user(x,p) \
170 ({ \
171 might_fault(); \
172 __get_user_check(x,p); \
173 })
174
Russell King9641c7c2006-06-21 20:38:17 +0100175extern int __put_user_1(void *, unsigned int);
176extern int __put_user_2(void *, unsigned int);
177extern int __put_user_4(void *, unsigned int);
178extern int __put_user_8(void *, unsigned long long);
179
Russell King84046632012-09-07 18:22:28 +0100180#define __put_user_x(__r2,__p,__e,__l,__s) \
Russell King9641c7c2006-06-21 20:38:17 +0100181 __asm__ __volatile__ ( \
182 __asmeq("%0", "r0") __asmeq("%2", "r2") \
Russell King84046632012-09-07 18:22:28 +0100183 __asmeq("%3", "r1") \
Russell King9641c7c2006-06-21 20:38:17 +0100184 "bl __put_user_" #__s \
185 : "=&r" (__e) \
Russell King84046632012-09-07 18:22:28 +0100186 : "0" (__p), "r" (__r2), "r" (__l) \
Russell King9641c7c2006-06-21 20:38:17 +0100187 : "ip", "lr", "cc")
188
Will Deaconad729072012-09-07 18:24:10 +0100189#define __put_user_check(x,p) \
Russell King9641c7c2006-06-21 20:38:17 +0100190 ({ \
Russell King84046632012-09-07 18:22:28 +0100191 unsigned long __limit = current_thread_info()->addr_limit - 1; \
Andrey Ryabinin537094b2014-05-07 08:07:25 +0100192 const typeof(*(p)) __user *__tmp_p = (p); \
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100193 register const typeof(*(p)) __r2 asm("r2") = (x); \
Andrey Ryabinin537094b2014-05-07 08:07:25 +0100194 register const typeof(*(p)) __user *__p asm("r0") = __tmp_p; \
Russell King84046632012-09-07 18:22:28 +0100195 register unsigned long __l asm("r1") = __limit; \
Russell King9641c7c2006-06-21 20:38:17 +0100196 register int __e asm("r0"); \
197 switch (sizeof(*(__p))) { \
198 case 1: \
Russell King84046632012-09-07 18:22:28 +0100199 __put_user_x(__r2, __p, __e, __l, 1); \
Russell King9641c7c2006-06-21 20:38:17 +0100200 break; \
201 case 2: \
Russell King84046632012-09-07 18:22:28 +0100202 __put_user_x(__r2, __p, __e, __l, 2); \
Russell King9641c7c2006-06-21 20:38:17 +0100203 break; \
204 case 4: \
Russell King84046632012-09-07 18:22:28 +0100205 __put_user_x(__r2, __p, __e, __l, 4); \
Russell King9641c7c2006-06-21 20:38:17 +0100206 break; \
207 case 8: \
Russell King84046632012-09-07 18:22:28 +0100208 __put_user_x(__r2, __p, __e, __l, 8); \
Russell King9641c7c2006-06-21 20:38:17 +0100209 break; \
210 default: __e = __put_user_bad(); break; \
211 } \
212 __e; \
213 })
214
Will Deaconad729072012-09-07 18:24:10 +0100215#define put_user(x,p) \
216 ({ \
217 might_fault(); \
218 __put_user_check(x,p); \
219 })
220
Russell King9641c7c2006-06-21 20:38:17 +0100221#else /* CONFIG_MMU */
222
223/*
224 * uClinux has only one addr space, so has simplified address limits.
225 */
226#define USER_DS KERNEL_DS
227
228#define segment_eq(a,b) (1)
Arnd Bergmann8e7fc182012-04-30 13:18:46 +0000229#define __addr_ok(addr) ((void)(addr),1)
230#define __range_ok(addr,size) ((void)(addr),0)
Russell King9641c7c2006-06-21 20:38:17 +0100231#define get_fs() (KERNEL_DS)
232
233static inline void set_fs(mm_segment_t fs)
234{
235}
236
237#define get_user(x,p) __get_user(x,p)
238#define put_user(x,p) __put_user(x,p)
239
240#endif /* CONFIG_MMU */
241
242#define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
243
Will Deacon8c56cc82012-07-06 15:45:39 +0100244#define user_addr_max() \
Uwe Kleine-König83de9112014-06-05 10:23:10 +0200245 (segment_eq(get_fs(), KERNEL_DS) ? ~0UL : get_fs())
Will Deacon8c56cc82012-07-06 15:45:39 +0100246
Russell King9641c7c2006-06-21 20:38:17 +0100247/*
248 * The "__xxx" versions of the user access functions do not verify the
249 * address space - it must have been done previously with a separate
250 * "access_ok()" call.
251 *
252 * The "xxx_error" versions set the third argument to EFAULT if an
253 * error occurs, and leave it unchanged on success. Note that these
254 * versions are void (ie, don't return a value as such).
255 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define __get_user(x,ptr) \
257({ \
258 long __gu_err = 0; \
259 __get_user_err((x),(ptr),__gu_err); \
260 __gu_err; \
261})
262
263#define __get_user_error(x,ptr,err) \
264({ \
265 __get_user_err((x),(ptr),err); \
266 (void) 0; \
267})
268
269#define __get_user_err(x,ptr,err) \
270do { \
271 unsigned long __gu_addr = (unsigned long)(ptr); \
272 unsigned long __gu_val; \
273 __chk_user_ptr(ptr); \
Will Deaconad729072012-09-07 18:24:10 +0100274 might_fault(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 switch (sizeof(*(ptr))) { \
276 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
277 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
278 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
279 default: (__gu_val) = __get_user_bad(); \
280 } \
281 (x) = (__typeof__(*(ptr)))__gu_val; \
282} while (0)
283
284#define __get_user_asm_byte(x,addr,err) \
285 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100286 "1: " TUSER(ldrb) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100288 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 " .align 2\n" \
290 "3: mov %0, %3\n" \
291 " mov %1, #0\n" \
292 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100293 " .popsection\n" \
294 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 " .align 3\n" \
296 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100297 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 : "+r" (err), "=&r" (x) \
299 : "r" (addr), "i" (-EFAULT) \
300 : "cc")
301
302#ifndef __ARMEB__
303#define __get_user_asm_half(x,__gu_addr,err) \
304({ \
305 unsigned long __b1, __b2; \
306 __get_user_asm_byte(__b1, __gu_addr, err); \
307 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
308 (x) = __b1 | (__b2 << 8); \
309})
310#else
311#define __get_user_asm_half(x,__gu_addr,err) \
312({ \
313 unsigned long __b1, __b2; \
314 __get_user_asm_byte(__b1, __gu_addr, err); \
315 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
316 (x) = (__b1 << 8) | __b2; \
317})
318#endif
319
320#define __get_user_asm_word(x,addr,err) \
321 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100322 "1: " TUSER(ldr) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100324 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 " .align 2\n" \
326 "3: mov %0, %3\n" \
327 " mov %1, #0\n" \
328 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100329 " .popsection\n" \
330 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 " .align 3\n" \
332 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100333 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 : "+r" (err), "=&r" (x) \
335 : "r" (addr), "i" (-EFAULT) \
336 : "cc")
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#define __put_user(x,ptr) \
339({ \
340 long __pu_err = 0; \
341 __put_user_err((x),(ptr),__pu_err); \
342 __pu_err; \
343})
344
345#define __put_user_error(x,ptr,err) \
346({ \
347 __put_user_err((x),(ptr),err); \
348 (void) 0; \
349})
350
351#define __put_user_err(x,ptr,err) \
352do { \
353 unsigned long __pu_addr = (unsigned long)(ptr); \
354 __typeof__(*(ptr)) __pu_val = (x); \
355 __chk_user_ptr(ptr); \
Will Deaconad729072012-09-07 18:24:10 +0100356 might_fault(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 switch (sizeof(*(ptr))) { \
358 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
359 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
360 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
361 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
362 default: __put_user_bad(); \
363 } \
364} while (0)
365
366#define __put_user_asm_byte(x,__pu_addr,err) \
367 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100368 "1: " TUSER(strb) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100370 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 " .align 2\n" \
372 "3: mov %0, %3\n" \
373 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100374 " .popsection\n" \
375 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 " .align 3\n" \
377 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100378 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 : "+r" (err) \
380 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
381 : "cc")
382
383#ifndef __ARMEB__
384#define __put_user_asm_half(x,__pu_addr,err) \
385({ \
386 unsigned long __temp = (unsigned long)(x); \
387 __put_user_asm_byte(__temp, __pu_addr, err); \
388 __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \
389})
390#else
391#define __put_user_asm_half(x,__pu_addr,err) \
392({ \
393 unsigned long __temp = (unsigned long)(x); \
394 __put_user_asm_byte(__temp >> 8, __pu_addr, err); \
395 __put_user_asm_byte(__temp, __pu_addr + 1, err); \
396})
397#endif
398
399#define __put_user_asm_word(x,__pu_addr,err) \
400 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100401 "1: " TUSER(str) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100403 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 " .align 2\n" \
405 "3: mov %0, %3\n" \
406 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100407 " .popsection\n" \
408 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 " .align 3\n" \
410 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100411 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 : "+r" (err) \
413 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
414 : "cc")
415
416#ifndef __ARMEB__
417#define __reg_oper0 "%R2"
418#define __reg_oper1 "%Q2"
419#else
420#define __reg_oper0 "%Q2"
421#define __reg_oper1 "%R2"
422#endif
423
424#define __put_user_asm_dword(x,__pu_addr,err) \
425 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100426 ARM( "1: " TUSER(str) " " __reg_oper1 ", [%1], #4\n" ) \
427 ARM( "2: " TUSER(str) " " __reg_oper0 ", [%1]\n" ) \
428 THUMB( "1: " TUSER(str) " " __reg_oper1 ", [%1]\n" ) \
429 THUMB( "2: " TUSER(str) " " __reg_oper0 ", [%1, #4]\n" ) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 "3:\n" \
Russell King42604152010-04-19 10:15:03 +0100431 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 " .align 2\n" \
433 "4: mov %0, %3\n" \
434 " b 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100435 " .popsection\n" \
436 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 " .align 3\n" \
438 " .long 1b, 4b\n" \
439 " .long 2b, 4b\n" \
Russell King42604152010-04-19 10:15:03 +0100440 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 : "+r" (err), "+r" (__pu_addr) \
442 : "r" (x), "i" (-EFAULT) \
443 : "cc")
444
Russell King02fcb972006-06-21 14:44:52 +0100445
Russell King9641c7c2006-06-21 20:38:17 +0100446#ifdef CONFIG_MMU
Russell King99573292006-10-26 10:27:42 +0100447extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
448extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
Nicolas Pitrea1f98842009-03-08 22:34:45 -0400449extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
Russell King99573292006-10-26 10:27:42 +0100450extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
Nicolas Pitrea1f98842009-03-08 22:34:45 -0400451extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
Russell King9641c7c2006-06-21 20:38:17 +0100452#else
453#define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
454#define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
455#define __clear_user(addr,n) (memset((void __force *)addr, 0, n), 0)
456#endif
457
Russell King99573292006-10-26 10:27:42 +0100458static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
460 if (access_ok(VERIFY_READ, from, n))
Russell King02fcb972006-06-21 14:44:52 +0100461 n = __copy_from_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 else /* security hole - plug it */
Russell King59f0cb02008-10-27 11:24:09 +0000463 memset(to, 0, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 return n;
465}
466
Russell King99573292006-10-26 10:27:42 +0100467static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
469 if (access_ok(VERIFY_WRITE, to, n))
Russell King02fcb972006-06-21 14:44:52 +0100470 n = __copy_to_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return n;
472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define __copy_to_user_inatomic __copy_to_user
475#define __copy_from_user_inatomic __copy_from_user
476
Russell King99573292006-10-26 10:27:42 +0100477static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
479 if (access_ok(VERIFY_WRITE, to, n))
Russell King02fcb972006-06-21 14:44:52 +0100480 n = __clear_user(to, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return n;
482}
483
Will Deacon8c56cc82012-07-06 15:45:39 +0100484extern long strncpy_from_user(char *dest, const char __user *src, long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Will Deacon8c56cc82012-07-06 15:45:39 +0100486extern __must_check long strlen_user(const char __user *str);
487extern __must_check long strnlen_user(const char __user *str, long n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489#endif /* _ASMARM_UACCESS_H */