Dash Core  0.12.2.1
P2P Digital Currency
pagelocker.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "support/pagelocker.h"
6 
7 #if defined(HAVE_CONFIG_H)
8 #include "config/dash-config.h"
9 #endif
10 
11 #ifdef WIN32
12 #ifdef _WIN32_WINNT
13 #undef _WIN32_WINNT
14 #endif
15 #define _WIN32_WINNT 0x0501
16 #define WIN32_LEAN_AND_MEAN 1
17 #ifndef NOMINMAX
18 #define NOMINMAX
19 #endif
20 #include <windows.h>
21 // This is used to attempt to keep keying material out of swap
22 // Note that VirtualLock does not provide this as a guarantee on Windows,
23 // but, in practice, memory that has been VirtualLock'd almost never gets written to
24 // the pagefile except in rare circumstances where memory is extremely low.
25 #else
26 #include <sys/mman.h>
27 #include <limits.h> // for PAGESIZE
28 #include <unistd.h> // for sysconf
29 #endif
30 
32 boost::once_flag LockedPageManager::init_flag = BOOST_ONCE_INIT;
33 
35 static inline size_t GetSystemPageSize()
36 {
37  size_t page_size;
38 #if defined(WIN32)
39  SYSTEM_INFO sSysInfo;
40  GetSystemInfo(&sSysInfo);
41  page_size = sSysInfo.dwPageSize;
42 #elif defined(PAGESIZE) // defined in limits.h
43  page_size = PAGESIZE;
44 #else // assume some POSIX OS
45  page_size = sysconf(_SC_PAGESIZE);
46 #endif
47  return page_size;
48 }
49 
50 bool MemoryPageLocker::Lock(const void* addr, size_t len)
51 {
52 #ifdef WIN32
53  return VirtualLock(const_cast<void*>(addr), len) != 0;
54 #else
55  return mlock(addr, len) == 0;
56 #endif
57 }
58 
59 bool MemoryPageLocker::Unlock(const void* addr, size_t len)
60 {
61 #ifdef WIN32
62  return VirtualUnlock(const_cast<void*>(addr), len) != 0;
63 #else
64  return munlock(addr, len) == 0;
65 #endif
66 }
67 
69 {
70 }
static LockedPageManager * _instance
Definition: pagelocker.h:156
bool Unlock(const void *addr, size_t len)
Definition: pagelocker.cpp:59
static size_t GetSystemPageSize()
Definition: pagelocker.cpp:35
bool Lock(const void *addr, size_t len)
Definition: pagelocker.cpp:50
static boost::once_flag init_flag
Definition: pagelocker.h:157