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 | |
1da177e4 LT |
11 | extern int sysctl_overcommit_memory; |
12 | extern int sysctl_overcommit_ratio; | |
49f0ce5f | 13 | extern unsigned long sysctl_overcommit_kbytes; |
00a62ce9 | 14 | extern struct percpu_counter vm_committed_as; |
1da177e4 | 15 | |
917d9290 TC |
16 | #ifdef CONFIG_SMP |
17 | extern s32 vm_committed_as_batch; | |
18 | #else | |
19 | #define vm_committed_as_batch 0 | |
20 | #endif | |
21 | ||
997071bc S |
22 | unsigned long vm_memory_committed(void); |
23 | ||
1da177e4 LT |
24 | static inline void vm_acct_memory(long pages) |
25 | { | |
104b4e51 | 26 | percpu_counter_add_batch(&vm_committed_as, pages, vm_committed_as_batch); |
1da177e4 | 27 | } |
1da177e4 LT |
28 | |
29 | static inline void vm_unacct_memory(long pages) | |
30 | { | |
31 | vm_acct_memory(-pages); | |
32 | } | |
33 | ||
b845f313 DK |
34 | /* |
35 | * Allow architectures to handle additional protection bits | |
36 | */ | |
37 | ||
38 | #ifndef arch_calc_vm_prot_bits | |
e6bfb709 | 39 | #define arch_calc_vm_prot_bits(prot, pkey) 0 |
b845f313 DK |
40 | #endif |
41 | ||
42 | #ifndef arch_vm_get_page_prot | |
43 | #define arch_vm_get_page_prot(vm_flags) __pgprot(0) | |
44 | #endif | |
45 | ||
46 | #ifndef arch_validate_prot | |
47 | /* | |
48 | * This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have | |
49 | * already been masked out. | |
50 | * | |
51 | * Returns true if the prot flags are valid | |
52 | */ | |
949bed2f | 53 | static inline bool arch_validate_prot(unsigned long prot) |
b845f313 DK |
54 | { |
55 | return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0; | |
56 | } | |
57 | #define arch_validate_prot arch_validate_prot | |
58 | #endif | |
59 | ||
1da177e4 LT |
60 | /* |
61 | * Optimisation macro. It is equivalent to: | |
62 | * (x & bit1) ? bit2 : 0 | |
63 | * but this version is faster. | |
64 | * ("bit1" and "bit2" must be single bits) | |
65 | */ | |
66 | #define _calc_vm_trans(x, bit1, bit2) \ | |
f58a90e0 | 67 | ((!(bit1) || !(bit2)) ? 0 : \ |
1da177e4 | 68 | ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \ |
f58a90e0 | 69 | : ((x) & (bit1)) / ((bit1) / (bit2)))) |
1da177e4 LT |
70 | |
71 | /* | |
72 | * Combine the mmap "prot" argument into "vm_flags" used internally. | |
73 | */ | |
74 | static inline unsigned long | |
e6bfb709 | 75 | calc_vm_prot_bits(unsigned long prot, unsigned long pkey) |
1da177e4 LT |
76 | { |
77 | return _calc_vm_trans(prot, PROT_READ, VM_READ ) | | |
78 | _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) | | |
b845f313 | 79 | _calc_vm_trans(prot, PROT_EXEC, VM_EXEC) | |
e6bfb709 | 80 | arch_calc_vm_prot_bits(prot, pkey); |
1da177e4 LT |
81 | } |
82 | ||
83 | /* | |
84 | * Combine the mmap "flags" argument into "vm_flags" used internally. | |
85 | */ | |
86 | static inline unsigned long | |
87 | calc_vm_flag_bits(unsigned long flags) | |
88 | { | |
89 | return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | | |
90 | _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) | | |
09a9f1d2 | 91 | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ); |
1da177e4 | 92 | } |
00619bcc JM |
93 | |
94 | unsigned long vm_commit_limit(void); | |
1da177e4 | 95 | #endif /* _LINUX_MMAN_H */ |