^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __UM_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __UM_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define __under_task_size(addr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) (((unsigned long) (addr) < TASK_SIZE) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) (((unsigned long) (addr) + (size)) < TASK_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define __access_ok_vsyscall(addr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) (((unsigned long) (addr) >= FIXADDR_USER_START) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define __addr_range_nowrap(addr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) extern long __strncpy_from_user(char *dst, const char __user *src, long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) extern long __strnlen_user(const void __user *str, long len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) extern unsigned long __clear_user(void __user *mem, unsigned long len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static inline int __access_ok(unsigned long addr, unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Teach asm-generic/uaccess.h that we have C functions for these. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define __access_ok __access_ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define __clear_user __clear_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define __strnlen_user __strnlen_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define __strncpy_from_user __strncpy_from_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define INLINE_COPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define INLINE_COPY_TO_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm-generic/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static inline int __access_ok(unsigned long addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return __addr_range_nowrap(addr, size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) (__under_task_size(addr, size) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) __access_ok_vsyscall(addr, size) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) uaccess_kernel());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #endif