]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - include/linux/mman.h
mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags
[mirror_ubuntu-bionic-kernel.git] / include / linux / mman.h
index c8367041fafde6e761044e7d77fb25736e58a863..74452e3f25360e39d663550382533ba1352a5f0a 100644 (file)
@@ -7,6 +7,45 @@
 #include <linux/atomic.h>
 #include <uapi/linux/mman.h>
 
+/*
+ * Arrange for legacy / undefined architecture specific flags to be
+ * ignored by default in LEGACY_MAP_MASK.
+ */
+#ifndef MAP_32BIT
+#define MAP_32BIT 0
+#endif
+#ifndef MAP_HUGE_2MB
+#define MAP_HUGE_2MB 0
+#endif
+#ifndef MAP_HUGE_1GB
+#define MAP_HUGE_1GB 0
+#endif
+#ifndef MAP_UNINITIALIZED
+#define MAP_UNINITIALIZED 0
+#endif
+
+/*
+ * The historical set of flags that all mmap implementations implicitly
+ * support when a ->mmap_validate() op is not provided in file_operations.
+ */
+#define LEGACY_MAP_MASK (MAP_SHARED \
+               | MAP_PRIVATE \
+               | MAP_FIXED \
+               | MAP_ANONYMOUS \
+               | MAP_DENYWRITE \
+               | MAP_EXECUTABLE \
+               | MAP_UNINITIALIZED \
+               | MAP_GROWSDOWN \
+               | MAP_LOCKED \
+               | MAP_NORESERVE \
+               | MAP_POPULATE \
+               | MAP_NONBLOCK \
+               | MAP_STACK \
+               | MAP_HUGETLB \
+               | MAP_32BIT \
+               | MAP_HUGE_2MB \
+               | MAP_HUGE_1GB)
+
 extern int sysctl_overcommit_memory;
 extern int sysctl_overcommit_ratio;
 extern unsigned long sysctl_overcommit_kbytes;
@@ -63,8 +102,9 @@ static inline bool arch_validate_prot(unsigned long prot)
  * ("bit1" and "bit2" must be single bits)
  */
 #define _calc_vm_trans(x, bit1, bit2) \
+  ((!(bit1) || !(bit2)) ? 0 : \
   ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
-   : ((x) & (bit1)) / ((bit1) / (bit2)))
+   : ((x) & (bit1)) / ((bit1) / (bit2))))
 
 /*
  * Combine the mmap "prot" argument into "vm_flags" used internally.