mman.h 1.6 KB

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