| Index: third_party/sqlite/sqlite-src-3100200/src/os_win.c
|
| diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/sqlite-src-3100200/src/os_win.c
|
| similarity index 95%
|
| copy from third_party/sqlite/src/src/os_win.c
|
| copy to third_party/sqlite/sqlite-src-3100200/src/os_win.c
|
| index 2e757f85cd86407a9a5078f1c6998011474b0daa..c54bfd6a900bbb7a06f590b305c7ea85fb3beae1 100644
|
| --- a/third_party/sqlite/src/src/os_win.c
|
| +++ b/third_party/sqlite/sqlite-src-3100200/src/os_win.c
|
| @@ -34,6 +34,11 @@
|
| with SQLITE_OMIT_WAL."
|
| #endif
|
|
|
| +#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
|
| +# error "Memory mapped files require support from the Windows NT kernel,\
|
| + compile with SQLITE_MAX_MMAP_SIZE=0."
|
| +#endif
|
| +
|
| /*
|
| ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
|
| ** based on the sub-platform)?
|
| @@ -163,10 +168,11 @@
|
|
|
| /*
|
| ** Do we need to manually define the Win32 file mapping APIs for use with WAL
|
| -** mode (e.g. these APIs are available in the Windows CE SDK; however, they
|
| -** are not present in the header file)?
|
| +** mode or memory mapped files (e.g. these APIs are available in the Windows
|
| +** CE SDK; however, they are not present in the header file)?
|
| */
|
| -#if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL)
|
| +#if SQLITE_WIN32_FILEMAPPING_API && \
|
| + (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
|
| /*
|
| ** Two of the file mapping APIs are different under WinRT. Figure out which
|
| ** set we need.
|
| @@ -191,10 +197,12 @@ WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
|
| #endif /* SQLITE_OS_WINRT */
|
|
|
| /*
|
| -** This file mapping API is common to both Win32 and WinRT.
|
| +** These file mapping APIs are common to both Win32 and WinRT.
|
| */
|
| +
|
| +WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T);
|
| WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
|
| -#endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */
|
| +#endif /* SQLITE_WIN32_FILEMAPPING_API */
|
|
|
| /*
|
| ** Some Microsoft compilers lack this definition.
|
| @@ -487,7 +495,7 @@ static struct win_syscall {
|
| LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
|
|
|
| #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
|
| - !defined(SQLITE_OMIT_WAL))
|
| + (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
|
| { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
|
| #else
|
| { "CreateFileMappingA", (SYSCALL)0, 0 },
|
| @@ -497,7 +505,7 @@ static struct win_syscall {
|
| DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
|
|
|
| #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
|
| - !defined(SQLITE_OMIT_WAL))
|
| + (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
|
| { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
|
| #else
|
| { "CreateFileMappingW", (SYSCALL)0, 0 },
|
| @@ -837,7 +845,8 @@ static struct win_syscall {
|
| LPOVERLAPPED))aSyscall[48].pCurrent)
|
| #endif
|
|
|
| -#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
|
| +#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \
|
| + (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
|
| { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
|
| #else
|
| { "MapViewOfFile", (SYSCALL)0, 0 },
|
| @@ -907,7 +916,7 @@ static struct win_syscall {
|
| #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
|
| LPOVERLAPPED))aSyscall[58].pCurrent)
|
|
|
| -#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
|
| +#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
|
| { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
|
| #else
|
| { "UnmapViewOfFile", (SYSCALL)0, 0 },
|
| @@ -970,7 +979,7 @@ static struct win_syscall {
|
| #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
|
| FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
|
|
|
| -#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
|
| +#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
|
| { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
|
| #else
|
| { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
|
| @@ -1034,7 +1043,7 @@ static struct win_syscall {
|
|
|
| #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
|
|
|
| -#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
|
| +#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
|
| { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
|
| #else
|
| { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
|
| @@ -1059,6 +1068,32 @@ static struct win_syscall {
|
| SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent)
|
| #endif /* defined(InterlockedCompareExchange) */
|
|
|
| +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
|
| + { "UuidCreate", (SYSCALL)UuidCreate, 0 },
|
| +#else
|
| + { "UuidCreate", (SYSCALL)0, 0 },
|
| +#endif
|
| +
|
| +#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent)
|
| +
|
| +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
|
| + { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
|
| +#else
|
| + { "UuidCreateSequential", (SYSCALL)0, 0 },
|
| +#endif
|
| +
|
| +#define osUuidCreateSequential \
|
| + ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent)
|
| +
|
| +#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
|
| + { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
|
| +#else
|
| + { "FlushViewOfFile", (SYSCALL)0, 0 },
|
| +#endif
|
| +
|
| +#define osFlushViewOfFile \
|
| + ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
|
| +
|
| }; /* End of the overrideable system calls */
|
|
|
| /*
|
| @@ -1196,8 +1231,8 @@ int sqlite3_win32_reset_heap(){
|
| int rc;
|
| MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
|
| MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
|
| - MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
|
| - MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
|
| + MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
|
| + MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
|
| sqlite3_mutex_enter(pMaster);
|
| sqlite3_mutex_enter(pMem);
|
| winMemAssertMagic();
|
| @@ -1942,11 +1977,11 @@ static int winRetryIoerr(int *pnRetry, DWORD *pError){
|
| /*
|
| ** Log a I/O error retry episode.
|
| */
|
| -static void winLogIoerr(int nRetry){
|
| +static void winLogIoerr(int nRetry, int lineno){
|
| if( nRetry ){
|
| - sqlite3_log(SQLITE_IOERR,
|
| - "delayed %dms for lock/sharing conflict",
|
| - winIoerrRetryDelay*nRetry*(nRetry+1)/2
|
| + sqlite3_log(SQLITE_NOTICE,
|
| + "delayed %dms for lock/sharing conflict at line %d",
|
| + winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
|
| );
|
| }
|
| }
|
| @@ -2426,7 +2461,8 @@ static int winClose(sqlite3_file *id){
|
| assert( pFile->pShm==0 );
|
| #endif
|
| assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
|
| - OSTRACE(("CLOSE file=%p\n", pFile->h));
|
| + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
|
|
| #if SQLITE_MAX_MMAP_SIZE>0
|
| winUnmapfile(pFile);
|
| @@ -2455,7 +2491,8 @@ static int winClose(sqlite3_file *id){
|
| pFile->h = NULL;
|
| }
|
| OpenCounter(-1);
|
| - OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed"));
|
| + OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed"));
|
| return rc ? SQLITE_OK
|
| : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(),
|
| "winClose", pFile->zPath);
|
| @@ -2472,7 +2509,7 @@ static int winRead(
|
| int amt, /* Number of bytes to read */
|
| sqlite3_int64 offset /* Begin reading at this offset */
|
| ){
|
| -#if !SQLITE_OS_WINCE
|
| +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| OVERLAPPED overlapped; /* The offset for ReadFile. */
|
| #endif
|
| winFile *pFile = (winFile*)id; /* file handle */
|
| @@ -2483,7 +2520,8 @@ static int winRead(
|
| assert( amt>0 );
|
| assert( offset>=0 );
|
| SimulateIOError(return SQLITE_IOERR_READ);
|
| - OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
|
| + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
|
| + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
|
| pFile->h, pBuf, amt, offset, pFile->locktype));
|
|
|
| #if SQLITE_MAX_MMAP_SIZE>0
|
| @@ -2492,7 +2530,8 @@ static int winRead(
|
| if( offset<pFile->mmapSize ){
|
| if( offset+amt <= pFile->mmapSize ){
|
| memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
|
| - OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h));
|
| + OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_OK;
|
| }else{
|
| int nCopy = (int)(pFile->mmapSize - offset);
|
| @@ -2504,9 +2543,10 @@ static int winRead(
|
| }
|
| #endif
|
|
|
| -#if SQLITE_OS_WINCE
|
| +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| if( winSeekFile(pFile, offset) ){
|
| - OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
|
| + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_FULL;
|
| }
|
| while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
|
| @@ -2520,19 +2560,22 @@ static int winRead(
|
| DWORD lastErrno;
|
| if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
|
| pFile->lastErrno = lastErrno;
|
| - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h));
|
| + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
|
| "winRead", pFile->zPath);
|
| }
|
| - winLogIoerr(nRetry);
|
| + winLogIoerr(nRetry, __LINE__);
|
| if( nRead<(DWORD)amt ){
|
| /* Unread parts of the buffer must be zero-filled */
|
| memset(&((char*)pBuf)[nRead], 0, amt-nRead);
|
| - OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h));
|
| + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_IOERR_SHORT_READ;
|
| }
|
|
|
| - OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h));
|
| + OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_OK;
|
| }
|
|
|
| @@ -2555,17 +2598,18 @@ static int winWrite(
|
| SimulateIOError(return SQLITE_IOERR_WRITE);
|
| SimulateDiskfullError(return SQLITE_FULL);
|
|
|
| - OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
|
| + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
|
| + "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
|
| pFile->h, pBuf, amt, offset, pFile->locktype));
|
|
|
| -#if !SQLITE_MMAP_READ_ONLY
|
| -#if SQLITE_MAX_MMAP_SIZE>0
|
| +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
|
| /* Deal with as much of this write request as possible by transfering
|
| ** data from the memory mapping using memcpy(). */
|
| if( offset<pFile->mmapSize ){
|
| if( offset+amt <= pFile->mmapSize ){
|
| memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
|
| - OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h));
|
| + OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_OK;
|
| }else{
|
| int nCopy = (int)(pFile->mmapSize - offset);
|
| @@ -2576,15 +2620,14 @@ static int winWrite(
|
| }
|
| }
|
| #endif
|
| -#endif
|
|
|
| -#if SQLITE_OS_WINCE
|
| +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| rc = winSeekFile(pFile, offset);
|
| if( rc==0 ){
|
| #else
|
| {
|
| #endif
|
| -#if !SQLITE_OS_WINCE
|
| +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| OVERLAPPED overlapped; /* The offset for WriteFile. */
|
| #endif
|
| u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
|
| @@ -2592,14 +2635,14 @@ static int winWrite(
|
| DWORD nWrite; /* Bytes written by each WriteFile() call */
|
| DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
|
|
|
| -#if !SQLITE_OS_WINCE
|
| +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| memset(&overlapped, 0, sizeof(OVERLAPPED));
|
| overlapped.Offset = (LONG)(offset & 0xffffffff);
|
| overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
|
| #endif
|
|
|
| while( nRem>0 ){
|
| -#if SQLITE_OS_WINCE
|
| +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
|
| #else
|
| if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
|
| @@ -2612,7 +2655,7 @@ static int winWrite(
|
| lastErrno = osGetLastError();
|
| break;
|
| }
|
| -#if !SQLITE_OS_WINCE
|
| +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
|
| offset += nWrite;
|
| overlapped.Offset = (LONG)(offset & 0xffffffff);
|
| overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
|
| @@ -2629,17 +2672,20 @@ static int winWrite(
|
| if( rc ){
|
| if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
|
| || ( pFile->lastErrno==ERROR_DISK_FULL )){
|
| - OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h));
|
| + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return winLogError(SQLITE_FULL, pFile->lastErrno,
|
| "winWrite1", pFile->zPath);
|
| }
|
| - OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h));
|
| + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
|
| "winWrite2", pFile->zPath);
|
| }else{
|
| - winLogIoerr(nRetry);
|
| + winLogIoerr(nRetry, __LINE__);
|
| }
|
| - OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h));
|
| + OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_OK;
|
| }
|
|
|
| @@ -2653,8 +2699,8 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
|
|
|
| assert( pFile );
|
| SimulateIOError(return SQLITE_IOERR_TRUNCATE);
|
| - OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n",
|
| - pFile->h, nByte, pFile->locktype));
|
| + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype));
|
|
|
| /* If the user has configured a chunk-size for this file, truncate the
|
| ** file so that it consists of an integer number of chunks (i.e. the
|
| @@ -2686,7 +2732,8 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
|
| }
|
| #endif
|
|
|
| - OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
|
| + OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc)));
|
| return rc;
|
| }
|
|
|
| @@ -2710,7 +2757,7 @@ static int winSync(sqlite3_file *id, int flags){
|
| BOOL rc;
|
| #endif
|
| #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \
|
| - (defined(SQLITE_TEST) && defined(SQLITE_DEBUG))
|
| + defined(SQLITE_HAVE_OS_TRACE)
|
| /*
|
| ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
|
| ** OSTRACE() macros.
|
| @@ -2731,8 +2778,9 @@ static int winSync(sqlite3_file *id, int flags){
|
| */
|
| SimulateDiskfullError( return SQLITE_FULL );
|
|
|
| - OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n",
|
| - pFile->h, flags, pFile->locktype));
|
| + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h, flags,
|
| + pFile->locktype));
|
|
|
| #ifndef SQLITE_TEST
|
| UNUSED_PARAMETER(flags);
|
| @@ -2747,19 +2795,38 @@ static int winSync(sqlite3_file *id, int flags){
|
| ** no-op
|
| */
|
| #ifdef SQLITE_NO_SYNC
|
| - OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h));
|
| + OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_OK;
|
| #else
|
| +#if SQLITE_MAX_MMAP_SIZE>0
|
| + if( pFile->pMapRegion ){
|
| + if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
|
| + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
|
| + "rc=SQLITE_OK\n", osGetCurrentProcessId(),
|
| + pFile, pFile->pMapRegion));
|
| + }else{
|
| + pFile->lastErrno = osGetLastError();
|
| + OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, "
|
| + "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(),
|
| + pFile, pFile->pMapRegion));
|
| + return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
|
| + "winSync1", pFile->zPath);
|
| + }
|
| + }
|
| +#endif
|
| rc = osFlushFileBuffers(pFile->h);
|
| SimulateIOError( rc=FALSE );
|
| if( rc ){
|
| - OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h));
|
| + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return SQLITE_OK;
|
| }else{
|
| pFile->lastErrno = osGetLastError();
|
| - OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h));
|
| + OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n",
|
| + osGetCurrentProcessId(), pFile, pFile->h));
|
| return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
|
| - "winSync", pFile->zPath);
|
| + "winSync2", pFile->zPath);
|
| }
|
| #endif
|
| }
|
| @@ -2948,6 +3015,12 @@ static int winLock(sqlite3_file *id, int locktype){
|
| return SQLITE_OK;
|
| }
|
|
|
| + /* Do not allow any kind of write-lock on a read-only database
|
| + */
|
| + if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
|
| + return SQLITE_IOERR_LOCK;
|
| + }
|
| +
|
| /* Make sure the locking sequence is correct
|
| */
|
| assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
|
| @@ -3077,7 +3150,7 @@ static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
|
| res = 1;
|
| OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
|
| }else{
|
| - res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0);
|
| + res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
|
| if( res ){
|
| winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
|
| }
|
| @@ -3317,14 +3390,14 @@ static SYSTEM_INFO winSysInfo;
|
| ** winShmLeaveMutex()
|
| */
|
| static void winShmEnterMutex(void){
|
| - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
| + sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
|
| }
|
| static void winShmLeaveMutex(void){
|
| - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
| + sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
|
| }
|
| #ifndef NDEBUG
|
| static int winShmMutexHeld(void) {
|
| - return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
|
| + return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
|
| }
|
| #endif
|
|
|
| @@ -3367,7 +3440,7 @@ struct winShmNode {
|
| int nRef; /* Number of winShm objects pointing to this */
|
| winShm *pFirst; /* All winShm objects pointing to this */
|
| winShmNode *pNext; /* Next in list of all winShmNode objects */
|
| -#ifdef SQLITE_DEBUG
|
| +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
|
| u8 nextShmId; /* Next available winShm.id value */
|
| #endif
|
| };
|
| @@ -3398,7 +3471,7 @@ struct winShm {
|
| u8 hasMutex; /* True if holding the winShmNode mutex */
|
| u16 sharedMask; /* Mask of shared locks held */
|
| u16 exclMask; /* Mask of exclusive locks held */
|
| -#ifdef SQLITE_DEBUG
|
| +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
|
| u8 id; /* Id of this connection with its winShmNode */
|
| #endif
|
| };
|
| @@ -3589,7 +3662,7 @@ static int winOpenSharedMemory(winFile *pDbFd){
|
|
|
| /* Make the new connection a child of the winShmNode */
|
| p->pShmNode = pShmNode;
|
| -#ifdef SQLITE_DEBUG
|
| +#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
|
| p->id = pShmNode->nextShmId++;
|
| #endif
|
| pShmNode->nRef++;
|
| @@ -3777,8 +3850,8 @@ static void winShmBarrier(
|
| sqlite3_file *fd /* Database holding the shared memory */
|
| ){
|
| UNUSED_PARAMETER(fd);
|
| - /* MemoryBarrier(); // does not work -- do not know why not */
|
| - winShmEnterMutex();
|
| + sqlite3MemoryBarrier(); /* compiler-defined memory barrier */
|
| + winShmEnterMutex(); /* Also mutex, for redundancy */
|
| winShmLeaveMutex();
|
| }
|
|
|
| @@ -3809,16 +3882,16 @@ static int winShmMap(
|
| void volatile **pp /* OUT: Mapped memory */
|
| ){
|
| winFile *pDbFd = (winFile*)fd;
|
| - winShm *p = pDbFd->pShm;
|
| + winShm *pShm = pDbFd->pShm;
|
| winShmNode *pShmNode;
|
| int rc = SQLITE_OK;
|
|
|
| - if( !p ){
|
| + if( !pShm ){
|
| rc = winOpenSharedMemory(pDbFd);
|
| if( rc!=SQLITE_OK ) return rc;
|
| - p = pDbFd->pShm;
|
| + pShm = pDbFd->pShm;
|
| }
|
| - pShmNode = p->pShmNode;
|
| + pShmNode = pShm->pShmNode;
|
|
|
| sqlite3_mutex_enter(pShmNode->mutex);
|
| assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
|
| @@ -3858,7 +3931,7 @@ static int winShmMap(
|
| }
|
|
|
| /* Map the requested memory region into this processes address space. */
|
| - apNew = (struct ShmRegion *)sqlite3_realloc(
|
| + apNew = (struct ShmRegion *)sqlite3_realloc64(
|
| pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
|
| );
|
| if( !apNew ){
|
| @@ -4023,7 +4096,7 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
|
| DWORD flags = FILE_MAP_READ;
|
|
|
| winUnmapfile(pFd);
|
| -#if !SQLITE_MMAP_READ_ONLY
|
| +#ifdef SQLITE_MMAP_READWRITE
|
| if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
|
| protect = PAGE_READWRITE;
|
| flags |= FILE_MAP_WRITE;
|
| @@ -4732,7 +4805,7 @@ static int winOpen(
|
| }
|
| }
|
| #endif
|
| - winLogIoerr(cnt);
|
| + winLogIoerr(cnt, __LINE__);
|
|
|
| OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name,
|
| dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
|
| @@ -4916,7 +4989,7 @@ static int winDelete(
|
| if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){
|
| rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename);
|
| }else{
|
| - winLogIoerr(cnt);
|
| + winLogIoerr(cnt, __LINE__);
|
| }
|
| sqlite3_free(zConverted);
|
| OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc)));
|
| @@ -4966,7 +5039,7 @@ static int winAccess(
|
| attr = sAttrData.dwFileAttributes;
|
| }
|
| }else{
|
| - winLogIoerr(cnt);
|
| + winLogIoerr(cnt, __LINE__);
|
| if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
|
| sqlite3_free(zConverted);
|
| return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
|
| @@ -5307,7 +5380,7 @@ static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
|
| static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
| int n = 0;
|
| UNUSED_PARAMETER(pVfs);
|
| -#if defined(SQLITE_TEST)
|
| +#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
|
| n = nBuf;
|
| memset(zBuf, 0, nBuf);
|
| #else
|
| @@ -5341,7 +5414,23 @@ static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
| memcpy(&zBuf[n], &i, sizeof(i));
|
| n += sizeof(i);
|
| }
|
| +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
|
| + if( sizeof(UUID)<=nBuf-n ){
|
| + UUID id;
|
| + memset(&id, 0, sizeof(UUID));
|
| + osUuidCreate(&id);
|
| + memcpy(&zBuf[n], &id, sizeof(UUID));
|
| + n += sizeof(UUID);
|
| + }
|
| + if( sizeof(UUID)<=nBuf-n ){
|
| + UUID id;
|
| + memset(&id, 0, sizeof(UUID));
|
| + osUuidCreateSequential(&id);
|
| + memcpy(&zBuf[n], &id, sizeof(UUID));
|
| + n += sizeof(UUID);
|
| + }
|
| #endif
|
| +#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
|
| return n;
|
| }
|
|
|
| @@ -5519,7 +5608,7 @@ int sqlite3_os_init(void){
|
|
|
| /* Double-check that the aSyscall[] array has been constructed
|
| ** correctly. See ticket [bb3a86e890c8e96ab] */
|
| - assert( ArraySize(aSyscall)==77 );
|
| + assert( ArraySize(aSyscall)==80 );
|
|
|
| /* get memory map allocation granularity */
|
| memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
|
| @@ -5550,12 +5639,4 @@ 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 */
|
|
|