mincore.cpp 889 B

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