diff options
Diffstat (limited to 'src/utils/mlock.cpp')
-rw-r--r-- | src/utils/mlock.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
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 } } |