aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-05-22 12:10:15 -0400
committerJack Lloyd <[email protected]>2019-05-22 12:10:15 -0400
commit7be91937f8f276071189f9bae3520f13a1c34e2b (patch)
treee407e214816b5a1a60bb682ab1c8dc76ad3d3497 /src/lib/utils
parent851fc12c82af276dfccc61b1fa4a2dfb179d72bf (diff)
parentf87bcc670875d270f022dafe3d8a8462562bcf56 (diff)
Merge GH #1962 Add getauxval replacement for older Android
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/os_utils.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index 394ccf13e..f30f18ae9 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -40,7 +40,8 @@
#include <emscripten/emscripten.h>
#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 <sys/auxv.h>
#endif
@@ -49,6 +50,11 @@
#include <windows.h>
#endif
+#if defined(BOTAN_TARGET_OS_IS_ANDROID)
+ #include <elf.h>
+ extern "C" char **environ;
+#endif
+
namespace Botan {
// Not defined in OS namespace for historical reasons
@@ -99,6 +105,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<Elf32_auxv_t *>(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 +134,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