aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-04 15:27:40 -0500
committerJack Lloyd <[email protected]>2018-02-04 15:27:40 -0500
commit2cb0fa04472f4bc60f02d822daa8f4f8ad487e7e (patch)
treedc48529923d296a06b44b9730bd535f63efe16d9 /src/lib
parenta17f1b71254e7e4c9de1a86a246fb85a3a4f25b9 (diff)
Alternate method of forcing allocator initialization
That doesn't require a malloc/free every time we call ec_group_data()
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp7
-rw-r--r--src/lib/utils/mem_ops.cpp7
-rw-r--r--src/lib/utils/mem_ops.h5
3 files changed, 18 insertions, 1 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index c5c39b6b3..0c2cd566c 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -175,8 +175,13 @@ EC_Group_Data_Map& EC_Group::ec_group_data()
* This exists purely to ensure the allocator is constructed before g_ec_data,
* which ensures that its destructor runs after ~g_ec_data is complete.
*/
- secure_vector<uint8_t> initialize_allocator(1);
+ class Allocator_Initializer
+ {
+ public:
+ Allocator_Initializer() { initialize_allocator(); }
+ };
+ static Allocator_Initializer g_init_allocator;
static EC_Group_Data_Map g_ec_data;
return g_ec_data;
}
diff --git a/src/lib/utils/mem_ops.cpp b/src/lib/utils/mem_ops.cpp
index 3fd463195..b7ecd5326 100644
--- a/src/lib/utils/mem_ops.cpp
+++ b/src/lib/utils/mem_ops.cpp
@@ -41,6 +41,13 @@ void deallocate_memory(void* p, size_t elems, size_t elem_size)
std::free(p);
}
+void initialize_allocator()
+ {
+#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
+ mlock_allocator::instance();
+#endif
+ }
+
bool constant_time_compare(const uint8_t x[],
const uint8_t y[],
size_t len)
diff --git a/src/lib/utils/mem_ops.h b/src/lib/utils/mem_ops.h
index be75da655..5fb5752fc 100644
--- a/src/lib/utils/mem_ops.h
+++ b/src/lib/utils/mem_ops.h
@@ -33,6 +33,11 @@ BOTAN_PUBLIC_API(2,3) BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t
BOTAN_PUBLIC_API(2,3) void deallocate_memory(void* p, size_t elems, size_t elem_size);
/**
+* Ensure the allocator is initialized
+*/
+void initialize_allocator();
+
+/**
* Scrub memory contents in a way that a compiler should not elide,
* using some system specific technique. Note that this function might
* not zero the memory (for example, in some hypothetical