我们的 Android 软件使用 SQLite 的虚拟文件系统 (VFS),该系统一直正常工作。一旦我们开始在 Android 6 (Marshmallow) 上使用它,就会开始出现各种奇怪的错误,将大的负偏移量传递给 ftruncate()、堆栈溢出、数据损坏等。使用readelf
(以及其他工具),我们最终追踪到了问题更改使用的导入libsqlite.so
:棒棒糖和更早的导入ftruncate
和mmap
,最新的库导入ftruncate64
和mmap64
。我们通过根据 API 版本(Marshmallow 是 23 版)更改我们使用的函数来“解决”这个问题:
/*
* Empirical testing of Tab S2 running Marshmallow revealed the SQLite
* unix_syscall table uses "ftruncate" and "mmap" as connection points,
* but the actual functions linked against are the *64 versions. This
* leads to stack corruption and all sorts of nasty errors as a result.
*/
if (getApiVersion() >= 23) // for Marshmallow
{ setUnixSystemCall(NULL, "ftruncate", our_ftruncate64);
setUnixSystemCall(NULL, "mmap", our_mmap64);
}
else // for Lollipop & older
{ setUnixSystemCall(NULL, "ftruncate", our_ftruncate);
setUnixSystemCall(NULL, "mmap", our_mmap);
}
查看来自http://www.sqlite.org/2015/sqlite-amalgamation-3081002.zip和https://github.com/android/platform_external_sqlite/blob/master/dist/sqlite3.c的源代码C
消息来源是ftruncate
,mmap
这使得我们的方法充其量是“有问题的” 。
如何libsqlite.so
导入和使用ftruncate64
以及mmap64
源代码只调用ftruncate
和mmap
?我们不是在查看正确的源代码存储库吗?链接步骤是否发生了什么?Marshmallow 是否删除了对这些函数的非 64 位版本的支持?