Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dlopen() is not working with android-n

dlopen() is working fine at API-23, but For Android-N, when I tried to open any sofile using dlopen it return a soinfo structure type pointer. but when i tried to access any variable of this structure the application get crash.

si = (soinfo*) dlopen("/data/app/com.xxx.xxx.sampleapp.android-1/lib/x86/libtest.so", RTLD_GLOBAL);

if (si == NULL)
    return;

LOGI("value of dlopen [%d]", si->size);

Is there any change in dlopen() functionality with Android-N??

like image 809
vinit Avatar asked Dec 21 '25 01:12

vinit


1 Answers

dlopen() doesn't return a pointer to some soinfo structure, it returns void*, the standard Linux man page is very specific about this:

The function dlopen() loads the dynamic shared object (shared library) file named by the null-terminated string filename and returns an opaque "handle" for the loaded object. This handle is employed with other functions in the dlopen API, such as dlsym(3), dladdr(3), dlinfo(3), and dlclose().

So the fact that you could interpret returned value in some way was non-standard and now Google is just enforcing that with this change:

commit  ae74e8750b9dae51b24a22fdb4b0e0a2d84f37b9
author  Dimitry Ivanov <[email protected]>
...
linker: hide the pointer to soinfo

Handle no longer is a pointer to soinfo of
a corresponding library. This is done to
prevent access to linker internal fields.

Bug: http://b/25593965
Change-Id: I62bff0d0e5b2dc842e6bf0babb30fcc4c000be24
(cherry picked from commit d88e1f350111b3dfd71c6492321f0503cb5540db)

So unless your application is targeting SDK version 23 or less (see soinfo::to_handle()), you're now getting the handle that could only be converted back to soinfo* with an internal bionic soinfo_from_handle().

like image 82
Roman Khimov Avatar answered Dec 23 '25 15:12

Roman Khimov