API for getting Android system properties is removed on arm64 platforms

I use __system_property_get () from sys / system_properties.h to get the system property. I am trying to use r10c ndk because I need the arm64 toolchain.

__ system_property_get () is defined in libc.so. The output of readelf libc.so for armv5 / armv7a is shown below.

readelf -Ws libc.so | grep property_get 194: 00009100 20 FUNC GLOBAL DEFAULT 4 __system_property_get 198: 00009100 20 FUNC GLOBAL DEFAULT 4 __system_property_get 

But it looks like it was removed for the arm64 version! I get a linker error saying that it is not defined. I have analyzed all common arm64 libraries, but not one of them has this symbol.

Is there an alternative API to get a system property in native code?

Thanks!

+6
source share
3 answers

It was never intended for a public API. It is hidden in 64-bit instrumental networks, because we could do this without breaking compatibility with ABI.

Is there an alternative API to get a system property in native code?

No. This feature should never be displayed in applications.

What are you trying to do?

+2
source

This is a useful API for native applications, as well as for Java applications, it comes from the native side (see http://rxwen.blogspot.com/2010/01/android-property-system.html ) and other Android system code uses it, so it’s unlikely to leave soon.

 #include <android/log.h> #include <dlfcn.h> #if (__ANDROID_API__ >= 21) // Android 'L' makes __system_property_get a non-global symbol. // Here we provide a stub which loads the symbol from libc via dlsym. typedef int (*PFN_SYSTEM_PROP_GET)(const char *, char *); int __system_property_get(const char* name, char* value) { static PFN_SYSTEM_PROP_GET __real_system_property_get = NULL; if (!__real_system_property_get) { // libc.so should already be open, get a handle to it. void *handle = dlopen("libc.so", RTLD_NOLOAD); if (!handle) { __android_log_print(ANDROID_LOG_ERROR, "foobar", "Cannot dlopen libc.so: %s.\n", dlerror()); } else { __real_system_property_get = (PFN_SYSTEM_PROP_GET)dlsym(handle, "__system_property_get"); } if (!__real_system_property_get) { __android_log_print(ANDROID_LOG_ERROR, "foobar", "Cannot resolve __system_property_get(): %s.\n", dlerror()); } } return (*__real_system_property_get)(name, value); } #endif // __ANDROID_API__ >= 21 
+7
source

Confirm @bleater's answer as a workaround for unexposed __system_properties_ * characters: dlopen libc and dlsym if necessary.

-1
source

Source: https://habr.com/ru/post/982210/


All Articles