blob: 07be349c00adcd755104d3fe5863d539891cfe1d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_M32R_UACCESS_H
2#define _ASM_M32R_UACCESS_H
3
4/*
5 * linux/include/asm-m32r/uaccess.h
6 *
7 * M32R version.
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -07008 * Copyright (C) 2004, 2006 Hirokazu Takata <takata at linux-m32r.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011/*
12 * User space memory access functions
13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/page.h>
Adrian Bunkec0ced12008-06-05 22:46:48 -070015#include <asm/setup.h>
Al Viro9a677342017-03-21 12:02:25 -040016#include <linux/prefetch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
19 * The fs value determines whether argument validity checking should be
20 * performed or not. If get_fs() == USER_DS, checking is performed, with
21 * get_fs() == KERNEL_DS, checking is bypassed.
22 *
23 * For historical reasons, these macros are grossly misnamed.
24 */
25
26#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
27
28#ifdef CONFIG_MMU
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
31#define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define get_ds() (KERNEL_DS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define get_fs() (current_thread_info()->addr_limit)
34#define set_fs(x) (current_thread_info()->addr_limit = (x))
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -070035
36#else /* not CONFIG_MMU */
37
38#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
39#define USER_DS MAKE_MM_SEG(0xFFFFFFFF)
40#define get_ds() (KERNEL_DS)
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static inline mm_segment_t get_fs(void)
43{
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -070044 return USER_DS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47static inline void set_fs(mm_segment_t s)
48{
49}
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -070050
51#endif /* not CONFIG_MMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +020053#define segment_eq(a, b) ((a).seg == (b).seg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define __addr_ok(addr) \
56 ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
57
58/*
59 * Test whether a block of memory is a valid user space address.
60 * Returns 0 if the range is valid, nonzero otherwise.
61 *
62 * This is equivalent to the following test:
63 * (u33)addr + (u33)size >= (u33)current->addr_limit.seg
64 *
65 * This needs 33-bit arithmetic. We have a carry...
66 */
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +020067#define __range_ok(addr, size) ({ \
Tilman Schmidt16cf5b32007-02-10 01:45:41 -080068 unsigned long flag, roksum; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 __chk_user_ptr(addr); \
70 asm ( \
71 " cmpu %1, %1 ; clear cbit\n" \
72 " addx %1, %3 ; set cbit if overflow\n" \
73 " subx %0, %0\n" \
74 " cmpu %4, %1\n" \
75 " subx %0, %5\n" \
Tilman Schmidt16cf5b32007-02-10 01:45:41 -080076 : "=&r" (flag), "=r" (roksum) \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -070077 : "1" (addr), "r" ((int)(size)), \
78 "r" (current_thread_info()->addr_limit.seg), "r" (0) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 : "cbit" ); \
80 flag; })
81
82/**
83 * access_ok: - Checks if a user space pointer is valid
84 * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
85 * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
86 * to write to a block, it is always safe to read from it.
87 * @addr: User space pointer to start of block to check
88 * @size: Size of block to check
89 *
David Hildenbrandb3c395ef2015-05-11 17:52:08 +020090 * Context: User context only. This function may sleep if pagefaults are
91 * enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 *
93 * Checks if a pointer to a block of memory in user space is valid.
94 *
95 * Returns true (nonzero) if the memory block may be valid, false (zero)
96 * if it is definitely invalid.
97 *
98 * Note that, depending on architecture, this function probably just
99 * checks that the pointer is in the user space range - after calling
100 * this function, memory access functions may still return -EFAULT.
101 */
102#ifdef CONFIG_MMU
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200103#define access_ok(type, addr, size) (likely(__range_ok(addr, size) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#else
105static inline int access_ok(int type, const void *addr, unsigned long size)
106{
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700107 unsigned long val = (unsigned long)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700109 return ((val >= memory_start) && ((val + size) < memory_end));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111#endif /* CONFIG_MMU */
112
Al Viro35f8acd2016-12-25 03:33:03 -0500113#include <asm/extable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/*
116 * These are the main single-value transfer routines. They automatically
117 * use the right size if we just have the right pointer type.
118 *
119 * This gets kind of ugly. We want to return _two_ values in "get_user()"
120 * and yet we don't want to do any pointers, because that is too much
121 * of a performance impact. Thus we have a few rather ugly macros here,
122 * and hide all the uglyness from the user.
123 *
124 * The "__xxx" versions of the user access functions are versions that
125 * do not verify the address space, that must have been done previously
126 * with a separate "access_ok()" call (this is used when we do multiple
127 * accesses to the same area of user memory).
128 */
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* Careful: we have to cast the result to the type of the pointer for sign
131 reasons */
132/**
133 * get_user: - Get a simple variable from user space.
134 * @x: Variable to store result.
135 * @ptr: Source address, in user space.
136 *
David Hildenbrandb3c395ef2015-05-11 17:52:08 +0200137 * Context: User context only. This function may sleep if pagefaults are
138 * enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 *
140 * This macro copies a single simple variable from user space to kernel
141 * space. It supports simple types like char and int, but not larger
142 * data types like structures or arrays.
143 *
144 * @ptr must have pointer-to-simple-variable type, and the result of
145 * dereferencing @ptr must be assignable to @x without a cast.
146 *
147 * Returns zero on success, or -EFAULT on error.
148 * On error, the variable @x is set to zero.
149 */
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200150#define get_user(x, ptr) \
151 __get_user_check((x), (ptr), sizeof(*(ptr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153/**
154 * put_user: - Write a simple value into user space.
155 * @x: Value to copy to user space.
156 * @ptr: Destination address, in user space.
157 *
David Hildenbrandb3c395ef2015-05-11 17:52:08 +0200158 * Context: User context only. This function may sleep if pagefaults are
159 * enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 *
161 * This macro copies a single simple value from kernel space to user
162 * space. It supports simple types like char and int, but not larger
163 * data types like structures or arrays.
164 *
165 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
166 * to the result of dereferencing @ptr.
167 *
168 * Returns zero on success, or -EFAULT on error.
169 */
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200170#define put_user(x, ptr) \
171 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173/**
174 * __get_user: - Get a simple variable from user space, with less checking.
175 * @x: Variable to store result.
176 * @ptr: Source address, in user space.
177 *
David Hildenbrandb3c395ef2015-05-11 17:52:08 +0200178 * Context: User context only. This function may sleep if pagefaults are
179 * enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 *
181 * This macro copies a single simple variable from user space to kernel
182 * space. It supports simple types like char and int, but not larger
183 * data types like structures or arrays.
184 *
185 * @ptr must have pointer-to-simple-variable type, and the result of
186 * dereferencing @ptr must be assignable to @x without a cast.
187 *
188 * Caller must check the pointer with access_ok() before calling this
189 * function.
190 *
191 * Returns zero on success, or -EFAULT on error.
192 * On error, the variable @x is set to zero.
193 */
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200194#define __get_user(x, ptr) \
195 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200197#define __get_user_nocheck(x, ptr, size) \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700198({ \
199 long __gu_err = 0; \
Al Viroc90a3bc2016-09-09 19:20:13 -0400200 unsigned long __gu_val = 0; \
Michael S. Tsirkin01682572013-05-26 17:30:51 +0300201 might_fault(); \
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200202 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
Michael S. Tsirkina6183372014-12-12 01:56:04 +0200203 (x) = (__force __typeof__(*(ptr)))__gu_val; \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700204 __gu_err; \
205})
206
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200207#define __get_user_check(x, ptr, size) \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700208({ \
209 long __gu_err = -EFAULT; \
210 unsigned long __gu_val = 0; \
211 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
Michael S. Tsirkin01682572013-05-26 17:30:51 +0300212 might_fault(); \
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200213 if (access_ok(VERIFY_READ, __gu_addr, size)) \
214 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
Michael S. Tsirkina6183372014-12-12 01:56:04 +0200215 (x) = (__force __typeof__(*(ptr)))__gu_val; \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700216 __gu_err; \
217})
218
219extern long __get_user_bad(void);
220
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200221#define __get_user_size(x, ptr, size, retval) \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700222do { \
223 retval = 0; \
224 __chk_user_ptr(ptr); \
225 switch (size) { \
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200226 case 1: __get_user_asm(x, ptr, retval, "ub"); break; \
227 case 2: __get_user_asm(x, ptr, retval, "uh"); break; \
228 case 4: __get_user_asm(x, ptr, retval, ""); break; \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700229 default: (x) = __get_user_bad(); \
230 } \
231} while (0)
232
233#define __get_user_asm(x, addr, err, itype) \
234 __asm__ __volatile__( \
235 " .fillinsn\n" \
236 "1: ld"itype" %1,@%2\n" \
237 " .fillinsn\n" \
238 "2:\n" \
239 ".section .fixup,\"ax\"\n" \
240 " .balign 4\n" \
241 "3: ldi %0,%3\n" \
242 " seth r14,#high(2b)\n" \
243 " or3 r14,r14,#low(2b)\n" \
244 " jmp r14\n" \
245 ".previous\n" \
246 ".section __ex_table,\"a\"\n" \
247 " .balign 4\n" \
248 " .long 1b,3b\n" \
249 ".previous" \
250 : "=&r" (err), "=&r" (x) \
251 : "r" (addr), "i" (-EFAULT), "0" (err) \
252 : "r14", "memory")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254/**
255 * __put_user: - Write a simple value into user space, with less checking.
256 * @x: Value to copy to user space.
257 * @ptr: Destination address, in user space.
258 *
David Hildenbrandb3c395ef2015-05-11 17:52:08 +0200259 * Context: User context only. This function may sleep if pagefaults are
260 * enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 *
262 * This macro copies a single simple value from kernel space to user
263 * space. It supports simple types like char and int, but not larger
264 * data types like structures or arrays.
265 *
266 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
267 * to the result of dereferencing @ptr.
268 *
269 * Caller must check the pointer with access_ok() before calling this
270 * function.
271 *
272 * Returns zero on success, or -EFAULT on error.
273 */
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200274#define __put_user(x, ptr) \
275 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200278#define __put_user_nocheck(x, ptr, size) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279({ \
280 long __pu_err; \
Michael S. Tsirkin01682572013-05-26 17:30:51 +0300281 might_fault(); \
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200282 __put_user_size((x), (ptr), (size), __pu_err); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 __pu_err; \
284})
285
286
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200287#define __put_user_check(x, ptr, size) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288({ \
289 long __pu_err = -EFAULT; \
290 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
Michael S. Tsirkin01682572013-05-26 17:30:51 +0300291 might_fault(); \
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200292 if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
293 __put_user_size((x), __pu_addr, (size), __pu_err); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 __pu_err; \
295})
296
297#if defined(__LITTLE_ENDIAN__)
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700298#define __put_user_u64(x, addr, err) \
299 __asm__ __volatile__( \
300 " .fillinsn\n" \
301 "1: st %L1,@%2\n" \
302 " .fillinsn\n" \
303 "2: st %H1,@(4,%2)\n" \
304 " .fillinsn\n" \
305 "3:\n" \
306 ".section .fixup,\"ax\"\n" \
307 " .balign 4\n" \
308 "4: ldi %0,%3\n" \
309 " seth r14,#high(3b)\n" \
310 " or3 r14,r14,#low(3b)\n" \
311 " jmp r14\n" \
312 ".previous\n" \
313 ".section __ex_table,\"a\"\n" \
314 " .balign 4\n" \
315 " .long 1b,4b\n" \
316 " .long 2b,4b\n" \
317 ".previous" \
318 : "=&r" (err) \
319 : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 : "r14", "memory")
321
322#elif defined(__BIG_ENDIAN__)
323#define __put_user_u64(x, addr, err) \
324 __asm__ __volatile__( \
325 " .fillinsn\n" \
326 "1: st %H1,@%2\n" \
327 " .fillinsn\n" \
328 "2: st %L1,@(4,%2)\n" \
329 " .fillinsn\n" \
330 "3:\n" \
331 ".section .fixup,\"ax\"\n" \
332 " .balign 4\n" \
333 "4: ldi %0,%3\n" \
334 " seth r14,#high(3b)\n" \
335 " or3 r14,r14,#low(3b)\n" \
336 " jmp r14\n" \
337 ".previous\n" \
338 ".section __ex_table,\"a\"\n" \
339 " .balign 4\n" \
340 " .long 1b,4b\n" \
341 " .long 2b,4b\n" \
342 ".previous" \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700343 : "=&r" (err) \
344 : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 : "r14", "memory")
346#else
347#error no endian defined
348#endif
349
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700350extern void __put_user_bad(void);
351
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200352#define __put_user_size(x, ptr, size, retval) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353do { \
354 retval = 0; \
355 __chk_user_ptr(ptr); \
356 switch (size) { \
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200357 case 1: __put_user_asm(x, ptr, retval, "b"); break; \
358 case 2: __put_user_asm(x, ptr, retval, "h"); break; \
359 case 4: __put_user_asm(x, ptr, retval, ""); break; \
360 case 8: __put_user_u64((__typeof__(*ptr))(x), ptr, retval); break;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 default: __put_user_bad(); \
362 } \
363} while (0)
364
365struct __large_struct { unsigned long buf[100]; };
366#define __m(x) (*(struct __large_struct *)(x))
367
368/*
369 * Tell gcc we read from memory instead of writing: this is because
370 * we do not write to any memory gcc knows about, so there are no
371 * aliasing issues.
372 */
373#define __put_user_asm(x, addr, err, itype) \
374 __asm__ __volatile__( \
375 " .fillinsn\n" \
376 "1: st"itype" %1,@%2\n" \
377 " .fillinsn\n" \
378 "2:\n" \
379 ".section .fixup,\"ax\"\n" \
380 " .balign 4\n" \
381 "3: ldi %0,%3\n" \
382 " seth r14,#high(2b)\n" \
383 " or3 r14,r14,#low(2b)\n" \
384 " jmp r14\n" \
385 ".previous\n" \
386 ".section __ex_table,\"a\"\n" \
387 " .balign 4\n" \
388 " .long 1b,3b\n" \
389 ".previous" \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700390 : "=&r" (err) \
391 : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 : "r14", "memory")
393
394/*
395 * Here we special-case 1, 2 and 4-byte copy_*_user invocations. On a fault
396 * we return the initial request size (1, 2 or 4), as copy_*_user should do.
397 * If a store crosses a page boundary and gets a fault, the m32r will not write
398 * anything, so this is accurate.
399 */
400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401/*
402 * Copy To/From Userspace
403 */
404
405/* Generic arbitrary sized copy. */
406/* Return the number of bytes NOT copied. */
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200407#define __copy_user(to, from, size) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408do { \
409 unsigned long __dst, __src, __c; \
410 __asm__ __volatile__ ( \
411 " mv r14, %0\n" \
412 " or r14, %1\n" \
413 " beq %0, %1, 9f\n" \
414 " beqz %2, 9f\n" \
415 " and3 r14, r14, #3\n" \
416 " bnez r14, 2f\n" \
417 " and3 %2, %2, #3\n" \
418 " beqz %3, 2f\n" \
419 " addi %0, #-4 ; word_copy \n" \
420 " .fillinsn\n" \
421 "0: ld r14, @%1+\n" \
422 " addi %3, #-1\n" \
423 " .fillinsn\n" \
424 "1: st r14, @+%0\n" \
425 " bnez %3, 0b\n" \
426 " beqz %2, 9f\n" \
427 " addi %0, #4\n" \
428 " .fillinsn\n" \
429 "2: ldb r14, @%1 ; byte_copy \n" \
430 " .fillinsn\n" \
431 "3: stb r14, @%0\n" \
432 " addi %1, #1\n" \
433 " addi %2, #-1\n" \
434 " addi %0, #1\n" \
435 " bnez %2, 2b\n" \
436 " .fillinsn\n" \
437 "9:\n" \
438 ".section .fixup,\"ax\"\n" \
439 " .balign 4\n" \
440 "5: addi %3, #1\n" \
441 " addi %1, #-4\n" \
442 " .fillinsn\n" \
443 "6: slli %3, #2\n" \
444 " add %2, %3\n" \
445 " addi %0, #4\n" \
446 " .fillinsn\n" \
447 "7: seth r14, #high(9b)\n" \
448 " or3 r14, r14, #low(9b)\n" \
449 " jmp r14\n" \
450 ".previous\n" \
451 ".section __ex_table,\"a\"\n" \
452 " .balign 4\n" \
453 " .long 0b,6b\n" \
454 " .long 1b,5b\n" \
455 " .long 2b,9b\n" \
456 " .long 3b,9b\n" \
457 ".previous\n" \
Hirokazu Takata04dfd0d2006-04-10 22:53:20 -0700458 : "=&r" (__dst), "=&r" (__src), "=&r" (size), \
459 "=&r" (__c) \
460 : "0" (to), "1" (from), "2" (size), "3" (size / 4) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 : "r14", "memory"); \
462} while (0)
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/* We let the __ versions of copy_from/to_user inline, because they're often
465 * used in fast paths and have only a small space overhead.
466 */
Al Viro9a677342017-03-21 12:02:25 -0400467static inline unsigned long
468raw_copy_from_user(void *to, const void __user *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Al Viro9a677342017-03-21 12:02:25 -0400470 prefetchw(to);
Al Viro8cd920f2017-03-19 16:11:13 -0400471 __copy_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return n;
473}
474
Al Viro9a677342017-03-21 12:02:25 -0400475static inline unsigned long
476raw_copy_to_user(void __user *to, const void *from, unsigned long n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Al Viro9a677342017-03-21 12:02:25 -0400478 prefetch(from);
Michael S. Tsirkin0ab06602015-01-06 15:11:13 +0200479 __copy_user(to, from, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return n;
481}
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483long __must_check strncpy_from_user(char *dst, const char __user *src,
484 long count);
485long __must_check __strncpy_from_user(char *dst,
486 const char __user *src, long count);
487
488/**
489 * __clear_user: - Zero a block of memory in user space, with less checking.
490 * @to: Destination address, in user space.
491 * @n: Number of bytes to zero.
492 *
493 * Zero a block of memory in user space. Caller must check
494 * the specified block with access_ok() before calling this function.
495 *
496 * Returns number of bytes that could not be cleared.
497 * On success, this will be zero.
498 */
499unsigned long __clear_user(void __user *mem, unsigned long len);
500
501/**
502 * clear_user: - Zero a block of memory in user space.
503 * @to: Destination address, in user space.
504 * @n: Number of bytes to zero.
505 *
506 * Zero a block of memory in user space. Caller must check
507 * the specified block with access_ok() before calling this function.
508 *
509 * Returns number of bytes that could not be cleared.
510 * On success, this will be zero.
511 */
512unsigned long clear_user(void __user *mem, unsigned long len);
513
514/**
515 * strlen_user: - Get the size of a string in user space.
516 * @str: The string to measure.
517 *
David Hildenbrandb3c395ef2015-05-11 17:52:08 +0200518 * Context: User context only. This function may sleep if pagefaults are
519 * enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 *
521 * Get the size of a NUL-terminated string in user space.
522 *
523 * Returns the size of the string INCLUDING the terminating NUL.
524 * On exception, returns 0.
525 *
526 * If there is a limit on the length of a valid string, you may wish to
527 * consider using strnlen_user() instead.
528 */
529#define strlen_user(str) strnlen_user(str, ~0UL >> 1)
530long strnlen_user(const char __user *str, long n);
531
532#endif /* _ASM_M32R_UACCESS_H */