18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 48c2ecf20Sopenharmony_ci * Copyright (C) 2015 Richard Weinberger (richard@nod.at) 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __UM_UACCESS_H 88c2ecf20Sopenharmony_ci#define __UM_UACCESS_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <asm/elf.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define __under_task_size(addr, size) \ 138c2ecf20Sopenharmony_ci (((unsigned long) (addr) < TASK_SIZE) && \ 148c2ecf20Sopenharmony_ci (((unsigned long) (addr) + (size)) < TASK_SIZE)) 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define __access_ok_vsyscall(addr, size) \ 178c2ecf20Sopenharmony_ci (((unsigned long) (addr) >= FIXADDR_USER_START) && \ 188c2ecf20Sopenharmony_ci ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \ 198c2ecf20Sopenharmony_ci ((unsigned long) (addr) + (size) >= (unsigned long)(addr))) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define __addr_range_nowrap(addr, size) \ 228c2ecf20Sopenharmony_ci ((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciextern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n); 258c2ecf20Sopenharmony_ciextern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n); 268c2ecf20Sopenharmony_ciextern long __strncpy_from_user(char *dst, const char __user *src, long count); 278c2ecf20Sopenharmony_ciextern long __strnlen_user(const void __user *str, long len); 288c2ecf20Sopenharmony_ciextern unsigned long __clear_user(void __user *mem, unsigned long len); 298c2ecf20Sopenharmony_cistatic inline int __access_ok(unsigned long addr, unsigned long size); 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* Teach asm-generic/uaccess.h that we have C functions for these. */ 328c2ecf20Sopenharmony_ci#define __access_ok __access_ok 338c2ecf20Sopenharmony_ci#define __clear_user __clear_user 348c2ecf20Sopenharmony_ci#define __strnlen_user __strnlen_user 358c2ecf20Sopenharmony_ci#define __strncpy_from_user __strncpy_from_user 368c2ecf20Sopenharmony_ci#define INLINE_COPY_FROM_USER 378c2ecf20Sopenharmony_ci#define INLINE_COPY_TO_USER 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <asm-generic/uaccess.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic inline int __access_ok(unsigned long addr, unsigned long size) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci return __addr_range_nowrap(addr, size) && 448c2ecf20Sopenharmony_ci (__under_task_size(addr, size) || 458c2ecf20Sopenharmony_ci __access_ok_vsyscall(addr, size) || 468c2ecf20Sopenharmony_ci uaccess_kernel()); 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#endif 50