blob: 75d95799b6e6df7238dd425dc66da51ddb006633 [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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Russell King84046632012-09-07 18:22:28 +0100111#define __GUP_CLOBBER_1 "lr", "cc"
112#ifdef CONFIG_CPU_USE_DOMAINS
113#define __GUP_CLOBBER_2 "ip", "lr", "cc"
114#else
115#define __GUP_CLOBBER_2 "lr", "cc"
116#endif
117#define __GUP_CLOBBER_4 "lr", "cc"
118
119#define __get_user_x(__r2,__p,__e,__l,__s) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 __asm__ __volatile__ ( \
121 __asmeq("%0", "r0") __asmeq("%1", "r2") \
Russell King84046632012-09-07 18:22:28 +0100122 __asmeq("%3", "r1") \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 "bl __get_user_" #__s \
124 : "=&r" (__e), "=r" (__r2) \
Russell King84046632012-09-07 18:22:28 +0100125 : "0" (__p), "r" (__l) \
126 : __GUP_CLOBBER_##__s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Will Deaconad729072012-09-07 18:24:10 +0100128#define __get_user_check(x,p) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 ({ \
Russell King84046632012-09-07 18:22:28 +0100130 unsigned long __limit = current_thread_info()->addr_limit - 1; \
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100131 register const typeof(*(p)) __user *__p asm("r0") = (p);\
Al Virofc048b52006-10-11 17:22:54 +0100132 register unsigned long __r2 asm("r2"); \
Russell King84046632012-09-07 18:22:28 +0100133 register unsigned long __l asm("r1") = __limit; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 register int __e asm("r0"); \
135 switch (sizeof(*(__p))) { \
136 case 1: \
Russell King84046632012-09-07 18:22:28 +0100137 __get_user_x(__r2, __p, __e, __l, 1); \
138 break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 case 2: \
Russell King84046632012-09-07 18:22:28 +0100140 __get_user_x(__r2, __p, __e, __l, 2); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 break; \
142 case 4: \
Russell King84046632012-09-07 18:22:28 +0100143 __get_user_x(__r2, __p, __e, __l, 4); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 default: __e = __get_user_bad(); break; \
146 } \
Russell Kingd2c5b692005-11-18 14:22:03 +0000147 x = (typeof(*(p))) __r2; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 __e; \
149 })
150
Will Deaconad729072012-09-07 18:24:10 +0100151#define get_user(x,p) \
152 ({ \
153 might_fault(); \
154 __get_user_check(x,p); \
155 })
156
Russell King9641c7c2006-06-21 20:38:17 +0100157extern int __put_user_1(void *, unsigned int);
158extern int __put_user_2(void *, unsigned int);
159extern int __put_user_4(void *, unsigned int);
160extern int __put_user_8(void *, unsigned long long);
161
Russell King84046632012-09-07 18:22:28 +0100162#define __put_user_x(__r2,__p,__e,__l,__s) \
Russell King9641c7c2006-06-21 20:38:17 +0100163 __asm__ __volatile__ ( \
164 __asmeq("%0", "r0") __asmeq("%2", "r2") \
Russell King84046632012-09-07 18:22:28 +0100165 __asmeq("%3", "r1") \
Russell King9641c7c2006-06-21 20:38:17 +0100166 "bl __put_user_" #__s \
167 : "=&r" (__e) \
Russell King84046632012-09-07 18:22:28 +0100168 : "0" (__p), "r" (__r2), "r" (__l) \
Russell King9641c7c2006-06-21 20:38:17 +0100169 : "ip", "lr", "cc")
170
Will Deaconad729072012-09-07 18:24:10 +0100171#define __put_user_check(x,p) \
Russell King9641c7c2006-06-21 20:38:17 +0100172 ({ \
Russell King84046632012-09-07 18:22:28 +0100173 unsigned long __limit = current_thread_info()->addr_limit - 1; \
Andrey Ryabinin537094b2014-05-07 08:07:25 +0100174 const typeof(*(p)) __user *__tmp_p = (p); \
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100175 register const typeof(*(p)) __r2 asm("r2") = (x); \
Andrey Ryabinin537094b2014-05-07 08:07:25 +0100176 register const typeof(*(p)) __user *__p asm("r0") = __tmp_p; \
Russell King84046632012-09-07 18:22:28 +0100177 register unsigned long __l asm("r1") = __limit; \
Russell King9641c7c2006-06-21 20:38:17 +0100178 register int __e asm("r0"); \
179 switch (sizeof(*(__p))) { \
180 case 1: \
Russell King84046632012-09-07 18:22:28 +0100181 __put_user_x(__r2, __p, __e, __l, 1); \
Russell King9641c7c2006-06-21 20:38:17 +0100182 break; \
183 case 2: \
Russell King84046632012-09-07 18:22:28 +0100184 __put_user_x(__r2, __p, __e, __l, 2); \
Russell King9641c7c2006-06-21 20:38:17 +0100185 break; \
186 case 4: \
Russell King84046632012-09-07 18:22:28 +0100187 __put_user_x(__r2, __p, __e, __l, 4); \
Russell King9641c7c2006-06-21 20:38:17 +0100188 break; \
189 case 8: \
Russell King84046632012-09-07 18:22:28 +0100190 __put_user_x(__r2, __p, __e, __l, 8); \
Russell King9641c7c2006-06-21 20:38:17 +0100191 break; \
192 default: __e = __put_user_bad(); break; \
193 } \
194 __e; \
195 })
196
Will Deaconad729072012-09-07 18:24:10 +0100197#define put_user(x,p) \
198 ({ \
199 might_fault(); \
200 __put_user_check(x,p); \
201 })
202
Russell King9641c7c2006-06-21 20:38:17 +0100203#else /* CONFIG_MMU */
204
205/*
206 * uClinux has only one addr space, so has simplified address limits.
207 */
208#define USER_DS KERNEL_DS
209
210#define segment_eq(a,b) (1)
Arnd Bergmann8e7fc182012-04-30 13:18:46 +0000211#define __addr_ok(addr) ((void)(addr),1)
212#define __range_ok(addr,size) ((void)(addr),0)
Russell King9641c7c2006-06-21 20:38:17 +0100213#define get_fs() (KERNEL_DS)
214
215static inline void set_fs(mm_segment_t fs)
216{
217}
218
219#define get_user(x,p) __get_user(x,p)
220#define put_user(x,p) __put_user(x,p)
221
222#endif /* CONFIG_MMU */
223
224#define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
225
Will Deacon8c56cc82012-07-06 15:45:39 +0100226#define user_addr_max() \
227 (segment_eq(get_fs(), USER_DS) ? TASK_SIZE : ~0UL)
228
Russell King9641c7c2006-06-21 20:38:17 +0100229/*
230 * The "__xxx" versions of the user access functions do not verify the
231 * address space - it must have been done previously with a separate
232 * "access_ok()" call.
233 *
234 * The "xxx_error" versions set the third argument to EFAULT if an
235 * error occurs, and leave it unchanged on success. Note that these
236 * versions are void (ie, don't return a value as such).
237 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define __get_user(x,ptr) \
239({ \
240 long __gu_err = 0; \
241 __get_user_err((x),(ptr),__gu_err); \
242 __gu_err; \
243})
244
245#define __get_user_error(x,ptr,err) \
246({ \
247 __get_user_err((x),(ptr),err); \
248 (void) 0; \
249})
250
251#define __get_user_err(x,ptr,err) \
252do { \
253 unsigned long __gu_addr = (unsigned long)(ptr); \
254 unsigned long __gu_val; \
255 __chk_user_ptr(ptr); \
Will Deaconad729072012-09-07 18:24:10 +0100256 might_fault(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 switch (sizeof(*(ptr))) { \
258 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
259 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
260 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
261 default: (__gu_val) = __get_user_bad(); \
262 } \
263 (x) = (__typeof__(*(ptr)))__gu_val; \
264} while (0)
265
266#define __get_user_asm_byte(x,addr,err) \
267 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100268 "1: " TUSER(ldrb) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100270 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 " .align 2\n" \
272 "3: mov %0, %3\n" \
273 " mov %1, #0\n" \
274 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100275 " .popsection\n" \
276 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 " .align 3\n" \
278 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100279 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 : "+r" (err), "=&r" (x) \
281 : "r" (addr), "i" (-EFAULT) \
282 : "cc")
283
284#ifndef __ARMEB__
285#define __get_user_asm_half(x,__gu_addr,err) \
286({ \
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 | (__b2 << 8); \
291})
292#else
293#define __get_user_asm_half(x,__gu_addr,err) \
294({ \
295 unsigned long __b1, __b2; \
296 __get_user_asm_byte(__b1, __gu_addr, err); \
297 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
298 (x) = (__b1 << 8) | __b2; \
299})
300#endif
301
302#define __get_user_asm_word(x,addr,err) \
303 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100304 "1: " TUSER(ldr) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100306 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 " .align 2\n" \
308 "3: mov %0, %3\n" \
309 " mov %1, #0\n" \
310 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100311 " .popsection\n" \
312 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 " .align 3\n" \
314 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100315 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 : "+r" (err), "=&r" (x) \
317 : "r" (addr), "i" (-EFAULT) \
318 : "cc")
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define __put_user(x,ptr) \
321({ \
322 long __pu_err = 0; \
323 __put_user_err((x),(ptr),__pu_err); \
324 __pu_err; \
325})
326
327#define __put_user_error(x,ptr,err) \
328({ \
329 __put_user_err((x),(ptr),err); \
330 (void) 0; \
331})
332
333#define __put_user_err(x,ptr,err) \
334do { \
335 unsigned long __pu_addr = (unsigned long)(ptr); \
336 __typeof__(*(ptr)) __pu_val = (x); \
337 __chk_user_ptr(ptr); \
Will Deaconad729072012-09-07 18:24:10 +0100338 might_fault(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 switch (sizeof(*(ptr))) { \
340 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
341 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
342 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
343 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
344 default: __put_user_bad(); \
345 } \
346} while (0)
347
348#define __put_user_asm_byte(x,__pu_addr,err) \
349 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100350 "1: " TUSER(strb) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100352 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 " .align 2\n" \
354 "3: mov %0, %3\n" \
355 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100356 " .popsection\n" \
357 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 " .align 3\n" \
359 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100360 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 : "+r" (err) \
362 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
363 : "cc")
364
365#ifndef __ARMEB__
366#define __put_user_asm_half(x,__pu_addr,err) \
367({ \
368 unsigned long __temp = (unsigned long)(x); \
369 __put_user_asm_byte(__temp, __pu_addr, err); \
370 __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \
371})
372#else
373#define __put_user_asm_half(x,__pu_addr,err) \
374({ \
375 unsigned long __temp = (unsigned long)(x); \
376 __put_user_asm_byte(__temp >> 8, __pu_addr, err); \
377 __put_user_asm_byte(__temp, __pu_addr + 1, err); \
378})
379#endif
380
381#define __put_user_asm_word(x,__pu_addr,err) \
382 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100383 "1: " TUSER(str) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100385 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 " .align 2\n" \
387 "3: mov %0, %3\n" \
388 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100389 " .popsection\n" \
390 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 " .align 3\n" \
392 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100393 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 : "+r" (err) \
395 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
396 : "cc")
397
398#ifndef __ARMEB__
399#define __reg_oper0 "%R2"
400#define __reg_oper1 "%Q2"
401#else
402#define __reg_oper0 "%Q2"
403#define __reg_oper1 "%R2"
404#endif
405
406#define __put_user_asm_dword(x,__pu_addr,err) \
407 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100408 ARM( "1: " TUSER(str) " " __reg_oper1 ", [%1], #4\n" ) \
409 ARM( "2: " TUSER(str) " " __reg_oper0 ", [%1]\n" ) \
410 THUMB( "1: " TUSER(str) " " __reg_oper1 ", [%1]\n" ) \
411 THUMB( "2: " TUSER(str) " " __reg_oper0 ", [%1, #4]\n" ) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 "3:\n" \
Russell King42604152010-04-19 10:15:03 +0100413 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 " .align 2\n" \
415 "4: mov %0, %3\n" \
416 " b 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100417 " .popsection\n" \
418 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 " .align 3\n" \
420 " .long 1b, 4b\n" \
421 " .long 2b, 4b\n" \
Russell King42604152010-04-19 10:15:03 +0100422 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 : "+r" (err), "+r" (__pu_addr) \
424 : "r" (x), "i" (-EFAULT) \
425 : "cc")
426
Russell King02fcb972006-06-21 14:44:52 +0100427
Russell King9641c7c2006-06-21 20:38:17 +0100428#ifdef CONFIG_MMU
Russell King99573292006-10-26 10:27:42 +0100429extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
430extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
Nicolas Pitrea1f98842009-03-08 22:34:45 -0400431extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
Russell King99573292006-10-26 10:27:42 +0100432extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
Nicolas Pitrea1f98842009-03-08 22:34:45 -0400433extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
Russell King9641c7c2006-06-21 20:38:17 +0100434#else
435#define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
436#define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
437#define __clear_user(addr,n) (memset((void __force *)addr, 0, n), 0)
438#endif
439
Russell King99573292006-10-26 10:27:42 +0100440static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 if (access_ok(VERIFY_READ, from, n))
Russell King02fcb972006-06-21 14:44:52 +0100443 n = __copy_from_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 else /* security hole - plug it */
Russell King59f0cb02008-10-27 11:24:09 +0000445 memset(to, 0, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return n;
447}
448
Russell King99573292006-10-26 10:27:42 +0100449static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
451 if (access_ok(VERIFY_WRITE, to, n))
Russell King02fcb972006-06-21 14:44:52 +0100452 n = __copy_to_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return n;
454}
455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define __copy_to_user_inatomic __copy_to_user
457#define __copy_from_user_inatomic __copy_from_user
458
Russell King99573292006-10-26 10:27:42 +0100459static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
461 if (access_ok(VERIFY_WRITE, to, n))
Russell King02fcb972006-06-21 14:44:52 +0100462 n = __clear_user(to, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 return n;
464}
465
Will Deacon8c56cc82012-07-06 15:45:39 +0100466extern long strncpy_from_user(char *dest, const char __user *src, long count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Will Deacon8c56cc82012-07-06 15:45:39 +0100468extern __must_check long strlen_user(const char __user *str);
469extern __must_check long strnlen_user(const char __user *str, long n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471#endif /* _ASMARM_UACCESS_H */