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

Commit fdc1e34

Browse files
committed
Applied Android changes to v3.40.0
1 parent fbb02a0 commit fdc1e34

File tree

3 files changed

+225
-19
lines changed

3 files changed

+225
-19
lines changed

dist/Android.patch

Lines changed: 168 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,157 @@
1-
--- orig/shell.c 2022-09-01 12:39:01.340032408 +0100
2-
+++ shell.c 2022-09-01 12:39:01.528030292 +0100
3-
@@ -107,6 +107,11 @@
1+
diff --git a/dist/Android.patch b/dist/Android.patch
2+
index 3647d10..e69de29 100644
3+
--- a/dist/Android.patch
4+
+++ b/dist/Android.patch
5+
@@ -1,144 +0,0 @@
6+
---- orig/shell.c 2022-09-01 12:39:01.340032408 +0100
7+
-+++ shell.c 2022-09-01 12:39:01.528030292 +0100
8+
-@@ -107,6 +107,11 @@
9+
- #endif
10+
- #include <ctype.h>
11+
- #include <stdarg.h>
12+
-+// Begin Android Add
13+
-+#ifndef NO_ANDROID_FUNCS
14+
-+#include <sqlite3_android.h>
15+
-+#endif
16+
-+// End Android Add
17+
-
18+
- #if !defined(_WIN32) && !defined(WIN32)
19+
- # include <signal.h>
20+
-@@ -16177,6 +16182,22 @@
21+
- sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
22+
- editFunc, 0, 0);
23+
- #endif
24+
-+
25+
-+// Begin Android Add
26+
-+#ifndef NO_ANDROID_FUNCS
27+
-+ int err = register_localized_collators(p->db, "en_US", 0);
28+
-+ if (err != SQLITE_OK) {
29+
-+ fprintf(stderr, "register_localized_collators() failed\n");
30+
-+ exit(1);
31+
-+ }
32+
-+ err = register_android_functions(p->db, 0);
33+
-+ if (err != SQLITE_OK) {
34+
-+ fprintf(stderr, "register_android_functions() failed\n");
35+
-+ exit(1);
36+
-+ }
37+
-+#endif
38+
-+// End Android Add
39+
-+
40+
- if( p->openMode==SHELL_OPEN_ZIPFILE ){
41+
- char *zSql = sqlite3_mprintf(
42+
- "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
43+
---- orig/sqlite3.c 2022-09-01 12:39:01.356032228 +0100
44+
-+++ sqlite3.c 2022-09-01 12:39:15.955867966 +0100
45+
-@@ -35608,6 +35608,10 @@
46+
- # include <sys/mount.h>
47+
- #endif
48+
-
49+
-+#if defined(__BIONIC__)
50+
-+# include <android/fdsan.h>
51+
-+#endif
52+
-+
53+
- #ifdef HAVE_UTIME
54+
- # include <utime.h>
55+
- #endif
56+
-@@ -36170,6 +36174,12 @@
57+
- #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
58+
- osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
59+
- #endif
60+
-+
61+
-+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
62+
-+ uint64_t tag = android_fdsan_create_owner_tag(
63+
-+ ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
64+
-+ android_fdsan_exchange_owner_tag(fd, 0, tag);
65+
-+#endif
66+
- }
67+
- return fd;
68+
- }
69+
-@@ -36750,7 +36760,13 @@
70+
- ** and move on.
71+
- */
72+
- static void robust_close(unixFile *pFile, int h, int lineno){
73+
-+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
74+
-+ uint64_t tag = android_fdsan_create_owner_tag(
75+
-+ ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
76+
-+ if( android_fdsan_close_with_tag(h, tag) ){
77+
-+#else
78+
- if( osClose(h) ){
79+
-+#endif
80+
- unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
81+
- pFile ? pFile->zPath : 0, lineno);
82+
- }
83+
-@@ -39305,7 +39321,7 @@
84+
- SimulateIOError( rc=1 );
85+
- if( rc!=0 ){
86+
- storeLastErrno((unixFile*)id, errno);
87+
-- return SQLITE_IOERR_FSTAT;
88+
-+ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
89+
- }
90+
- *pSize = buf.st_size;
91+
-
92+
-@@ -39341,7 +39357,7 @@
93+
- struct stat buf; /* Used to hold return values of fstat() */
94+
-
95+
- if( osFstat(pFile->h, &buf) ){
96+
-- return SQLITE_IOERR_FSTAT;
97+
-+ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
98+
- }
99+
-
100+
- nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
101+
-@@ -40083,7 +40099,7 @@
102+
- ** with the same permissions.
103+
- */
104+
- if( osFstat(pDbFd->h, &sStat) ){
105+
-- rc = SQLITE_IOERR_FSTAT;
106+
-+ rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
107+
- goto shm_open_err;
108+
- }
109+
-
110+
-@@ -134802,7 +134818,7 @@
111+
- }
112+
- if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
113+
- sqlite3SetString(pzErrMsg, db, "unsupported file format");
114+
-- rc = SQLITE_ERROR;
115+
-+ rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
116+
- goto initone_error_out;
117+
- }
118+
-
119+
-@@ -180855,7 +180871,9 @@
120+
- ** module with sqlite.
121+
- */
122+
- if( SQLITE_OK==rc
123+
-+#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
124+
- && SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
125+
-+#endif
126+
- && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
127+
- && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
128+
- && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
129+
-@@ -180866,6 +180884,20 @@
130+
- rc = sqlite3_create_module_v2(
131+
- db, "fts3", &fts3Module, (void *)pHash, hashDestroy
132+
- );
133+
-+#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
134+
-+ if( rc==SQLITE_OK ){
135+
-+ pHash->nRef++;
136+
-+ rc = sqlite3_create_module_v2(
137+
-+ db, "fts1", &fts3Module, (void *)pHash, hashDestroy
138+
-+ );
139+
-+ }
140+
-+ if( rc==SQLITE_OK ){
141+
-+ pHash->nRef++;
142+
-+ rc = sqlite3_create_module_v2(
143+
-+ db, "fts2", &fts3Module, (void *)pHash, hashDestroy
144+
-+ );
145+
-+ }
146+
-+#endif
147+
- if( rc==SQLITE_OK ){
148+
- pHash->nRef++;
149+
- rc = sqlite3_create_module_v2(
150+
diff --git a/dist/shell.c b/dist/shell.c
151+
index 6280ebf..8bf6d38 100644
152+
--- a/dist/shell.c
153+
+++ b/dist/shell.c
154+
@@ -126,6 +126,11 @@ typedef unsigned char u8;
4155
#endif
5156
#include <ctype.h>
6157
#include <stdarg.h>
@@ -12,7 +163,7 @@
12163

13164
#if !defined(_WIN32) && !defined(WIN32)
14165
# include <signal.h>
15-
@@ -16177,6 +16182,22 @@
166+
@@ -19557,6 +19562,22 @@ static void open_db(ShellState *p, int openFlags){
16167
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
17168
editFunc, 0, 0);
18169
#endif
@@ -35,9 +186,11 @@
35186
if( p->openMode==SHELL_OPEN_ZIPFILE ){
36187
char *zSql = sqlite3_mprintf(
37188
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
38-
--- orig/sqlite3.c 2022-09-01 12:39:01.356032228 +0100
39-
+++ sqlite3.c 2022-09-01 12:39:15.955867966 +0100
40-
@@ -35608,6 +35608,10 @@
189+
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
190+
index 2763b1b..4c366a0 100644
191+
--- a/dist/sqlite3.c
192+
+++ b/dist/sqlite3.c
193+
@@ -36795,6 +36795,10 @@ SQLITE_PRIVATE int sqlite3KvvfsInit(void){
41194
# include <sys/mount.h>
42195
#endif
43196

@@ -48,7 +201,7 @@
48201
#ifdef HAVE_UTIME
49202
# include <utime.h>
50203
#endif
51-
@@ -36170,6 +36174,12 @@
204+
@@ -37357,6 +37361,12 @@ static int robust_open(const char *z, int f, mode_t m){
52205
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
53206
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
54207
#endif
@@ -61,7 +214,7 @@
61214
}
62215
return fd;
63216
}
64-
@@ -36750,7 +36760,13 @@
217+
@@ -37937,7 +37947,13 @@ static int unixLogErrorAtLine(
65218
** and move on.
66219
*/
67220
static void robust_close(unixFile *pFile, int h, int lineno){
@@ -75,7 +228,7 @@
75228
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
76229
pFile ? pFile->zPath : 0, lineno);
77230
}
78-
@@ -39305,7 +39321,7 @@
231+
@@ -40492,7 +40508,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
79232
SimulateIOError( rc=1 );
80233
if( rc!=0 ){
81234
storeLastErrno((unixFile*)id, errno);
@@ -84,7 +237,7 @@
84237
}
85238
*pSize = buf.st_size;
86239

87-
@@ -39341,7 +39357,7 @@
240+
@@ -40528,7 +40544,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
88241
struct stat buf; /* Used to hold return values of fstat() */
89242

90243
if( osFstat(pFile->h, &buf) ){
@@ -93,7 +246,7 @@
93246
}
94247

95248
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
96-
@@ -40083,7 +40099,7 @@
249+
@@ -41270,7 +41286,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
97250
** with the same permissions.
98251
*/
99252
if( osFstat(pDbFd->h, &sStat) ){
@@ -102,7 +255,7 @@
102255
goto shm_open_err;
103256
}
104257

105-
@@ -134802,7 +134818,7 @@
258+
@@ -136541,7 +136557,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
106259
}
107260
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
108261
sqlite3SetString(pzErrMsg, db, "unsupported file format");
@@ -111,7 +264,7 @@
111264
goto initone_error_out;
112265
}
113266

114-
@@ -180855,7 +180871,9 @@
267+
@@ -182688,7 +182704,9 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
115268
** module with sqlite.
116269
*/
117270
if( SQLITE_OK==rc
@@ -121,7 +274,7 @@
121274
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
122275
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
123276
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
124-
@@ -180866,6 +180884,20 @@
277+
@@ -182699,6 +182717,20 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
125278
rc = sqlite3_create_module_v2(
126279
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
127280
);

dist/shell.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ typedef unsigned char u8;
126126
#endif
127127
#include <ctype.h>
128128
#include <stdarg.h>
129+
// Begin Android Add
130+
#ifndef NO_ANDROID_FUNCS
131+
#include <sqlite3_android.h>
132+
#endif
133+
// End Android Add
129134

130135
#if !defined(_WIN32) && !defined(WIN32)
131136
# include <signal.h>
@@ -19557,6 +19562,22 @@ static void open_db(ShellState *p, int openFlags){
1955719562
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1955819563
editFunc, 0, 0);
1955919564
#endif
19565+
19566+
// Begin Android Add
19567+
#ifndef NO_ANDROID_FUNCS
19568+
int err = register_localized_collators(p->db, "en_US", 0);
19569+
if (err != SQLITE_OK) {
19570+
fprintf(stderr, "register_localized_collators() failed\n");
19571+
exit(1);
19572+
}
19573+
err = register_android_functions(p->db, 0);
19574+
if (err != SQLITE_OK) {
19575+
fprintf(stderr, "register_android_functions() failed\n");
19576+
exit(1);
19577+
}
19578+
#endif
19579+
// End Android Add
19580+
1956019581
if( p->openMode==SHELL_OPEN_ZIPFILE ){
1956119582
char *zSql = sqlite3_mprintf(
1956219583
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);

dist/sqlite3.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36795,6 +36795,10 @@ SQLITE_PRIVATE int sqlite3KvvfsInit(void){
3679536795
# include <sys/mount.h>
3679636796
#endif
3679736797

36798+
#if defined(__BIONIC__)
36799+
# include <android/fdsan.h>
36800+
#endif
36801+
3679836802
#ifdef HAVE_UTIME
3679936803
# include <utime.h>
3680036804
#endif
@@ -37357,6 +37361,12 @@ static int robust_open(const char *z, int f, mode_t m){
3735737361
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
3735837362
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
3735937363
#endif
37364+
37365+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
37366+
uint64_t tag = android_fdsan_create_owner_tag(
37367+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
37368+
android_fdsan_exchange_owner_tag(fd, 0, tag);
37369+
#endif
3736037370
}
3736137371
return fd;
3736237372
}
@@ -37937,7 +37947,13 @@ static int unixLogErrorAtLine(
3793737947
** and move on.
3793837948
*/
3793937949
static void robust_close(unixFile *pFile, int h, int lineno){
37950+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
37951+
uint64_t tag = android_fdsan_create_owner_tag(
37952+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
37953+
if( android_fdsan_close_with_tag(h, tag) ){
37954+
#else
3794037955
if( osClose(h) ){
37956+
#endif
3794137957
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
3794237958
pFile ? pFile->zPath : 0, lineno);
3794337959
}
@@ -40492,7 +40508,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
4049240508
SimulateIOError( rc=1 );
4049340509
if( rc!=0 ){
4049440510
storeLastErrno((unixFile*)id, errno);
40495-
return SQLITE_IOERR_FSTAT;
40511+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
4049640512
}
4049740513
*pSize = buf.st_size;
4049840514

@@ -40528,7 +40544,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
4052840544
struct stat buf; /* Used to hold return values of fstat() */
4052940545

4053040546
if( osFstat(pFile->h, &buf) ){
40531-
return SQLITE_IOERR_FSTAT;
40547+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
4053240548
}
4053340549

4053440550
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
@@ -41270,7 +41286,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
4127041286
** with the same permissions.
4127141287
*/
4127241288
if( osFstat(pDbFd->h, &sStat) ){
41273-
rc = SQLITE_IOERR_FSTAT;
41289+
rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
4127441290
goto shm_open_err;
4127541291
}
4127641292

@@ -136541,7 +136557,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
136541136557
}
136542136558
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
136543136559
sqlite3SetString(pzErrMsg, db, "unsupported file format");
136544-
rc = SQLITE_ERROR;
136560+
rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
136545136561
goto initone_error_out;
136546136562
}
136547136563

@@ -182688,7 +182704,9 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
182688182704
** module with sqlite.
182689182705
*/
182690182706
if( SQLITE_OK==rc
182707+
#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
182691182708
&& SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
182709+
#endif
182692182710
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
182693182711
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
182694182712
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
@@ -182699,6 +182717,20 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
182699182717
rc = sqlite3_create_module_v2(
182700182718
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
182701182719
);
182720+
#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
182721+
if( rc==SQLITE_OK ){
182722+
pHash->nRef++;
182723+
rc = sqlite3_create_module_v2(
182724+
db, "fts1", &fts3Module, (void *)pHash, hashDestroy
182725+
);
182726+
}
182727+
if( rc==SQLITE_OK ){
182728+
pHash->nRef++;
182729+
rc = sqlite3_create_module_v2(
182730+
db, "fts2", &fts3Module, (void *)pHash, hashDestroy
182731+
);
182732+
}
182733+
#endif
182702182734
if( rc==SQLITE_OK ){
182703182735
pHash->nRef++;
182704182736
rc = sqlite3_create_module_v2(

0 commit comments

Comments
 (0)