blob: 3a148464d31d2b131db703324b0a5432d78e13ff [file] [log] [blame]
From 3b4029bed436558ae745630e970b0f6d8040fb54 Mon Sep 17 00:00:00 2001
From: dumi <dumi@chromium.org>
Date: Mon, 20 Jul 2009 23:40:51 +0000
Subject: [PATCH 03/10] Modify default VFS to support WebDatabase.
The renderer WebDatabase implementation needs to broker certain requests
to the browser. This modifies SQLite to allow monkey-patching the VFS
to support this.
NOTE(shess): This patch relies on core SQLite implementation details
remaining unchanged. When importing a new version of SQLite, pay very
close attention to whether the change is still doing what is intended.
Original review URLs:
https://codereview.chromium.org/159044
https://codereview.chromium.org/384075
https://codereview.chromium.org/377039
[Possibly not a complete list.]
---
third_party/sqlite/src/src/os_unix.c | 50 ++++++++++++++++++++++++++++++++++
third_party/sqlite/src/src/os_win.c | 8 ++++++
third_party/sqlite/src/src/sqlite.h.in | 23 ++++++++++++++++
3 files changed, 81 insertions(+)
diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/os_unix.c
index 1b7e5f344a69..6ed6f6a8fc98 100644
--- a/third_party/sqlite/src/src/os_unix.c
+++ b/third_party/sqlite/src/src/os_unix.c
@@ -1366,6 +1366,12 @@ static int fileHasMoved(unixFile *pFile){
return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
#else
struct stat buf;
+
+ /* TODO(shess): This check doesn't work when the Chromium's WebDB code is
+ ** running in the sandbox.
+ */
+ return 0;
+
return pFile->pInode!=0 &&
(osStat(pFile->zPath, &buf)!=0
|| (u64)buf.st_ino!=pFile->pInode->fileId.ino);
@@ -5688,6 +5694,45 @@ static int findCreateFileMode(
return rc;
}
+/*
+** Initialize |unixFile| internals of |file| on behalf of chromiumOpen() in
+** WebDatabase SQLiteFileSystemPosix.cpp. Function is a subset of unixOpen(),
+** each duplicated piece is marked by "Duplicated in" comment in unixOpen().
+*/
+CHROMIUM_SQLITE_API
+int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs,
+ int fd,
+ sqlite3_file* pFile,
+ const char* zPath,
+ int noLock,
+ int flags) {
+ unixFile *p = (unixFile *)pFile;
+ const int eType = flags&0xFFFFFF00; /* Type of file to open */
+ const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0);
+ int rc;
+
+ memset(p, 0, sizeof(unixFile));
+
+ /* osStat() will not work in the sandbox, so findReusableFd() will always
+ ** fail, so directly include the failure-case setup then initialize
+ ** pPreallocatedUnused.
+ */
+ if( eType==SQLITE_OPEN_MAIN_DB ){
+ p->pPreallocatedUnused = sqlite3_malloc(sizeof(*p->pPreallocatedUnused));
+ if (!p->pPreallocatedUnused) {
+ return SQLITE_NOMEM_BKPT;
+ }
+ p->pPreallocatedUnused->fd = fd;
+ p->pPreallocatedUnused->flags = flags;
+ }
+
+ rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
+ if( rc!=SQLITE_OK ){
+ sqlite3_free(p->pPreallocatedUnused);
+ }
+ return rc;
+}
+
/*
** Open the file zPath.
**
@@ -5789,6 +5834,7 @@ static int unixOpen(
sqlite3_randomness(0,0);
}
+ /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */
memset(p, 0, sizeof(unixFile));
if( eType==SQLITE_OPEN_MAIN_DB ){
@@ -5797,6 +5843,7 @@ static int unixOpen(
if( pUnused ){
fd = pUnused->fd;
}else{
+ /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */
pUnused = sqlite3_malloc64(sizeof(*pUnused));
if( !pUnused ){
return SQLITE_NOMEM_BKPT;
@@ -5874,6 +5921,7 @@ static int unixOpen(
}
if( p->pPreallocatedUnused ){
+ /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */
p->pPreallocatedUnused->fd = fd;
p->pPreallocatedUnused->flags = flags;
}
@@ -5955,10 +6003,12 @@ static int unixOpen(
assert( zPath==0 || zPath[0]=='/'
|| eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
);
+ /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */
rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
open_finished:
if( rc!=SQLITE_OK ){
+ /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */
sqlite3_free(p->pPreallocatedUnused);
}
return rc;
diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os_win.c
index 245a86045bae..eeb2c149800d 100644
--- a/third_party/sqlite/src/src/os_win.c
+++ b/third_party/sqlite/src/src/os_win.c
@@ -6026,4 +6026,12 @@ int sqlite3_os_end(void){
return SQLITE_OK;
}
+CHROMIUM_SQLITE_API
+void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle) {
+ winFile* winSQLite3File = (winFile*)file;
+ memset(file, 0, sizeof(*file));
+ winSQLite3File->pMethod = &winIoMethod;
+ winSQLite3File->h = handle;
+}
+
#endif /* SQLITE_OS_WIN */
diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src/sqlite.h.in
index 64685fef4569..877e79f74af2 100644
--- a/third_party/sqlite/src/src/sqlite.h.in
+++ b/third_party/sqlite/src/src/sqlite.h.in
@@ -7954,6 +7954,29 @@ int sqlite3_strnicmp(const char *, const char *, int);
*/
int sqlite3_strglob(const char *zGlob, const char *zStr);
+/* Begin WebDatabase patch for Chromium */
+/* Expose some SQLite internals for the WebDatabase vfs.
+** DO NOT EXTEND THE USE OF THIS.
+*/
+#ifndef CHROMIUM_SQLITE_API
+#define CHROMIUM_SQLITE_API SQLITE_API
+#endif
+#if defined(CHROMIUM_SQLITE_INTERNALS)
+#ifdef _WIN32
+CHROMIUM_SQLITE_API
+void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle);
+#else /* _WIN32 */
+CHROMIUM_SQLITE_API
+int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs,
+ int fd,
+ sqlite3_file* pFile,
+ const char* zPath,
+ int noLock,
+ int flags);
+#endif /* _WIN32 */
+#endif /* CHROMIUM_SQLITE_INTERNALS */
+/* End WebDatabase patch for Chromium */
+
/*
** CAPI3REF: String LIKE Matching
*
--
2.14.0