Skip to content

Commit

Permalink
Applied Android patch
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Feb 12, 2019
1 parent d29618c commit 8212a2d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 20 deletions.
36 changes: 20 additions & 16 deletions dist/Android.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
--- orig/shell.c 2018-02-18 23:53:25.407627650 -0800
+++ shell.c 2018-02-18 23:53:25.467627374 -0800
@@ -87,6 +87,12 @@
diff --git a/dist/shell.c b/dist/shell.c
index b7f1b24..7110d66 100644
--- a/dist/shell.c
+++ b/dist/shell.c
@@ -87,6 +87,12 @@ typedef unsigned char u8;
#endif
#include <ctype.h>
#include <stdarg.h>
Expand All @@ -13,10 +15,10 @@

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

+#if defined(__BIONIC__)
+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
+# include <android/fdsan.h>
+#endif
+
#ifdef HAVE_UTIME
# include <utime.h>
#endif
@@ -31422,6 +31426,12 @@
@@ -33084,6 +33088,12 @@ static int robust_open(const char *z, int f, mode_t m){
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif
Expand All @@ -63,7 +67,7 @@
}
return fd;
}
@@ -31954,7 +31964,13 @@
@@ -33664,7 +33674,13 @@ static int unixLogErrorAtLine(
** and move on.
*/
static void robust_close(unixFile *pFile, int h, int lineno){
Expand All @@ -77,7 +81,7 @@
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
pFile ? pFile->zPath : 0, lineno);
}
@@ -34428,7 +34444,7 @@
@@ -36197,7 +36213,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
SimulateIOError( rc=1 );
if( rc!=0 ){
storeLastErrno((unixFile*)id, errno);
Expand All @@ -86,7 +90,7 @@
}
*pSize = buf.st_size;

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

if( osFstat(pFile->h, &buf) ){
Expand All @@ -95,7 +99,7 @@
}

nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
@@ -35139,7 +35155,7 @@
@@ -36919,7 +36935,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
** with the same permissions.
*/
if( osFstat(pDbFd->h, &sStat) ){
Expand All @@ -104,7 +108,7 @@
goto shm_open_err;
}

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

@@ -152769,13 +152785,25 @@
@@ -163354,13 +163370,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
** module with sqlite.
*/
if( SQLITE_OK==rc
Expand Down
23 changes: 23 additions & 0 deletions dist/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ typedef unsigned char u8;
#endif
#include <ctype.h>
#include <stdarg.h>
// Begin Android Add
#ifndef NO_ANDROID_FUNCS
#include "IcuUtils.h"
#include <sqlite3_android.h>
#endif
// End Android Add

#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
Expand Down Expand Up @@ -11632,6 +11638,23 @@ static void open_db(ShellState *p, int openFlags){
sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
editFunc, 0, 0);
#endif

// Begin Android Add
#ifndef NO_ANDROID_FUNCS
InitializeIcuOrDie();
int err = register_localized_collators(p->db, "en_US", 0);
if (err != SQLITE_OK) {
fprintf(stderr, "register_localized_collators() failed\n");
exit(1);
}
err = register_android_functions(p->db, 0);
if (err != SQLITE_OK) {
fprintf(stderr, "register_android_functions() failed\n");
exit(1);
}
#endif
// End Android Add

if( p->openMode==SHELL_OPEN_ZIPFILE ){
char *zSql = sqlite3_mprintf(
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
Expand Down
36 changes: 32 additions & 4 deletions dist/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -32325,6 +32325,10 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
# include <sys/mount.h>
#endif

#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
# include <android/fdsan.h>
#endif

#ifdef HAVE_UTIME
# include <utime.h>
#endif
Expand Down Expand Up @@ -33084,6 +33088,12 @@ static int robust_open(const char *z, int f, mode_t m){
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif

#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
uint64_t tag = android_fdsan_create_owner_tag(
ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
android_fdsan_exchange_owner_tag(fd, 0, tag);
#endif
}
return fd;
}
Expand Down Expand Up @@ -33664,7 +33674,13 @@ static int unixLogErrorAtLine(
** and move on.
*/
static void robust_close(unixFile *pFile, int h, int lineno){
#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
uint64_t tag = android_fdsan_create_owner_tag(
ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
if( android_fdsan_close_with_tag(h, tag) ){
#else
if( osClose(h) ){
#endif
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
pFile ? pFile->zPath : 0, lineno);
}
Expand Down Expand Up @@ -36197,7 +36213,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
SimulateIOError( rc=1 );
if( rc!=0 ){
storeLastErrno((unixFile*)id, errno);
return SQLITE_IOERR_FSTAT;
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
}
*pSize = buf.st_size;

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

if( osFstat(pFile->h, &buf) ){
return SQLITE_IOERR_FSTAT;
return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
}

nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
Expand Down Expand Up @@ -36919,7 +36935,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
** with the same permissions.
*/
if( osFstat(pDbFd->h, &sStat) ){
rc = SQLITE_IOERR_FSTAT;
rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
goto shm_open_err;
}

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

Expand Down Expand Up @@ -163354,13 +163370,25 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
** module with sqlite.
*/
if( SQLITE_OK==rc
#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
#endif
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
){
#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
rc = sqlite3_create_module_v2(
db, "fts1", &fts3Module, (void *)pHash, 0
);
if(rc) return rc;
rc = sqlite3_create_module_v2(
db, "fts2", &fts3Module, (void *)pHash, 0
);
if(rc) return rc;
#endif
rc = sqlite3_create_module_v2(
db, "fts3", &fts3Module, (void *)pHash, hashDestroy
);
Expand Down

0 comments on commit 8212a2d

Please sign in to comment.