| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2002 Jeff Dike ([email protected]) |
| 4 |
* Copyright (C) 2015 Richard Weinberger ([email protected]) |
| 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_FROM_USER |
| 31 |
#define INLINE_COPY_TO_USER |
| 32 |
|
| 33 |
#include <asm-generic/uaccess.h> |
| 34 |
|
| 35 |
static inline int __access_ok(const void __user *ptr, unsigned long size) |
| 36 |
{ |
| 37 |
unsigned long addr = (unsigned long)ptr; |
| 38 |
return __addr_range_nowrap(addr, size) && __under_task_size(addr, size); |
| 39 |
} |
| 40 |
|
| 41 |
#define __get_kernel_nofault(dst, src, type, err_label) \ |
| 42 |
do { \ |
| 43 |
int __faulted; \ |
| 44 |
\ |
| 45 |
___backtrack_faulted(__faulted); \ |
| 46 |
if (__faulted) { \ |
| 47 |
*((type *)dst) = (type) 0; \ |
| 48 |
goto err_label; \ |
| 49 |
} \ |
| 50 |
*((type *)dst) = get_unaligned((type *)(src)); \ |
| 51 |
barrier(); \ |
| 52 |
current->thread.segv_continue = NULL; \ |
| 53 |
} while (0) |
| 54 |
|
| 55 |
#define __put_kernel_nofault(dst, src, type, err_label) \ |
| 56 |
do { \ |
| 57 |
int __faulted; \ |
| 58 |
\ |
| 59 |
___backtrack_faulted(__faulted); \ |
| 60 |
if (__faulted) \ |
| 61 |
goto err_label; \ |
| 62 |
put_unaligned(*((type *)src), (type *)(dst)); \ |
| 63 |
barrier(); \ |
| 64 |
current->thread.segv_continue = NULL; \ |
| 65 |
} while (0) |
| 66 |
|
| 67 |
#endif |