aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-18 01:19:25 +0000
committerlloyd <[email protected]>2011-12-18 01:19:25 +0000
commit8809043895d1d4cf37ff476cb69c9277b33cc957 (patch)
tree72ca6a117cce901c9a36631422b1a7e5d88e1aac /src/utils
parent5a76eb4c07f0caedde1a3d1d2824f2764a46a582 (diff)
parenta3d81efbd2c56749d4abf9e6a27cb36cbbb10702 (diff)
propagate from branch 'net.randombit.botan' (head 39f53266912f33dc48e942b1b865ddcd6af66d8d)
to branch 'net.randombit.botan.cxx11' (head 0bf26cec09f71e75c547b4ec53365748c6d80d86)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/cpuid.cpp34
-rw-r--r--src/utils/dyn_load/dyn_load.cpp5
2 files changed, 34 insertions, 5 deletions
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index 917789f65..f6581f09c 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -10,10 +10,20 @@
#include <botan/get_byte.h>
#include <botan/mem_ops.h>
+#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
+
#if defined(BOTAN_TARGET_OS_IS_DARWIN)
#include <sys/sysctl.h>
#endif
+#if defined(BOTAN_TARGET_OS_IS_OPENBSD)
+ #include <sys/param.h>
+ #include <sys/sysctl.h>
+ #include <machine/cpu.h>
+#endif
+
+#endif
+
#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
#if defined(BOTAN_BUILD_COMPILER_IS_MSVC)
@@ -24,9 +34,9 @@
#elif defined(BOTAN_BUILD_COMPILER_IS_INTEL)
#include <ia32intrin.h>
- #define CALL_CPUID(type, out) do { __cpuid(out, type); } while(0);
+ #define CALL_CPUID(type, out) do { __cpuid(out, type); } while(0)
-#elif (BOTAN_GCC_VERSION >= 430)
+#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 430)
// Only available starting in GCC 4.3
#include <cpuid.h>
@@ -46,6 +56,20 @@ namespace {
}
+#elif defined(BOTAN_TARGET_ARCH_IS_X86_64) && \
+ (defined(BOTAN_BUILD_COMPILER_IS_CLANG) || defined(BOTAN_BUILD_COMPILER_IS_GCC))
+
+ /*
+ * We can't safely use this on x86-32 as some 32-bit ABIs use ebx as
+ * a PIC register, and in theory there are some x86-32s still out
+ * there that don't support cpuid at all; it requires strange
+ * contortions to detect them.
+ */
+
+ #define CALL_CPUID(type, out) \
+ asm("cpuid\n\t" : "=a" (out[0]), "=b" (out[1]), "=c" (out[2]), "=d" (out[3]) \
+ : "0" (type))
+
#else
#warning "No method of calling CPUID for this compiler"
#endif
@@ -92,10 +116,14 @@ u32bit get_x86_cache_line_size()
bool altivec_check_sysctl()
{
-#if defined(BOTAN_TARGET_OS_IS_DARWIN)
+#if defined(BOTAN_TARGET_OS_IS_DARWIN) || defined(BOTAN_TARGET_OS_IS_OPENBSD)
+#if defined(BOTAN_TARGET_OS_IS_OPENBSD)
+ int sels[2] = { CTL_MACHDEP, CPU_ALTIVEC };
+#else
// From Apple's docs
int sels[2] = { CTL_HW, HW_VECTORUNIT };
+#endif
int vector_type = 0;
size_t length = sizeof(vector_type);
int error = sysctl(sels, 2, &vector_type, &length, NULL, 0);
diff --git a/src/utils/dyn_load/dyn_load.cpp b/src/utils/dyn_load/dyn_load.cpp
index 4a8cb16fa..06b8c5df3 100644
--- a/src/utils/dyn_load/dyn_load.cpp
+++ b/src/utils/dyn_load/dyn_load.cpp
@@ -39,7 +39,7 @@ Dynamically_Loaded_Library::Dynamically_Loaded_Library(
raise_runtime_loader_exception(lib_name, dlerror());
#elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
- lib = ::LoadLibrary(lib_name.c_str());
+ lib = ::LoadLibraryA(lib_name.c_str());
if(!lib)
raise_runtime_loader_exception(lib_name, "LoadLibrary failed");
@@ -65,7 +65,8 @@ void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol)
#if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
addr = ::dlsym(lib, symbol.c_str());
#elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
- addr = ::GetProcAddress((HMODULE)lib, symbol.c_str());
+ addr = reinterpret_cast<void*>(::GetProcAddress((HMODULE)lib,
+ symbol.c_str()));
#endif
if(!addr)