blob: b04850fdeb5b5f630c6671fa06a659781177f321 [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
22#define VERIFY_READ 0
23#define VERIFY_WRITE 1
24
25/*
26 * The exception table consists of pairs of addresses: the first is the
27 * address of an instruction that is allowed to fault, and the second is
28 * the address at which the program should continue. No registers are
29 * modified, so it is entirely up to the continuation code to figure out
30 * what to do.
31 *
32 * All the routines below use bits of fixup code that are out of line
33 * with the main instruction path. This means when everything is well,
34 * we don't even have to jump over them. Further, they do not intrude
35 * on our cache or tlb entries.
36 */
37
38struct exception_table_entry
39{
40 unsigned long insn, fixup;
41};
42
43extern int fixup_exception(struct pt_regs *regs);
44
45/*
Russell King9641c7c2006-06-21 20:38:17 +010046 * These two are intentionally not defined anywhere - if the kernel
47 * code generates any references to them, that's a bug.
48 */
49extern int __get_user_bad(void);
50extern int __put_user_bad(void);
51
52/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * Note that this is actually 0x1,0000,0000
54 */
55#define KERNEL_DS 0x00000000
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define get_ds() (KERNEL_DS)
Russell King9641c7c2006-06-21 20:38:17 +010057
58#ifdef CONFIG_MMU
59
60#define USER_DS TASK_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define get_fs() (current_thread_info()->addr_limit)
62
Russell King9641c7c2006-06-21 20:38:17 +010063static inline void set_fs(mm_segment_t fs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 current_thread_info()->addr_limit = fs;
66 modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
67}
68
69#define segment_eq(a,b) ((a) == (b))
70
71#define __addr_ok(addr) ({ \
72 unsigned long flag; \
73 __asm__("cmp %2, %0; movlo %0, #0" \
74 : "=&r" (flag) \
75 : "0" (current_thread_info()->addr_limit), "r" (addr) \
76 : "cc"); \
77 (flag == 0); })
78
79/* We use 33-bit arithmetic here... */
80#define __range_ok(addr,size) ({ \
Tilman Schmidt16cf5b32007-02-10 01:45:41 -080081 unsigned long flag, roksum; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 __chk_user_ptr(addr); \
83 __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \
Tilman Schmidt16cf5b32007-02-10 01:45:41 -080084 : "=&r" (flag), "=&r" (roksum) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 : "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \
86 : "cc"); \
87 flag; })
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/*
90 * Single-value transfer routines. They automatically use the right
91 * size if we just have the right pointer type. Note that the functions
92 * which read from user space (*get_*) need to take care not to leak
93 * kernel data even if the calling code is buggy and fails to check
94 * the return value. This means zeroing out the destination variable
95 * or buffer on error. Normally this is done out of line by the
96 * fixup code, but there are a few places where it intrudes on the
97 * main code path. When we only write to user space, there is no
98 * problem.
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100extern int __get_user_1(void *);
101extern int __get_user_2(void *);
102extern int __get_user_4(void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Russell King8cc876d2012-09-07 18:22:28 +0100104#define __GUP_CLOBBER_1 "lr", "cc"
105#ifdef CONFIG_CPU_USE_DOMAINS
106#define __GUP_CLOBBER_2 "ip", "lr", "cc"
107#else
108#define __GUP_CLOBBER_2 "lr", "cc"
109#endif
110#define __GUP_CLOBBER_4 "lr", "cc"
111
112#define __get_user_x(__r2,__p,__e,__l,__s) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 __asm__ __volatile__ ( \
114 __asmeq("%0", "r0") __asmeq("%1", "r2") \
Russell King8cc876d2012-09-07 18:22:28 +0100115 __asmeq("%3", "r1") \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 "bl __get_user_" #__s \
117 : "=&r" (__e), "=r" (__r2) \
Russell King8cc876d2012-09-07 18:22:28 +0100118 : "0" (__p), "r" (__l) \
119 : __GUP_CLOBBER_##__s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121#define get_user(x,p) \
122 ({ \
Russell King8cc876d2012-09-07 18:22:28 +0100123 unsigned long __limit = current_thread_info()->addr_limit - 1; \
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100124 register const typeof(*(p)) __user *__p asm("r0") = (p);\
Al Virofc048b52006-10-11 17:22:54 +0100125 register unsigned long __r2 asm("r2"); \
Russell King8cc876d2012-09-07 18:22:28 +0100126 register unsigned long __l asm("r1") = __limit; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 register int __e asm("r0"); \
128 switch (sizeof(*(__p))) { \
129 case 1: \
Russell King8cc876d2012-09-07 18:22:28 +0100130 __get_user_x(__r2, __p, __e, __l, 1); \
131 break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 case 2: \
Russell King8cc876d2012-09-07 18:22:28 +0100133 __get_user_x(__r2, __p, __e, __l, 2); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 break; \
135 case 4: \
Russell King8cc876d2012-09-07 18:22:28 +0100136 __get_user_x(__r2, __p, __e, __l, 4); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 default: __e = __get_user_bad(); break; \
139 } \
Russell Kingd2c5b692005-11-18 14:22:03 +0000140 x = (typeof(*(p))) __r2; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 __e; \
142 })
143
Russell King9641c7c2006-06-21 20:38:17 +0100144extern int __put_user_1(void *, unsigned int);
145extern int __put_user_2(void *, unsigned int);
146extern int __put_user_4(void *, unsigned int);
147extern int __put_user_8(void *, unsigned long long);
148
Russell King8cc876d2012-09-07 18:22:28 +0100149#define __put_user_x(__r2,__p,__e,__l,__s) \
Russell King9641c7c2006-06-21 20:38:17 +0100150 __asm__ __volatile__ ( \
151 __asmeq("%0", "r0") __asmeq("%2", "r2") \
Russell King8cc876d2012-09-07 18:22:28 +0100152 __asmeq("%3", "r1") \
Russell King9641c7c2006-06-21 20:38:17 +0100153 "bl __put_user_" #__s \
154 : "=&r" (__e) \
Russell King8cc876d2012-09-07 18:22:28 +0100155 : "0" (__p), "r" (__r2), "r" (__l) \
Russell King9641c7c2006-06-21 20:38:17 +0100156 : "ip", "lr", "cc")
157
158#define put_user(x,p) \
159 ({ \
Russell King8cc876d2012-09-07 18:22:28 +0100160 unsigned long __limit = current_thread_info()->addr_limit - 1; \
Andrey Ryabininee40d722014-05-07 08:07:25 +0100161 const typeof(*(p)) __user *__tmp_p = (p); \
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100162 register const typeof(*(p)) __r2 asm("r2") = (x); \
Andrey Ryabininee40d722014-05-07 08:07:25 +0100163 register const typeof(*(p)) __user *__p asm("r0") = __tmp_p; \
Russell King8cc876d2012-09-07 18:22:28 +0100164 register unsigned long __l asm("r1") = __limit; \
Russell King9641c7c2006-06-21 20:38:17 +0100165 register int __e asm("r0"); \
166 switch (sizeof(*(__p))) { \
167 case 1: \
Russell King8cc876d2012-09-07 18:22:28 +0100168 __put_user_x(__r2, __p, __e, __l, 1); \
Russell King9641c7c2006-06-21 20:38:17 +0100169 break; \
170 case 2: \
Russell King8cc876d2012-09-07 18:22:28 +0100171 __put_user_x(__r2, __p, __e, __l, 2); \
Russell King9641c7c2006-06-21 20:38:17 +0100172 break; \
173 case 4: \
Russell King8cc876d2012-09-07 18:22:28 +0100174 __put_user_x(__r2, __p, __e, __l, 4); \
Russell King9641c7c2006-06-21 20:38:17 +0100175 break; \
176 case 8: \
Russell King8cc876d2012-09-07 18:22:28 +0100177 __put_user_x(__r2, __p, __e, __l, 8); \
Russell King9641c7c2006-06-21 20:38:17 +0100178 break; \
179 default: __e = __put_user_bad(); break; \
180 } \
181 __e; \
182 })
183
184#else /* CONFIG_MMU */
185
186/*
187 * uClinux has only one addr space, so has simplified address limits.
188 */
189#define USER_DS KERNEL_DS
190
191#define segment_eq(a,b) (1)
192#define __addr_ok(addr) (1)
193#define __range_ok(addr,size) (0)
194#define get_fs() (KERNEL_DS)
195
196static inline void set_fs(mm_segment_t fs)
197{
198}
199
200#define get_user(x,p) __get_user(x,p)
201#define put_user(x,p) __put_user(x,p)
202
203#endif /* CONFIG_MMU */
204
205#define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
206
207/*
208 * The "__xxx" versions of the user access functions do not verify the
209 * address space - it must have been done previously with a separate
210 * "access_ok()" call.
211 *
212 * The "xxx_error" versions set the third argument to EFAULT if an
213 * error occurs, and leave it unchanged on success. Note that these
214 * versions are void (ie, don't return a value as such).
215 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define __get_user(x,ptr) \
217({ \
218 long __gu_err = 0; \
219 __get_user_err((x),(ptr),__gu_err); \
220 __gu_err; \
221})
222
223#define __get_user_error(x,ptr,err) \
224({ \
225 __get_user_err((x),(ptr),err); \
226 (void) 0; \
227})
228
229#define __get_user_err(x,ptr,err) \
230do { \
231 unsigned long __gu_addr = (unsigned long)(ptr); \
232 unsigned long __gu_val; \
233 __chk_user_ptr(ptr); \
234 switch (sizeof(*(ptr))) { \
235 case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
236 case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
237 case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
238 default: (__gu_val) = __get_user_bad(); \
239 } \
240 (x) = (__typeof__(*(ptr)))__gu_val; \
241} while (0)
242
243#define __get_user_asm_byte(x,addr,err) \
244 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100245 "1: " TUSER(ldrb) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100247 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 " .align 2\n" \
249 "3: mov %0, %3\n" \
250 " mov %1, #0\n" \
251 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100252 " .popsection\n" \
253 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 " .align 3\n" \
255 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100256 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 : "+r" (err), "=&r" (x) \
258 : "r" (addr), "i" (-EFAULT) \
259 : "cc")
260
261#ifndef __ARMEB__
262#define __get_user_asm_half(x,__gu_addr,err) \
263({ \
264 unsigned long __b1, __b2; \
265 __get_user_asm_byte(__b1, __gu_addr, err); \
266 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
267 (x) = __b1 | (__b2 << 8); \
268})
269#else
270#define __get_user_asm_half(x,__gu_addr,err) \
271({ \
272 unsigned long __b1, __b2; \
273 __get_user_asm_byte(__b1, __gu_addr, err); \
274 __get_user_asm_byte(__b2, __gu_addr + 1, err); \
275 (x) = (__b1 << 8) | __b2; \
276})
277#endif
278
279#define __get_user_asm_word(x,addr,err) \
280 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100281 "1: " TUSER(ldr) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100283 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 " .align 2\n" \
285 "3: mov %0, %3\n" \
286 " mov %1, #0\n" \
287 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100288 " .popsection\n" \
289 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 " .align 3\n" \
291 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100292 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 : "+r" (err), "=&r" (x) \
294 : "r" (addr), "i" (-EFAULT) \
295 : "cc")
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#define __put_user(x,ptr) \
298({ \
299 long __pu_err = 0; \
300 __put_user_err((x),(ptr),__pu_err); \
301 __pu_err; \
302})
303
304#define __put_user_error(x,ptr,err) \
305({ \
306 __put_user_err((x),(ptr),err); \
307 (void) 0; \
308})
309
310#define __put_user_err(x,ptr,err) \
311do { \
312 unsigned long __pu_addr = (unsigned long)(ptr); \
313 __typeof__(*(ptr)) __pu_val = (x); \
314 __chk_user_ptr(ptr); \
315 switch (sizeof(*(ptr))) { \
316 case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
317 case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
318 case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
319 case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
320 default: __put_user_bad(); \
321 } \
322} while (0)
323
324#define __put_user_asm_byte(x,__pu_addr,err) \
325 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100326 "1: " TUSER(strb) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100328 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 " .align 2\n" \
330 "3: mov %0, %3\n" \
331 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100332 " .popsection\n" \
333 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 " .align 3\n" \
335 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100336 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 : "+r" (err) \
338 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
339 : "cc")
340
341#ifndef __ARMEB__
342#define __put_user_asm_half(x,__pu_addr,err) \
343({ \
344 unsigned long __temp = (unsigned long)(x); \
345 __put_user_asm_byte(__temp, __pu_addr, err); \
346 __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \
347})
348#else
349#define __put_user_asm_half(x,__pu_addr,err) \
350({ \
351 unsigned long __temp = (unsigned long)(x); \
352 __put_user_asm_byte(__temp >> 8, __pu_addr, err); \
353 __put_user_asm_byte(__temp, __pu_addr + 1, err); \
354})
355#endif
356
357#define __put_user_asm_word(x,__pu_addr,err) \
358 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100359 "1: " TUSER(str) " %1,[%2],#0\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 "2:\n" \
Russell King42604152010-04-19 10:15:03 +0100361 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 " .align 2\n" \
363 "3: mov %0, %3\n" \
364 " b 2b\n" \
Russell King42604152010-04-19 10:15:03 +0100365 " .popsection\n" \
366 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 " .align 3\n" \
368 " .long 1b, 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100369 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 : "+r" (err) \
371 : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
372 : "cc")
373
374#ifndef __ARMEB__
375#define __reg_oper0 "%R2"
376#define __reg_oper1 "%Q2"
377#else
378#define __reg_oper0 "%Q2"
379#define __reg_oper1 "%R2"
380#endif
381
382#define __put_user_asm_dword(x,__pu_addr,err) \
383 __asm__ __volatile__( \
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100384 ARM( "1: " TUSER(str) " " __reg_oper1 ", [%1], #4\n" ) \
385 ARM( "2: " TUSER(str) " " __reg_oper0 ", [%1]\n" ) \
386 THUMB( "1: " TUSER(str) " " __reg_oper1 ", [%1]\n" ) \
387 THUMB( "2: " TUSER(str) " " __reg_oper0 ", [%1, #4]\n" ) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 "3:\n" \
Russell King42604152010-04-19 10:15:03 +0100389 " .pushsection .fixup,\"ax\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 " .align 2\n" \
391 "4: mov %0, %3\n" \
392 " b 3b\n" \
Russell King42604152010-04-19 10:15:03 +0100393 " .popsection\n" \
394 " .pushsection __ex_table,\"a\"\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 " .align 3\n" \
396 " .long 1b, 4b\n" \
397 " .long 2b, 4b\n" \
Russell King42604152010-04-19 10:15:03 +0100398 " .popsection" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 : "+r" (err), "+r" (__pu_addr) \
400 : "r" (x), "i" (-EFAULT) \
401 : "cc")
402
Russell King02fcb972006-06-21 14:44:52 +0100403
Russell King9641c7c2006-06-21 20:38:17 +0100404#ifdef CONFIG_MMU
Russell King99573292006-10-26 10:27:42 +0100405extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
406extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
Nicolas Pitrea1f98842009-03-08 22:34:45 -0400407extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
Russell King99573292006-10-26 10:27:42 +0100408extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
Nicolas Pitrea1f98842009-03-08 22:34:45 -0400409extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
Russell King9641c7c2006-06-21 20:38:17 +0100410#else
411#define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
412#define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
413#define __clear_user(addr,n) (memset((void __force *)addr, 0, n), 0)
414#endif
415
Russell King99573292006-10-26 10:27:42 +0100416extern unsigned long __must_check __strncpy_from_user(char *to, const char __user *from, unsigned long count);
417extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Russell King99573292006-10-26 10:27:42 +0100419static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
421 if (access_ok(VERIFY_READ, from, n))
Russell King02fcb972006-06-21 14:44:52 +0100422 n = __copy_from_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 else /* security hole - plug it */
Russell King59f0cb02008-10-27 11:24:09 +0000424 memset(to, 0, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return n;
426}
427
Russell King99573292006-10-26 10:27:42 +0100428static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 if (access_ok(VERIFY_WRITE, to, n))
Russell King02fcb972006-06-21 14:44:52 +0100431 n = __copy_to_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return n;
433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define __copy_to_user_inatomic __copy_to_user
436#define __copy_from_user_inatomic __copy_from_user
437
Russell King99573292006-10-26 10:27:42 +0100438static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 if (access_ok(VERIFY_WRITE, to, n))
Russell King02fcb972006-06-21 14:44:52 +0100441 n = __clear_user(to, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return n;
443}
444
Russell King99573292006-10-26 10:27:42 +0100445static inline long __must_check strncpy_from_user(char *dst, const char __user *src, long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
447 long res = -EFAULT;
448 if (access_ok(VERIFY_READ, src, 1))
Russell King02fcb972006-06-21 14:44:52 +0100449 res = __strncpy_from_user(dst, src, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return res;
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define strlen_user(s) strnlen_user(s, ~0UL >> 1)
454
Russell King99573292006-10-26 10:27:42 +0100455static inline long __must_check strnlen_user(const char __user *s, long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
457 unsigned long res = 0;
458
459 if (__addr_ok(s))
Russell King02fcb972006-06-21 14:44:52 +0100460 res = __strnlen_user(s, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 return res;
463}
464
465#endif /* _ASMARM_UACCESS_H */