1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5294825Shselasky * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 6289565Shselasky * Copyright (c) 2015 Fran��ois Tigeot 7219820Sjeff * All rights reserved. 8219820Sjeff * 9219820Sjeff * Redistribution and use in source and binary forms, with or without 10219820Sjeff * modification, are permitted provided that the following conditions 11219820Sjeff * are met: 12219820Sjeff * 1. Redistributions of source code must retain the above copyright 13219820Sjeff * notice unmodified, this list of conditions, and the following 14219820Sjeff * disclaimer. 15219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 16219820Sjeff * notice, this list of conditions and the following disclaimer in the 17219820Sjeff * documentation and/or other materials provided with the distribution. 18219820Sjeff * 19219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29289644Shselasky * 30289644Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/uaccess.h 329978 2018-02-25 10:47:33Z hselasky $ 31219820Sjeff */ 32328653Shselasky 33219820Sjeff#ifndef _LINUX_UACCESS_H_ 34219820Sjeff#define _LINUX_UACCESS_H_ 35219820Sjeff 36328653Shselasky#include <sys/param.h> 37328653Shselasky#include <sys/lock.h> 38328653Shselasky#include <sys/proc.h> 39328653Shselasky 40328653Shselasky#include <vm/vm.h> 41328653Shselasky#include <vm/vm_extern.h> 42328653Shselasky 43289593Shselasky#include <linux/compiler.h> 44289593Shselasky 45328653Shselasky#define VERIFY_READ VM_PROT_READ 46328653Shselasky#define VERIFY_WRITE VM_PROT_WRITE 47328653Shselasky 48299530Shselasky#define __get_user(_x, _p) ({ \ 49299530Shselasky int __err; \ 50299530Shselasky __typeof(*(_p)) __x; \ 51299530Shselasky __err = linux_copyin((_p), &(__x), sizeof(*(_p))); \ 52299530Shselasky (_x) = __x; \ 53299530Shselasky __err; \ 54294825Shselasky}) 55299530Shselasky 56299530Shselasky#define __put_user(_x, _p) ({ \ 57299530Shselasky __typeof(*(_p)) __x = (_x); \ 58299530Shselasky linux_copyout(&(__x), (_p), sizeof(*(_p))); \ 59294825Shselasky}) 60299530Shselasky#define get_user(_x, _p) linux_copyin((_p), &(_x), sizeof(*(_p))) 61329978Shselasky#define put_user(_x, _p) __put_user(_x, _p) 62328653Shselasky#define clear_user(...) linux_clear_user(__VA_ARGS__) 63328653Shselasky#define access_ok(...) linux_access_ok(__VA_ARGS__) 64219820Sjeff 65299530Shselaskyextern int linux_copyin(const void *uaddr, void *kaddr, size_t len); 66299530Shselaskyextern int linux_copyout(const void *kaddr, void *uaddr, size_t len); 67328653Shselaskyextern size_t linux_clear_user(void *uaddr, size_t len); 68328653Shselaskyextern int linux_access_ok(int rw, const void *uaddr, size_t len); 69299530Shselasky 70289593Shselasky/* 71328653Shselasky * NOTE: Each pagefault_disable() call must have a corresponding 72328653Shselasky * pagefault_enable() call in the same scope. The former creates a new 73328653Shselasky * block and defines a temporary variable, and the latter uses the 74328653Shselasky * temporary variable and closes the block. Failure to balance the 75328653Shselasky * calls will result in a compile-time error. 76289593Shselasky */ 77328653Shselasky#define pagefault_disable(void) do { \ 78328653Shselasky int __saved_pflags = \ 79328653Shselasky vm_fault_disable_pagefaults() 80289565Shselasky 81328653Shselasky#define pagefault_enable(void) \ 82328653Shselasky vm_fault_enable_pagefaults(__saved_pflags); \ 83328653Shselasky} while (0) 84328653Shselasky 85328653Shselaskystatic inline bool 86328653Shselaskypagefault_disabled(void) 87289565Shselasky{ 88328653Shselasky return ((curthread->td_pflags & TDP_NOFAULTING) != 0); 89289565Shselasky} 90289565Shselasky 91328653Shselasky#endif /* _LINUX_UACCESS_H_ */ 92