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

Commit 8212a2d

Browse files
committed
Applied Android patch
1 parent d29618c commit 8212a2d

File tree

3 files changed

+75
-20
lines changed

3 files changed

+75
-20
lines changed

dist/Android.patch

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
--- orig/shell.c 2018-02-18 23:53:25.407627650 -0800
2-
+++ shell.c 2018-02-18 23:53:25.467627374 -0800
3-
@@ -87,6 +87,12 @@
1+
diff --git a/dist/shell.c b/dist/shell.c
2+
index b7f1b24..7110d66 100644
3+
--- a/dist/shell.c
4+
+++ b/dist/shell.c
5+
@@ -87,6 +87,12 @@ typedef unsigned char u8;
46
#endif
57
#include <ctype.h>
68
#include <stdarg.h>
@@ -13,10 +15,10 @@
1315

1416
#if !defined(_WIN32) && !defined(WIN32)
1517
# include <signal.h>
16-
@@ -10389,6 +10395,23 @@
17-
editFunc, 0, 0);
18+
@@ -11632,6 +11638,23 @@ static void open_db(ShellState *p, int openFlags){
1819
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1920
editFunc, 0, 0);
21+
#endif
2022
+
2123
+ // Begin Android Add
2224
+ #ifndef NO_ANDROID_FUNCS
@@ -37,20 +39,22 @@
3739
if( p->openMode==SHELL_OPEN_ZIPFILE ){
3840
char *zSql = sqlite3_mprintf(
3941
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
40-
--- orig/sqlite3.c 2018-02-18 23:53:25.459627411 -0800
41-
+++ sqlite3.c 2018-08-22 15:28:04.016188846 -0700
42-
@@ -30672,6 +30672,10 @@
42+
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
43+
index 70e84b5..ce6f8ab 100644
44+
--- a/dist/sqlite3.c
45+
+++ b/dist/sqlite3.c
46+
@@ -32325,6 +32325,10 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
4347
# include <sys/mount.h>
4448
#endif
4549

46-
+#if defined(__BIONIC__)
50+
+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
4751
+# include <android/fdsan.h>
4852
+#endif
4953
+
5054
#ifdef HAVE_UTIME
5155
# include <utime.h>
5256
#endif
53-
@@ -31422,6 +31426,12 @@
57+
@@ -33084,6 +33088,12 @@ static int robust_open(const char *z, int f, mode_t m){
5458
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
5559
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
5660
#endif
@@ -63,7 +67,7 @@
6367
}
6468
return fd;
6569
}
66-
@@ -31954,7 +31964,13 @@
70+
@@ -33664,7 +33674,13 @@ static int unixLogErrorAtLine(
6771
** and move on.
6872
*/
6973
static void robust_close(unixFile *pFile, int h, int lineno){
@@ -77,7 +81,7 @@
7781
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
7882
pFile ? pFile->zPath : 0, lineno);
7983
}
80-
@@ -34428,7 +34444,7 @@
84+
@@ -36197,7 +36213,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
8185
SimulateIOError( rc=1 );
8286
if( rc!=0 ){
8387
storeLastErrno((unixFile*)id, errno);
@@ -86,7 +90,7 @@
8690
}
8791
*pSize = buf.st_size;
8892

89-
@@ -34464,7 +34480,7 @@
93+
@@ -36233,7 +36249,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
9094
struct stat buf; /* Used to hold return values of fstat() */
9195

9296
if( osFstat(pFile->h, &buf) ){
@@ -95,7 +99,7 @@
9599
}
96100

97101
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
98-
@@ -35139,7 +35155,7 @@
102+
@@ -36919,7 +36935,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
99103
** with the same permissions.
100104
*/
101105
if( osFstat(pDbFd->h, &sStat) ){
@@ -104,7 +108,7 @@
104108
goto shm_open_err;
105109
}
106110

107-
@@ -118054,7 +118070,7 @@
111+
@@ -123698,7 +123714,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
108112
}
109113
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
110114
sqlite3SetString(pzErrMsg, db, "unsupported file format");
@@ -113,7 +117,7 @@
113117
goto initone_error_out;
114118
}
115119

