diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/system/mincore.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/system/mincore.h')
-rw-r--r-- | util/system/mincore.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/util/system/mincore.h b/util/system/mincore.h new file mode 100644 index 0000000000..0f5d8b78c7 --- /dev/null +++ b/util/system/mincore.h @@ -0,0 +1,38 @@ +#pragma once + +#include "defaults.h" +/** + * Fills a vector that indicates whether pages of the calling process's virtual memory are resident in RAM. Each byte + * in the vector contains the status of a single page. The page size can be obtained via the NSystemInfo::GetPageSize() + * function. Use the IsPageInCore function to interpret the page status byte. + * + * Can be overly pessimistic: + * - Assumes nothing is in RAM on platforms other than Linux + * - Recent Linux kernels (4.21 and some backports) may return zeroes if the process doesn't have writing permissions + * for the given file. See CVE-2019-5489. + * + * @param[in] addr starting address of the memory range to be examined + * @param[in] len length (bytes) of the memory range to be examined + * @param[out] vec vector of bytes to store statuses of memory pages + * @param[in] vecLen length (bytes) of the vec, should be large enough to hold the requested pages count + * @throws yexception if there was a system error or if the vecLen is too small + * + * @note this is only a snapshot, results may be stale by the time they're used + * @see man 2 mincore + */ +void InCoreMemory(const void* addr, size_t len, unsigned char* vec, size_t vecLen); + +/** + * Takes as an argument an element of the vector previously filled by InCoreMemory. + * + * @param[in] byte corresponding to the status of a single page + * + * @returns true if this page was resident in memory at the time out the InCoreMemory execution + */ +inline bool IsPageInCore(unsigned char s) { + /* From mincore(2): On return, the least significant bit of each byte will be set if the corresponding page is + * currently resident in memory, and be clear otherwise. (The settings of the other bits in each byte are + * undefined; these bits are reserved for possible later use.) + */ + return s & 1; +} |