mman.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _LINUX_MMAN_H
  2. #define _LINUX_MMAN_H
  3. #include <linux/mm.h>
  4. #include <linux/percpu_counter.h>
  5. #include <linux/atomic.h>
  6. #include <uapi/linux/mman.h>
  7. extern int sysctl_overcommit_memory;
  8. extern int sysctl_overcommit_ratio;
  9. extern struct percpu_counter vm_committed_as;
  10. unsigned long vm_memory_committed(void);
  11. static inline void vm_acct_memory(long pages)
  12. {
  13. percpu_counter_add(&vm_committed_as, pages);
  14. }
  15. static inline void vm_unacct_memory(long pages)
  16. {
  17. vm_acct_memory(-pages);
  18. }
  19. /*
  20. * Allow architectures to handle additional protection bits
  21. */
  22. #ifndef arch_calc_vm_prot_bits
  23. #define arch_calc_vm_prot_bits(prot) 0
  24. #endif
  25. #ifndef arch_vm_get_page_prot
  26. #define arch_vm_get_page_prot(vm_flags) __pgprot(0)
  27. #endif
  28. #ifndef arch_validate_prot
  29. /*
  30. * This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have
  31. * already been masked out.
  32. *
  33. * Returns true if the prot flags are valid
  34. */
  35. static inline int arch_validate_prot(unsigned long prot)
  36. {
  37. return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0;
  38. }
  39. #define arch_validate_prot arch_validate_prot
  40. #endif
  41. /*
  42. * Optimisation macro. It is equivalent to:
  43. * (x & bit1) ? bit2 : 0
  44. * but this version is faster.
  45. * ("bit1" and "bit2" must be single bits)
  46. */
  47. #define _calc_vm_trans(x, bit1, bit2) \
  48. ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
  49. : ((x) & (bit1)) / ((bit1) / (bit2)))
  50. /*
  51. * Combine the mmap "prot" argument into "vm_flags" used internally.
  52. */
  53. static inline unsigned long
  54. calc_vm_prot_bits(unsigned long prot)
  55. {
  56. return _calc_vm_trans(prot, PROT_READ, VM_READ ) |
  57. _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
  58. _calc_vm_trans(prot, PROT_EXEC, VM_EXEC) |
  59. arch_calc_vm_prot_bits(prot);
  60. }
  61. /*
  62. * Combine the mmap "flags" argument into "vm_flags" used internally.
  63. */
  64. static inline unsigned long
  65. calc_vm_flag_bits(unsigned long flags)
  66. {
  67. return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
  68. _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
  69. ((flags & MAP_LOCKED) ? (VM_LOCKED | VM_POPULATE) : 0) |
  70. (((flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE) ?
  71. VM_POPULATE : 0);
  72. }
  73. #endif /* _LINUX_MMAN_H */