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 | |
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)
-rwxr-xr-x | configure.pl | 48 | ||||
-rw-r--r-- | src/build-data/os/freebsd | 4 | ||||
-rw-r--r-- | src/build-data/os/linux | 4 | ||||
-rw-r--r-- | src/build-data/os/solaris | 4 | ||||
-rw-r--r-- | src/build-data/os/windows | 4 | ||||
-rw-r--r-- | src/secalloc/ml_unix/mlock.cpp | 33 | ||||
-rw-r--r-- | src/secalloc/ml_unix/xxxinfo.txt | 25 | ||||
-rw-r--r-- | src/secalloc/ml_win32/mlock.cpp | 27 | ||||
-rw-r--r-- | src/secalloc/ml_win32/xxxinfo.txt | 12 | ||||
-rw-r--r-- | src/utils/info.txt | 4 | ||||
-rw-r--r-- | src/utils/mlock.cpp | 23 | ||||
-rw-r--r-- | src/utils/util.h | 2 |
12 files changed, 71 insertions, 119 deletions
diff --git a/configure.pl b/configure.pl index f9c18c5b6..6c7164be8 100755 --- a/configure.pl +++ b/configure.pl @@ -1043,11 +1043,25 @@ sub load_modules { $$config{'mod-list'} = join("\n", @mod_names); + my $unaligned_ok = 0; + my $gen_defines = sub { my $defines = ''; my $arch = $$config{'arch'}; + my $os = $$config{'os'}; + if($os ne 'generic') { + $defines .= '#define BOTAN_TARGET_OS_IS_' . uc $os . "\n"; + my @features = @{$OPERATING_SYSTEM{$os}{'target_features'}}; + + for my $feature (@features) { + $defines .= '#define BOTAN_TARGET_OS_HAS_' . uc $feature . "\n"; + } + + $defines .= "\n"; + } + if($arch ne 'generic') { my %cpu_info = %{$CPU{$arch}}; my $endian = $cpu_info{'endian'}; @@ -1069,15 +1083,6 @@ sub load_modules { $defines .= "#define BOTAN_TARGET_CPU_IS_$submodel\n"; } - my $os = $$config{'os'}; - if($os ne 'generic') { - $os = uc $os; - $submodel =~ s/-/_/g; - $defines .= "#define BOTAN_TARGET_OS_IS_$os\n"; - } - - my $unaligned_ok = 0; - if(defined($endian)) { $endian = uc $endian; $defines .= "#define BOTAN_TARGET_CPU_IS_${endian}_ENDIAN\n"; @@ -1104,26 +1109,29 @@ sub load_modules { $unaligned_ok = 1; } } - - $defines .= - "#define BOTAN_TARGET_UNALIGNED_LOADSTOR_OK $unaligned_ok\n"; } - my @defarray; + # always set (one or zero) + $defines .= + "#define BOTAN_TARGET_UNALIGNED_LOADSTOR_OK $unaligned_ok\n"; + + my %defines; + foreach my $mod (sort keys %{$$config{'modules'}}) { next unless $$config{'modules'}{$mod} > 0; my $defs = $MODULES{$mod}{'define'}; next unless $defs; - push @defarray, split(/,/, $defs); + push @{$defines{$MODULES{$mod}{'type'}}}, split(/,/, $defs); } - $defines .= "\n" if(@defarray); - - foreach (sort @defarray) { - die unless(defined $_ and $_ ne ''); - $defines .= "#define BOTAN_HAS_$_\n"; + foreach my $type (sort keys %defines) { + $defines .= "\n/* $type */\n"; + for my $macro (@{$defines{$type}}) { + die unless(defined $macro and $macro ne ''); + $defines .= "#define BOTAN_HAS_$macro\n"; + } } chomp($defines); return $defines; @@ -1540,6 +1548,8 @@ sub get_os_info { read_list($_, $reader, 'aliases', list_push(\@{$info{'aliases'}})); + read_list($_, $reader, 'target_features', list_push(\@{$info{'target_features'}})); + read_list($_, $reader, 'supports_shared', list_push(\@{$info{'supports_shared'}})); } diff --git a/src/build-data/os/freebsd b/src/build-data/os/freebsd index e58ade517..ea96b0c88 100644 --- a/src/build-data/os/freebsd +++ b/src/build-data/os/freebsd @@ -2,6 +2,10 @@ realname "FreeBSD" os_type unix +<target_features> +posix_mlock +</target_features> + <supports_shared> all </supports_shared> diff --git a/src/build-data/os/linux b/src/build-data/os/linux index acf224244..53528511a 100644 --- a/src/build-data/os/linux +++ b/src/build-data/os/linux @@ -2,6 +2,10 @@ realname "Linux" os_type unix +<target_features> +posix_mlock +</target_features> + # Is this correct? <supports_shared> all diff --git a/src/build-data/os/solaris b/src/build-data/os/solaris index a1c1b40b3..8610b4898 100644 --- a/src/build-data/os/solaris +++ b/src/build-data/os/solaris @@ -2,6 +2,10 @@ realname "Solaris" os_type unix +<target_features> +posix_mlock +</target_features> + <supports_shared> all </supports_shared> diff --git a/src/build-data/os/windows b/src/build-data/os/windows index 62b271271..823c60d6c 100644 --- a/src/build-data/os/windows +++ b/src/build-data/os/windows @@ -12,6 +12,10 @@ doc_dir docs install_cmd_data copy install_cmd_exec copy +<target_features> +win32_virtual_lock +</target_features> + <supports_shared> msvc </supports_shared> diff --git a/src/secalloc/ml_unix/mlock.cpp b/src/secalloc/ml_unix/mlock.cpp deleted file mode 100644 index 98214a215..000000000 --- a/src/secalloc/ml_unix/mlock.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************* -* Memory Locking Functions Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/util.h> - -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199309 -#endif - -#include <sys/types.h> -#include <sys/mman.h> - -namespace Botan { - -/************************************************* -* Lock an area of memory into RAM * -*************************************************/ -void lock_mem(void* ptr, u32bit bytes) - { - mlock(ptr, bytes); - } - -/************************************************* -* Unlock a previously locked region of memory * -*************************************************/ -void unlock_mem(void* ptr, u32bit bytes) - { - munlock(ptr, bytes); - } - -} diff --git a/src/secalloc/ml_unix/xxxinfo.txt b/src/secalloc/ml_unix/xxxinfo.txt deleted file mode 100644 index 201a30ead..000000000 --- a/src/secalloc/ml_unix/xxxinfo.txt +++ /dev/null @@ -1,25 +0,0 @@ -realname "Memory Locking for Unix" - -load_on auto - -<replace> -mlock.cpp -</replace> - -<os> -aix -darwin -freebsd -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 -</os> - -<libs> -tru64 -> rt -</libs> diff --git a/src/secalloc/ml_win32/mlock.cpp b/src/secalloc/ml_win32/mlock.cpp deleted file mode 100644 index 8c5919934..000000000 --- a/src/secalloc/ml_win32/mlock.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/************************************************* -* Memory Locking Functions Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include <botan/util.h> -#include <windows.h> - -namespace Botan { - -/************************************************* -* Lock an area of memory into RAM * -*************************************************/ -void lock_mem(void* ptr, u32bit bytes) - { - VirtualLock(ptr, bytes); - } - -/************************************************* -* Unlock a previously locked region of memory * -*************************************************/ -void unlock_mem(void* ptr, u32bit bytes) - { - VirtualUnlock(ptr, bytes); - } - -} diff --git a/src/secalloc/ml_win32/xxxinfo.txt b/src/secalloc/ml_win32/xxxinfo.txt deleted file mode 100644 index 92936e1de..000000000 --- a/src/secalloc/ml_win32/xxxinfo.txt +++ /dev/null @@ -1,12 +0,0 @@ -realname "Memory Locking for Win32" - -load_on auto - -<replace> -mlock.cpp -</replace> - -<os> -windows -cygwin -</os> 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); /************************************************* |