116-
@@ -152769,13 +152785,25 @@
120+
@@ -163354,13 +163370,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
117121
** module with sqlite.
118122
*/
119123
if( SQLITE_OK==rc

dist/shell.c

+23
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ typedef unsigned char u8;
8787
#endif
8888
#include <ctype.h>
8989
#include <stdarg.h>
90+
// Begin Android Add
91+
#ifndef NO_ANDROID_FUNCS
92+
#include "IcuUtils.h"
93+
#include <sqlite3_android.h>
94+
#endif
95+
// End Android Add
9096

9197
#if !defined(_WIN32) && !defined(WIN32)
9298
# include <signal.h>
@@ -11632,6 +11638,23 @@ static void open_db(ShellState *p, int openFlags){
1163211638
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
1163311639
editFunc, 0, 0);
1163411640
#endif
11641+
11642+
// Begin Android Add
11643+
#ifndef NO_ANDROID_FUNCS
11644+
InitializeIcuOrDie();
11645+
int err = register_localized_collators(p->db, "en_US", 0);
11646+
if (err != SQLITE_OK) {
11647+
fprintf(stderr, "register_localized_collators() failed\n");
11648+
exit(1);
11649+
}
11650+
err = register_android_functions(p->db, 0);
11651+
if (err != SQLITE_OK) {
11652+
fprintf(stderr, "register_android_functions() failed\n");
11653+
exit(1);
11654+
}
11655+
#endif
11656+
// End Android Add
11657+
1163511658
if( p->openMode==SHELL_OPEN_ZIPFILE ){
1163611659
char *zSql = sqlite3_mprintf(
1163711660
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);

dist/sqlite3.c

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

32328+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
32329+
# include <android/fdsan.h>
32330+
#endif
32331+
3232832332
#ifdef HAVE_UTIME
3232932333
# include <utime.h>
3233032334
#endif
@@ -33084,6 +33088,12 @@ static int robust_open(const char *z, int f, mode_t m){
3308433088
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
3308533089
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
3308633090
#endif
33091+
33092+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
33093+
uint64_t tag = android_fdsan_create_owner_tag(
33094+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
33095+
android_fdsan_exchange_owner_tag(fd, 0, tag);
33096+
#endif
3308733097
}
3308833098
return fd;
3308933099
}
@@ -33664,7 +33674,13 @@ static int unixLogErrorAtLine(
3366433674
** and move on.
3366533675
*/
3366633676
static void robust_close(unixFile *pFile, int h, int lineno){
33677+
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
33678+
uint64_t tag = android_fdsan_create_owner_tag(
33679+
ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
33680+
if( android_fdsan_close_with_tag(h, tag) ){
33681+
#else
3366733682
if( osClose(h) ){
33683+
#endif
3366833684
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
3366933685
pFile ? pFile->zPath : 0, lineno);
3367033686
}
@@ -36197,7 +36213,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
3619736213
SimulateIOError( rc=1 );
3619836214
if( rc!=0 ){
3619936215
storeLastErrno((unixFile*)id, errno);
36200-
return SQLITE_IOERR_FSTAT;
36216+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
3620136217
}
3620236218
*pSize = buf.st_size;
3620336219

@@ -36233,7 +36249,7 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
3623336249
struct stat buf; /* Used to hold return values of fstat() */
3623436250

3623536251
if( osFstat(pFile->h, &buf) ){
36236-
return SQLITE_IOERR_FSTAT;
36252+
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
3623736253
}
3623836254

3623936255
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
@@ -36919,7 +36935,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
3691936935
** with the same permissions.
3692036936
*/
3692136937
if( osFstat(pDbFd->h, &sStat) ){
36922-
rc = SQLITE_IOERR_FSTAT;
36938+
rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
3692336939
goto shm_open_err;
3692436940
}
3692536941

@@ -123698,7 +123714,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
123698123714
}
123699123715
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
123700123716
sqlite3SetString(pzErrMsg, db, "unsupported file format");
123701-
rc = SQLITE_ERROR;
123717+
rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
123702123718
goto initone_error_out;
123703123719
}
123704123720

@@ -163354,13 +163370,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
163354163370
** module with sqlite.
163355163371
*/
163356163372
if( SQLITE_OK==rc
163373+
#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
163357163374
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
163375+
#endif
163358163376
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
163359163377
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
163360163378
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
163361163379
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
163362163380
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
163363163381
){
163382+
#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
163383+
rc = sqlite3_create_module_v2(
163384+
db, "fts1", &fts3Module, (void *)pHash, 0
163385+
);
163386+
if(rc) return rc;
163387+
rc = sqlite3_create_module_v2(
163388+
db, "fts2", &fts3Module, (void *)pHash, 0
163389+
);
163390+
if(rc) return rc;
163391+
#endif
163364163392
rc = sqlite3_create_module_v2(
163365163393
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
163366163394
);

0 commit comments

Comments
 (0)