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

Commit df4deab

Browse files
committed
Apply Android patch to 3.38.5
1 parent 58afac3 commit df4deab

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

dist/Android.patch

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
--- orig/shell.c 2020-07-09 13:55:18.598783417 +0100
2-
+++ shell.c 2020-10-06 00:01:10.631859326 +0100
3-
@@ -95,6 +95,11 @@
1+
diff --git a/dist/shell.c b/dist/shell.c
2+
index d104768..06a7a06 100644
3+
--- a/dist/shell.c
4+
+++ b/dist/shell.c
5+
@@ -107,6 +107,11 @@ typedef unsigned char u8;
46
#endif
57
#include <ctype.h>
68
#include <stdarg.h>
@@ -12,7 +14,7 @@
1214

1315
#if !defined(_WIN32) && !defined(WIN32)
1416
# include <signal.h>
15-
@@ -12957,6 +12962,22 @@
17+
@@ -16111,6 +16116,22 @@ static void open_db(ShellState *p, int openFlags){
1618
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1719
editFunc, 0, 0);
1820
#endif
@@ -34,10 +36,12 @@
3436
+
3537
if( p->openMode==SHELL_OPEN_ZIPFILE ){
3638
char *zSql = sqlite3_mprintf(
37-
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
38-
--- orig/sqlite3.c 2020-07-09 13:55:18.706784068 +0100
39-
+++ sqlite3.c 2020-07-09 13:55:18.814784719 +0100
40-
@@ -33395,6 +33395,10 @@
39+
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
40+
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
41+
index eb8d7d5..ed0b974 100644
42+
--- a/dist/sqlite3.c
43+
+++ b/dist/sqlite3.c
44+
@@ -34926,6 +34926,10 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
4145
# include <sys/mount.h>
4246
#endif
4347

@@ -48,7 +52,7 @@
4852
#ifdef HAVE_UTIME
4953
# include <utime.h>
5054
#endif
51-
@@ -34155,6 +34159,12 @@
55+
@@ -35488,6 +35492,12 @@ static int robust_open(const char *z, int f, mode_t m){
5256
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
5357
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
5458
#endif
@@ -61,7 +65,7 @@
6165
}
6266
return fd;
6367
}
64-
@@ -34735,7 +34745,13 @@
68+
@@ -36068,7 +36078,13 @@ static int unixLogErrorAtLine(
6569
** and move on.
6670
*/
6771
static void robust_close(unixFile *pFile, int h, int lineno){
@@ -75,7 +79,7 @@
7579
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
7680
pFile ? pFile->zPath : 0, lineno);
7781
}
78-
@@ -37269,7 +37285,7 @@
82+
@@ -38623,7 +38639,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
7983
SimulateIOError( rc=1 );
8084
if( rc!=0 ){
8185
storeLastErrno((unixFile*)id, errno);
@@ -84,16 +88,16 @@
8488
}
8589
*pSize = buf.st_size;
8690

87-
@@ -37305,7 +37321,7 @@
91+
@@ -38659,7 +38675,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
8892
struct stat buf; /* Used to hold return values of fstat() */
89-
93+
9094
if( osFstat(pFile->h, &buf) ){
9195
- return SQLITE_IOERR_FSTAT;
9296
+ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
9397
}
9498

9599
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
96-
@@ -38000,7 +38016,7 @@
100+
@@ -39401,7 +39417,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
97101
** with the same permissions.
98102
*/
99103
if( osFstat(pDbFd->h, &sStat) ){
@@ -102,7 +106,7 @@
102106
goto shm_open_err;
103107
}
104108

105-
@@ -128218,7 +128234,7 @@
109+
@@ -133547,7 +133563,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
106110
}
107111
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
108112
sqlite3SetString(pzErrMsg, db, "unsupported file format");
@@ -111,12 +115,12 @@
111115
goto initone_error_out;
112116
}
113117

