| 47 | } |
| 48 | |
| 49 | void UnlockMemory(const void* addr, size_t len) { |
| 50 | #if defined(_unix_) |
| 51 | if (0 == len) { |
| 52 | return; |
| 53 | } |
| 54 | Y_ASSERT(static_cast<ssize_t>(len) > 0); |
| 55 | const size_t pageSize = NSystemInfo::GetPageSize(); |
| 56 | const char* begin = AlignDown(static_cast<const char*>(addr), pageSize); |
| 57 | const char* end = AlignUp(static_cast<const char*>(addr) + len, pageSize); |
| 58 | if (munlock(begin, end - begin)) { |
| 59 | ythrow yexception() << LastSystemErrorText(); |
| 60 | } |
| 61 | #elif defined(_win_) |
| 62 | HANDLE hndl = GetCurrentProcess(); |
| 63 | SIZE_T min, max; |
| 64 | if (!GetProcessWorkingSetSize(hndl, &min, &max)) { |
| 65 | ythrow yexception() << LastSystemErrorText(); |
| 66 | } |
| 67 | if (!SetProcessWorkingSetSize(hndl, min - len, max - len)) { |
| 68 | ythrow yexception() << LastSystemErrorText(); |
| 69 | } |
| 70 | if (!VirtualUnlock((LPVOID)addr, len)) { |
| 71 | ythrow yexception() << LastSystemErrorText(); |
| 72 | } |
| 73 | #endif |
| 74 | } |
| 75 | |
| 76 | void LockAllMemory(ELockAllMemoryFlags flags) { |
| 77 | Y_UNUSED(flags); |
no test coverage detected