]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_MMAN_H |
3 | #define _LINUX_MMAN_H | |
4 | ||
9cdcb566 | 5 | #include <linux/mm.h> |
00a62ce9 | 6 | #include <linux/percpu_counter.h> |
9cdcb566 | 7 | |
60063497 | 8 | #include <linux/atomic.h> |
607ca46e | 9 | #include <uapi/linux/mman.h> |
9cdcb566 | 10 | |
1c972597 DW |
11 | /* |
12 | * Arrange for legacy / undefined architecture specific flags to be | |
b6fb293f | 13 | * ignored by mmap handling code. |
1c972597 DW |
14 | */ |
15 | #ifndef MAP_32BIT | |
16 | #define MAP_32BIT 0 | |
17 | #endif | |
18 | #ifndef MAP_HUGE_2MB | |
19 | #define MAP_HUGE_2MB 0 | |
20 | #endif | |
21 | #ifndef MAP_HUGE_1GB | |
22 | #define MAP_HUGE_1GB 0 | |
23 | #endif | |
24 | #ifndef MAP_UNINITIALIZED | |
25 | #define MAP_UNINITIALIZED 0 | |
26 | #endif | |
b6fb293f JK |
27 | #ifndef MAP_SYNC |
28 | #define MAP_SYNC 0 | |
29 | #endif | |
1c972597 DW |
30 | |
31 | /* | |
32 | * The historical set of flags that all mmap implementations implicitly | |
33 | * support when a ->mmap_validate() op is not provided in file_operations. | |
3b8db39f DH |
34 | * |
35 | * MAP_EXECUTABLE is completely ignored throughout the kernel. | |
1c972597 DW |
36 | */ |
37 | #define LEGACY_MAP_MASK (MAP_SHARED \ | |
38 | | MAP_PRIVATE \ | |
39 | | MAP_FIXED \ | |
40 | | MAP_ANONYMOUS \ | |
41 | | MAP_DENYWRITE \ | |
42 | | MAP_EXECUTABLE \ | |
43 | | MAP_UNINITIALIZED \ | |
44 | | MAP_GROWSDOWN \ | |
45 | | MAP_LOCKED \ | |
46 | | MAP_NORESERVE \ | |
47 | | MAP_POPULATE \ | |
48 | | MAP_NONBLOCK \ | |
49 | | MAP_STACK \ | |
50 | | MAP_HUGETLB \ | |
51 | | MAP_32BIT \ | |
52 | | MAP_HUGE_2MB \ | |
53 | | MAP_HUGE_1GB) | |
54 | ||
1da177e4 LT |
55 | extern int sysctl_overcommit_memory; |
56 | extern int sysctl_overcommit_ratio; | |
49f0ce5f | 57 | extern unsigned long sysctl_overcommit_kbytes; |
00a62ce9 | 58 | extern struct percpu_counter vm_committed_as; |
1da177e4 | 59 | |
917d9290 TC |
60 | #ifdef CONFIG_SMP |
61 | extern s32 vm_committed_as_batch; | |
56f3547b | 62 | extern void mm_compute_batch(int overcommit_policy); |
917d9290 TC |
63 | #else |
64 | #define vm_committed_as_batch 0 | |
56f3547b FT |
65 | static inline void mm_compute_batch(int overcommit_policy) |
66 | { | |
67 | } | |
917d9290 TC |
68 | #endif |
69 | ||
997071bc S |
70 | unsigned long vm_memory_committed(void); |
71 | ||
1da177e4 LT |
72 | static inline void vm_acct_memory(long pages) |
73 | { | |
104b4e51 | 74 | percpu_counter_add_batch(&vm_committed_as, pages, vm_committed_as_batch); |
1da177e4 | 75 | } |
1da177e4 LT |
76 | |
77 | static inline void vm_unacct_memory(long pages) | |
78 | { | |
79 | vm_acct_memory(-pages); | |
80 | } | |
81 | ||
b845f313 | 82 | /* |
b3fbbea4 KB |
83 | * Allow architectures to handle additional protection and flag bits. The |
84 | * overriding macros must be defined in the arch-specific asm/mman.h file. | |
b845f313 DK |
85 | */ |
86 | ||
87 | #ifndef arch_calc_vm_prot_bits | |
e6bfb709 | 88 | #define arch_calc_vm_prot_bits(prot, pkey) 0 |
b845f313 DK |
89 | #endif |
90 | ||
b3fbbea4 KB |
91 | #ifndef arch_calc_vm_flag_bits |
92 | #define arch_calc_vm_flag_bits(flags) 0 | |
93 | #endif | |
94 | ||
b845f313 DK |
95 | #ifndef arch_vm_get_page_prot |
96 | #define arch_vm_get_page_prot(vm_flags) __pgprot(0) | |
97 | #endif | |
98 | ||
99 | #ifndef arch_validate_prot | |
100 | /* | |
101 | * This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have | |
102 | * already been masked out. | |
103 | * | |
104 | * Returns true if the prot flags are valid | |
105 | */ | |
9035cf9a | 106 | static inline bool arch_validate_prot(unsigned long prot, unsigned long addr) |
b845f313 DK |
107 | { |
108 | return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0; | |
109 | } | |
110 | #define arch_validate_prot arch_validate_prot | |
111 | #endif | |
112 | ||
c462ac28 CM |
113 | #ifndef arch_validate_flags |
114 | /* | |
115 | * This is called from mmap() and mprotect() with the updated vma->vm_flags. | |
116 | * | |
117 | * Returns true if the VM_* flags are valid. | |
118 | */ | |
119 | static inline bool arch_validate_flags(unsigned long flags) | |
120 | { | |
121 | return true; | |
122 | } | |
123 | #define arch_validate_flags arch_validate_flags | |
124 | #endif | |
125 | ||
1da177e4 LT |
126 | /* |
127 | * Optimisation macro. It is equivalent to: | |
128 | * (x & bit1) ? bit2 : 0 | |
129 | * but this version is faster. | |
130 | * ("bit1" and "bit2" must be single bits) | |
131 | */ | |
132 | #define _calc_vm_trans(x, bit1, bit2) \ | |
592e2545 | 133 | ((!(bit1) || !(bit2)) ? 0 : \ |
1da177e4 | 134 | ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \ |
592e2545 | 135 | : ((x) & (bit1)) / ((bit1) / (bit2)))) |
1da177e4 LT |
136 | |
137 | /* | |
138 | * Combine the mmap "prot" argument into "vm_flags" used internally. | |
139 | */ | |
140 | static inline unsigned long | |
e6bfb709 | 141 | calc_vm_prot_bits(unsigned long prot, unsigned long pkey) |
1da177e4 LT |
142 | { |
143 | return _calc_vm_trans(prot, PROT_READ, VM_READ ) | | |
144 | _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) | | |
b845f313 | 145 | _calc_vm_trans(prot, PROT_EXEC, VM_EXEC) | |
e6bfb709 | 146 | arch_calc_vm_prot_bits(prot, pkey); |
1da177e4 LT |
147 | } |
148 | ||
149 | /* | |
150 | * Combine the mmap "flags" argument into "vm_flags" used internally. | |
151 | */ | |
152 | static inline unsigned long | |
153 | calc_vm_flag_bits(unsigned long flags) | |
154 | { | |
155 | return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | | |
156 | _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) | | |
b6fb293f | 157 | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) | |
b3fbbea4 KB |
158 | _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) | |
159 | arch_calc_vm_flag_bits(flags); | |
1da177e4 | 160 | } |
00619bcc JM |
161 | |
162 | unsigned long vm_commit_limit(void); | |
1da177e4 | 163 | #endif /* _LINUX_MMAN_H */ |