114-
@@ -170128,13 +170144,25 @@
118+
@@ -178738,13 +178754,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
115119
** module with sqlite.
116120
*/
117-
if( SQLITE_OK==rc
121+
if( SQLITE_OK==rc
118122
+#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
119-
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
123+
&& SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
120124
+#endif
121125
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
122126
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
@@ -134,6 +138,6 @@
134138
+ );
135139
+ if(rc) return rc;
136140
+#endif
141+
pHash->nRef++;
137142
rc = sqlite3_create_module_v2(
138143
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
139-
);

dist/shell.c

+21
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ typedef unsigned char u8;
107107
#endif
108108
#include <ctype.h>
109109
#include <stdarg.h>
110+
// Begin Android Add
111+
#ifndef NO_ANDROID_FUNCS
112+
#include <sqlite3_android.h>
113+
#endif
114+
// End Android Add
110115

111116
#if !defined(_WIN32) && !defined(WIN32)
112117
# include <signal.h>
@@ -16111,6 +16116,22 @@ static void open_db(ShellState *p, int openFlags){
1611116116
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1611216117
editFunc, 0, 0);
1611316118
#endif
16119+
16120+
// Begin Android Add
16121+
#ifndef NO_ANDROID_FUNCS
16122+
int err = register_localized_collators(p->db, "en_US", 0);
16123+
if (err != SQLITE_OK) {
16124+
fprintf(stderr, "register_localized_collators() failed\n");
16125+
exit(1);
16126+
}
16127+
err = register_android_functions(p->db, 0);
16128+
if (err != SQLITE_OK) {
16129+
fprintf(stderr, "register_android_functions() failed\n");
16130+
exit(1);
16131+
}
16132+
#endif
16133+
// End Android Add
16134+
1611416135
if( p->openMode==SHELL_OPEN_ZIPFILE ){
1611516136
char *zSql = sqlite3_mprintf(
1611616137
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);

dist/sqlite3.c

+32-4
Original file line numberDiff line numberDiff line change
@@ -34926,6 +34926,10 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
3492634926
# include <sys/mount.h>
3492734927
#endif
3492834928

34929+
#if defined(__BIONIC__)
34930+
# include <android/fdsan.h>
34931+
#endif
34932+
3492934933
#ifdef HAVE_UTIME
3493034934
# include <utime.h>
3493134935
#endif
@@ -35488,6 +35492,12 @@ static int robust_open(const char *z, int f, mode_t m){
3548835492
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
3548935493
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
3549035494
#endif
35495+
35496+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
35497+
uint64_t tag = android_fdsan_create_owner_tag(
35498+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
35499+
android_fdsan_exchange_owner_tag(fd, 0, tag);
35500+
#endif
3549135501
}
3549235502
return fd;
3549335503
}
@@ -36068,7 +36078,13 @@ static int unixLogErrorAtLine(
3606836078
** and move on.
3606936079
*/
3607036080
static void robust_close(unixFile *pFile, int h, int lineno){
36081+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
36082+
uint64_t tag = android_fdsan_create_owner_tag(
36083+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
36084+
if( android_fdsan_close_with_tag(h, tag) ){
36085+
#else
3607136086
if( osClose(h) ){
36087+
#endif
3607236088
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
3607336089
pFile ? pFile->zPath : 0, lineno);
3607436090
}
@@ -38623,7 +38639,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
3862338639
SimulateIOError( rc=1 );
3862438640
if( rc!=0 ){
3862538641
storeLastErrno((unixFile*)id, errno);
38626-
return SQLITE_IOERR_FSTAT;
38642+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
3862738643
}
3862838644
*pSize = buf.st_size;
3862938645

@@ -38659,7 +38675,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
3865938675
struct stat buf; /* Used to hold return values of fstat() */
3866038676

3866138677
if( osFstat(pFile->h, &buf) ){
38662-
return SQLITE_IOERR_FSTAT;
38678+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
3866338679
}
3866438680

3866538681
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
@@ -39401,7 +39417,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
3940139417
** with the same permissions.
3940239418
*/
3940339419
if( osFstat(pDbFd->h, &sStat) ){
39404-
rc = SQLITE_IOERR_FSTAT;
39420+
rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
3940539421
goto shm_open_err;
3940639422
}
3940739423

@@ -133547,7 +133563,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
133547133563
}
133548133564
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
133549133565
sqlite3SetString(pzErrMsg, db, "unsupported file format");
133550-
rc = SQLITE_ERROR;
133566+
rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
133551133567
goto initone_error_out;
133552133568
}
133553133569

@@ -178738,13 +178754,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
178738178754
** module with sqlite.
178739178755
*/
178740178756
if( SQLITE_OK==rc
178757+
#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
178741178758
&& SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
178759+
#endif
178742178760
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
178743178761
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
178744178762
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
178745178763
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
178746178764
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
178747178765
){
178766+
#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
178767+
rc = sqlite3_create_module_v2(
178768+
db, "fts1", &fts3Module, (void *)pHash, 0
178769+
);
178770+
if(rc) return rc;
178771+
rc = sqlite3_create_module_v2(
178772+
db, "fts2", &fts3Module, (void *)pHash, 0
178773+
);
178774+
if(rc) return rc;
178775+
#endif
178748178776
pHash->nRef++;
178749178777
rc = sqlite3_create_module_v2(
178750178778
db, "fts3", &fts3Module, (void *)pHash, hashDestroy

0 commit comments

Comments
 (0)