xref: /openbmc/linux/arch/um/include/asm/uaccess.h (revision a2cce7a9)
1 /*
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
4  * Licensed under the GPL
5  */
6 
7 #ifndef __UM_UACCESS_H
8 #define __UM_UACCESS_H
9 
10 #include <asm/thread_info.h>
11 #include <asm/elf.h>
12 
13 #define __under_task_size(addr, size) \
14 	(((unsigned long) (addr) < TASK_SIZE) && \
15 	 (((unsigned long) (addr) + (size)) < TASK_SIZE))
16 
17 #define __access_ok_vsyscall(addr, size) \
18 	  (((unsigned long) (addr) >= FIXADDR_USER_START) && \
19 	  ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
20 	  ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
21 
22 #define __addr_range_nowrap(addr, size) \
23 	((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
24 
25 extern long __copy_from_user(void *to, const void __user *from, unsigned long n);
26 extern long __copy_to_user(void __user *to, const void *from, unsigned long n);
27 extern long __strncpy_from_user(char *dst, const char __user *src, long count);
28 extern long __strnlen_user(const void __user *str, long len);
29 extern unsigned long __clear_user(void __user *mem, unsigned long len);
30 static inline int __access_ok(unsigned long addr, unsigned long size);
31 
32 /* Teach asm-generic/uaccess.h that we have C functions for these. */
33 #define __access_ok __access_ok
34 #define __clear_user __clear_user
35 #define __copy_to_user __copy_to_user
36 #define __copy_from_user __copy_from_user
37 #define __strnlen_user __strnlen_user
38 #define __strncpy_from_user __strncpy_from_user
39 #define __copy_to_user_inatomic __copy_to_user
40 #define __copy_from_user_inatomic __copy_from_user
41 
42 #include <asm-generic/uaccess.h>
43 
44 static inline int __access_ok(unsigned long addr, unsigned long size)
45 {
46 	return __addr_range_nowrap(addr, size) &&
47 		(__under_task_size(addr, size) ||
48 		__access_ok_vsyscall(addr, size) ||
49 		segment_eq(get_fs(), KERNEL_DS));
50 }
51 
52 #endif
53