diff options
author | lloyd <[email protected]> | 2008-09-29 21:45:25 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-29 21:45:25 +0000 |
commit | 98e89e86beec39c9a789f8dba72dc5746c31943d (patch) | |
tree | b0282892e61fa2930bd20e08d2a940c7adc4d176 /src/utils/mlock.cpp | |
parent | 8157ca69909e59682619822d6d54c9c7e90be406 (diff) |
Merge the 3 mlocks (ml_unix, ml_win32, stub mlock.cpp) into a single mlock.cpp
in utils.
Support OS feature macros, eg BOTAN_TARGET_OS_HAS_POSIX_MLOCK (how very autoconf)
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 } } |