|
3 | 3 | // Distributed under the MIT/X11 software license, see the accompanying
|
4 | 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 |
|
6 |
| -#ifndef BITCOIN_ALLOCATORS_H |
7 |
| -#define BITCOIN_ALLOCATORS_H |
| 6 | +#ifndef BITCOIN_ALLOCATORS_PAGELOCKER_H |
| 7 | +#define BITCOIN_ALLOCATORS_PAGELOCKER_H |
8 | 8 |
|
9 | 9 | #include "support/cleanse.h"
|
10 | 10 |
|
11 | 11 | #include <map>
|
12 |
| -#include <string.h> |
13 |
| -#include <string> |
14 |
| -#include <vector> |
15 | 12 |
|
16 | 13 | #include <boost/thread/mutex.hpp>
|
17 | 14 | #include <boost/thread/once.hpp>
|
@@ -160,91 +157,4 @@ class LockedPageManager : public LockedPageManagerBase<MemoryPageLocker>
|
160 | 157 | static boost::once_flag init_flag;
|
161 | 158 | };
|
162 | 159 |
|
163 |
| -// |
164 |
| -// Allocator that locks its contents from being paged |
165 |
| -// out of memory and clears its contents before deletion. |
166 |
| -// |
167 |
| -template <typename T> |
168 |
| -struct secure_allocator : public std::allocator<T> { |
169 |
| - // MSVC8 default copy constructor is broken |
170 |
| - typedef std::allocator<T> base; |
171 |
| - typedef typename base::size_type size_type; |
172 |
| - typedef typename base::difference_type difference_type; |
173 |
| - typedef typename base::pointer pointer; |
174 |
| - typedef typename base::const_pointer const_pointer; |
175 |
| - typedef typename base::reference reference; |
176 |
| - typedef typename base::const_reference const_reference; |
177 |
| - typedef typename base::value_type value_type; |
178 |
| - secure_allocator() throw() {} |
179 |
| - secure_allocator(const secure_allocator& a) throw() : base(a) {} |
180 |
| - template <typename U> |
181 |
| - secure_allocator(const secure_allocator<U>& a) throw() : base(a) |
182 |
| - { |
183 |
| - } |
184 |
| - ~secure_allocator() throw() {} |
185 |
| - template <typename _Other> |
186 |
| - struct rebind { |
187 |
| - typedef secure_allocator<_Other> other; |
188 |
| - }; |
189 |
| - |
190 |
| - T* allocate(std::size_t n, const void* hint = 0) |
191 |
| - { |
192 |
| - T* p; |
193 |
| - p = std::allocator<T>::allocate(n, hint); |
194 |
| - if (p != NULL) |
195 |
| - LockedPageManager::Instance().LockRange(p, sizeof(T) * n); |
196 |
| - return p; |
197 |
| - } |
198 |
| - |
199 |
| - void deallocate(T* p, std::size_t n) |
200 |
| - { |
201 |
| - if (p != NULL) { |
202 |
| - memory_cleanse(p, sizeof(T) * n); |
203 |
| - LockedPageManager::Instance().UnlockRange(p, sizeof(T) * n); |
204 |
| - } |
205 |
| - std::allocator<T>::deallocate(p, n); |
206 |
| - } |
207 |
| -}; |
208 |
| - |
209 |
| - |
210 |
| -// |
211 |
| -// Allocator that clears its contents before deletion. |
212 |
| -// |
213 |
| -template <typename T> |
214 |
| -struct zero_after_free_allocator : public std::allocator<T> { |
215 |
| - // MSVC8 default copy constructor is broken |
216 |
| - typedef std::allocator<T> base; |
217 |
| - typedef typename base::size_type size_type; |
218 |
| - typedef typename base::difference_type difference_type; |
219 |
| - typedef typename base::pointer pointer; |
220 |
| - typedef typename base::const_pointer const_pointer; |
221 |
| - typedef typename base::reference reference; |
222 |
| - typedef typename base::const_reference const_reference; |
223 |
| - typedef typename base::value_type value_type; |
224 |
| - zero_after_free_allocator() throw() {} |
225 |
| - zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} |
226 |
| - template <typename U> |
227 |
| - zero_after_free_allocator(const zero_after_free_allocator<U>& a) throw() : base(a) |
228 |
| - { |
229 |
| - } |
230 |
| - ~zero_after_free_allocator() throw() {} |
231 |
| - template <typename _Other> |
232 |
| - struct rebind { |
233 |
| - typedef zero_after_free_allocator<_Other> other; |
234 |
| - }; |
235 |
| - |
236 |
| - void deallocate(T* p, std::size_t n) |
237 |
| - { |
238 |
| - if (p != NULL) |
239 |
| - memory_cleanse(p, sizeof(T) * n); |
240 |
| - std::allocator<T>::deallocate(p, n); |
241 |
| - } |
242 |
| -}; |
243 |
| - |
244 |
| -// This is exactly like std::string, but with a custom allocator. |
245 |
| -typedef std::basic_string<char, std::char_traits<char>, secure_allocator<char> > SecureString; |
246 |
| - |
247 |
| -// Byte-vector that clears its contents before deletion. |
248 |
| -typedef std::vector<char, zero_after_free_allocator<char> > CSerializeData; |
249 |
| - |
250 |
| -#endif // BITCOIN_ALLOCATORS_H |
| 160 | +#endif // BITCOIN_ALLOCATORS_PAGELOCKER_H |
0 commit comments