From 85423f990fa216369e442661c09f900cd7a1deca Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 21 May 2019 21:43:24 +0100 Subject: Providing little getauxval implementation for Android<18 tested with armv7 and ndk 16. --- src/lib/utils/os_utils.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 394ccf13e..2c93f31e8 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -34,14 +34,17 @@ #include #include #undef B0 + extern "C" char **environ; #endif #if defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) #include #endif -#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) +#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_IS_ANDROID) || \ + defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) #include + #include #endif #if defined(BOTAN_TARGET_OS_HAS_WIN32) @@ -99,6 +102,23 @@ unsigned long OS::get_auxval(unsigned long id) { #if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) return ::getauxval(id); +#elif defined(BOTAN_TARGET_OS_IS_ANDROID) + char **p = environ; + + while (*p++!=nullptr); + + Elf32_auxv_t *e = reinterpret_cast(p); + + while (e!=nullptr) + { + if (e->a_type == 0) + continue; + if (e->a_type == id) + return e->a_un.a_val; + e++; + } + + return 0; #elif defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) unsigned long auxinfo = 0; ::elf_aux_info(id, &auxinfo, sizeof(auxinfo)); @@ -111,8 +131,8 @@ unsigned long OS::get_auxval(unsigned long id) bool OS::running_in_privileged_state() { -#if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) && defined(AT_SECURE) - return ::getauxval(AT_SECURE) != 0; +#if defined(AT_SECURE) + return OS::get_auxval(AT_SECURE) != 0; #elif defined(BOTAN_TARGET_OS_HAS_POSIX1) return (::getuid() != ::geteuid()) || (::getgid() != ::getegid()); #else -- cgit v1.2.3 From f87bcc670875d270f022dafe3d8a8462562bcf56 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 22 May 2019 05:04:28 +0100 Subject: tweak --- src/lib/utils/os_utils.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 2c93f31e8..f30f18ae9 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -34,7 +34,6 @@ #include #include #undef B0 - extern "C" char **environ; #endif #if defined(BOTAN_TARGET_OS_IS_EMSCRIPTEN) @@ -44,7 +43,6 @@ #if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_IS_ANDROID) || \ defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO) #include - #include #endif #if defined(BOTAN_TARGET_OS_HAS_WIN32) @@ -52,6 +50,11 @@ #include #endif +#if defined(BOTAN_TARGET_OS_IS_ANDROID) + #include + extern "C" char **environ; +#endif + namespace Botan { // Not defined in OS namespace for historical reasons -- cgit v1.2.3