aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-13 18:34:20 +0000
committerlloyd <[email protected]>2010-03-13 18:34:20 +0000
commit2fbe098b29b9ca611d83d8aedb7457dc925860eb (patch)
tree16085502d8637e29df59dcd92a4aeb98c899ea32 /src/utils
parentbdb4cd3df0e2ed94d39cff95a83fcd88141c1ef4 (diff)
At startup, test if lock_mem() at least seems to work. If it doesn't,
immediately fall back the the plain malloc-based allocator, which is typically quite a bit faster.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mlock.cpp9
-rw-r--r--src/utils/mlock.h5
2 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/mlock.cpp b/src/utils/mlock.cpp
index 5d6fc3591..bc6ddc67e 100644
--- a/src/utils/mlock.cpp
+++ b/src/utils/mlock.cpp
@@ -16,6 +16,15 @@
namespace Botan {
+bool has_mlock()
+ {
+ byte buf[4096];
+ if(!lock_mem(&buf, sizeof(buf)))
+ return false;
+ unlock_mem(&buf, sizeof(buf));
+ return true;
+ }
+
/*
* Lock an area of memory into RAM
*/
diff --git a/src/utils/mlock.h b/src/utils/mlock.h
index 66ced9e63..fea56d438 100644
--- a/src/utils/mlock.h
+++ b/src/utils/mlock.h
@@ -13,6 +13,11 @@
namespace Botan {
/**
+* Check if we can at least potentially lock memory
+*/
+bool has_mlock();
+
+/**
* Lock memory into RAM if possible
* @param addr the start of the memory block
* @param length the length of the memory block in bytes