Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v4.6-rc2 52 lines 1.8 kB view raw
1/* 2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 3 * Copyright (C) 2015 Richard Weinberger (richard@nod.at) 4 * Licensed under the GPL 5 */ 6 7#ifndef __UM_UACCESS_H 8#define __UM_UACCESS_H 9 10#include <asm/thread_info.h> 11#include <asm/elf.h> 12 13#define __under_task_size(addr, size) \ 14 (((unsigned long) (addr) < TASK_SIZE) && \ 15 (((unsigned long) (addr) + (size)) < TASK_SIZE)) 16 17#define __access_ok_vsyscall(addr, size) \ 18 (((unsigned long) (addr) >= FIXADDR_USER_START) && \ 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 25extern long __copy_from_user(void *to, const void __user *from, unsigned long n); 26extern long __copy_to_user(void __user *to, const void *from, unsigned long n); 27extern long __strncpy_from_user(char *dst, const char __user *src, long count); 28extern long __strnlen_user(const void __user *str, long len); 29extern unsigned long __clear_user(void __user *mem, unsigned long len); 30static inline int __access_ok(unsigned long addr, unsigned long size); 31 32/* Teach asm-generic/uaccess.h that we have C functions for these. */ 33#define __access_ok __access_ok 34#define __clear_user __clear_user 35#define __copy_to_user __copy_to_user 36#define __copy_from_user __copy_from_user 37#define __strnlen_user __strnlen_user 38#define __strncpy_from_user __strncpy_from_user 39#define __copy_to_user_inatomic __copy_to_user 40#define __copy_from_user_inatomic __copy_from_user 41 42#include <asm-generic/uaccess.h> 43 44static inline int __access_ok(unsigned long addr, unsigned long size) 45{ 46 return __addr_range_nowrap(addr, size) && 47 (__under_task_size(addr, size) || 48 __access_ok_vsyscall(addr, size) || 49 segment_eq(get_fs(), KERNEL_DS)); 50} 51 52#endif