vin*_*nit 3 linux android 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);
Run Code Online (Sandbox Code Playgroud)
dlopen()Android-N的功能是否有任何变化?
dlopen()没有返回指向某个soinfo结构的指针,它返回void*,标准Linux手册页对此非常具体:
函数dlopen()加载由以null结尾的字符串文件名命名的动态共享对象(共享库)文件,并为加载的对象返回不透明的"句柄".此句柄与dlopen API中的其他函数一起使用,例如dlsym(3),dladdr(3),dlinfo(3)和dlclose().
因此,您可以以某种方式解释返回值的事实是非标准的,现在Google只是通过此更改强制执行:
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)
Run Code Online (Sandbox Code Playgroud)
因此,除非您的应用程序针对的是SDK版本23或更低版本(请参阅参考资料soinfo::to_handle()),否则您现在可以获得只能通过soinfo*内部仿生转换回来的句柄soinfo_from_handle().