mman.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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)) ? 0 : \
  55. ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
  56. : ((x) & (bit1)) / ((bit1) / (bit2))))
  57. /*
  58. * Combine the mmap "prot" argument into "vm_flags" used internally.
  59. */
  60. static inline unsigned long
  61. calc_vm_prot_bits(unsigned long prot, unsigned long pkey)
  62. {
  63. return _calc_vm_trans(prot, PROT_READ, VM_READ ) |
  64. _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
  65. _calc_vm_trans(prot, PROT_EXEC, VM_EXEC) |
  66. arch_calc_vm_prot_bits(prot, pkey);
  67. }
  68. /*
  69. * Combine the mmap "flags" argument into "vm_flags" used internally.
  70. */
  71. static inline unsigned long
  72. calc_vm_flag_bits(unsigned long flags)
  73. {
  74. return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
  75. _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
  76. _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
  77. }
  78. unsigned long vm_commit_limit(void);
  79. #endif /* _LINUX_MMAN_H */