Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / third_party / sqlite / patches / 0005-Modify-default-VFS-to-support-WebDatabase.patch
blob81343dad6836b1a9d2ad8631752f40ba9048372d
1 From 4b957c2c198a53498fe18ad9668e2817ace98b1e Mon Sep 17 00:00:00 2001
2 From: dumi <dumi@chromium.org>
3 Date: Mon, 20 Jul 2009 23:40:51 +0000
4 Subject: [PATCH 05/11] Modify default VFS to support WebDatabase.
6 The renderer WebDatabase implementation needs to broker certain requests
7 to the browser. This modifies SQLite to allow monkey-patching the VFS
8 to support this.
10 NOTE(shess): This patch relies on core SQLite implementation details
11 remaining unchanged. When importing a new version of SQLite, pay very
12 close attention to whether the change is still doing what is intended.
14 Original review URLs:
15 https://codereview.chromium.org/159044
16 https://codereview.chromium.org/384075
17 https://codereview.chromium.org/377039
18 [Possibly not a complete list.]
19 ---
20 third_party/sqlite/src/src/os_unix.c | 100 +++++++++++++++++++++++++++------
21 third_party/sqlite/src/src/os_win.c | 8 +++
22 third_party/sqlite/src/src/sqlite.h.in | 36 ++++++++++++
23 3 files changed, 128 insertions(+), 16 deletions(-)
25 diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/os_unix.c
26 index a9344ee..75b71dc 100644
27 --- a/third_party/sqlite/src/src/os_unix.c
28 +++ b/third_party/sqlite/src/src/os_unix.c
29 @@ -1321,6 +1321,12 @@ static int fileHasMoved(unixFile *pFile){
30 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
31 #else
32 struct stat buf;
34 + /* TODO(shess): This check doesn't work when the Chromium's WebDB code is
35 + ** running in the sandbox.
36 + */
37 + return 0;
39 return pFile->pInode!=0 &&
40 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
41 #endif
42 @@ -5615,6 +5621,78 @@ static int findCreateFileMode(
46 +** Initializes a unixFile structure with zeros.
47 +*/
48 +CHROMIUM_SQLITE_API
49 +void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file) {
50 + memset(file, 0, sizeof(unixFile));
53 +CHROMIUM_SQLITE_API
54 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs,
55 + int fd,
56 + int dirfd,
57 + sqlite3_file* file,
58 + const char* fileName,
59 + int noLock) {
60 + int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0);
61 + return fillInUnixFile(vfs, fd, file, fileName, ctrlFlags);
64 +/*
65 +** Search for an unused file descriptor that was opened on the database file.
66 +** If a suitable file descriptor if found, then it is stored in *fd; otherwise,
67 +** *fd is not modified.
68 +**
69 +** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot
70 +** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned.
71 +*/
72 +CHROMIUM_SQLITE_API
73 +int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file,
74 + const char* fileName,
75 + int flags,
76 + int* fd) {
77 + unixFile* unixSQLite3File = (unixFile*)file;
78 + int fileType = flags & 0xFFFFFF00;
79 + if (fileType == SQLITE_OPEN_MAIN_DB) {
80 + UnixUnusedFd *unusedFd = findReusableFd(fileName, flags);
81 + if (unusedFd) {
82 + *fd = unusedFd->fd;
83 + } else {
84 + unusedFd = sqlite3_malloc(sizeof(*unusedFd));
85 + if (!unusedFd) {
86 + return SQLITE_NOMEM;
87 + }
88 + }
89 + unixSQLite3File->pUnused = unusedFd;
90 + }
91 + return SQLITE_OK;
94 +/*
95 +** Marks 'fd' as the unused file descriptor for 'pFile'.
96 +*/
97 +CHROMIUM_SQLITE_API
98 +void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file,
99 + int fd,
100 + int flags) {
101 + unixFile* unixSQLite3File = (unixFile*)file;
102 + if (unixSQLite3File->pUnused) {
103 + unixSQLite3File->pUnused->fd = fd;
104 + unixSQLite3File->pUnused->flags = flags;
109 +** Destroys pFile's field that keeps track of the unused file descriptor.
111 +CHROMIUM_SQLITE_API
112 +void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file) {
113 + unixFile* unixSQLite3File = (unixFile*)file;
114 + sqlite3_free(unixSQLite3File->pUnused);
118 ** Open the file zPath.
120 ** Previously, the SQLite OS layer used three functions in place of this
121 @@ -5715,20 +5793,13 @@ static int unixOpen(
122 sqlite3_randomness(0,0);
125 - memset(p, 0, sizeof(unixFile));
126 + chromium_sqlite3_initialize_unix_sqlite3_file(pFile);
128 if( eType==SQLITE_OPEN_MAIN_DB ){
129 - UnixUnusedFd *pUnused;
130 - pUnused = findReusableFd(zName, flags);
131 - if( pUnused ){
132 - fd = pUnused->fd;
133 - }else{
134 - pUnused = sqlite3_malloc(sizeof(*pUnused));
135 - if( !pUnused ){
136 - return SQLITE_NOMEM;
138 + rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd);
139 + if( rc!=SQLITE_OK ){
140 + return rc;
142 - p->pUnused = pUnused;
144 /* Database filenames are double-zero terminated if they are not
145 ** URIs with parameters. Hence, they can always be passed into
146 @@ -5798,10 +5869,7 @@ static int unixOpen(
147 *pOutFlags = flags;
150 - if( p->pUnused ){
151 - p->pUnused->fd = fd;
152 - p->pUnused->flags = flags;
154 + chromium_sqlite3_update_reusable_file_handle(pFile, fd, flags);
156 if( isDelete ){
157 #if OS_VXWORKS
158 @@ -5893,7 +5961,7 @@ static int unixOpen(
160 open_finished:
161 if( rc!=SQLITE_OK ){
162 - sqlite3_free(p->pUnused);
163 + chromium_sqlite3_destroy_reusable_file_handle(pFile);
165 return rc;
167 diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os_win.c
168 index 8ca2107..9320bfc 100644
169 --- a/third_party/sqlite/src/src/os_win.c
170 +++ b/third_party/sqlite/src/src/os_win.c
171 @@ -5546,4 +5546,12 @@ int sqlite3_os_end(void){
172 return SQLITE_OK;
175 +CHROMIUM_SQLITE_API
176 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle) {
177 + winFile* winSQLite3File = (winFile*)file;
178 + memset(file, 0, sizeof(*file));
179 + winSQLite3File->pMethod = &winIoMethod;
180 + winSQLite3File->h = handle;
183 #endif /* SQLITE_OS_WIN */
184 diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src/sqlite.h.in
185 index f1d4e40..36aa999 100644
186 --- a/third_party/sqlite/src/src/sqlite.h.in
187 +++ b/third_party/sqlite/src/src/sqlite.h.in
188 @@ -7408,6 +7408,42 @@ int sqlite3_vtab_on_conflict(sqlite3 *);
192 +/* Begin WebDatabase patch for Chromium */
193 +/* Expose some SQLite internals for the WebDatabase vfs.
194 +** DO NOT EXTEND THE USE OF THIS.
196 +#ifndef CHROMIUM_SQLITE_API
197 +#define CHROMIUM_SQLITE_API SQLITE_API
198 +#endif
199 +#if defined(CHROMIUM_SQLITE_INTERNALS)
200 +#ifdef _WIN32
201 +CHROMIUM_SQLITE_API
202 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle);
203 +#else /* _WIN32 */
204 +CHROMIUM_SQLITE_API
205 +void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file);
206 +CHROMIUM_SQLITE_API
207 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs,
208 + int fd,
209 + int dirfd,
210 + sqlite3_file* file,
211 + const char* fileName,
212 + int noLock);
213 +CHROMIUM_SQLITE_API
214 +int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file,
215 + const char* fileName,
216 + int flags,
217 + int* fd);
218 +CHROMIUM_SQLITE_API
219 +void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file,
220 + int fd,
221 + int flags);
222 +CHROMIUM_SQLITE_API
223 +void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file);
224 +#endif /* _WIN32 */
225 +#endif /* CHROMIUM_SQLITE_INTERNALS */
226 +/* End WebDatabase patch for Chromium */
229 ** Undo the hack that converts floating point types to integer for
230 ** builds on processors without floating point support.
232 2.4.5