summaryrefslogtreecommitdiffstats
path: root/base/sys_info_android.cc
diff options
context:
space:
mode:
authorrmcilroy@chromium.org <rmcilroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 05:41:54 +0000
committerrmcilroy@chromium.org <rmcilroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 05:41:54 +0000
commit2e4045d61f18883c791dbc6eced8d11e2df85e97 (patch)
tree2cc0d3a84ebc6d12aca75cde2618f49154519d99 /base/sys_info_android.cc
parent313c692bcc6dd958a9e0e2783c0bc7ace75aaa74 (diff)
downloadchromium_src-2e4045d61f18883c791dbc6eced8d11e2df85e97.zip
chromium_src-2e4045d61f18883c791dbc6eced8d11e2df85e97.tar.gz
chromium_src-2e4045d61f18883c791dbc6eced8d11e2df85e97.tar.bz2
Workaround removal of __system_property_get in Android NDK.
The 'L' release of Android will remove __system_property_get from the NDK. Until we can replace all calls of __system_property_get, this CL adds a temporary work-around for builds compiled against the 'L' API. The workaround involves creating a stub __system_property_get, which uses dlsym to dynamically load the address of the real __system_property_get symbol in libc.so (which is still available as a hidden symbol on the devices libc.so dispite having been removed from the NDK). BUG=392191,393903 Review URL: https://codereview.chromium.org/393923002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284012 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_info_android.cc')
-rw-r--r--base/sys_info_android.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
index 92eefef..ab760e5 100644
--- a/base/sys_info_android.cc
+++ b/base/sys_info_android.cc
@@ -4,6 +4,7 @@
#include "base/sys_info.h"
+#include <dlfcn.h>
#include <sys/system_properties.h>
#include "base/android/sys_utils.h"
@@ -14,6 +15,45 @@
#include "base/strings/stringprintf.h"
#include "base/sys_info_internal.h"
+// TODO(rmcilroy): Update API level when 'L' gets an official API level.
+#if (__ANDROID_API__ >= 9999 /* 'L' */)
+
+namespace {
+
+typedef int (SystemPropertyGetFunction)(const char*, char*);
+
+SystemPropertyGetFunction* DynamicallyLoadRealSystemPropertyGet() {
+ // libc.so should already be open, get a handle to it.
+ void* handle = dlopen("libc.so", RTLD_NOLOAD);
+ if (!handle) {
+ LOG(FATAL) << "Cannot dlopen libc.so: " << dlerror();
+ }
+ SystemPropertyGetFunction* real_system_property_get =
+ reinterpret_cast<SystemPropertyGetFunction*>(
+ dlsym(handle, "__system_property_get"));
+ if (!real_system_property_get) {
+ LOG(FATAL) << "Cannot resolve __system_property_get(): " << dlerror();
+ }
+ return real_system_property_get;
+}
+
+static base::LazyInstance<base::internal::LazySysInfoValue<
+ SystemPropertyGetFunction*, DynamicallyLoadRealSystemPropertyGet> >::Leaky
+ g_lazy_real_system_property_get = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+// Android 'L' removes __system_property_get from the NDK, however it is still
+// a hidden symbol in libc. Until we remove all calls of __system_property_get
+// from Chrome we work around this by defining a weak stub here, which uses
+// dlsym to but ensures that Chrome uses the real system
+// implementatation when loaded. http://crbug.com/392191.
+int __system_property_get(const char* name, char* value) {
+ return g_lazy_real_system_property_get.Get().value()(name, value);
+}
+
+#endif
+
namespace {
// Default version of Android to fall back to when actual version numbers