1995c3b88SEmmanuel Vadot /*-
2995c3b88SEmmanuel Vadot  * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
3995c3b88SEmmanuel Vadot  *
4995c3b88SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
5995c3b88SEmmanuel Vadot  * modification, are permitted provided that the following conditions
6995c3b88SEmmanuel Vadot  * are met:
7995c3b88SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
8995c3b88SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
9995c3b88SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
10995c3b88SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
11995c3b88SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
12995c3b88SEmmanuel Vadot  *
13995c3b88SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14995c3b88SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15995c3b88SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16995c3b88SEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17995c3b88SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18995c3b88SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19995c3b88SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20995c3b88SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21995c3b88SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22995c3b88SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23995c3b88SEmmanuel Vadot  * SUCH DAMAGE.
24995c3b88SEmmanuel Vadot  *
25995c3b88SEmmanuel Vadot  */
26995c3b88SEmmanuel Vadot 
27995c3b88SEmmanuel Vadot #ifndef _LINUXKPI_LINUX_MMAP_LOCK_H_
28995c3b88SEmmanuel Vadot #define	_LINUXKPI_LINUX_MMAP_LOCK_H_
29995c3b88SEmmanuel Vadot 
30995c3b88SEmmanuel Vadot #include <linux/mm_types.h>
31995c3b88SEmmanuel Vadot #include <linux/rwsem.h>
32995c3b88SEmmanuel Vadot 
33995c3b88SEmmanuel Vadot static inline void
mmap_read_lock(struct mm_struct * mm)34995c3b88SEmmanuel Vadot mmap_read_lock(struct mm_struct *mm)
35995c3b88SEmmanuel Vadot {
36995c3b88SEmmanuel Vadot 
37995c3b88SEmmanuel Vadot 	down_read(&mm->mmap_sem);
38995c3b88SEmmanuel Vadot }
39995c3b88SEmmanuel Vadot 
40995c3b88SEmmanuel Vadot static inline void
mmap_read_unlock(struct mm_struct * mm)41995c3b88SEmmanuel Vadot mmap_read_unlock(struct mm_struct *mm)
42995c3b88SEmmanuel Vadot {
43995c3b88SEmmanuel Vadot 
44995c3b88SEmmanuel Vadot 	up_read(&mm->mmap_sem);
45995c3b88SEmmanuel Vadot }
46995c3b88SEmmanuel Vadot 
47995c3b88SEmmanuel Vadot static inline void
mmap_write_lock_killable(struct mm_struct * mm)48995c3b88SEmmanuel Vadot mmap_write_lock_killable(struct mm_struct *mm)
49995c3b88SEmmanuel Vadot {
50995c3b88SEmmanuel Vadot 
51995c3b88SEmmanuel Vadot 	down_write_killable(&mm->mmap_sem);
52995c3b88SEmmanuel Vadot }
53995c3b88SEmmanuel Vadot 
54995c3b88SEmmanuel Vadot #endif	/* _LINUXKPI_LINUX_MMAP_LOCK_H_ */
55