xref: /freebsd/sys/compat/linuxkpi/common/include/linux/compat.h (revision 1e3db1de0cf6b904373e0f4c9e738b9713f3e17b)
18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
5*1e3db1deSHans Petter Selasky  * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky  * All rights reserved.
78d59ecb2SHans Petter Selasky  *
88d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky  * are met:
118d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky  *    disclaimer.
148d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky  *
188d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky  *
298d59ecb2SHans Petter Selasky  * $FreeBSD$
308d59ecb2SHans Petter Selasky  */
318d59ecb2SHans Petter Selasky #ifndef	_LINUX_COMPAT_H_
328d59ecb2SHans Petter Selasky #define	_LINUX_COMPAT_H_
338d59ecb2SHans Petter Selasky 
34*1e3db1deSHans Petter Selasky #include <sys/param.h>
35*1e3db1deSHans Petter Selasky #include <sys/proc.h>
36*1e3db1deSHans Petter Selasky #include <sys/malloc.h>
37*1e3db1deSHans Petter Selasky 
383ce12630SHans Petter Selasky struct thread;
393ce12630SHans Petter Selasky struct task_struct;
403ce12630SHans Petter Selasky 
41*1e3db1deSHans Petter Selasky extern int linux_alloc_current(struct thread *, int flags);
42*1e3db1deSHans Petter Selasky extern void linux_free_current(struct task_struct *);
43*1e3db1deSHans Petter Selasky 
44*1e3db1deSHans Petter Selasky static inline void
45*1e3db1deSHans Petter Selasky linux_set_current(struct thread *td)
46*1e3db1deSHans Petter Selasky {
47*1e3db1deSHans Petter Selasky 	if (__predict_false(td->td_lkpi_task == NULL))
48*1e3db1deSHans Petter Selasky 		linux_alloc_current(td, M_WAITOK);
49*1e3db1deSHans Petter Selasky }
50*1e3db1deSHans Petter Selasky 
51*1e3db1deSHans Petter Selasky static inline int
52*1e3db1deSHans Petter Selasky linux_set_current_flags(struct thread *td, int flags)
53*1e3db1deSHans Petter Selasky {
54*1e3db1deSHans Petter Selasky 	if (__predict_false(td->td_lkpi_task == NULL))
55*1e3db1deSHans Petter Selasky 		return (linux_alloc_current(td, flags));
56*1e3db1deSHans Petter Selasky 	return (0);
57*1e3db1deSHans Petter Selasky }
583ce12630SHans Petter Selasky 
598d59ecb2SHans Petter Selasky #endif	/* _LINUX_COMPAT_H_ */
60