Alex Dewar | f2f4bf5 | 2019-08-25 10:49:19 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 4 | * Copyright (C) 2015 Richard Weinberger (richard@nod.at) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __UM_UACCESS_H |
| 8 | #define __UM_UACCESS_H |
| 9 | |
Al Viro | fced95c | 2011-08-18 20:08:49 +0100 | [diff] [blame] | 10 | #include <asm/elf.h> |
Christoph Hellwig | 8bb227a | 2021-12-15 17:56:12 +0100 | [diff] [blame] | 11 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Al Viro | fced95c | 2011-08-18 20:08:49 +0100 | [diff] [blame] | 13 | #define __under_task_size(addr, size) \ |
| 14 | (((unsigned long) (addr) < TASK_SIZE) && \ |
| 15 | (((unsigned long) (addr) + (size)) < TASK_SIZE)) |
| 16 | |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 17 | #define __access_ok_vsyscall(addr, size) \ |
| 18 | (((unsigned long) (addr) >= FIXADDR_USER_START) && \ |
Al Viro | fced95c | 2011-08-18 20:08:49 +0100 | [diff] [blame] | 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 | |
Al Viro | a668ce3 | 2017-03-28 01:33:09 -0400 | [diff] [blame] | 25 | extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n); |
| 26 | extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n); |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 27 | extern unsigned long __clear_user(void __user *mem, unsigned long len); |
| 28 | static inline int __access_ok(unsigned long addr, unsigned long size); |
Al Viro | fced95c | 2011-08-18 20:08:49 +0100 | [diff] [blame] | 29 | |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 30 | /* Teach asm-generic/uaccess.h that we have C functions for these. */ |
| 31 | #define __access_ok __access_ok |
| 32 | #define __clear_user __clear_user |
Arnd Bergmann | 166ec46 | 2020-01-17 17:26:54 +0100 | [diff] [blame] | 33 | |
Al Viro | a668ce3 | 2017-03-28 01:33:09 -0400 | [diff] [blame] | 34 | #define INLINE_COPY_FROM_USER |
| 35 | #define INLINE_COPY_TO_USER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 37 | #include <asm-generic/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 39 | static inline int __access_ok(unsigned long addr, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 41 | return __addr_range_nowrap(addr, size) && |
| 42 | (__under_task_size(addr, size) || |
Christoph Hellwig | 8bb227a | 2021-12-15 17:56:12 +0100 | [diff] [blame] | 43 | __access_ok_vsyscall(addr, size)); |
Richard Weinberger | f8d65d2 | 2015-05-12 00:17:28 +0200 | [diff] [blame] | 44 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Christoph Hellwig | 8bb227a | 2021-12-15 17:56:12 +0100 | [diff] [blame] | 46 | /* no pagefaults for kernel addresses in um */ |
| 47 | #define HAVE_GET_KERNEL_NOFAULT 1 |
| 48 | |
| 49 | #define __get_kernel_nofault(dst, src, type, err_label) \ |
| 50 | do { \ |
| 51 | *((type *)dst) = get_unaligned((type *)(src)); \ |
| 52 | if (0) /* make sure the label looks used to the compiler */ \ |
| 53 | goto err_label; \ |
| 54 | } while (0) |
| 55 | |
| 56 | #define __put_kernel_nofault(dst, src, type, err_label) \ |
| 57 | do { \ |
| 58 | put_unaligned(*((type *)src), (type *)(dst)); \ |
| 59 | if (0) /* make sure the label looks used to the compiler */ \ |
| 60 | goto err_label; \ |
| 61 | } while (0) |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #endif |