mman.h 2.2 KB

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