mlock.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include "defaults.h"
  3. #include <util/generic/flags.h>
  4. // on some systems (not win, freebd, linux, but darwin (Mac OS X)
  5. // multiple mlock calls on the same address range
  6. // require the corresponding number of munlock calls to actually unlock the pages
  7. // on some systems you must have privilege and resource limit
  8. void LockMemory(const void* addr, size_t len);
  9. void UnlockMemory(const void* addr, size_t len);
  10. enum ELockAllMemoryFlag {
  11. /** Lock all pages which are currently mapped into the address space of the process. */
  12. LockCurrentMemory = 1,
  13. /** Lock all pages which will become mapped into the address space of the process in the future. */
  14. LockFutureMemory = 2,
  15. /** Since Linux 4.4, with LockCurrentMemory or LockFutureMemory or both, lock only pages that are or once they are present in memory. */
  16. LockMemoryOnFault = 4,
  17. };
  18. Y_DECLARE_FLAGS(ELockAllMemoryFlags, ELockAllMemoryFlag);
  19. Y_DECLARE_OPERATORS_FOR_FLAGS(ELockAllMemoryFlags);
  20. /**
  21. * Performs provided locking operation.
  22. *
  23. * Does nothing on windows.
  24. *
  25. * \param flags Locking operation to perform.
  26. */
  27. void LockAllMemory(ELockAllMemoryFlags flags);
  28. /**
  29. * Unlocks whatever was locked with a previous call to `LockAllMemory`.
  30. *
  31. * Does nothing on windows.
  32. */
  33. void UnlockAllMemory();