aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/mlock.h
blob: 389f65570d0c17a2db0c4b0e6a25429a46a1c42c (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
36
37
38
39
40
41
42
43
#pragma once

#include "defaults.h"

#include <util/generic/flags.h>

//on some systems (not win, freebd, linux, but darwin (Mac OS X)
//multiple mlock calls on the same address range
//require the corresponding number of munlock calls to actually unlock the pages

//on some systems you must have privilege and resource limit

void LockMemory(const void* addr, size_t len);
void UnlockMemory(const void* addr, size_t len);

enum ELockAllMemoryFlag {
    /** Lock all pages which are currently mapped into the address space of the process. */
    LockCurrentMemory = 1,

    /** Lock all pages which will become mapped into the address space of the process in the future. */
    LockFutureMemory = 2,

    /** Since Linux 4.4, with LockCurrentMemory or LockFutureMemory or both, lock only pages that are or once they are present in memory. */
    LockMemoryOnFault = 4,
}; 
Y_DECLARE_FLAGS(ELockAllMemoryFlags, ELockAllMemoryFlag)
Y_DECLARE_OPERATORS_FOR_FLAGS(ELockAllMemoryFlags)
 
/**
 * Performs provided locking operation.
 *
 * Does nothing on windows.
 *
 * \param flags                         Locking operation to perform.
 */
void LockAllMemory(ELockAllMemoryFlags flags);
 
/**
 * Unlocks whatever was locked with a previous call to `LockAllMemory`.
 *
 * Does nothing on windows.
 */
void UnlockAllMemory();