11
11
#include < map>
12
12
#include < openssl/crypto.h> // for OPENSSL_cleanse()
13
13
14
- #ifdef WIN32
15
- #ifdef _WIN32_WINNT
16
- #undef _WIN32_WINNT
17
- #endif
18
- #define _WIN32_WINNT 0x0501
19
- #define WIN32_LEAN_AND_MEAN 1
20
- #ifndef NOMINMAX
21
- #define NOMINMAX
22
- #endif
23
- #include < windows.h>
24
- // This is used to attempt to keep keying material out of swap
25
- // Note that VirtualLock does not provide this as a guarantee on Windows,
26
- // but, in practice, memory that has been VirtualLock'd almost never gets written to
27
- // the pagefile except in rare circumstances where memory is extremely low.
28
- #else
29
- #include < sys/mman.h>
30
- #include < limits.h> // for PAGESIZE
31
- #include < unistd.h> // for sysconf
32
- #endif
33
14
34
15
/* *
35
16
* Thread-safe class to keep track of locked (ie, non-swappable) memory pages.
@@ -115,21 +96,6 @@ template <class Locker> class LockedPageManagerBase
115
96
Histogram histogram;
116
97
};
117
98
118
- /* * Determine system page size in bytes */
119
- static inline size_t GetSystemPageSize ()
120
- {
121
- size_t page_size;
122
- #if defined(WIN32)
123
- SYSTEM_INFO sSysInfo ;
124
- GetSystemInfo (&sSysInfo );
125
- page_size = sSysInfo .dwPageSize ;
126
- #elif defined(PAGESIZE) // defined in limits.h
127
- page_size = PAGESIZE;
128
- #else // assume some POSIX OS
129
- page_size = sysconf (_SC_PAGESIZE);
130
- #endif
131
- return page_size;
132
- }
133
99
134
100
/* *
135
101
* OS-dependent memory page locking/unlocking.
@@ -141,25 +107,11 @@ class MemoryPageLocker
141
107
/* * Lock memory pages.
142
108
* addr and len must be a multiple of the system page size
143
109
*/
144
- bool Lock (const void *addr, size_t len)
145
- {
146
- #ifdef WIN32
147
- return VirtualLock (const_cast <void *>(addr), len);
148
- #else
149
- return mlock (addr, len) == 0 ;
150
- #endif
151
- }
110
+ bool Lock (const void *addr, size_t len);
152
111
/* * Unlock memory pages.
153
112
* addr and len must be a multiple of the system page size
154
113
*/
155
- bool Unlock (const void *addr, size_t len)
156
- {
157
- #ifdef WIN32
158
- return VirtualUnlock (const_cast <void *>(addr), len);
159
- #else
160
- return munlock (addr, len) == 0 ;
161
- #endif
162
- }
114
+ bool Unlock (const void *addr, size_t len);
163
115
};
164
116
165
117
/* *
@@ -171,9 +123,7 @@ class LockedPageManager: public LockedPageManagerBase<MemoryPageLocker>
171
123
public:
172
124
static LockedPageManager instance; // instantiated in util.cpp
173
125
private:
174
- LockedPageManager ():
175
- LockedPageManagerBase<MemoryPageLocker>(GetSystemPageSize())
176
- {}
126
+ LockedPageManager ();
177
127
};
178
128
179
129
//
0 commit comments