aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/info.txt4
-rw-r--r--src/utils/mlock.cpp23
-rw-r--r--src/utils/util.h2
3 files changed, 26 insertions, 3 deletions
diff --git a/src/utils/info.txt b/src/utils/info.txt
index 5effb77ed..820c3069f 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -4,6 +4,10 @@ define UTIL_FUNCTIONS
load_on auto
+<libs>
+tru64 -> rt
+</libs>
+
<add>
charset.cpp
mlock.cpp
diff --git a/src/utils/mlock.cpp b/src/utils/mlock.cpp
index e4456658d..12947709d 100644
--- a/src/utils/mlock.cpp
+++ b/src/utils/mlock.cpp
@@ -5,20 +5,39 @@
#include <botan/util.h>
+#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
+ #include <sys/types.h>
+ #include <sys/mman.h>
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
+ #include <windows.h>
+#endif
+
namespace Botan {
/*************************************************
* Lock an area of memory into RAM *
*************************************************/
-void lock_mem(void*, u32bit)
+bool lock_mem(void* ptr, u32bit bytes)
{
+#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
+ return (mlock(ptr, bytes) == 0);
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
+ return (VirtualLock(ptr, bytes) != 0);
+#else
+ return false;
+#endif
}
/*************************************************
* Unlock a previously locked region of memory *
*************************************************/
-void unlock_mem(void*, u32bit)
+void unlock_mem(void* ptr, u32bit bytes)
{
+#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
+ munlock(ptr, bytes);
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
+ VirtualUnlock(ptr, bytes);
+#endif
}
}
diff --git a/src/utils/util.h b/src/utils/util.h
index 879acd1db..62ecb948d 100644
--- a/src/utils/util.h
+++ b/src/utils/util.h
@@ -18,7 +18,7 @@ BOTAN_DLL u64bit system_time();
/*************************************************
* Memory Locking Functions *
*************************************************/
-BOTAN_DLL void lock_mem(void*, u32bit);
+BOTAN_DLL bool lock_mem(void*, u32bit);
BOTAN_DLL void unlock_mem(void*, u32bit);
/*************************************************