我們的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位版本的支持?