android - dlopen() 不适用于 android-n

标签 android linux dlopen android-7.0-nougat

dlopen() 在 API-23 上运行良好,但对于 Android-N,当我尝试使用 dlopen 打开任何 sofile 时,它​​返回一个 soinfo 结构类型指针。但是当我尝试访问此结构的任何变量时,应用程序会崩溃。

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

Android-N 的 dlopen() 功能有什么变化吗??

最佳答案

dlopen() 不返回指向某些 soinfo 结构的指针,它返回 void*,标准的 Linux 手册页非常具体说明:

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().

因此,您可以以某种方式解释返回值的事实是非标准的,现在 Google 只是通过 this change 强制执行此操作:

commit  ae74e8750b9dae51b24a22fdb4b0e0a2d84f37b9
author  Dimitry Ivanov <dimitry@google.com>
...
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)

因此,除非您的应用程序以 SDK 版本 23 或更低版本为目标(参见 soinfo::to_handle()),否则您现在获得的句柄只能转换回 soinfo* 带有内部仿生 soinfo_from_handle()

关于android - dlopen() 不适用于 android-n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39325753/

相关文章:

linux - 动态加载时的库路径?

java - 如何在Android(API 19)中获取MEDIA(MediaStore.Audio.Media)的封面

android - 如何在我的自定义键盘中添加语音识别

android - Android 密码管理器应用程序如何工作?

android - In App Billing BroadcastReceiver内存泄漏

linux - 如何使用 grep 过滤管道信息并在找到单​​词时过滤所有信息

objective-c - GC 能力不匹配0?

c++ - 了解 C++ (Linux) 中的 fork、exec 和 wait

linux - 在逐行文件读取的第一个正斜杠之前在字符串周围加上引号

C++:使用 dlopen() 加载共享库时 undefined symbol