mincore.cpp 939 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "align.h"
  2. #include "compiler.h"
  3. #include "info.h"
  4. #include "mincore.h"
  5. #include <util/generic/yexception.h>
  6. #include <cstring>
  7. #if defined(_unix_)
  8. #include <sys/unistd.h>
  9. #include <sys/mman.h>
  10. #if defined(_android_)
  11. #include <sys/syscall.h>
  12. #endif
  13. #endif
  14. void InCoreMemory(const void* addr, size_t len, unsigned char* vec, size_t vecLen) {
  15. #if defined(_linux_)
  16. const size_t pageSize = NSystemInfo::GetPageSize();
  17. void* maddr = const_cast<void*>(AlignDown(addr, pageSize));
  18. len = AlignUp(len, pageSize);
  19. if (vecLen * pageSize < len) {
  20. ythrow yexception() << "vector argument for mincore is too small: " << vecLen * pageSize << " < " << len;
  21. }
  22. if (::mincore(maddr, len, vec)) {
  23. ythrow yexception() << LastSystemErrorText();
  24. }
  25. #else
  26. // pessimistic assumption: nothing is in core
  27. Y_UNUSED(addr);
  28. Y_UNUSED(len);
  29. ::memset(vec, 0, vecLen);
  30. #endif
  31. }