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') 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