diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-08 14:30:41 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-12 13:49:54 +0200 |
commit | ab0a50979b9eb4dfa3320eff7e187e41efedf7a9 (patch) | |
tree | 498dfb8a97ff3361a9f7486863a52bb4e26bb898 /chromium/third_party/sqlite | |
parent | 4ce69f7403811819800e7c5ae1318b2647e778d1 (diff) |
Update Chromium to beta version 37.0.2062.68
Change-Id: I188e3b5aff1bec75566014291b654eb19f5bc8ca
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'chromium/third_party/sqlite')
-rw-r--r-- | chromium/third_party/sqlite/BUILD.gn | 117 | ||||
-rw-r--r-- | chromium/third_party/sqlite/README.chromium | 7 | ||||
-rw-r--r-- | chromium/third_party/sqlite/amalgamation/sqlite3.c | 228 | ||||
-rw-r--r-- | chromium/third_party/sqlite/amalgamation/sqlite3.h | 15 | ||||
-rw-r--r-- | chromium/third_party/sqlite/preload-cache.patch | 280 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/build.c | 30 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/pager.c | 172 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/pager.h | 2 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/pcache.c | 2 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/pcache.h | 2 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/recover.c | 7 | ||||
-rw-r--r-- | chromium/third_party/sqlite/src/src/sqlite.h.in | 15 |
12 files changed, 143 insertions, 734 deletions
diff --git a/chromium/third_party/sqlite/BUILD.gn b/chromium/third_party/sqlite/BUILD.gn new file mode 100644 index 00000000000..b78bd11a954 --- /dev/null +++ b/chromium/third_party/sqlite/BUILD.gn @@ -0,0 +1,117 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +config("sqlite_config") { + include_dirs = [ "." ] +} + +source_set("sqlite") { + sources = [ + "amalgamation/sqlite3.h", + "amalgamation/sqlite3.c", + # fts2.c currently has a lot of conflicts when added to + # the amalgamation. It is probably not worth fixing that. + "src/ext/fts2/fts2.c", + "src/ext/fts2/fts2.h", + "src/ext/fts2/fts2_hash.c", + "src/ext/fts2/fts2_hash.h", + "src/ext/fts2/fts2_icu.c", + "src/ext/fts2/fts2_porter.c", + "src/ext/fts2/fts2_tokenizer.c", + "src/ext/fts2/fts2_tokenizer.h", + "src/ext/fts2/fts2_tokenizer1.c", + ] + + cflags = [] + defines = [ + "SQLITE_CORE", + "SQLITE_ENABLE_BROKEN_FTS2", + "SQLITE_ENABLE_FTS2", + "SQLITE_ENABLE_FTS3", + "SQLITE_ENABLE_ICU", + "SQLITE_ENABLE_MEMORY_MANAGEMENT", + "SQLITE_SECURE_DELETE", + "SQLITE_SEPARATE_CACHE_POOLS", + "THREADSAFE", + "_HAS_EXCEPTIONS=0", + ] + if (is_chromeos) { + defines += [ + # Despite obvious warnings about not using this flag in deployment, we + # are turning off sync in ChromeOS and relying on the underlying + # journaling filesystem to do error recovery properly. It's much faster. + "SQLITE_NO_SYNC", + ] + } + + include_dirs = [ + "amalgamation", + "src/src", # Needed for fts2 to build. + ] + + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ "//build/config/compiler:no_chromium_code" ] + + if (is_win) { + cflags += [ "/wd4267" ] # Conversion from size_t to "type". + } else if (is_linux) { + cflags += [ + # SQLite doesn"t believe in compiler warnings, + # preferring testing. + # http://www.sqlite.org/faq.html#q17 + "-Wno-int-to-pointer-cast", + "-Wno-pointer-to-int-cast", + ] + libs = [ "dl" ] + } else if (is_mac || is_ios) { + libs = [ "CoreFoundation.framework" ] + } else if (is_android) { + defines += [ + "HAVE_USLEEP=1", + "SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576", + "SQLITE_DEFAULT_AUTOVACUUM=1", + "SQLITE_TEMP_STORE=3", + "SQLITE_ENABLE_FTS3_BACKWARDS", + "DSQLITE_DEFAULT_FILE_FORMAT=4", + ] + } + + if (is_clang) { + cflags += [ + # sqlite does `if (*a++ && *b++);` in a non-buggy way. + "-Wno-empty-body", + # sqlite has some `unsigned < 0` checks. + "-Wno-tautological-compare", + ] + } + + direct_dependent_configs = [ ":sqlite_config" ] + + deps = [ + "//third_party/icu", + ] +} + +if (is_linux) { + executable("sqlite_shell") { + sources = [ + "src/src/shell.c", + "src/src/shell_icu_linux.c", + # Include a dummy c++ file to force linking of libstdc++. + "build_as_cpp.cc", + ] + + deps = [ + ":sqlite", + "//third_party/icu", + ] + } +} + +if (is_ios) { + source_set("sqlite_regexp") { + sources = [ "src/ext/icu/icu.c" ] + deps = [ "//third_party/icu" ] + } +} diff --git a/chromium/third_party/sqlite/README.chromium b/chromium/third_party/sqlite/README.chromium index da14b0ef501..aeacf146741 100644 --- a/chromium/third_party/sqlite/README.chromium +++ b/chromium/third_party/sqlite/README.chromium @@ -59,7 +59,6 @@ applied to a vanilla SQLite (of the version we currently have) to get, in principle, exactly what is checked in: misc.patch -preload-cache.patch safe-tolower.patch fts2.patch fts3.patch @@ -81,7 +80,6 @@ So, e.g. you could do this to apply all our patches to vanilla SQLite: cd sqlite-$LATEST patch -p0 < ../sqlite/misc.patch -patch -p0 < ../sqlite/preload-cache.patch patch -p0 < ../sqlite/fts2.patch patch -p0 < ../sqlite/fts3.patch patch -p0 < ../sqlite/fts3_85522.patch @@ -167,11 +165,6 @@ Changes from Chrome: our ICU data. shell.c has been modifed to call into these files. - fts2_icu.c and fts3_icu.c have a critical bug. U8_NEXT is used over a UTF-16 string. It's rep$ by U16_NEXT (jungshik) - - Added a new function sqlite3_preload we use to prime the database cache. It - allows much faster performance by reading the file in one contiguous - operation rather than bringing it in organically, which involves a lot of - seeking. This change also required sqlite3PcacheGetCachesize to be compiled - even outside SQLITE_TEST. - Added a new function chromium_sqlite3_initialize_win_sqlite3_file() at the end of os_win.c. It allows the Windows-specific Chromium VFS to reuse most of the win32 SQLite VFS. diff --git a/chromium/third_party/sqlite/amalgamation/sqlite3.c b/chromium/third_party/sqlite/amalgamation/sqlite3.c index 7c835a69914..c0315fffb7d 100644 --- a/chromium/third_party/sqlite/amalgamation/sqlite3.c +++ b/chromium/third_party/sqlite/amalgamation/sqlite3.c @@ -5234,21 +5234,6 @@ struct sqlite3_index_info { double estimatedCost; /* Estimated cost of using this index */ }; -/* Begin preload-cache.patch for Chromium */ -/* -** Preload the databases into the pager cache, up to the maximum size of the -** pager cache. -** -** For a database to be loaded successfully, the pager must be active. That is, -** there must be an open statement on that database. See sqlite3pager_loadall -** -** There might be many databases attached to the given connection. We iterate -** them all and try to load them. If none are loadable successfully, we return -** an error. Otherwise, we return OK. -*/ -SQLITE_API int sqlite3_preload(sqlite3 *db); -/* End preload-cache.patch for Chromium */ - /* ** CAPI3REF: Virtual Table Constraint Operator Codes ** @@ -8459,8 +8444,6 @@ SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*); SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); SQLITE_PRIVATE int sqlite3PagerNosync(Pager*); -/* This function is for preload-cache.patch for Chromium: */ -SQLITE_PRIVATE int sqlite3PagerLoadall(Pager*); SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); @@ -8631,7 +8614,9 @@ SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHd ** of the suggested cache-sizes. */ SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int); +#ifdef SQLITE_TEST SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *); +#endif #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT /* Try to return memory used by the pcache module to the main memory heap */ @@ -34893,12 +34878,14 @@ SQLITE_PRIVATE int sqlite3PcachePagecount(PCache *pCache){ return nPage; } +#ifdef SQLITE_TEST /* ** Get the suggested cache-size value. */ SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *pCache){ return pCache->nMax; } +#endif /* ** Set the suggested cache-size value. @@ -37234,16 +37221,6 @@ static int pagerUseWal(Pager *pPager){ # define pagerBeginReadTransaction(z) SQLITE_OK #endif -/* Begin preload-cache.patch for Chromium */ -/* See comments above the definition. */ -SQLITE_PRIVATE int sqlite3PagerAcquire2( - Pager *pPager, - Pgno pgno, - DbPage **ppPage, - int noContent, - unsigned char *pDataToFill); -/* End preload-cache.patch for Chromium */ - #ifndef NDEBUG /* ** Usage: @@ -41413,25 +41390,6 @@ SQLITE_PRIVATE int sqlite3PagerAcquire( DbPage **ppPage, /* Write a pointer to the page here */ int noContent /* Do not bother reading content from disk if true */ ){ - /* This just passes through to our modified version with NULL data. */ - return sqlite3PagerAcquire2(pPager, pgno, ppPage, noContent, 0); -} - -/* -** This is an internal version of sqlite3PagerAcquire that takes an extra -** parameter of data to use to fill the page with. This allows more efficient -** filling for preloaded data. If this extra parameter is NULL, we'll go to -** the file. -** -** See sqlite3PagerLoadall which uses this function. -*/ -SQLITE_PRIVATE int sqlite3PagerAcquire2( - Pager *pPager, /* The pager open on the database file */ - Pgno pgno, /* Page number to fetch */ - DbPage **ppPage, /* Write a pointer to the page here */ - int noContent, /* Do not bother reading content from disk if true */ - unsigned char* pDataToFill -){ int rc; PgHdr *pPg; @@ -41507,17 +41465,9 @@ SQLITE_PRIVATE int sqlite3PagerAcquire2( IOTRACE(("ZERO %p %d\n", pPager, pgno)); }else{ assert( pPg->pPager==pPager ); - if( pDataToFill ){ - /* Just copy from the given memory */ - memcpy(pPg->pData, pDataToFill, pPager->pageSize); - CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM; - goto pager_acquire_err); - }else{ - /* Load from disk (old regular sqlite code path) */ - rc = readDbPage(pPg); - if( rc!=SQLITE_OK ){ - goto pager_acquire_err; - } + rc = readDbPage(pPg); + if( rc!=SQLITE_OK ){ + goto pager_acquire_err; } } pager_set_pagehash(pPg); @@ -42939,135 +42889,6 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i } #endif -/* Begin preload-cache.patch for Chromium */ -#if 1 -/* NOTE(shess): Testing to see if simply reading the data into the - * filesystem buffers will have the positive speed impact without the - * negative memory impact. - */ -SQLITE_PRIVATE int sqlite3PagerLoadall(Pager* pPager) -{ - int i, pageSize, loadPages, rc; - unsigned char *fileData; - - /* TODO(shess): This test may not be relevant for this - * implementation, but keep the invariant consistent. - */ - pageSize = pPager->pageSize; - if (pPager->dbSize < 0 || pageSize < 0) { - /* pager not initialized, this means a statement is not open */ - return SQLITE_MISUSE; - } - - /* Allocate a buffer to read pages into. */ - /* TODO(shess): No need to read by page, this could be a fixed-size - * buffer on stack. - */ - fileData = sqlite3Malloc(pageSize); - if (!fileData) - return SQLITE_NOMEM; - - /* Load the smaller of the entire cache or the entire database. */ - loadPages = sqlite3PcacheGetCachesize(pPager->pPCache); - if (loadPages > pPager->dbSize) - loadPages = pPager->dbSize; - - /* Read database page by page. */ - rc = SQLITE_OK; - for(i=0; i < loadPages; i++) { - rc = sqlite3OsRead(pPager->fd, fileData, pageSize, i*pageSize); - if (rc != SQLITE_OK) - break; - } - sqlite3_free(fileData); - return rc; -} -#else -/** -** When making large allocations, there is no need to stress the heap and -** potentially hold its lock while we allocate a bunch of memory. If we know -** the allocation will be large, go directly to the OS instead of the heap. -**/ -static void* allocLarge(size_t size) { -#if SQLITE_OS_WIN - return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); -#else - return sqlite3Malloc(size); -#endif -} - -static void freeLarge(void* ptr) { -#if SQLITE_OS_WIN - VirtualFree(ptr, 0, MEM_RELEASE); -#else - sqlite3_free(ptr); -#endif -} - -/** -** Addition: This will attempt to populate the database cache with -** the first N bytes of the file, where N is the total size of the cache. -** Because we can load this as one chunk from the disk, this is much faster -** than loading a subset of the pages one at a time in random order. -** -** The pager must be initialized before this function is called. This means a -* statement must be open that has initialized the pager and is keeping the -** cache in memory. -**/ -SQLITE_PRIVATE int sqlite3PagerLoadall(Pager* pPager) -{ - int i; - int rc; - int nMax; - int loadSize; - int loadPages; - unsigned char *fileData; - - if (pPager->dbSize < 0 || pPager->pageSize < 0) { - /* pager not initialized, this means a statement is not open */ - return SQLITE_MISUSE; - } - - /* compute sizes */ - nMax = sqlite3PcacheGetCachesize(pPager->pPCache); - if (nMax < pPager->dbSize) - loadPages = nMax; - else - loadPages = pPager->dbSize; - loadSize = loadPages * pPager->pageSize; - - /* load the file as one chunk */ - fileData = allocLarge(loadSize); - if (! fileData) - return SQLITE_NOMEM; - rc = sqlite3OsRead(pPager->fd, fileData, loadSize, 0); - if (rc != SQLITE_OK) { - freeLarge(fileData); - return rc; - } - - /* Copy the data to each page. Note that the page numbers we pass to _get - * are one-based, 0 is a marker for no page. We also need to check that we - * haven't loaded more pages than the cache can hold total. There may have - * already been a few pages loaded before, so we may fill the cache before - * loading all of the pages we want to. - */ - for(i=1; - i <= loadPages && sqlite3PcachePagecount(pPager->pPCache) < nMax; - i++) { - DbPage *pPage = 0; - rc = sqlite3PagerAcquire2(pPager, i, &pPage, 0, - &fileData[(i-1)*(i64)pPager->pageSize]); - if (rc != SQLITE_OK) - break; - sqlite3PagerUnref(pPage); - } - freeLarge(fileData); - return SQLITE_OK; -} -#endif -/* End preload-cache.patch for Chromium */ - /* ** Return a pointer to the data for the specified page. */ @@ -77042,7 +76863,6 @@ SQLITE_PRIVATE void sqlite3AuthContextPop(AuthContext *pContext){ ** ROLLBACK */ - /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Initialize the pParse structure as needed. @@ -80775,33 +80595,6 @@ SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ return pKey; } -/* Begin preload-cache.patch for Chromium */ -/* See declaration in sqlite3.h for information */ -SQLITE_API int sqlite3_preload(sqlite3 *db) -{ - Pager *pPager; - Btree *pBt; - int rc; - int i; - int dbsLoaded = 0; - - for(i=0; i<db->nDb; i++) { - pBt = db->aDb[i].pBt; - if( !pBt ) - continue; - pPager = sqlite3BtreePager(pBt); - if( pPager ) { - rc = sqlite3PagerLoadall(pPager); - if (rc == SQLITE_OK) - dbsLoaded++; - } - } - if (dbsLoaded == 0) - return SQLITE_ERROR; - return SQLITE_OK; -} -/* End preload-cache.patch for Chromium */ - /************** End of build.c ***********************************************/ /************** Begin file callback.c ****************************************/ /* @@ -111728,6 +111521,7 @@ static int ValidateError(){ /* Setup the cursor for reading the information from cell iCell. */ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ const unsigned char *pPageHeader; /* Header of current page. */ + const unsigned char *pPageEnd; /* Byte after end of current page. */ const unsigned char *pCellOffsets; /* Pointer to page's cell offsets. */ unsigned iCellOffset; /* Offset of current cell (iCell). */ const unsigned char *pCell; /* Pointer to data at iCellOffset. */ @@ -111750,6 +111544,10 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ /* Find the offset to the row. */ pPageHeader = PageHeader(pCursor->pPage); pCellOffsets = pPageHeader + knPageLeafHeaderBytes; + pPageEnd = PageData(pCursor->pPage, pCursor->nPageSize); + if( pCellOffsets + pCursor->iCell*2 + 2 > pPageEnd ){ + return ValidateError(); + } iCellOffset = decodeUnsigned16(pCellOffsets + pCursor->iCell*2); if( iCellOffset>=pCursor->nPageSize ){ return ValidateError(); @@ -111791,7 +111589,7 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ /* Check that no other cell starts within this cell. */ iEndOffset = pCursor->iRecordOffset + pCursor->nLocalRecordBytes; - for( i=0; i<pCursor->nCells; ++i ){ + for( i=0; i<pCursor->nCells && pCellOffsets + i*2 + 2 <= pPageEnd; ++i ){ const unsigned iOtherOffset = decodeUnsigned16(pCellOffsets + i*2); if( iOtherOffset>iCellOffset && iOtherOffset<iEndOffset ){ return ValidateError(); diff --git a/chromium/third_party/sqlite/amalgamation/sqlite3.h b/chromium/third_party/sqlite/amalgamation/sqlite3.h index 5d56618caef..91ac9145f89 100644 --- a/chromium/third_party/sqlite/amalgamation/sqlite3.h +++ b/chromium/third_party/sqlite/amalgamation/sqlite3.h @@ -4691,21 +4691,6 @@ struct sqlite3_index_info { double estimatedCost; /* Estimated cost of using this index */ }; -/* Begin preload-cache.patch for Chromium */ -/* -** Preload the databases into the pager cache, up to the maximum size of the -** pager cache. -** -** For a database to be loaded successfully, the pager must be active. That is, -** there must be an open statement on that database. See sqlite3pager_loadall -** -** There might be many databases attached to the given connection. We iterate -** them all and try to load them. If none are loadable successfully, we return -** an error. Otherwise, we return OK. -*/ -SQLITE_API int sqlite3_preload(sqlite3 *db); -/* End preload-cache.patch for Chromium */ - /* ** CAPI3REF: Virtual Table Constraint Operator Codes ** diff --git a/chromium/third_party/sqlite/preload-cache.patch b/chromium/third_party/sqlite/preload-cache.patch deleted file mode 100644 index 7a361d19f0a..00000000000 --- a/chromium/third_party/sqlite/preload-cache.patch +++ /dev/null @@ -1,280 +0,0 @@ -Adds a new API function sqlite3_preload(). This fills the page cache -with the first pages of the database. - -Index: src/build.c -=================================================================== ---- src/build.c 2009-09-11 07:02:46.000000000 -0700 -+++ src/build.c 2009-09-14 18:16:46.000000000 -0700 -@@ -26,6 +26,9 @@ - */ - #include "sqliteInt.h" - -+#include "pager.h" -+#include "btree.h" -+ - /* - ** This routine is called when a new SQL statement is beginning to - ** be parsed. Initialize the pParse structure as needed. -@@ -3659,3 +3662,30 @@ - } - return pKey; - } -+ -+/* Begin preload-cache.patch for Chromium */ -+/* See declaration in sqlite3.h for information */ -+int sqlite3_preload(sqlite3 *db) -+{ -+ Pager *pPager; -+ Btree *pBt; -+ int rc; -+ int i; -+ int dbsLoaded = 0; -+ -+ for(i=0; i<db->nDb; i++) { -+ pBt = db->aDb[i].pBt; -+ if( !pBt ) -+ continue; -+ pPager = sqlite3BtreePager(pBt); -+ if( pPager ) { -+ rc = sqlite3PagerLoadall(pPager); -+ if (rc == SQLITE_OK) -+ dbsLoaded++; -+ } -+ } -+ if (dbsLoaded == 0) -+ return SQLITE_ERROR; -+ return SQLITE_OK; -+} -+/* End preload-cache.patch for Chromium */ -Index: src/sqlite3.h.in -=================================================================== ---- src/sqlite.h.in 2009-09-09 07:03:20.000000000 -0700 -+++ src/sqlite.h.in 2009-09-15 11:34:26.000000000 -0700 -@@ -4677,6 +4677,21 @@ - */ - int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); - -+/* Begin preload-cache.patch for Chromium */ -+/* -+** Preload the databases into the pager cache, up to the maximum size of the -+** pager cache. -+** -+** For a database to be loaded successfully, the pager must be active. That is, -+** there must be an open statement on that database. See sqlite3pager_loadall -+** -+** There might be many databases attached to the given connection. We iterate -+** them all and try to load them. If none are loadable successfully, we return -+** an error. Otherwise, we return OK. -+*/ -+int sqlite3_preload(sqlite3 *db); -+/* End preload-cache.patch for Chromium */ -+ - /* - ** CAPI3REF: Virtual File System Objects {H11200} <S20100> - ** -Index: src/pager.c -=================================================================== ---- src/pager.c 2009-09-07 08:58:09.000000000 -0700 -+++ src/pager.c 2009-09-15 16:43:07.000000000 -0700 -@@ -388,6 +388,16 @@ - */ - #define PAGER_MAX_PGNO 2147483647 - -+/* Begin preload-cache.patch for Chromium */ -+/* See comments above the definition. */ -+int sqlite3PagerAcquire2( -+ Pager *pPager, -+ Pgno pgno, -+ DbPage **ppPage, -+ int noContent, -+ unsigned char *pDataToFill); -+/* End preload-cache.patch for Chromium */ -+ - #ifndef NDEBUG - /* - ** Usage: -@@ -3788,6 +3798,25 @@ - DbPage **ppPage, /* Write a pointer to the page here */ - int noContent /* Do not bother reading content from disk if true */ - ){ -+ /* This just passes through to our modified version with NULL data. */ -+ return sqlite3PagerAcquire2(pPager, pgno, ppPage, noContent, 0); -+} -+ -+/* -+** This is an internal version of sqlite3PagerAcquire that takes an extra -+** parameter of data to use to fill the page with. This allows more efficient -+** filling for preloaded data. If this extra parameter is NULL, we'll go to -+** the file. -+** -+** See sqlite3PagerLoadall which uses this function. -+*/ -+int sqlite3PagerAcquire2( -+ Pager *pPager, /* The pager open on the database file */ -+ Pgno pgno, /* Page number to fetch */ -+ DbPage **ppPage, /* Write a pointer to the page here */ -+ int noContent, /* Do not bother reading content from disk if true */ -+ unsigned char* pDataToFill -+){ - int rc; - PgHdr *pPg; - -@@ -3870,9 +3899,17 @@ - IOTRACE(("ZERO %p %d\n", pPager, pgno)); - }else{ - assert( pPg->pPager==pPager ); -- rc = readDbPage(pPg); -- if( rc!=SQLITE_OK ){ -- goto pager_acquire_err; -+ if( pDataToFill ){ -+ /* Just copy from the given memory */ -+ memcpy(pPg->pData, pDataToFill, pPager->pageSize); -+ CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM; -+ goto pager_acquire_err); -+ }else{ -+ /* Load from disk (old regular sqlite code path) */ -+ rc = readDbPage(pPg); -+ if( rc!=SQLITE_OK ){ -+ goto pager_acquire_err; -+ } - } - } - #ifdef SQLITE_CHECK_PAGES -@@ -5221,6 +5258,91 @@ - } - #endif - -+/* Begin preload-cache.patch for Chromium */ -+/** -+** When making large allocations, there is no need to stress the heap and -+** potentially hold its lock while we allocate a bunch of memory. If we know -+** the allocation will be large, go directly to the OS instead of the heap. -+**/ -+static void* allocLarge(size_t size) { -+#if SQLITE_OS_WIN -+ return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); -+#else -+ return sqlite3Malloc(size); -+#endif -+} -+ -+static void freeLarge(void* ptr) { -+#if SQLITE_OS_WIN -+ VirtualFree(ptr, 0, MEM_RELEASE); -+#else -+ sqlite3_free(ptr); -+#endif -+} -+ -+/** -+** Addition: This will attempt to populate the database cache with -+** the first N bytes of the file, where N is the total size of the cache. -+** Because we can load this as one chunk from the disk, this is much faster -+** than loading a subset of the pages one at a time in random order. -+** -+** The pager must be initialized before this function is called. This means a -+* statement must be open that has initialized the pager and is keeping the -+** cache in memory. -+**/ -+int sqlite3PagerLoadall(Pager* pPager) -+{ -+ int i; -+ int rc; -+ int nMax; -+ int loadSize; -+ int loadPages; -+ unsigned char *fileData; -+ -+ if (pPager->dbSize < 0 || pPager->pageSize < 0) { -+ /* pager not initialized, this means a statement is not open */ -+ return SQLITE_MISUSE; -+ } -+ -+ /* compute sizes */ -+ nMax = sqlite3PcacheGetCachesize(pPager->pPCache); -+ if (nMax < pPager->dbSize) -+ loadPages = nMax; -+ else -+ loadPages = pPager->dbSize; -+ loadSize = loadPages * pPager->pageSize; -+ -+ /* load the file as one chunk */ -+ fileData = allocLarge(loadSize); -+ if (! fileData) -+ return SQLITE_NOMEM; -+ rc = sqlite3OsRead(pPager->fd, fileData, loadSize, 0); -+ if (rc != SQLITE_OK) { -+ freeLarge(fileData); -+ return rc; -+ } -+ -+ /* Copy the data to each page. Note that the page numbers we pass to _get -+ * are one-based, 0 is a marker for no page. We also need to check that we -+ * haven't loaded more pages than the cache can hold total. There may have -+ * already been a few pages loaded before, so we may fill the cache before -+ * loading all of the pages we want to. -+ */ -+ for(i=1; -+ i <= loadPages && sqlite3PcachePagecount(pPager->pPCache) < nMax; -+ i++) { -+ DbPage *pPage = 0; -+ rc = sqlite3PagerAcquire2(pPager, i, &pPage, 0, -+ &fileData[(i-1)*(i64)pPager->pageSize]); -+ if (rc != SQLITE_OK) -+ break; -+ sqlite3PagerUnref(pPage); -+ } -+ freeLarge(fileData); -+ return SQLITE_OK; -+} -+/* End preload-cache.patch for Chromium */ -+ - /* - ** Return a pointer to the data for the specified page. - */ -Index: src/pager.h -=================================================================== ---- src/pager.h 2009-09-04 13:37:42.000000000 -0700 -+++ src/pager.h 2009-09-15 11:31:55.000000000 -0700 -@@ -143,6 +143,8 @@ - sqlite3_file *sqlite3PagerFile(Pager*); - const char *sqlite3PagerJournalname(Pager*); - int sqlite3PagerNosync(Pager*); -+/* This function is for preload-cache.patch for Chromium: */ -+int sqlite3PagerLoadall(Pager*); - void *sqlite3PagerTempSpace(Pager*); - int sqlite3PagerIsMemdb(Pager*); - -Index: src/pcache.c -=================================================================== ---- src/pcache.c 2009-09-04 13:37:42.000000000 -0700 -+++ src/pcache.c 2009-09-15 16:41:55.000000000 -0700 -@@ -542,14 +542,12 @@ - return nPage; - } - --#ifdef SQLITE_TEST - /* - ** Get the suggested cache-size value. - */ - int sqlite3PcacheGetCachesize(PCache *pCache){ - return pCache->nMax; - } --#endif - - /* - ** Set the suggested cache-size value. -Index: src/pcache.h -=================================================================== ---- src/pcache.h 2009-09-04 13:37:42.000000000 -0700 -+++ src/pcache.h 2009-09-15 16:41:52.000000000 -0700 -@@ -139,9 +139,7 @@ - ** of the suggested cache-sizes. - */ - void sqlite3PcacheSetCachesize(PCache *, int); --#ifdef SQLITE_TEST - int sqlite3PcacheGetCachesize(PCache *); --#endif - - #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT - /* Try to return memory used by the pcache module to the main memory heap */ diff --git a/chromium/third_party/sqlite/src/src/build.c b/chromium/third_party/sqlite/src/src/build.c index 4f4f8ed7f5e..25a74ca7ed2 100644 --- a/chromium/third_party/sqlite/src/src/build.c +++ b/chromium/third_party/sqlite/src/src/build.c @@ -24,9 +24,6 @@ */ #include "sqliteInt.h" -#include "pager.h" -#include "btree.h" - /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Initialize the pParse structure as needed. @@ -3758,30 +3755,3 @@ KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ } return pKey; } - -/* Begin preload-cache.patch for Chromium */ -/* See declaration in sqlite3.h for information */ -int sqlite3_preload(sqlite3 *db) -{ - Pager *pPager; - Btree *pBt; - int rc; - int i; - int dbsLoaded = 0; - - for(i=0; i<db->nDb; i++) { - pBt = db->aDb[i].pBt; - if( !pBt ) - continue; - pPager = sqlite3BtreePager(pBt); - if( pPager ) { - rc = sqlite3PagerLoadall(pPager); - if (rc == SQLITE_OK) - dbsLoaded++; - } - } - if (dbsLoaded == 0) - return SQLITE_ERROR; - return SQLITE_OK; -} -/* End preload-cache.patch for Chromium */ diff --git a/chromium/third_party/sqlite/src/src/pager.c b/chromium/third_party/sqlite/src/src/pager.c index a4189662bb9..a4fe3186937 100644 --- a/chromium/third_party/sqlite/src/src/pager.c +++ b/chromium/third_party/sqlite/src/src/pager.c @@ -791,16 +791,6 @@ static int pagerUseWal(Pager *pPager){ # define pagerBeginReadTransaction(z) SQLITE_OK #endif -/* Begin preload-cache.patch for Chromium */ -/* See comments above the definition. */ -int sqlite3PagerAcquire2( - Pager *pPager, - Pgno pgno, - DbPage **ppPage, - int noContent, - unsigned char *pDataToFill); -/* End preload-cache.patch for Chromium */ - #ifndef NDEBUG /* ** Usage: @@ -4970,25 +4960,6 @@ int sqlite3PagerAcquire( DbPage **ppPage, /* Write a pointer to the page here */ int noContent /* Do not bother reading content from disk if true */ ){ - /* This just passes through to our modified version with NULL data. */ - return sqlite3PagerAcquire2(pPager, pgno, ppPage, noContent, 0); -} - -/* -** This is an internal version of sqlite3PagerAcquire that takes an extra -** parameter of data to use to fill the page with. This allows more efficient -** filling for preloaded data. If this extra parameter is NULL, we'll go to -** the file. -** -** See sqlite3PagerLoadall which uses this function. -*/ -int sqlite3PagerAcquire2( - Pager *pPager, /* The pager open on the database file */ - Pgno pgno, /* Page number to fetch */ - DbPage **ppPage, /* Write a pointer to the page here */ - int noContent, /* Do not bother reading content from disk if true */ - unsigned char* pDataToFill -){ int rc; PgHdr *pPg; @@ -5064,17 +5035,9 @@ int sqlite3PagerAcquire2( IOTRACE(("ZERO %p %d\n", pPager, pgno)); }else{ assert( pPg->pPager==pPager ); - if( pDataToFill ){ - /* Just copy from the given memory */ - memcpy(pPg->pData, pDataToFill, pPager->pageSize); - CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM; - goto pager_acquire_err); - }else{ - /* Load from disk (old regular sqlite code path) */ - rc = readDbPage(pPg); - if( rc!=SQLITE_OK ){ - goto pager_acquire_err; - } + rc = readDbPage(pPg); + if( rc!=SQLITE_OK ){ + goto pager_acquire_err; } } pager_set_pagehash(pPg); @@ -6496,135 +6459,6 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){ } #endif -/* Begin preload-cache.patch for Chromium */ -#if 1 -/* NOTE(shess): Testing to see if simply reading the data into the - * filesystem buffers will have the positive speed impact without the - * negative memory impact. - */ -int sqlite3PagerLoadall(Pager* pPager) -{ - int i, pageSize, loadPages, rc; - unsigned char *fileData; - - /* TODO(shess): This test may not be relevant for this - * implementation, but keep the invariant consistent. - */ - pageSize = pPager->pageSize; - if (pPager->dbSize < 0 || pageSize < 0) { - /* pager not initialized, this means a statement is not open */ - return SQLITE_MISUSE; - } - - /* Allocate a buffer to read pages into. */ - /* TODO(shess): No need to read by page, this could be a fixed-size - * buffer on stack. - */ - fileData = sqlite3Malloc(pageSize); - if (!fileData) - return SQLITE_NOMEM; - - /* Load the smaller of the entire cache or the entire database. */ - loadPages = sqlite3PcacheGetCachesize(pPager->pPCache); - if (loadPages > pPager->dbSize) - loadPages = pPager->dbSize; - - /* Read database page by page. */ - rc = SQLITE_OK; - for(i=0; i < loadPages; i++) { - rc = sqlite3OsRead(pPager->fd, fileData, pageSize, i*pageSize); - if (rc != SQLITE_OK) - break; - } - sqlite3_free(fileData); - return rc; -} -#else -/** -** When making large allocations, there is no need to stress the heap and -** potentially hold its lock while we allocate a bunch of memory. If we know -** the allocation will be large, go directly to the OS instead of the heap. -**/ -static void* allocLarge(size_t size) { -#if SQLITE_OS_WIN - return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); -#else - return sqlite3Malloc(size); -#endif -} - -static void freeLarge(void* ptr) { -#if SQLITE_OS_WIN - VirtualFree(ptr, 0, MEM_RELEASE); -#else - sqlite3_free(ptr); -#endif -} - -/** -** Addition: This will attempt to populate the database cache with -** the first N bytes of the file, where N is the total size of the cache. -** Because we can load this as one chunk from the disk, this is much faster -** than loading a subset of the pages one at a time in random order. -** -** The pager must be initialized before this function is called. This means a -* statement must be open that has initialized the pager and is keeping the -** cache in memory. -**/ -int sqlite3PagerLoadall(Pager* pPager) -{ - int i; - int rc; - int nMax; - int loadSize; - int loadPages; - unsigned char *fileData; - - if (pPager->dbSize < 0 || pPager->pageSize < 0) { - /* pager not initialized, this means a statement is not open */ - return SQLITE_MISUSE; - } - - /* compute sizes */ - nMax = sqlite3PcacheGetCachesize(pPager->pPCache); - if (nMax < pPager->dbSize) - loadPages = nMax; - else - loadPages = pPager->dbSize; - loadSize = loadPages * pPager->pageSize; - - /* load the file as one chunk */ - fileData = allocLarge(loadSize); - if (! fileData) - return SQLITE_NOMEM; - rc = sqlite3OsRead(pPager->fd, fileData, loadSize, 0); - if (rc != SQLITE_OK) { - freeLarge(fileData); - return rc; - } - - /* Copy the data to each page. Note that the page numbers we pass to _get - * are one-based, 0 is a marker for no page. We also need to check that we - * haven't loaded more pages than the cache can hold total. There may have - * already been a few pages loaded before, so we may fill the cache before - * loading all of the pages we want to. - */ - for(i=1; - i <= loadPages && sqlite3PcachePagecount(pPager->pPCache) < nMax; - i++) { - DbPage *pPage = 0; - rc = sqlite3PagerAcquire2(pPager, i, &pPage, 0, - &fileData[(i-1)*(i64)pPager->pageSize]); - if (rc != SQLITE_OK) - break; - sqlite3PagerUnref(pPage); - } - freeLarge(fileData); - return SQLITE_OK; -} -#endif -/* End preload-cache.patch for Chromium */ - /* ** Return a pointer to the data for the specified page. */ diff --git a/chromium/third_party/sqlite/src/src/pager.h b/chromium/third_party/sqlite/src/src/pager.h index 211fe8cfbcb..eab7ddaf80b 100644 --- a/chromium/third_party/sqlite/src/src/pager.h +++ b/chromium/third_party/sqlite/src/src/pager.h @@ -153,8 +153,6 @@ const sqlite3_vfs *sqlite3PagerVfs(Pager*); sqlite3_file *sqlite3PagerFile(Pager*); const char *sqlite3PagerJournalname(Pager*); int sqlite3PagerNosync(Pager*); -/* This function is for preload-cache.patch for Chromium: */ -int sqlite3PagerLoadall(Pager*); void *sqlite3PagerTempSpace(Pager*); int sqlite3PagerIsMemdb(Pager*); diff --git a/chromium/third_party/sqlite/src/src/pcache.c b/chromium/third_party/sqlite/src/src/pcache.c index 6dec5506843..242f3071d90 100644 --- a/chromium/third_party/sqlite/src/src/pcache.c +++ b/chromium/third_party/sqlite/src/src/pcache.c @@ -553,12 +553,14 @@ int sqlite3PcachePagecount(PCache *pCache){ return nPage; } +#ifdef SQLITE_TEST /* ** Get the suggested cache-size value. */ int sqlite3PcacheGetCachesize(PCache *pCache){ return pCache->nMax; } +#endif /* ** Set the suggested cache-size value. diff --git a/chromium/third_party/sqlite/src/src/pcache.h b/chromium/third_party/sqlite/src/src/pcache.h index a9bea983e4a..33735d2cbb2 100644 --- a/chromium/third_party/sqlite/src/src/pcache.h +++ b/chromium/third_party/sqlite/src/src/pcache.h @@ -137,7 +137,9 @@ void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)); ** of the suggested cache-sizes. */ void sqlite3PcacheSetCachesize(PCache *, int); +#ifdef SQLITE_TEST int sqlite3PcacheGetCachesize(PCache *); +#endif #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT /* Try to return memory used by the pcache module to the main memory heap */ diff --git a/chromium/third_party/sqlite/src/src/recover.c b/chromium/third_party/sqlite/src/src/recover.c index 24ccfbd584e..e67ef5409fe 100644 --- a/chromium/third_party/sqlite/src/src/recover.c +++ b/chromium/third_party/sqlite/src/src/recover.c @@ -1275,6 +1275,7 @@ static int ValidateError(){ /* Setup the cursor for reading the information from cell iCell. */ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ const unsigned char *pPageHeader; /* Header of current page. */ + const unsigned char *pPageEnd; /* Byte after end of current page. */ const unsigned char *pCellOffsets; /* Pointer to page's cell offsets. */ unsigned iCellOffset; /* Offset of current cell (iCell). */ const unsigned char *pCell; /* Pointer to data at iCellOffset. */ @@ -1297,6 +1298,10 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ /* Find the offset to the row. */ pPageHeader = PageHeader(pCursor->pPage); pCellOffsets = pPageHeader + knPageLeafHeaderBytes; + pPageEnd = PageData(pCursor->pPage, pCursor->nPageSize); + if( pCellOffsets + pCursor->iCell*2 + 2 > pPageEnd ){ + return ValidateError(); + } iCellOffset = decodeUnsigned16(pCellOffsets + pCursor->iCell*2); if( iCellOffset>=pCursor->nPageSize ){ return ValidateError(); @@ -1338,7 +1343,7 @@ static int leafCursorCellDecode(RecoverLeafCursor *pCursor){ /* Check that no other cell starts within this cell. */ iEndOffset = pCursor->iRecordOffset + pCursor->nLocalRecordBytes; - for( i=0; i<pCursor->nCells; ++i ){ + for( i=0; i<pCursor->nCells && pCellOffsets + i*2 + 2 <= pPageEnd; ++i ){ const unsigned iOtherOffset = decodeUnsigned16(pCellOffsets + i*2); if( iOtherOffset>iCellOffset && iOtherOffset<iEndOffset ){ return ValidateError(); diff --git a/chromium/third_party/sqlite/src/src/sqlite.h.in b/chromium/third_party/sqlite/src/src/sqlite.h.in index fb766593453..00c8510b77d 100644 --- a/chromium/third_party/sqlite/src/src/sqlite.h.in +++ b/chromium/third_party/sqlite/src/src/sqlite.h.in @@ -4686,21 +4686,6 @@ struct sqlite3_index_info { double estimatedCost; /* Estimated cost of using this index */ }; -/* Begin preload-cache.patch for Chromium */ -/* -** Preload the databases into the pager cache, up to the maximum size of the -** pager cache. -** -** For a database to be loaded successfully, the pager must be active. That is, -** there must be an open statement on that database. See sqlite3pager_loadall -** -** There might be many databases attached to the given connection. We iterate -** them all and try to load them. If none are loadable successfully, we return -** an error. Otherwise, we return OK. -*/ -int sqlite3_preload(sqlite3 *db); -/* End preload-cache.patch for Chromium */ - /* ** CAPI3REF: Virtual Table Constraint Operator Codes ** |