mman.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/config.h>
  11. #include <linux/mm.h>
  12. #include <asm/atomic.h>
  13. extern int sysctl_overcommit_memory;
  14. extern int sysctl_overcommit_ratio;
  15. extern atomic_t vm_committed_space;
  16. #ifdef CONFIG_SMP
  17. extern void vm_acct_memory(long pages);
  18. #else
  19. static inline void vm_acct_memory(long pages)
  20. {
  21. atomic_add(pages, &vm_committed_space);
  22. }
  23. #endif
  24. static inline void vm_unacct_memory(long pages)
  25. {
  26. vm_acct_memory(-pages);
  27. }
  28. /*
  29. * Optimisation macro. It is equivalent to:
  30. * (x & bit1) ? bit2 : 0
  31. * but this version is faster.
  32. * ("bit1" and "bit2" must be single bits)
  33. */
  34. #define _calc_vm_trans(x, bit1, bit2) \
  35. ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
  36. : ((x) & (bit1)) / ((bit1) / (bit2)))
  37. /*
  38. * Combine the mmap "prot" argument into "vm_flags" used internally.
  39. */
  40. static inline unsigned long
  41. calc_vm_prot_bits(unsigned long prot)
  42. {
  43. return _calc_vm_trans(prot, PROT_READ, VM_READ ) |
  44. _calc_vm_trans(prot, PROT_WRITE, VM_WRITE) |
  45. _calc_vm_trans(prot, PROT_EXEC, VM_EXEC );
  46. }
  47. /*
  48. * Combine the mmap "flags" argument into "vm_flags" used internally.
  49. */
  50. static inline unsigned long
  51. calc_vm_flag_bits(unsigned long flags)
  52. {
  53. return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
  54. _calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
  55. _calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
  56. _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
  57. }
  58. #endif /* __KERNEL__ */
  59. #endif /* _LINUX_MMAN_H */