我们的Android软件为SQLite使用了一个虚拟文件系统(VFS),它一直在正常工作。一旦我们开始在Android 6(Marshmallow)中使用它,各种奇怪的错误开始发生,传递给ftruncate(),堆栈溢出,数据损坏等的负偏移量很大。使用readelf
(和其他工具),我们最终跟踪问题到libsqlite.so
使用的进口变化:棒棒糖和较早的进口ftruncate
和mmap
,最新的库进口ftruncate64
和mmap64
。我们通过改变“解决”这个问题我们使用取决于API版本的功能(棉花糖是版本23):当源代码调用ftruncate时,Android Marshmallow libsqlite.so如何使用ftruncate64?
/*
* 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
?我们没有看到正确的源代码库吗?在链接步骤中发生了什么?棉花糖是否取消了对这些功能的非64位版本的支持?