From d04668a76d3780540b30bcbc2bc638f3f31d577d Mon Sep 17 00:00:00 2001 From: Jamie Lokier Date: Thu, 4 Sep 2003 21:42:15 -0700 Subject: [PATCH] Common PROT_xxx -> VM_xxx mapping This moves the mapping of PROT_* bits to VM_* bits from mmap.c to the common header file . The mapping is needed for mprotect too. --- include/linux/mman.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'include/linux') diff --git a/include/linux/mman.h b/include/linux/mman.h index a8956f6588ad..cfb6ac61bbde 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -2,6 +2,7 @@ #define _LINUX_MMAN_H #include +#include #include #include @@ -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 */ -- cgit v1.2.3