mman.h 2.3 KB

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