xref: /linux/arch/um/include/asm/uaccess.h (revision 2d7eaeb05ae265bd64270376e6a2c0d80244771f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
4  * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
5  */
6 
7 #ifndef __UM_UACCESS_H
8 #define __UM_UACCESS_H
9 
10 #include <asm/elf.h>
11 #include <linux/unaligned.h>
12 #include <sysdep/faultinfo.h>
13 
14 #define __under_task_size(addr, size) \
15 	(((unsigned long) (addr) < TASK_SIZE) && \
16 	 (((unsigned long) (addr) + (size)) < TASK_SIZE))
17 
18 #define __addr_range_nowrap(addr, size) \
19 	((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
20 
21 #ifdef CONFIG_MMU
22 extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
23 extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
24 extern unsigned long __clear_user(void __user *mem, unsigned long len);
25 static inline int __access_ok(const void __user *ptr, unsigned long size);
26 
27 /* Teach asm-generic/uaccess.h that we have C functions for these. */
28 #define __access_ok __access_ok
29 #define __clear_user __clear_user
30 
31 #define INLINE_COPY_USER
32 
33 static inline int __access_ok(const void __user *ptr, unsigned long size)
34 {
35 	unsigned long addr = (unsigned long)ptr;
36 	return __addr_range_nowrap(addr, size) && __under_task_size(addr, size);
37 }
38 
39 #define __get_kernel_nofault(dst, src, type, err_label)			\
40 do {									\
41 	int __faulted;							\
42 									\
43 	___backtrack_faulted(__faulted);				\
44 	if (__faulted) {						\
45 		*((type *)dst) = (type) 0;				\
46 		goto err_label;						\
47 	}								\
48 	*((type *)dst) = get_unaligned((type *)(src));			\
49 	barrier();							\
50 	current->thread.segv_continue = NULL;				\
51 } while (0)
52 
53 #define __put_kernel_nofault(dst, src, type, err_label)			\
54 do {									\
55 	int __faulted;							\
56 									\
57 	___backtrack_faulted(__faulted);				\
58 	if (__faulted)							\
59 		goto err_label;						\
60 	put_unaligned(*((type *)src), (type *)(dst));			\
61 	barrier();							\
62 	current->thread.segv_continue = NULL;				\
63 } while (0)
64 #endif
65 
66 #include <asm-generic/uaccess.h>
67 
68 #endif
69