]> git.hungrycats.org Git - linux/commitdiff
[PATCH] Common PROT_xxx -> VM_xxx mapping
authorJamie Lokier <jamie@shareable.org>
Fri, 5 Sep 2003 04:42:15 +0000 (21:42 -0700)
committerLinus Torvalds <torvalds@home.osdl.org>
Fri, 5 Sep 2003 04:42:15 +0000 (21:42 -0700)
This moves the mapping of PROT_* bits to VM_* bits from mmap.c to the
common header file <linux/mman.h>.  The mapping is needed for mprotect
too.

include/linux/mman.h
mm/mmap.c

index a8956f6588adea55e0373cf59998068851c0e6cf..cfb6ac61bbdefc3c7cc07180c9be3f0e63e040a8 100644 (file)
@@ -2,6 +2,7 @@
 #define _LINUX_MMAN_H
 
 #include <linux/config.h>
+#include <linux/mm.h>
 
 #include <asm/atomic.h>
 #include <asm/mman.h>
@@ -27,4 +28,32 @@ static inline void vm_unacct_memory(long pages)
        vm_acct_memory(-pages);
 }
 
+/* Optimisation macro. */
+#define _calc_vm_trans(x,bit1,bit2) \
+  ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
+   : ((x) & (bit1)) / ((bit1) / (bit2)))
+
+/*
+ * Combine the mmap "prot" argument into "vm_flags" used internally.
+ */
+static inline unsigned long
+calc_vm_prot_bits(unsigned long prot)
+{
+       return _calc_vm_trans(prot, PROT_READ,  VM_READ ) |
+              _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
+              _calc_vm_trans(prot, PROT_EXEC,  VM_EXEC );
+}
+
+/*
+ * Combine the mmap "flags" argument into "vm_flags" used internally.
+ */
+static inline unsigned long
+calc_vm_flag_bits(unsigned long flags)
+{
+       return _calc_vm_trans(flags, MAP_GROWSDOWN,  VM_GROWSDOWN ) |
+              _calc_vm_trans(flags, MAP_DENYWRITE,  VM_DENYWRITE ) |
+              _calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
+              _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    );
+}
+
 #endif /* _LINUX_MMAN_H */
index bcc28864eab613183a4056bccd61fac7d1933aa6..61c9f5ca5f829860053b2b964551d024ab620829 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -136,29 +136,6 @@ out:
        return retval;
 }
 
-/* Combine the mmap "prot" and "flags" argument into one "vm_flags" used
- * internally. Essentially, translate the "PROT_xxx" and "MAP_xxx" bits
- * into "VM_xxx".
- */
-static inline unsigned long
-calc_vm_flags(unsigned long prot, unsigned long flags)
-{
-#define _trans(x,bit1,bit2) \
-((bit1==bit2)?(x&bit1):(x&bit1)?bit2:0)
-
-       unsigned long prot_bits, flag_bits;
-       prot_bits =
-               _trans(prot, PROT_READ, VM_READ) |
-               _trans(prot, PROT_WRITE, VM_WRITE) |
-               _trans(prot, PROT_EXEC, VM_EXEC);
-       flag_bits =
-               _trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN) |
-               _trans(flags, MAP_DENYWRITE, VM_DENYWRITE) |
-               _trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE);
-       return prot_bits | flag_bits;
-#undef _trans
-}
-
 #ifdef DEBUG_MM_RB
 static int browse_rb(struct rb_node * rb_node) {
        int i = 0;
@@ -500,8 +477,8 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
         * to. we assume access permissions have been handled by the open
         * of the memory object, so we don't do any here.
         */
-       vm_flags = calc_vm_flags(prot,flags) | mm->def_flags |
-                       VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
+       vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
+                       mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
 
        if (flags & MAP_LOCKED) {
                if (!capable(CAP_IPC_LOCK))