0001
0002 #ifndef _LINUX_MMAN_H
0003 #define _LINUX_MMAN_H
0004
0005 #include <linux/mm.h>
0006 #include <linux/percpu_counter.h>
0007
0008 #include <linux/atomic.h>
0009 #include <uapi/linux/mman.h>
0010
0011
0012
0013
0014
0015 #ifndef MAP_32BIT
0016 #define MAP_32BIT 0
0017 #endif
0018 #ifndef MAP_HUGE_2MB
0019 #define MAP_HUGE_2MB 0
0020 #endif
0021 #ifndef MAP_HUGE_1GB
0022 #define MAP_HUGE_1GB 0
0023 #endif
0024 #ifndef MAP_UNINITIALIZED
0025 #define MAP_UNINITIALIZED 0
0026 #endif
0027 #ifndef MAP_SYNC
0028 #define MAP_SYNC 0
0029 #endif
0030
0031
0032
0033
0034
0035
0036
0037
0038 #define LEGACY_MAP_MASK (MAP_SHARED \
0039 | MAP_PRIVATE \
0040 | MAP_FIXED \
0041 | MAP_ANONYMOUS \
0042 | MAP_DENYWRITE \
0043 | MAP_EXECUTABLE \
0044 | MAP_UNINITIALIZED \
0045 | MAP_GROWSDOWN \
0046 | MAP_LOCKED \
0047 | MAP_NORESERVE \
0048 | MAP_POPULATE \
0049 | MAP_NONBLOCK \
0050 | MAP_STACK \
0051 | MAP_HUGETLB \
0052 | MAP_32BIT \
0053 | MAP_HUGE_2MB \
0054 | MAP_HUGE_1GB)
0055
0056 extern int sysctl_overcommit_memory;
0057 extern int sysctl_overcommit_ratio;
0058 extern unsigned long sysctl_overcommit_kbytes;
0059 extern struct percpu_counter vm_committed_as;
0060
0061 #ifdef CONFIG_SMP
0062 extern s32 vm_committed_as_batch;
0063 extern void mm_compute_batch(int overcommit_policy);
0064 #else
0065 #define vm_committed_as_batch 0
0066 static inline void mm_compute_batch(int overcommit_policy)
0067 {
0068 }
0069 #endif
0070
0071 unsigned long vm_memory_committed(void);
0072
0073 static inline void vm_acct_memory(long pages)
0074 {
0075 percpu_counter_add_batch(&vm_committed_as, pages, vm_committed_as_batch);
0076 }
0077
0078 static inline void vm_unacct_memory(long pages)
0079 {
0080 vm_acct_memory(-pages);
0081 }
0082
0083
0084
0085
0086
0087
0088 #ifndef arch_calc_vm_prot_bits
0089 #define arch_calc_vm_prot_bits(prot, pkey) 0
0090 #endif
0091
0092 #ifndef arch_calc_vm_flag_bits
0093 #define arch_calc_vm_flag_bits(flags) 0
0094 #endif
0095
0096 #ifndef arch_validate_prot
0097
0098
0099
0100
0101
0102
0103 static inline bool arch_validate_prot(unsigned long prot, unsigned long addr)
0104 {
0105 return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0;
0106 }
0107 #define arch_validate_prot arch_validate_prot
0108 #endif
0109
0110 #ifndef arch_validate_flags
0111
0112
0113
0114
0115
0116 static inline bool arch_validate_flags(unsigned long flags)
0117 {
0118 return true;
0119 }
0120 #define arch_validate_flags arch_validate_flags
0121 #endif
0122
0123
0124
0125
0126
0127
0128
0129 #define _calc_vm_trans(x, bit1, bit2) \
0130 ((!(bit1) || !(bit2)) ? 0 : \
0131 ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
0132 : ((x) & (bit1)) / ((bit1) / (bit2))))
0133
0134
0135
0136
0137 static inline unsigned long
0138 calc_vm_prot_bits(unsigned long prot, unsigned long pkey)
0139 {
0140 return _calc_vm_trans(prot, PROT_READ, VM_READ ) |
0141 _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
0142 _calc_vm_trans(prot, PROT_EXEC, VM_EXEC) |
0143 arch_calc_vm_prot_bits(prot, pkey);
0144 }
0145
0146
0147
0148
0149 static inline unsigned long
0150 calc_vm_flag_bits(unsigned long flags)
0151 {
0152 return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
0153 _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) |
0154 _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) |
0155 arch_calc_vm_flag_bits(flags);
0156 }
0157
0158 unsigned long vm_commit_limit(void);
0159 #endif