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 extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n); 22 extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n); 23 extern unsigned long __clear_user(void __user *mem, unsigned long len); 24 static inline int __access_ok(const void __user *ptr, unsigned long size); 25 26 /* Teach asm-generic/uaccess.h that we have C functions for these. */ 27 #define __access_ok __access_ok 28 #define __clear_user __clear_user 29 30 #define INLINE_COPY_USER 31 32 #include <asm-generic/uaccess.h> 33 34 static inline int __access_ok(const void __user *ptr, unsigned long size) 35 { 36 unsigned long addr = (unsigned long)ptr; 37 return __addr_range_nowrap(addr, size) && __under_task_size(addr, size); 38 } 39 40 #define __get_kernel_nofault(dst, src, type, err_label) \ 41 do { \ 42 int __faulted; \ 43 \ 44 ___backtrack_faulted(__faulted); \ 45 if (__faulted) { \ 46 *((type *)dst) = (type) 0; \ 47 goto err_label; \ 48 } \ 49 *((type *)dst) = get_unaligned((type *)(src)); \ 50 barrier(); \ 51 current->thread.segv_continue = NULL; \ 52 } while (0) 53 54 #define __put_kernel_nofault(dst, src, type, err_label) \ 55 do { \ 56 int __faulted; \ 57 \ 58 ___backtrack_faulted(__faulted); \ 59 if (__faulted) \ 60 goto err_label; \ 61 put_unaligned(*((type *)src), (type *)(dst)); \ 62 barrier(); \ 63 current->thread.segv_continue = NULL; \ 64 } while (0) 65 66 #endif 67