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