uaccess.h revision 294825
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: head/sys/compat/linuxkpi/common/include/linux/uaccess.h 294825 2016-01-26 14:21:30Z hselasky $
31219820Sjeff */
32219820Sjeff#ifndef	_LINUX_UACCESS_H_
33219820Sjeff#define	_LINUX_UACCESS_H_
34219820Sjeff
35289593Shselasky#include <linux/compiler.h>
36289593Shselasky
37294825Shselasky#define	__get_user(_x, _p) ({				\
38294825Shselasky	int __err;					\
39294825Shselasky	__typeof(*(_p)) __x;				\
40294825Shselasky	__err = -copyin((_p), &(__x), sizeof(*(_p)));	\
41294825Shselasky	(_x) = __x;					\
42294825Shselasky	__err;						\
43294825Shselasky})
44294825Shselasky#define	__put_user(_x, _p) ({			\
45294825Shselasky	__typeof(*(_p)) __x = (_x);		\
46294825Shselasky	-copyout(&(__x), (_p), sizeof(*(_p)));	\
47294825Shselasky})
48219820Sjeff#define	get_user(_x, _p)	-copyin((_p), &(_x), sizeof(*(_p)))
49219820Sjeff#define	put_user(_x, _p)	-copyout(&(_x), (_p), sizeof(*(_p)))
50219820Sjeff
51289593Shselasky/*
52289593Shselasky * NOTE: The returned value from pagefault_disable() must be stored
53289593Shselasky * and passed to pagefault_enable(). Else possible recursion on the
54289593Shselasky * state can be lost.
55289593Shselasky */
56289593Shselaskystatic inline int __must_check
57289593Shselaskypagefault_disable(void)
58289565Shselasky{
59289593Shselasky	return (vm_fault_disable_pagefaults());
60289565Shselasky}
61289565Shselasky
62289593Shselaskystatic inline void
63289593Shselaskypagefault_enable(int save)
64289565Shselasky{
65289593Shselasky	vm_fault_enable_pagefaults(save);
66289565Shselasky}
67289565Shselasky
68219820Sjeff#endif	/* _LINUX_UACCESS_H_ */
69