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 | |
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')
-rw-r--r-- | src/utils/info.txt | 4 | ||||
-rw-r--r-- | src/utils/mlock.cpp | 23 | ||||
-rw-r--r-- | src/utils/util.h | 2 |
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); /************************************************* |