diff options
-rw-r--r-- | doc/os.rst | 1 | ||||
-rw-r--r-- | src/build-data/os/freebsd.txt | 1 | ||||
-rw-r--r-- | src/lib/utils/cpuid/cpuid_arm.cpp | 12 | ||||
-rw-r--r-- | src/lib/utils/cpuid/cpuid_ppc.cpp | 8 | ||||
-rw-r--r-- | src/lib/utils/os_utils.cpp | 15 | ||||
-rw-r--r-- | src/lib/utils/os_utils.h | 2 |
6 files changed, 26 insertions, 13 deletions
diff --git a/doc/os.rst b/doc/os.rst index a19d27f6a..3f7456093 100644 --- a/doc/os.rst +++ b/doc/os.rst @@ -41,6 +41,7 @@ A summary of OS features as defined in ``src/build-data/os``. "commoncrypto", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", " " "crypto_ng", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", " " "dev_random", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", " ", "X", " ", "X", " ", " ", "X", "X", "X", "X", " ", " " + "elf_aux_info", " ", " ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " "explicit_bzero", " ", " ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", " ", " ", " ", " " "explicit_memset", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", " ", " ", " ", " ", " " "filesystem", "X", "X", "X", "X", "X", "X", "X", "X", "X", " ", "X", "X", "X", "X", "X", " ", "X", "X", "X", "X", "X", "X" diff --git a/src/build-data/os/freebsd.txt b/src/build-data/os/freebsd.txt index abae36116..c02c347f5 100644 --- a/src/build-data/os/freebsd.txt +++ b/src/build-data/os/freebsd.txt @@ -11,6 +11,7 @@ dev_random arc4random explicit_bzero cap_enter +elf_aux_info sockets threads diff --git a/src/lib/utils/cpuid/cpuid_arm.cpp b/src/lib/utils/cpuid/cpuid_arm.cpp index b5626f96b..bc9ac5daa 100644 --- a/src/lib/utils/cpuid/cpuid_arm.cpp +++ b/src/lib/utils/cpuid/cpuid_arm.cpp @@ -9,10 +9,7 @@ #if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) -#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) - #include <sys/auxv.h> - -#elif defined(BOTAN_TARGET_OS_IS_IOS) +#if defined(BOTAN_TARGET_OS_IS_IOS) #include <sys/types.h> #include <sys/sysctl.h> @@ -106,7 +103,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size) { uint64_t detected_features = 0; -#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) +#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) /* * On systems with getauxval these bits should normally be defined * in bits/auxv.h but some buggy? glibc installs seem to miss them. @@ -142,6 +139,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size) }; #if defined(AT_DCACHEBSIZE) + // Exists only on Linux const unsigned long dcache_line = ::getauxval(AT_DCACHEBSIZE); // plausibility check @@ -149,7 +147,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size) *cache_line_size = static_cast<size_t>(dcache_line); #endif - const unsigned long hwcap_neon = ::getauxval(ARM_hwcap_bit::ARCH_hwcap_neon); + const unsigned long hwcap_neon = OS::get_auxval(ARM_hwcap_bit::ARCH_hwcap_neon); if(hwcap_neon & ARM_hwcap_bit::NEON_bit) detected_features |= CPUID::CPUID_ARM_NEON_BIT; @@ -158,7 +156,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size) It doesn't seem worth optimizing this out, since getauxval is just reading a field in the ELF header. */ - const unsigned long hwcap_crypto = ::getauxval(ARM_hwcap_bit::ARCH_hwcap_crypto); + const unsigned long hwcap_crypto = OS::get_auxval(ARM_hwcap_bit::ARCH_hwcap_crypto); if(hwcap_crypto & ARM_hwcap_bit::AES_bit) detected_features |= CPUID::CPUID_ARM_AES_BIT; if(hwcap_crypto & ARM_hwcap_bit::PMULL_bit) diff --git a/src/lib/utils/cpuid/cpuid_ppc.cpp b/src/lib/utils/cpuid/cpuid_ppc.cpp index 1c1b68658..08a04cafd 100644 --- a/src/lib/utils/cpuid/cpuid_ppc.cpp +++ b/src/lib/utils/cpuid/cpuid_ppc.cpp @@ -19,8 +19,6 @@ #include <sys/param.h> #include <sys/sysctl.h> #include <machine/cpu.h> -#elif defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) - #include <sys/auxv.h> #endif #endif @@ -55,7 +53,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size) if(error == 0 && vector_type > 0) return CPUID::CPUID_ALTIVEC_BIT; -#elif defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) && defined(BOTAN_TARGET_ARCH_IS_PPC64) +#elif (defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_HAS_ELF_AUX_INFO)) && defined(BOTAN_TARGET_ARCH_IS_PPC64) enum PPC_hwcap_bit { ALTIVEC_bit = (1 << 28), @@ -67,11 +65,11 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size) uint64_t detected_features = 0; - const unsigned long hwcap_altivec = ::getauxval(PPC_hwcap_bit::ARCH_hwcap_altivec); + const unsigned long hwcap_altivec = OS::get_auxval(PPC_hwcap_bit::ARCH_hwcap_altivec); if(hwcap_altivec & PPC_hwcap_bit::ALTIVEC_bit) detected_features |= CPUID::CPUID_ALTIVEC_BIT; - const unsigned long hwcap_crypto = ::getauxval(PPC_hwcap_bit::ARCH_hwcap_crypto); + const unsigned long hwcap_crypto = OS::get_auxval(PPC_hwcap_bit::ARCH_hwcap_crypto); if(hwcap_crypto & PPC_hwcap_bit::CRYPTO_bit) detected_features |= CPUID::CPUID_PPC_CRYPTO_BIT; diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 516a2cabd..384f5ab75 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -40,7 +40,7 @@ #include <emscripten/emscripten.h> #endif -#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) +#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) #include <sys/auxv.h> #endif @@ -95,6 +95,19 @@ uint32_t OS::get_process_id() #endif } +unsigned long OS::get_auxval(unsigned long id) + { +#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) + return ::getauxval(id); +#elif defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) + unsigned long auxinfo = 0; + ::elf_aux_info(id, &auxinfo, sizeof(auxinfo)); + return auxinfo; +#else + return 0; +#endif + } + bool OS::running_in_privileged_state() { #if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) && defined(AT_SECURE) diff --git a/src/lib/utils/os_utils.h b/src/lib/utils/os_utils.h index f597387c7..81d66f170 100644 --- a/src/lib/utils/os_utils.h +++ b/src/lib/utils/os_utils.h @@ -53,6 +53,8 @@ uint64_t BOTAN_TEST_API get_cpu_cycle_counter(); size_t BOTAN_TEST_API get_cpu_total(); size_t BOTAN_TEST_API get_cpu_available(); +unsigned long get_auxval(unsigned long); + /* * @return best resolution timestamp available * |