Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit cfe06e0

Browse files
committed
Applied Android changes to v3.32.2.
1 parent a8f3de3 commit cfe06e0

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ the following procedure should be followed:
2323
* Apply `Android.patch` to the `dist` directory:
2424

2525
$ cd dist
26-
$ patch -p2 < Android.patch
26+
$ patch -p0 < Android.patch
2727

2828
* If there are hunks which failed to apply, fix them
2929
* Update `Android.patch`:

dist/shell.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ typedef unsigned char u8;
9595
#endif
9696
#include <ctype.h>
9797
#include <stdarg.h>
98+
// Begin Android Add
99+
#ifndef NO_ANDROID_FUNCS
100+
#include <sqlite3_android.h>
101+
#endif
102+
// End Android Add
98103

99104
#if !defined(_WIN32) && !defined(WIN32)
100105
# include <signal.h>
@@ -12957,6 +12962,22 @@ static void open_db(ShellState *p, int openFlags){
1295712962
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1295812963
editFunc, 0, 0);
1295912964
#endif
12965+
12966+
// Begin Android Add
12967+
#ifndef NO_ANDROID_FUNCS
12968+
int err = register_localized_collators(p->db, "en_US", 0);
12969+
if (err != SQLITE_OK) {
12970+
fprintf(stderr, "register_localized_collators() failed\n");
12971+
exit(1);
12972+
}
12973+
err = register_android_functions(p->db, 0);
12974+
if (err != SQLITE_OK) {
12975+
fprintf(stderr, "register_android_functions() failed\n");
12976+
exit(1);
12977+
}
12978+
#endif
12979+
// End Android Add
12980+
1296012981
if( p->openMode==SHELL_OPEN_ZIPFILE ){
1296112982
char *zSql = sqlite3_mprintf(
1296212983
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);

dist/sqlite3.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33395,6 +33395,10 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
3339533395
# include <sys/mount.h>
3339633396
#endif
3339733397

33398+
#if defined(__BIONIC__)
33399+
# include <android/fdsan.h>
33400+
#endif
33401+
3339833402
#ifdef HAVE_UTIME
3339933403
# include <utime.h>
3340033404
#endif
@@ -34155,6 +34159,12 @@ static int robust_open(const char *z, int f, mode_t m){
3415534159
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
3415634160
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
3415734161
#endif
34162+
34163+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
34164+
uint64_t tag = android_fdsan_create_owner_tag(
34165+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
34166+
android_fdsan_exchange_owner_tag(fd, 0, tag);
34167+
#endif
3415834168
}
3415934169
return fd;
3416034170
}
@@ -34735,7 +34745,13 @@ static int unixLogErrorAtLine(
3473534745
** and move on.
3473634746
*/
3473734747
static void robust_close(unixFile *pFile, int h, int lineno){
34748+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
34749+
uint64_t tag = android_fdsan_create_owner_tag(
34750+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
34751+
if( android_fdsan_close_with_tag(h, tag) ){
34752+
#else
3473834753
if( osClose(h) ){
34754+
#endif
3473934755
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
3474034756
pFile ? pFile->zPath : 0, lineno);
3474134757
}
@@ -37269,7 +37285,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
3726937285
SimulateIOError( rc=1 );
3727037286
if( rc!=0 ){
3727137287
storeLastErrno((unixFile*)id, errno);
37272-
return SQLITE_IOERR_FSTAT;
37288+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
3727337289
}
3727437290
*pSize = buf.st_size;
3727537291

@@ -37305,7 +37321,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
3730537321
struct stat buf; /* Used to hold return values of fstat() */
3730637322

3730737323
if( osFstat(pFile->h, &buf) ){
37308-
return SQLITE_IOERR_FSTAT;
37324+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
3730937325
}
3731037326

3731137327
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
@@ -38000,7 +38016,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
3800038016
** with the same permissions.
3800138017
*/
3800238018
if( osFstat(pDbFd->h, &sStat) ){
38003-
rc = SQLITE_IOERR_FSTAT;
38019+
rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
3800438020
goto shm_open_err;
3800538021
}
3800638022

@@ -128218,7 +128234,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
128218128234
}
128219128235
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
128220128236
sqlite3SetString(pzErrMsg, db, "unsupported file format");
128221-
rc = SQLITE_ERROR;
128237+
rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
128222128238
goto initone_error_out;
128223128239
}
128224128240

@@ -170128,13 +170144,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
170128170144
** module with sqlite.
170129170145
*/
170130170146
if( SQLITE_OK==rc
170147+
#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
170131170148
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
170149+
#endif
170132170150
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
170133170151
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
170134170152
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
170135170153
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
170136170154
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
170137170155
){
170156+
#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
170157+
rc = sqlite3_create_module_v2(
170158+
db, "fts1", &fts3Module, (void *)pHash, 0
170159+
);
170160+
if(rc) return rc;
170161+
rc = sqlite3_create_module_v2(
170162+
db, "fts2", &fts3Module, (void *)pHash, 0
170163+
);
170164+
if(rc) return rc;
170165+
#endif
170138170166
rc = sqlite3_create_module_v2(
170139170167
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
170140170168
);

0 commit comments

Comments
 (0)