• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _LINUX_MMAP_LOCK_H
2 #define _LINUX_MMAP_LOCK_H
3 
4 #include <linux/mmdebug.h>
5 
6 #define MMAP_LOCK_INITIALIZER(name) \
7 	.mmap_lock = __RWSEM_INITIALIZER((name).mmap_lock),
8 
mmap_init_lock(struct mm_struct * mm)9 static inline void mmap_init_lock(struct mm_struct *mm)
10 {
11 	init_rwsem(&mm->mmap_lock);
12 }
13 
mmap_write_lock(struct mm_struct * mm)14 static inline void mmap_write_lock(struct mm_struct *mm)
15 {
16 	down_write(&mm->mmap_lock);
17 }
18 
mmap_write_lock_nested(struct mm_struct * mm,int subclass)19 static inline void mmap_write_lock_nested(struct mm_struct *mm, int subclass)
20 {
21 	down_write_nested(&mm->mmap_lock, subclass);
22 }
23 
mmap_write_lock_killable(struct mm_struct * mm)24 static inline int mmap_write_lock_killable(struct mm_struct *mm)
25 {
26 	return down_write_killable(&mm->mmap_lock);
27 }
28 
mmap_write_trylock(struct mm_struct * mm)29 static inline bool mmap_write_trylock(struct mm_struct *mm)
30 {
31 	return down_write_trylock(&mm->mmap_lock) != 0;
32 }
33 
mmap_write_unlock(struct mm_struct * mm)34 static inline void mmap_write_unlock(struct mm_struct *mm)
35 {
36 	up_write(&mm->mmap_lock);
37 }
38 
mmap_write_downgrade(struct mm_struct * mm)39 static inline void mmap_write_downgrade(struct mm_struct *mm)
40 {
41 	downgrade_write(&mm->mmap_lock);
42 }
43 
mmap_read_lock(struct mm_struct * mm)44 static inline void mmap_read_lock(struct mm_struct *mm)
45 {
46 	down_read(&mm->mmap_lock);
47 }
48 
mmap_read_lock_killable(struct mm_struct * mm)49 static inline int mmap_read_lock_killable(struct mm_struct *mm)
50 {
51 	return down_read_killable(&mm->mmap_lock);
52 }
53 
mmap_read_trylock(struct mm_struct * mm)54 static inline bool mmap_read_trylock(struct mm_struct *mm)
55 {
56 	return down_read_trylock(&mm->mmap_lock) != 0;
57 }
58 
mmap_read_unlock(struct mm_struct * mm)59 static inline void mmap_read_unlock(struct mm_struct *mm)
60 {
61 	up_read(&mm->mmap_lock);
62 }
63 
mmap_read_trylock_non_owner(struct mm_struct * mm)64 static inline bool mmap_read_trylock_non_owner(struct mm_struct *mm)
65 {
66 	if (down_read_trylock(&mm->mmap_lock)) {
67 		rwsem_release(&mm->mmap_lock.dep_map, _RET_IP_);
68 		return true;
69 	}
70 	return false;
71 }
72 
mmap_read_unlock_non_owner(struct mm_struct * mm)73 static inline void mmap_read_unlock_non_owner(struct mm_struct *mm)
74 {
75 	up_read_non_owner(&mm->mmap_lock);
76 }
77 
mmap_assert_locked(struct mm_struct * mm)78 static inline void mmap_assert_locked(struct mm_struct *mm)
79 {
80 	lockdep_assert_held(&mm->mmap_lock);
81 	VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
82 }
83 
mmap_assert_write_locked(struct mm_struct * mm)84 static inline void mmap_assert_write_locked(struct mm_struct *mm)
85 {
86 	lockdep_assert_held_write(&mm->mmap_lock);
87 	VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
88 }
89 
mmap_lock_is_contended(struct mm_struct * mm)90 static inline int mmap_lock_is_contended(struct mm_struct *mm)
91 {
92 	return rwsem_is_contended(&mm->mmap_lock);
93 }
94 
95 #endif /* _LINUX_MMAP_LOCK_H */
96