OLD | NEW |
1 /* | 1 /* |
2 ** 2004 May 22 | 2 ** 2004 May 22 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 ** already available. | 69 ** already available. |
70 */ | 70 */ |
71 #ifndef NTDDI_WIN8 | 71 #ifndef NTDDI_WIN8 |
72 # define NTDDI_WIN8 0x06020000 | 72 # define NTDDI_WIN8 0x06020000 |
73 #endif | 73 #endif |
74 | 74 |
75 #ifndef NTDDI_WINBLUE | 75 #ifndef NTDDI_WINBLUE |
76 # define NTDDI_WINBLUE 0x06030000 | 76 # define NTDDI_WINBLUE 0x06030000 |
77 #endif | 77 #endif |
78 | 78 |
| 79 #ifndef NTDDI_WINTHRESHOLD |
| 80 # define NTDDI_WINTHRESHOLD 0x06040000 |
| 81 #endif |
| 82 |
79 /* | 83 /* |
80 ** Check to see if the GetVersionEx[AW] functions are deprecated on the | 84 ** Check to see if the GetVersionEx[AW] functions are deprecated on the |
81 ** target system. GetVersionEx was first deprecated in Win8.1. | 85 ** target system. GetVersionEx was first deprecated in Win8.1. |
82 */ | 86 */ |
83 #ifndef SQLITE_WIN32_GETVERSIONEX | 87 #ifndef SQLITE_WIN32_GETVERSIONEX |
84 # if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE | 88 # if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE |
85 # define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */ | 89 # define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */ |
86 # else | 90 # else |
87 # define SQLITE_WIN32_GETVERSIONEX 1 /* GetVersionEx() is current */ | 91 # define SQLITE_WIN32_GETVERSIONEX 1 /* GetVersionEx() is current */ |
88 # endif | 92 # endif |
89 #endif | 93 #endif |
90 | 94 |
91 /* | 95 /* |
| 96 ** Check to see if the CreateFileMappingA function is supported on the |
| 97 ** target system. It is unavailable when using "mincore.lib" on Win10. |
| 98 ** When compiling for Windows 10, always assume "mincore.lib" is in use. |
| 99 */ |
| 100 #ifndef SQLITE_WIN32_CREATEFILEMAPPINGA |
| 101 # if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINTHRESHOLD |
| 102 # define SQLITE_WIN32_CREATEFILEMAPPINGA 0 |
| 103 # else |
| 104 # define SQLITE_WIN32_CREATEFILEMAPPINGA 1 |
| 105 # endif |
| 106 #endif |
| 107 |
| 108 /* |
92 ** This constant should already be defined (in the "WinDef.h" SDK file). | 109 ** This constant should already be defined (in the "WinDef.h" SDK file). |
93 */ | 110 */ |
94 #ifndef MAX_PATH | 111 #ifndef MAX_PATH |
95 # define MAX_PATH (260) | 112 # define MAX_PATH (260) |
96 #endif | 113 #endif |
97 | 114 |
98 /* | 115 /* |
99 ** Maximum pathname length (in chars) for Win32. This should normally be | 116 ** Maximum pathname length (in chars) for Win32. This should normally be |
100 ** MAX_PATH. | 117 ** MAX_PATH. |
101 */ | 118 */ |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 int nFetchOut; /* Number of outstanding xFetch references */ | 284 int nFetchOut; /* Number of outstanding xFetch references */ |
268 HANDLE hMap; /* Handle for accessing memory mapping */ | 285 HANDLE hMap; /* Handle for accessing memory mapping */ |
269 void *pMapRegion; /* Area memory mapped */ | 286 void *pMapRegion; /* Area memory mapped */ |
270 sqlite3_int64 mmapSize; /* Usable size of mapped region */ | 287 sqlite3_int64 mmapSize; /* Usable size of mapped region */ |
271 sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */ | 288 sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */ |
272 sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */ | 289 sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */ |
273 #endif | 290 #endif |
274 }; | 291 }; |
275 | 292 |
276 /* | 293 /* |
| 294 ** The winVfsAppData structure is used for the pAppData member for all of the |
| 295 ** Win32 VFS variants. |
| 296 */ |
| 297 typedef struct winVfsAppData winVfsAppData; |
| 298 struct winVfsAppData { |
| 299 const sqlite3_io_methods *pMethod; /* The file I/O methods to use. */ |
| 300 void *pAppData; /* The extra pAppData, if any. */ |
| 301 BOOL bNoLock; /* Non-zero if locking is disabled. */ |
| 302 }; |
| 303 |
| 304 /* |
277 ** Allowed values for winFile.ctrlFlags | 305 ** Allowed values for winFile.ctrlFlags |
278 */ | 306 */ |
279 #define WINFILE_RDONLY 0x02 /* Connection is read only */ | 307 #define WINFILE_RDONLY 0x02 /* Connection is read only */ |
280 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ | 308 #define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ |
281 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ | 309 #define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ |
282 | 310 |
283 /* | 311 /* |
284 * The size of the buffer used by sqlite3_win32_write_debug(). | 312 * The size of the buffer used by sqlite3_win32_write_debug(). |
285 */ | 313 */ |
286 #ifndef SQLITE_WIN32_DBG_BUF_SIZE | 314 #ifndef SQLITE_WIN32_DBG_BUF_SIZE |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 * function), all data that was allocated using the isolated heap will | 349 * function), all data that was allocated using the isolated heap will |
322 * be freed immediately and any attempt to access any of that freed | 350 * be freed immediately and any attempt to access any of that freed |
323 * data will almost certainly result in an immediate access violation. | 351 * data will almost certainly result in an immediate access violation. |
324 ****************************************************************************** | 352 ****************************************************************************** |
325 */ | 353 */ |
326 #ifndef SQLITE_WIN32_HEAP_CREATE | 354 #ifndef SQLITE_WIN32_HEAP_CREATE |
327 # define SQLITE_WIN32_HEAP_CREATE (TRUE) | 355 # define SQLITE_WIN32_HEAP_CREATE (TRUE) |
328 #endif | 356 #endif |
329 | 357 |
330 /* | 358 /* |
| 359 * This is cache size used in the calculation of the initial size of the |
| 360 * Win32-specific heap. It cannot be negative. |
| 361 */ |
| 362 #ifndef SQLITE_WIN32_CACHE_SIZE |
| 363 # if SQLITE_DEFAULT_CACHE_SIZE>=0 |
| 364 # define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE) |
| 365 # else |
| 366 # define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE)) |
| 367 # endif |
| 368 #endif |
| 369 |
| 370 /* |
331 * The initial size of the Win32-specific heap. This value may be zero. | 371 * The initial size of the Win32-specific heap. This value may be zero. |
332 */ | 372 */ |
333 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE | 373 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE |
334 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \ | 374 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \ |
335 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304) | 375 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304) |
336 #endif | 376 #endif |
337 | 377 |
338 /* | 378 /* |
339 * The maximum size of the Win32-specific heap. This value may be zero. | 379 * The maximum size of the Win32-specific heap. This value may be zero. |
340 */ | 380 */ |
341 #ifndef SQLITE_WIN32_HEAP_MAX_SIZE | 381 #ifndef SQLITE_WIN32_HEAP_MAX_SIZE |
342 # define SQLITE_WIN32_HEAP_MAX_SIZE (0) | 382 # define SQLITE_WIN32_HEAP_MAX_SIZE (0) |
343 #endif | 383 #endif |
344 | 384 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 527 |
488 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) | 528 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) |
489 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, | 529 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
490 #else | 530 #else |
491 { "CreateFileW", (SYSCALL)0, 0 }, | 531 { "CreateFileW", (SYSCALL)0, 0 }, |
492 #endif | 532 #endif |
493 | 533 |
494 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ | 534 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
495 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) | 535 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
496 | 536 |
497 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ | 537 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ |
498 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) | 538 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \ |
| 539 SQLITE_WIN32_CREATEFILEMAPPINGA |
499 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, | 540 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
500 #else | 541 #else |
501 { "CreateFileMappingA", (SYSCALL)0, 0 }, | 542 { "CreateFileMappingA", (SYSCALL)0, 0 }, |
502 #endif | 543 #endif |
503 | 544 |
504 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ | 545 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
505 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) | 546 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
506 | 547 |
507 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ | 548 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
508 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) | 549 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent) | 759 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent) |
719 | 760 |
720 #if !SQLITE_OS_WINRT | 761 #if !SQLITE_OS_WINRT |
721 { "GetTickCount", (SYSCALL)GetTickCount, 0 }, | 762 { "GetTickCount", (SYSCALL)GetTickCount, 0 }, |
722 #else | 763 #else |
723 { "GetTickCount", (SYSCALL)0, 0 }, | 764 { "GetTickCount", (SYSCALL)0, 0 }, |
724 #endif | 765 #endif |
725 | 766 |
726 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) | 767 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) |
727 | 768 |
728 #if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \ | 769 #if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX |
729 SQLITE_WIN32_GETVERSIONEX | |
730 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, | 770 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, |
731 #else | 771 #else |
732 { "GetVersionExA", (SYSCALL)0, 0 }, | 772 { "GetVersionExA", (SYSCALL)0, 0 }, |
733 #endif | 773 #endif |
734 | 774 |
735 #define osGetVersionExA ((BOOL(WINAPI*)( \ | 775 #define osGetVersionExA ((BOOL(WINAPI*)( \ |
736 LPOSVERSIONINFOA))aSyscall[34].pCurrent) | 776 LPOSVERSIONINFOA))aSyscall[34].pCurrent) |
737 | 777 |
738 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ | 778 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
739 defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX | 779 SQLITE_WIN32_GETVERSIONEX |
740 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, | 780 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, |
741 #else | 781 #else |
742 { "GetVersionExW", (SYSCALL)0, 0 }, | 782 { "GetVersionExW", (SYSCALL)0, 0 }, |
743 #endif | 783 #endif |
744 | 784 |
745 #define osGetVersionExW ((BOOL(WINAPI*)( \ | 785 #define osGetVersionExW ((BOOL(WINAPI*)( \ |
746 LPOSVERSIONINFOW))aSyscall[35].pCurrent) | 786 LPOSVERSIONINFOW))aSyscall[35].pCurrent) |
747 | 787 |
748 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, | 788 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, |
749 | 789 |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 assert( hHeap!=INVALID_HANDLE_VALUE ); | 1238 assert( hHeap!=INVALID_HANDLE_VALUE ); |
1199 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) | 1239 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) |
1200 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); | 1240 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
1201 #endif | 1241 #endif |
1202 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT | 1242 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT |
1203 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){ | 1243 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){ |
1204 DWORD lastErrno = osGetLastError(); | 1244 DWORD lastErrno = osGetLastError(); |
1205 if( lastErrno==NO_ERROR ){ | 1245 if( lastErrno==NO_ERROR ){ |
1206 sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p", | 1246 sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p", |
1207 (void*)hHeap); | 1247 (void*)hHeap); |
1208 rc = SQLITE_NOMEM; | 1248 rc = SQLITE_NOMEM_BKPT; |
1209 }else{ | 1249 }else{ |
1210 sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p", | 1250 sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p", |
1211 osGetLastError(), (void*)hHeap); | 1251 osGetLastError(), (void*)hHeap); |
1212 rc = SQLITE_ERROR; | 1252 rc = SQLITE_ERROR; |
1213 } | 1253 } |
1214 } | 1254 } |
1215 #else | 1255 #else |
1216 sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p", | 1256 sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p", |
1217 (void*)hHeap); | 1257 (void*)hHeap); |
1218 rc = SQLITE_NOTFOUND; | 1258 rc = SQLITE_NOTFOUND; |
1219 #endif | 1259 #endif |
1220 if( pnLargest ) *pnLargest = nLargest; | 1260 if( pnLargest ) *pnLargest = nLargest; |
1221 return rc; | 1261 return rc; |
1222 } | 1262 } |
1223 | 1263 |
1224 /* | 1264 /* |
1225 ** If a Win32 native heap has been configured, this function will attempt to | 1265 ** If a Win32 native heap has been configured, this function will attempt to |
1226 ** destroy and recreate it. If the Win32 native heap is not isolated and/or | 1266 ** destroy and recreate it. If the Win32 native heap is not isolated and/or |
1227 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will | 1267 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will |
1228 ** be returned and no changes will be made to the Win32 native heap. | 1268 ** be returned and no changes will be made to the Win32 native heap. |
1229 */ | 1269 */ |
1230 int sqlite3_win32_reset_heap(){ | 1270 int sqlite3_win32_reset_heap(){ |
1231 int rc; | 1271 int rc; |
1232 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ | 1272 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
1233 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ | 1273 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ |
1234 MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); ) | 1274 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
1235 MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); ) | 1275 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); ) |
1236 sqlite3_mutex_enter(pMaster); | 1276 sqlite3_mutex_enter(pMaster); |
1237 sqlite3_mutex_enter(pMem); | 1277 sqlite3_mutex_enter(pMem); |
1238 winMemAssertMagic(); | 1278 winMemAssertMagic(); |
1239 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ | 1279 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ |
1240 /* | 1280 /* |
1241 ** At this point, there should be no outstanding memory allocations on | 1281 ** At this point, there should be no outstanding memory allocations on |
1242 ** the heap. Also, since both the master and memsys locks are currently | 1282 ** the heap. Also, since both the master and memsys locks are currently |
1243 ** being held by us, no other function (i.e. from another thread) should | 1283 ** being held by us, no other function (i.e. from another thread) should |
1244 ** be able to even access the heap. Attempt to destroy and recreate our | 1284 ** be able to even access the heap. Attempt to destroy and recreate our |
1245 ** isolated Win32 native heap now. | 1285 ** isolated Win32 native heap now. |
(...skipping 24 matching lines...) Expand all Loading... |
1270 /* | 1310 /* |
1271 ** This function outputs the specified (ANSI) string to the Win32 debugger | 1311 ** This function outputs the specified (ANSI) string to the Win32 debugger |
1272 ** (if available). | 1312 ** (if available). |
1273 */ | 1313 */ |
1274 | 1314 |
1275 void sqlite3_win32_write_debug(const char *zBuf, int nBuf){ | 1315 void sqlite3_win32_write_debug(const char *zBuf, int nBuf){ |
1276 char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; | 1316 char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; |
1277 int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */ | 1317 int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */ |
1278 if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ | 1318 if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ |
1279 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); | 1319 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); |
| 1320 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1321 if( !zBuf ){ |
| 1322 (void)SQLITE_MISUSE_BKPT; |
| 1323 return; |
| 1324 } |
| 1325 #endif |
1280 #if defined(SQLITE_WIN32_HAS_ANSI) | 1326 #if defined(SQLITE_WIN32_HAS_ANSI) |
1281 if( nMin>0 ){ | 1327 if( nMin>0 ){ |
1282 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); | 1328 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); |
1283 memcpy(zDbgBuf, zBuf, nMin); | 1329 memcpy(zDbgBuf, zBuf, nMin); |
1284 osOutputDebugStringA(zDbgBuf); | 1330 osOutputDebugStringA(zDbgBuf); |
1285 }else{ | 1331 }else{ |
1286 osOutputDebugStringA(zBuf); | 1332 osOutputDebugStringA(zBuf); |
1287 } | 1333 } |
1288 #elif defined(SQLITE_WIN32_HAS_WIDE) | 1334 #elif defined(SQLITE_WIN32_HAS_WIDE) |
1289 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); | 1335 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 ** or WinCE. Return false (zero) for Win95, Win98, or WinME. | 1386 ** or WinCE. Return false (zero) for Win95, Win98, or WinME. |
1341 ** | 1387 ** |
1342 ** Here is an interesting observation: Win95, Win98, and WinME lack | 1388 ** Here is an interesting observation: Win95, Win98, and WinME lack |
1343 ** the LockFileEx() API. But we can still statically link against that | 1389 ** the LockFileEx() API. But we can still statically link against that |
1344 ** API as long as we don't call it when running Win95/98/ME. A call to | 1390 ** API as long as we don't call it when running Win95/98/ME. A call to |
1345 ** this routine is used to determine if the host is Win95/98/ME or | 1391 ** this routine is used to determine if the host is Win95/98/ME or |
1346 ** WinNT/2K/XP so that we will know whether or not we can safely call | 1392 ** WinNT/2K/XP so that we will know whether or not we can safely call |
1347 ** the LockFileEx() API. | 1393 ** the LockFileEx() API. |
1348 */ | 1394 */ |
1349 | 1395 |
1350 #if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX | 1396 #if !SQLITE_WIN32_GETVERSIONEX |
1351 # define osIsNT() (1) | 1397 # define osIsNT() (1) |
1352 #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) | 1398 #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) |
1353 # define osIsNT() (1) | 1399 # define osIsNT() (1) |
1354 #elif !defined(SQLITE_WIN32_HAS_WIDE) | 1400 #elif !defined(SQLITE_WIN32_HAS_WIDE) |
1355 # define osIsNT() (0) | 1401 # define osIsNT() (0) |
1356 #else | 1402 #else |
1357 # define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt()) | 1403 # define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt()) |
1358 #endif | 1404 #endif |
1359 | 1405 |
1360 /* | 1406 /* |
1361 ** This function determines if the machine is running a version of Windows | 1407 ** This function determines if the machine is running a version of Windows |
1362 ** based on the NT kernel. | 1408 ** based on the NT kernel. |
1363 */ | 1409 */ |
1364 int sqlite3_win32_is_nt(void){ | 1410 int sqlite3_win32_is_nt(void){ |
1365 #if SQLITE_OS_WINRT | 1411 #if SQLITE_OS_WINRT |
1366 /* | 1412 /* |
1367 ** NOTE: The WinRT sub-platform is always assumed to be based on the NT | 1413 ** NOTE: The WinRT sub-platform is always assumed to be based on the NT |
1368 ** kernel. | 1414 ** kernel. |
1369 */ | 1415 */ |
1370 return 1; | 1416 return 1; |
1371 #elif defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX | 1417 #elif SQLITE_WIN32_GETVERSIONEX |
1372 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ | 1418 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){ |
1373 #if defined(SQLITE_WIN32_HAS_ANSI) | 1419 #if defined(SQLITE_WIN32_HAS_ANSI) |
1374 OSVERSIONINFOA sInfo; | 1420 OSVERSIONINFOA sInfo; |
1375 sInfo.dwOSVersionInfoSize = sizeof(sInfo); | 1421 sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
1376 osGetVersionExA(&sInfo); | 1422 osGetVersionExA(&sInfo); |
1377 osInterlockedCompareExchange(&sqlite3_os_type, | 1423 osInterlockedCompareExchange(&sqlite3_os_type, |
1378 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); | 1424 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0); |
1379 #elif defined(SQLITE_WIN32_HAS_WIDE) | 1425 #elif defined(SQLITE_WIN32_HAS_WIDE) |
1380 OSVERSIONINFOW sInfo; | 1426 OSVERSIONINFOW sInfo; |
1381 sInfo.dwOSVersionInfoSize = sizeof(sInfo); | 1427 sInfo.dwOSVersionInfoSize = sizeof(sInfo); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 }else if( dwInitialSize>dwMaximumSize ){ | 1564 }else if( dwInitialSize>dwMaximumSize ){ |
1519 dwInitialSize = dwMaximumSize; | 1565 dwInitialSize = dwMaximumSize; |
1520 } | 1566 } |
1521 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS, | 1567 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS, |
1522 dwInitialSize, dwMaximumSize); | 1568 dwInitialSize, dwMaximumSize); |
1523 if( !pWinMemData->hHeap ){ | 1569 if( !pWinMemData->hHeap ){ |
1524 sqlite3_log(SQLITE_NOMEM, | 1570 sqlite3_log(SQLITE_NOMEM, |
1525 "failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu", | 1571 "failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu", |
1526 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize, | 1572 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize, |
1527 dwMaximumSize); | 1573 dwMaximumSize); |
1528 return SQLITE_NOMEM; | 1574 return SQLITE_NOMEM_BKPT; |
1529 } | 1575 } |
1530 pWinMemData->bOwned = TRUE; | 1576 pWinMemData->bOwned = TRUE; |
1531 assert( pWinMemData->bOwned ); | 1577 assert( pWinMemData->bOwned ); |
1532 } | 1578 } |
1533 #else | 1579 #else |
1534 pWinMemData->hHeap = osGetProcessHeap(); | 1580 pWinMemData->hHeap = osGetProcessHeap(); |
1535 if( !pWinMemData->hHeap ){ | 1581 if( !pWinMemData->hHeap ){ |
1536 sqlite3_log(SQLITE_NOMEM, | 1582 sqlite3_log(SQLITE_NOMEM, |
1537 "failed to GetProcessHeap (%lu)", osGetLastError()); | 1583 "failed to GetProcessHeap (%lu)", osGetLastError()); |
1538 return SQLITE_NOMEM; | 1584 return SQLITE_NOMEM_BKPT; |
1539 } | 1585 } |
1540 pWinMemData->bOwned = FALSE; | 1586 pWinMemData->bOwned = FALSE; |
1541 assert( !pWinMemData->bOwned ); | 1587 assert( !pWinMemData->bOwned ); |
1542 #endif | 1588 #endif |
1543 assert( pWinMemData->hHeap!=0 ); | 1589 assert( pWinMemData->hHeap!=0 ); |
1544 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); | 1590 assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE ); |
1545 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) | 1591 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE) |
1546 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); | 1592 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) ); |
1547 #endif | 1593 #endif |
1548 return SQLITE_OK; | 1594 return SQLITE_OK; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 }; | 1641 }; |
1596 return &winMemMethods; | 1642 return &winMemMethods; |
1597 } | 1643 } |
1598 | 1644 |
1599 void sqlite3MemSetDefault(void){ | 1645 void sqlite3MemSetDefault(void){ |
1600 sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32()); | 1646 sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32()); |
1601 } | 1647 } |
1602 #endif /* SQLITE_WIN32_MALLOC */ | 1648 #endif /* SQLITE_WIN32_MALLOC */ |
1603 | 1649 |
1604 /* | 1650 /* |
1605 ** Convert a UTF-8 string to Microsoft Unicode (UTF-16?). | 1651 ** Convert a UTF-8 string to Microsoft Unicode. |
1606 ** | 1652 ** |
1607 ** Space to hold the returned string is obtained from malloc. | 1653 ** Space to hold the returned string is obtained from sqlite3_malloc(). |
1608 */ | 1654 */ |
1609 static LPWSTR winUtf8ToUnicode(const char *zFilename){ | 1655 static LPWSTR winUtf8ToUnicode(const char *zText){ |
1610 int nChar; | 1656 int nChar; |
1611 LPWSTR zWideFilename; | 1657 LPWSTR zWideText; |
1612 | 1658 |
1613 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0); | 1659 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0); |
1614 if( nChar==0 ){ | 1660 if( nChar==0 ){ |
1615 return 0; | 1661 return 0; |
1616 } | 1662 } |
1617 zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) ); | 1663 zWideText = sqlite3MallocZero( nChar*sizeof(WCHAR) ); |
1618 if( zWideFilename==0 ){ | 1664 if( zWideText==0 ){ |
1619 return 0; | 1665 return 0; |
1620 } | 1666 } |
1621 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, | 1667 nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText, |
1622 nChar); | 1668 nChar); |
1623 if( nChar==0 ){ | 1669 if( nChar==0 ){ |
1624 sqlite3_free(zWideFilename); | 1670 sqlite3_free(zWideText); |
1625 zWideFilename = 0; | 1671 zWideText = 0; |
1626 } | 1672 } |
1627 return zWideFilename; | 1673 return zWideText; |
1628 } | 1674 } |
1629 | 1675 |
1630 /* | 1676 /* |
1631 ** Convert Microsoft Unicode to UTF-8. Space to hold the returned string is | 1677 ** Convert a Microsoft Unicode string to UTF-8. |
1632 ** obtained from sqlite3_malloc(). | 1678 ** |
1633 */ | 1679 ** Space to hold the returned string is obtained from sqlite3_malloc(). |
1634 static char *winUnicodeToUtf8(LPCWSTR zWideFilename){ | 1680 */ |
| 1681 static char *winUnicodeToUtf8(LPCWSTR zWideText){ |
1635 int nByte; | 1682 int nByte; |
1636 char *zFilename; | 1683 char *zText; |
1637 | 1684 |
1638 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); | 1685 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0); |
1639 if( nByte == 0 ){ | 1686 if( nByte == 0 ){ |
1640 return 0; | 1687 return 0; |
1641 } | 1688 } |
1642 zFilename = sqlite3MallocZero( nByte ); | 1689 zText = sqlite3MallocZero( nByte ); |
1643 if( zFilename==0 ){ | 1690 if( zText==0 ){ |
1644 return 0; | 1691 return 0; |
1645 } | 1692 } |
1646 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, | 1693 nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte, |
1647 0, 0); | 1694 0, 0); |
1648 if( nByte == 0 ){ | 1695 if( nByte == 0 ){ |
1649 sqlite3_free(zFilename); | 1696 sqlite3_free(zText); |
1650 zFilename = 0; | 1697 zText = 0; |
1651 } | 1698 } |
1652 return zFilename; | 1699 return zText; |
1653 } | 1700 } |
1654 | 1701 |
1655 /* | 1702 /* |
1656 ** Convert an ANSI string to Microsoft Unicode, based on the | 1703 ** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM |
1657 ** current codepage settings for file apis. | 1704 ** code page. |
1658 ** | 1705 ** |
1659 ** Space to hold the returned string is obtained | 1706 ** Space to hold the returned string is obtained from sqlite3_malloc(). |
1660 ** from sqlite3_malloc. | 1707 */ |
1661 */ | 1708 static LPWSTR winMbcsToUnicode(const char *zText, int useAnsi){ |
1662 static LPWSTR winMbcsToUnicode(const char *zFilename){ | |
1663 int nByte; | 1709 int nByte; |
1664 LPWSTR zMbcsFilename; | 1710 LPWSTR zMbcsText; |
1665 int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP; | 1711 int codepage = useAnsi ? CP_ACP : CP_OEMCP; |
1666 | 1712 |
1667 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL, | 1713 nByte = osMultiByteToWideChar(codepage, 0, zText, -1, NULL, |
1668 0)*sizeof(WCHAR); | 1714 0)*sizeof(WCHAR); |
1669 if( nByte==0 ){ | 1715 if( nByte==0 ){ |
1670 return 0; | 1716 return 0; |
1671 } | 1717 } |
1672 zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) ); | 1718 zMbcsText = sqlite3MallocZero( nByte*sizeof(WCHAR) ); |
1673 if( zMbcsFilename==0 ){ | 1719 if( zMbcsText==0 ){ |
1674 return 0; | 1720 return 0; |
1675 } | 1721 } |
1676 nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, | 1722 nByte = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText, |
1677 nByte); | 1723 nByte); |
1678 if( nByte==0 ){ | 1724 if( nByte==0 ){ |
1679 sqlite3_free(zMbcsFilename); | 1725 sqlite3_free(zMbcsText); |
1680 zMbcsFilename = 0; | 1726 zMbcsText = 0; |
1681 } | 1727 } |
1682 return zMbcsFilename; | 1728 return zMbcsText; |
1683 } | 1729 } |
1684 | 1730 |
1685 /* | 1731 /* |
1686 ** Convert Microsoft Unicode to multi-byte character string, based on the | 1732 ** Convert a Microsoft Unicode string to a multi-byte character string, |
1687 ** user's ANSI codepage. | 1733 ** using the ANSI or OEM code page. |
1688 ** | 1734 ** |
1689 ** Space to hold the returned string is obtained from | 1735 ** Space to hold the returned string is obtained from sqlite3_malloc(). |
1690 ** sqlite3_malloc(). | 1736 */ |
1691 */ | 1737 static char *winUnicodeToMbcs(LPCWSTR zWideText, int useAnsi){ |
1692 static char *winUnicodeToMbcs(LPCWSTR zWideFilename){ | |
1693 int nByte; | 1738 int nByte; |
1694 char *zFilename; | 1739 char *zText; |
1695 int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP; | 1740 int codepage = useAnsi ? CP_ACP : CP_OEMCP; |
1696 | 1741 |
1697 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0); | 1742 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, 0, 0, 0, 0); |
1698 if( nByte == 0 ){ | 1743 if( nByte == 0 ){ |
1699 return 0; | 1744 return 0; |
1700 } | 1745 } |
1701 zFilename = sqlite3MallocZero( nByte ); | 1746 zText = sqlite3MallocZero( nByte ); |
1702 if( zFilename==0 ){ | 1747 if( zText==0 ){ |
1703 return 0; | 1748 return 0; |
1704 } | 1749 } |
1705 nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, | 1750 nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, zText, |
1706 nByte, 0, 0); | 1751 nByte, 0, 0); |
1707 if( nByte == 0 ){ | 1752 if( nByte == 0 ){ |
1708 sqlite3_free(zFilename); | 1753 sqlite3_free(zText); |
1709 zFilename = 0; | 1754 zText = 0; |
1710 } | 1755 } |
1711 return zFilename; | 1756 return zText; |
1712 } | 1757 } |
1713 | 1758 |
1714 /* | 1759 /* |
1715 ** Convert multibyte character string to UTF-8. Space to hold the | 1760 ** Convert a multi-byte character string to UTF-8. |
1716 ** returned string is obtained from sqlite3_malloc(). | 1761 ** |
1717 */ | 1762 ** Space to hold the returned string is obtained from sqlite3_malloc(). |
1718 char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){ | 1763 */ |
1719 char *zFilenameUtf8; | 1764 static char *winMbcsToUtf8(const char *zText, int useAnsi){ |
| 1765 char *zTextUtf8; |
1720 LPWSTR zTmpWide; | 1766 LPWSTR zTmpWide; |
1721 | 1767 |
1722 zTmpWide = winMbcsToUnicode(zFilename); | 1768 zTmpWide = winMbcsToUnicode(zText, useAnsi); |
1723 if( zTmpWide==0 ){ | 1769 if( zTmpWide==0 ){ |
1724 return 0; | 1770 return 0; |
1725 } | 1771 } |
1726 zFilenameUtf8 = winUnicodeToUtf8(zTmpWide); | 1772 zTextUtf8 = winUnicodeToUtf8(zTmpWide); |
1727 sqlite3_free(zTmpWide); | 1773 sqlite3_free(zTmpWide); |
1728 return zFilenameUtf8; | 1774 return zTextUtf8; |
1729 } | 1775 } |
1730 | 1776 |
1731 /* | 1777 /* |
1732 ** Convert UTF-8 to multibyte character string. Space to hold the | 1778 ** Convert a UTF-8 string to a multi-byte character string. |
1733 ** returned string is obtained from sqlite3_malloc(). | 1779 ** |
1734 */ | 1780 ** Space to hold the returned string is obtained from sqlite3_malloc(). |
1735 char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ | 1781 */ |
1736 char *zFilenameMbcs; | 1782 static char *winUtf8ToMbcs(const char *zText, int useAnsi){ |
| 1783 char *zTextMbcs; |
1737 LPWSTR zTmpWide; | 1784 LPWSTR zTmpWide; |
1738 | 1785 |
1739 zTmpWide = winUtf8ToUnicode(zFilename); | 1786 zTmpWide = winUtf8ToUnicode(zText); |
1740 if( zTmpWide==0 ){ | 1787 if( zTmpWide==0 ){ |
1741 return 0; | 1788 return 0; |
1742 } | 1789 } |
1743 zFilenameMbcs = winUnicodeToMbcs(zTmpWide); | 1790 zTextMbcs = winUnicodeToMbcs(zTmpWide, useAnsi); |
1744 sqlite3_free(zTmpWide); | 1791 sqlite3_free(zTmpWide); |
1745 return zFilenameMbcs; | 1792 return zTextMbcs; |
1746 } | 1793 } |
1747 | 1794 |
1748 /* | 1795 /* |
| 1796 ** This is a public wrapper for the winUtf8ToUnicode() function. |
| 1797 */ |
| 1798 LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText){ |
| 1799 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1800 if( !zText ){ |
| 1801 (void)SQLITE_MISUSE_BKPT; |
| 1802 return 0; |
| 1803 } |
| 1804 #endif |
| 1805 #ifndef SQLITE_OMIT_AUTOINIT |
| 1806 if( sqlite3_initialize() ) return 0; |
| 1807 #endif |
| 1808 return winUtf8ToUnicode(zText); |
| 1809 } |
| 1810 |
| 1811 /* |
| 1812 ** This is a public wrapper for the winUnicodeToUtf8() function. |
| 1813 */ |
| 1814 char *sqlite3_win32_unicode_to_utf8(LPCWSTR zWideText){ |
| 1815 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1816 if( !zWideText ){ |
| 1817 (void)SQLITE_MISUSE_BKPT; |
| 1818 return 0; |
| 1819 } |
| 1820 #endif |
| 1821 #ifndef SQLITE_OMIT_AUTOINIT |
| 1822 if( sqlite3_initialize() ) return 0; |
| 1823 #endif |
| 1824 return winUnicodeToUtf8(zWideText); |
| 1825 } |
| 1826 |
| 1827 /* |
| 1828 ** This is a public wrapper for the winMbcsToUtf8() function. |
| 1829 */ |
| 1830 char *sqlite3_win32_mbcs_to_utf8(const char *zText){ |
| 1831 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1832 if( !zText ){ |
| 1833 (void)SQLITE_MISUSE_BKPT; |
| 1834 return 0; |
| 1835 } |
| 1836 #endif |
| 1837 #ifndef SQLITE_OMIT_AUTOINIT |
| 1838 if( sqlite3_initialize() ) return 0; |
| 1839 #endif |
| 1840 return winMbcsToUtf8(zText, osAreFileApisANSI()); |
| 1841 } |
| 1842 |
| 1843 /* |
| 1844 ** This is a public wrapper for the winMbcsToUtf8() function. |
| 1845 */ |
| 1846 char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){ |
| 1847 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1848 if( !zText ){ |
| 1849 (void)SQLITE_MISUSE_BKPT; |
| 1850 return 0; |
| 1851 } |
| 1852 #endif |
| 1853 #ifndef SQLITE_OMIT_AUTOINIT |
| 1854 if( sqlite3_initialize() ) return 0; |
| 1855 #endif |
| 1856 return winMbcsToUtf8(zText, useAnsi); |
| 1857 } |
| 1858 |
| 1859 /* |
| 1860 ** This is a public wrapper for the winUtf8ToMbcs() function. |
| 1861 */ |
| 1862 char *sqlite3_win32_utf8_to_mbcs(const char *zText){ |
| 1863 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1864 if( !zText ){ |
| 1865 (void)SQLITE_MISUSE_BKPT; |
| 1866 return 0; |
| 1867 } |
| 1868 #endif |
| 1869 #ifndef SQLITE_OMIT_AUTOINIT |
| 1870 if( sqlite3_initialize() ) return 0; |
| 1871 #endif |
| 1872 return winUtf8ToMbcs(zText, osAreFileApisANSI()); |
| 1873 } |
| 1874 |
| 1875 /* |
| 1876 ** This is a public wrapper for the winUtf8ToMbcs() function. |
| 1877 */ |
| 1878 char *sqlite3_win32_utf8_to_mbcs_v2(const char *zText, int useAnsi){ |
| 1879 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1880 if( !zText ){ |
| 1881 (void)SQLITE_MISUSE_BKPT; |
| 1882 return 0; |
| 1883 } |
| 1884 #endif |
| 1885 #ifndef SQLITE_OMIT_AUTOINIT |
| 1886 if( sqlite3_initialize() ) return 0; |
| 1887 #endif |
| 1888 return winUtf8ToMbcs(zText, useAnsi); |
| 1889 } |
| 1890 |
| 1891 /* |
1749 ** This function sets the data directory or the temporary directory based on | 1892 ** This function sets the data directory or the temporary directory based on |
1750 ** the provided arguments. The type argument must be 1 in order to set the | 1893 ** the provided arguments. The type argument must be 1 in order to set the |
1751 ** data directory or 2 in order to set the temporary directory. The zValue | 1894 ** data directory or 2 in order to set the temporary directory. The zValue |
1752 ** argument is the name of the directory to use. The return value will be | 1895 ** argument is the name of the directory to use. The return value will be |
1753 ** SQLITE_OK if successful. | 1896 ** SQLITE_OK if successful. |
1754 */ | 1897 */ |
1755 int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){ | 1898 int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){ |
1756 char **ppDirectory = 0; | 1899 char **ppDirectory = 0; |
1757 #ifndef SQLITE_OMIT_AUTOINIT | 1900 #ifndef SQLITE_OMIT_AUTOINIT |
1758 int rc = sqlite3_initialize(); | 1901 int rc = sqlite3_initialize(); |
1759 if( rc ) return rc; | 1902 if( rc ) return rc; |
1760 #endif | 1903 #endif |
1761 if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){ | 1904 if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){ |
1762 ppDirectory = &sqlite3_data_directory; | 1905 ppDirectory = &sqlite3_data_directory; |
1763 }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){ | 1906 }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){ |
1764 ppDirectory = &sqlite3_temp_directory; | 1907 ppDirectory = &sqlite3_temp_directory; |
1765 } | 1908 } |
1766 assert( !ppDirectory || type==SQLITE_WIN32_DATA_DIRECTORY_TYPE | 1909 assert( !ppDirectory || type==SQLITE_WIN32_DATA_DIRECTORY_TYPE |
1767 || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE | 1910 || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE |
1768 ); | 1911 ); |
1769 assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) ); | 1912 assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) ); |
1770 if( ppDirectory ){ | 1913 if( ppDirectory ){ |
1771 char *zValueUtf8 = 0; | 1914 char *zValueUtf8 = 0; |
1772 if( zValue && zValue[0] ){ | 1915 if( zValue && zValue[0] ){ |
1773 zValueUtf8 = winUnicodeToUtf8(zValue); | 1916 zValueUtf8 = winUnicodeToUtf8(zValue); |
1774 if ( zValueUtf8==0 ){ | 1917 if ( zValueUtf8==0 ){ |
1775 return SQLITE_NOMEM; | 1918 return SQLITE_NOMEM_BKPT; |
1776 } | 1919 } |
1777 } | 1920 } |
1778 sqlite3_free(*ppDirectory); | 1921 sqlite3_free(*ppDirectory); |
1779 *ppDirectory = zValueUtf8; | 1922 *ppDirectory = zValueUtf8; |
1780 return SQLITE_OK; | 1923 return SQLITE_OK; |
1781 } | 1924 } |
1782 return SQLITE_ERROR; | 1925 return SQLITE_ERROR; |
1783 } | 1926 } |
1784 | 1927 |
1785 /* | 1928 /* |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 FORMAT_MESSAGE_IGNORE_INSERTS, | 1980 FORMAT_MESSAGE_IGNORE_INSERTS, |
1838 NULL, | 1981 NULL, |
1839 lastErrno, | 1982 lastErrno, |
1840 0, | 1983 0, |
1841 (LPSTR) &zTemp, | 1984 (LPSTR) &zTemp, |
1842 0, | 1985 0, |
1843 0); | 1986 0); |
1844 if( dwLen > 0 ){ | 1987 if( dwLen > 0 ){ |
1845 /* allocate a buffer and convert to UTF8 */ | 1988 /* allocate a buffer and convert to UTF8 */ |
1846 sqlite3BeginBenignMalloc(); | 1989 sqlite3BeginBenignMalloc(); |
1847 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); | 1990 zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI()); |
1848 sqlite3EndBenignMalloc(); | 1991 sqlite3EndBenignMalloc(); |
1849 /* free the system buffer allocated by FormatMessage */ | 1992 /* free the system buffer allocated by FormatMessage */ |
1850 osLocalFree(zTemp); | 1993 osLocalFree(zTemp); |
1851 } | 1994 } |
1852 } | 1995 } |
1853 #endif | 1996 #endif |
1854 if( 0 == dwLen ){ | 1997 if( 0 == dwLen ){ |
1855 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno); | 1998 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno); |
1856 }else{ | 1999 }else{ |
1857 /* copy a maximum of nBuf chars to output buffer */ | 2000 /* copy a maximum of nBuf chars to output buffer */ |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 */ | 2122 */ |
1980 static void winLogIoerr(int nRetry, int lineno){ | 2123 static void winLogIoerr(int nRetry, int lineno){ |
1981 if( nRetry ){ | 2124 if( nRetry ){ |
1982 sqlite3_log(SQLITE_NOTICE, | 2125 sqlite3_log(SQLITE_NOTICE, |
1983 "delayed %dms for lock/sharing conflict at line %d", | 2126 "delayed %dms for lock/sharing conflict at line %d", |
1984 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno | 2127 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno |
1985 ); | 2128 ); |
1986 } | 2129 } |
1987 } | 2130 } |
1988 | 2131 |
1989 #if SQLITE_OS_WINCE | 2132 /* |
1990 /************************************************************************* | 2133 ** This #if does not rely on the SQLITE_OS_WINCE define because the |
1991 ** This section contains code for WinCE only. | 2134 ** corresponding section in "date.c" cannot use it. |
1992 */ | 2135 */ |
1993 #if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API | 2136 #if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \ |
| 2137 (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API) |
1994 /* | 2138 /* |
1995 ** The MSVC CRT on Windows CE may not have a localtime() function. So | 2139 ** The MSVC CRT on Windows CE may not have a localtime() function. |
1996 ** create a substitute. | 2140 ** So define a substitute. |
1997 */ | 2141 */ |
1998 #include <time.h> | 2142 # include <time.h> |
1999 struct tm *__cdecl localtime(const time_t *t) | 2143 struct tm *__cdecl localtime(const time_t *t) |
2000 { | 2144 { |
2001 static struct tm y; | 2145 static struct tm y; |
2002 FILETIME uTm, lTm; | 2146 FILETIME uTm, lTm; |
2003 SYSTEMTIME pTm; | 2147 SYSTEMTIME pTm; |
2004 sqlite3_int64 t64; | 2148 sqlite3_int64 t64; |
2005 t64 = *t; | 2149 t64 = *t; |
2006 t64 = (t64 + 11644473600)*10000000; | 2150 t64 = (t64 + 11644473600)*10000000; |
2007 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); | 2151 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF); |
2008 uTm.dwHighDateTime= (DWORD)(t64 >> 32); | 2152 uTm.dwHighDateTime= (DWORD)(t64 >> 32); |
2009 osFileTimeToLocalFileTime(&uTm,&lTm); | 2153 osFileTimeToLocalFileTime(&uTm,&lTm); |
2010 osFileTimeToSystemTime(&lTm,&pTm); | 2154 osFileTimeToSystemTime(&lTm,&pTm); |
2011 y.tm_year = pTm.wYear - 1900; | 2155 y.tm_year = pTm.wYear - 1900; |
2012 y.tm_mon = pTm.wMonth - 1; | 2156 y.tm_mon = pTm.wMonth - 1; |
2013 y.tm_wday = pTm.wDayOfWeek; | 2157 y.tm_wday = pTm.wDayOfWeek; |
2014 y.tm_mday = pTm.wDay; | 2158 y.tm_mday = pTm.wDay; |
2015 y.tm_hour = pTm.wHour; | 2159 y.tm_hour = pTm.wHour; |
2016 y.tm_min = pTm.wMinute; | 2160 y.tm_min = pTm.wMinute; |
2017 y.tm_sec = pTm.wSecond; | 2161 y.tm_sec = pTm.wSecond; |
2018 return &y; | 2162 return &y; |
2019 } | 2163 } |
2020 #endif | 2164 #endif |
2021 | 2165 |
| 2166 #if SQLITE_OS_WINCE |
| 2167 /************************************************************************* |
| 2168 ** This section contains code for WinCE only. |
| 2169 */ |
2022 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] | 2170 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] |
2023 | 2171 |
2024 /* | 2172 /* |
2025 ** Acquire a lock on the handle h | 2173 ** Acquire a lock on the handle h |
2026 */ | 2174 */ |
2027 static void winceMutexAcquire(HANDLE h){ | 2175 static void winceMutexAcquire(HANDLE h){ |
2028 DWORD dwErr; | 2176 DWORD dwErr; |
2029 do { | 2177 do { |
2030 dwErr = osWaitForSingleObject(h, INFINITE); | 2178 dwErr = osWaitForSingleObject(h, INFINITE); |
2031 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED); | 2179 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED); |
(...skipping 10 matching lines...) Expand all Loading... |
2042 static int winceCreateLock(const char *zFilename, winFile *pFile){ | 2190 static int winceCreateLock(const char *zFilename, winFile *pFile){ |
2043 LPWSTR zTok; | 2191 LPWSTR zTok; |
2044 LPWSTR zName; | 2192 LPWSTR zName; |
2045 DWORD lastErrno; | 2193 DWORD lastErrno; |
2046 BOOL bLogged = FALSE; | 2194 BOOL bLogged = FALSE; |
2047 BOOL bInit = TRUE; | 2195 BOOL bInit = TRUE; |
2048 | 2196 |
2049 zName = winUtf8ToUnicode(zFilename); | 2197 zName = winUtf8ToUnicode(zFilename); |
2050 if( zName==0 ){ | 2198 if( zName==0 ){ |
2051 /* out of memory */ | 2199 /* out of memory */ |
2052 return SQLITE_IOERR_NOMEM; | 2200 return SQLITE_IOERR_NOMEM_BKPT; |
2053 } | 2201 } |
2054 | 2202 |
2055 /* Initialize the local lockdata */ | 2203 /* Initialize the local lockdata */ |
2056 memset(&pFile->local, 0, sizeof(pFile->local)); | 2204 memset(&pFile->local, 0, sizeof(pFile->local)); |
2057 | 2205 |
2058 /* Replace the backslashes from the filename and lowercase it | 2206 /* Replace the backslashes from the filename and lowercase it |
2059 ** to derive a mutex name. */ | 2207 ** to derive a mutex name. */ |
2060 zTok = osCharLowerW(zName); | 2208 zTok = osCharLowerW(zName); |
2061 for (;*zTok;zTok++){ | 2209 for (;*zTok;zTok++){ |
2062 if (*zTok == '\\') *zTok = '_'; | 2210 if (*zTok == '\\') *zTok = '_'; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2467 #if SQLITE_MAX_MMAP_SIZE>0 | 2615 #if SQLITE_MAX_MMAP_SIZE>0 |
2468 winUnmapfile(pFile); | 2616 winUnmapfile(pFile); |
2469 #endif | 2617 #endif |
2470 | 2618 |
2471 do{ | 2619 do{ |
2472 rc = osCloseHandle(pFile->h); | 2620 rc = osCloseHandle(pFile->h); |
2473 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ | 2621 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ |
2474 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); | 2622 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); |
2475 #if SQLITE_OS_WINCE | 2623 #if SQLITE_OS_WINCE |
2476 #define WINCE_DELETION_ATTEMPTS 3 | 2624 #define WINCE_DELETION_ATTEMPTS 3 |
2477 winceDestroyLock(pFile); | 2625 { |
| 2626 winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData; |
| 2627 if( pAppData==NULL || !pAppData->bNoLock ){ |
| 2628 winceDestroyLock(pFile); |
| 2629 } |
| 2630 } |
2478 if( pFile->zDeleteOnClose ){ | 2631 if( pFile->zDeleteOnClose ){ |
2479 int cnt = 0; | 2632 int cnt = 0; |
2480 while( | 2633 while( |
2481 osDeleteFileW(pFile->zDeleteOnClose)==0 | 2634 osDeleteFileW(pFile->zDeleteOnClose)==0 |
2482 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff | 2635 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff |
2483 && cnt++ < WINCE_DELETION_ATTEMPTS | 2636 && cnt++ < WINCE_DELETION_ATTEMPTS |
2484 ){ | 2637 ){ |
2485 sqlite3_win32_sleep(100); /* Wait a little before trying again */ | 2638 sqlite3_win32_sleep(100); /* Wait a little before trying again */ |
2486 } | 2639 } |
2487 sqlite3_free(pFile->zDeleteOnClose); | 2640 sqlite3_free(pFile->zDeleteOnClose); |
(...skipping 29 matching lines...) Expand all Loading... |
2517 int nRetry = 0; /* Number of retrys */ | 2670 int nRetry = 0; /* Number of retrys */ |
2518 | 2671 |
2519 assert( id!=0 ); | 2672 assert( id!=0 ); |
2520 assert( amt>0 ); | 2673 assert( amt>0 ); |
2521 assert( offset>=0 ); | 2674 assert( offset>=0 ); |
2522 SimulateIOError(return SQLITE_IOERR_READ); | 2675 SimulateIOError(return SQLITE_IOERR_READ); |
2523 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " | 2676 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
2524 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, | 2677 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
2525 pFile->h, pBuf, amt, offset, pFile->locktype)); | 2678 pFile->h, pBuf, amt, offset, pFile->locktype)); |
2526 | 2679 |
2527 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 | 2680 #if SQLITE_MAX_MMAP_SIZE>0 |
2528 /* Deal with as much of this read request as possible by transfering | 2681 /* Deal with as much of this read request as possible by transfering |
2529 ** data from the memory mapping using memcpy(). */ | 2682 ** data from the memory mapping using memcpy(). */ |
2530 if( offset<pFile->mmapSize ){ | 2683 if( offset<pFile->mmapSize ){ |
2531 if( offset+amt <= pFile->mmapSize ){ | 2684 if( offset+amt <= pFile->mmapSize ){ |
2532 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); | 2685 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
2533 OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", | 2686 OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
2534 osGetCurrentProcessId(), pFile, pFile->h)); | 2687 osGetCurrentProcessId(), pFile, pFile->h)); |
2535 return SQLITE_OK; | 2688 return SQLITE_OK; |
2536 }else{ | 2689 }else{ |
2537 int nCopy = (int)(pFile->mmapSize - offset); | 2690 int nCopy = (int)(pFile->mmapSize - offset); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3025 */ | 3178 */ |
3026 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK ); | 3179 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK ); |
3027 assert( locktype!=PENDING_LOCK ); | 3180 assert( locktype!=PENDING_LOCK ); |
3028 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK ); | 3181 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK ); |
3029 | 3182 |
3030 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or | 3183 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or |
3031 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of | 3184 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of |
3032 ** the PENDING_LOCK byte is temporary. | 3185 ** the PENDING_LOCK byte is temporary. |
3033 */ | 3186 */ |
3034 newLocktype = pFile->locktype; | 3187 newLocktype = pFile->locktype; |
3035 if( (pFile->locktype==NO_LOCK) | 3188 if( pFile->locktype==NO_LOCK |
3036 || ( (locktype==EXCLUSIVE_LOCK) | 3189 || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK) |
3037 && (pFile->locktype==RESERVED_LOCK)) | |
3038 ){ | 3190 ){ |
3039 int cnt = 3; | 3191 int cnt = 3; |
3040 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, | 3192 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, |
3041 PENDING_BYTE, 0, 1, 0))==0 ){ | 3193 PENDING_BYTE, 0, 1, 0))==0 ){ |
3042 /* Try 3 times to get the pending lock. This is needed to work | 3194 /* Try 3 times to get the pending lock. This is needed to work |
3043 ** around problems caused by indexing and/or anti-virus software on | 3195 ** around problems caused by indexing and/or anti-virus software on |
3044 ** Windows systems. | 3196 ** Windows systems. |
3045 ** If you are using this code as a model for alternative VFSes, do not | 3197 ** If you are using this code as a model for alternative VFSes, do not |
3046 ** copy this retry logic. It is a hack intended for Windows only. | 3198 ** copy this retry logic. It is a hack intended for Windows only. |
3047 */ | 3199 */ |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3200 } | 3352 } |
3201 if( type>=PENDING_LOCK ){ | 3353 if( type>=PENDING_LOCK ){ |
3202 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0); | 3354 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0); |
3203 } | 3355 } |
3204 pFile->locktype = (u8)locktype; | 3356 pFile->locktype = (u8)locktype; |
3205 OSTRACE(("UNLOCK file=%p, lock=%d, rc=%s\n", | 3357 OSTRACE(("UNLOCK file=%p, lock=%d, rc=%s\n", |
3206 pFile->h, pFile->locktype, sqlite3ErrName(rc))); | 3358 pFile->h, pFile->locktype, sqlite3ErrName(rc))); |
3207 return rc; | 3359 return rc; |
3208 } | 3360 } |
3209 | 3361 |
| 3362 /****************************************************************************** |
| 3363 ****************************** No-op Locking ********************************** |
| 3364 ** |
| 3365 ** Of the various locking implementations available, this is by far the |
| 3366 ** simplest: locking is ignored. No attempt is made to lock the database |
| 3367 ** file for reading or writing. |
| 3368 ** |
| 3369 ** This locking mode is appropriate for use on read-only databases |
| 3370 ** (ex: databases that are burned into CD-ROM, for example.) It can |
| 3371 ** also be used if the application employs some external mechanism to |
| 3372 ** prevent simultaneous access of the same database by two or more |
| 3373 ** database connections. But there is a serious risk of database |
| 3374 ** corruption if this locking mode is used in situations where multiple |
| 3375 ** database connections are accessing the same database file at the same |
| 3376 ** time and one or more of those connections are writing. |
| 3377 */ |
| 3378 |
| 3379 static int winNolockLock(sqlite3_file *id, int locktype){ |
| 3380 UNUSED_PARAMETER(id); |
| 3381 UNUSED_PARAMETER(locktype); |
| 3382 return SQLITE_OK; |
| 3383 } |
| 3384 |
| 3385 static int winNolockCheckReservedLock(sqlite3_file *id, int *pResOut){ |
| 3386 UNUSED_PARAMETER(id); |
| 3387 UNUSED_PARAMETER(pResOut); |
| 3388 return SQLITE_OK; |
| 3389 } |
| 3390 |
| 3391 static int winNolockUnlock(sqlite3_file *id, int locktype){ |
| 3392 UNUSED_PARAMETER(id); |
| 3393 UNUSED_PARAMETER(locktype); |
| 3394 return SQLITE_OK; |
| 3395 } |
| 3396 |
| 3397 /******************* End of the no-op lock implementation ********************* |
| 3398 ******************************************************************************/ |
| 3399 |
3210 /* | 3400 /* |
3211 ** If *pArg is initially negative then this is a query. Set *pArg to | 3401 ** If *pArg is initially negative then this is a query. Set *pArg to |
3212 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. | 3402 ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. |
3213 ** | 3403 ** |
3214 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. | 3404 ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. |
3215 */ | 3405 */ |
3216 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){ | 3406 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){ |
3217 if( *pArg<0 ){ | 3407 if( *pArg<0 ){ |
3218 *pArg = (pFile->ctrlFlags & mask)!=0; | 3408 *pArg = (pFile->ctrlFlags & mask)!=0; |
3219 }else if( (*pArg)==0 ){ | 3409 }else if( (*pArg)==0 ){ |
(...skipping 13 matching lines...) Expand all Loading... |
3233 */ | 3423 */ |
3234 static int winFileControl(sqlite3_file *id, int op, void *pArg){ | 3424 static int winFileControl(sqlite3_file *id, int op, void *pArg){ |
3235 winFile *pFile = (winFile*)id; | 3425 winFile *pFile = (winFile*)id; |
3236 OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg)); | 3426 OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg)); |
3237 switch( op ){ | 3427 switch( op ){ |
3238 case SQLITE_FCNTL_LOCKSTATE: { | 3428 case SQLITE_FCNTL_LOCKSTATE: { |
3239 *(int*)pArg = pFile->locktype; | 3429 *(int*)pArg = pFile->locktype; |
3240 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); | 3430 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
3241 return SQLITE_OK; | 3431 return SQLITE_OK; |
3242 } | 3432 } |
3243 case SQLITE_LAST_ERRNO: { | 3433 case SQLITE_FCNTL_LAST_ERRNO: { |
3244 *(int*)pArg = (int)pFile->lastErrno; | 3434 *(int*)pArg = (int)pFile->lastErrno; |
3245 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); | 3435 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
3246 return SQLITE_OK; | 3436 return SQLITE_OK; |
3247 } | 3437 } |
3248 case SQLITE_FCNTL_CHUNK_SIZE: { | 3438 case SQLITE_FCNTL_CHUNK_SIZE: { |
3249 pFile->szChunk = *(int *)pArg; | 3439 pFile->szChunk = *(int *)pArg; |
3250 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); | 3440 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
3251 return SQLITE_OK; | 3441 return SQLITE_OK; |
3252 } | 3442 } |
3253 case SQLITE_FCNTL_SIZE_HINT: { | 3443 case SQLITE_FCNTL_SIZE_HINT: { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3291 a[0] = winIoerrRetry; | 3481 a[0] = winIoerrRetry; |
3292 } | 3482 } |
3293 if( a[1]>0 ){ | 3483 if( a[1]>0 ){ |
3294 winIoerrRetryDelay = a[1]; | 3484 winIoerrRetryDelay = a[1]; |
3295 }else{ | 3485 }else{ |
3296 a[1] = winIoerrRetryDelay; | 3486 a[1] = winIoerrRetryDelay; |
3297 } | 3487 } |
3298 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); | 3488 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
3299 return SQLITE_OK; | 3489 return SQLITE_OK; |
3300 } | 3490 } |
| 3491 case SQLITE_FCNTL_WIN32_GET_HANDLE: { |
| 3492 LPHANDLE phFile = (LPHANDLE)pArg; |
| 3493 *phFile = pFile->h; |
| 3494 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 3495 return SQLITE_OK; |
| 3496 } |
3301 #ifdef SQLITE_TEST | 3497 #ifdef SQLITE_TEST |
3302 case SQLITE_FCNTL_WIN32_SET_HANDLE: { | 3498 case SQLITE_FCNTL_WIN32_SET_HANDLE: { |
3303 LPHANDLE phFile = (LPHANDLE)pArg; | 3499 LPHANDLE phFile = (LPHANDLE)pArg; |
3304 HANDLE hOldFile = pFile->h; | 3500 HANDLE hOldFile = pFile->h; |
3305 pFile->h = *phFile; | 3501 pFile->h = *phFile; |
3306 *phFile = hOldFile; | 3502 *phFile = hOldFile; |
3307 OSTRACE(("FCNTL oldFile=%p, newFile=%p, rc=SQLITE_OK\n", | 3503 OSTRACE(("FCNTL oldFile=%p, newFile=%p, rc=SQLITE_OK\n", |
3308 hOldFile, pFile->h)); | 3504 hOldFile, pFile->h)); |
3309 return SQLITE_OK; | 3505 return SQLITE_OK; |
3310 } | 3506 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3478 | 3674 |
3479 /* | 3675 /* |
3480 ** Constants used for locking | 3676 ** Constants used for locking |
3481 */ | 3677 */ |
3482 #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | 3678 #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
3483 #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ | 3679 #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
3484 | 3680 |
3485 /* | 3681 /* |
3486 ** Apply advisory locks for all n bytes beginning at ofst. | 3682 ** Apply advisory locks for all n bytes beginning at ofst. |
3487 */ | 3683 */ |
3488 #define _SHM_UNLCK 1 | 3684 #define WINSHM_UNLCK 1 |
3489 #define _SHM_RDLCK 2 | 3685 #define WINSHM_RDLCK 2 |
3490 #define _SHM_WRLCK 3 | 3686 #define WINSHM_WRLCK 3 |
3491 static int winShmSystemLock( | 3687 static int winShmSystemLock( |
3492 winShmNode *pFile, /* Apply locks to this open shared-memory segment */ | 3688 winShmNode *pFile, /* Apply locks to this open shared-memory segment */ |
3493 int lockType, /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */ | 3689 int lockType, /* WINSHM_UNLCK, WINSHM_RDLCK, or WINSHM_WRLCK */ |
3494 int ofst, /* Offset to first byte to be locked/unlocked */ | 3690 int ofst, /* Offset to first byte to be locked/unlocked */ |
3495 int nByte /* Number of bytes to lock or unlock */ | 3691 int nByte /* Number of bytes to lock or unlock */ |
3496 ){ | 3692 ){ |
3497 int rc = 0; /* Result code form Lock/UnlockFileEx() */ | 3693 int rc = 0; /* Result code form Lock/UnlockFileEx() */ |
3498 | 3694 |
3499 /* Access to the winShmNode object is serialized by the caller */ | 3695 /* Access to the winShmNode object is serialized by the caller */ |
3500 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); | 3696 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); |
3501 | 3697 |
3502 OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n", | 3698 OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n", |
3503 pFile->hFile.h, lockType, ofst, nByte)); | 3699 pFile->hFile.h, lockType, ofst, nByte)); |
3504 | 3700 |
3505 /* Release/Acquire the system-level lock */ | 3701 /* Release/Acquire the system-level lock */ |
3506 if( lockType==_SHM_UNLCK ){ | 3702 if( lockType==WINSHM_UNLCK ){ |
3507 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0); | 3703 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0); |
3508 }else{ | 3704 }else{ |
3509 /* Initialize the locking parameters */ | 3705 /* Initialize the locking parameters */ |
3510 DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY; | 3706 DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY; |
3511 if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK; | 3707 if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK; |
3512 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0); | 3708 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0); |
3513 } | 3709 } |
3514 | 3710 |
3515 if( rc!= 0 ){ | 3711 if( rc!= 0 ){ |
3516 rc = SQLITE_OK; | 3712 rc = SQLITE_OK; |
3517 }else{ | 3713 }else{ |
3518 pFile->lastErrno = osGetLastError(); | 3714 pFile->lastErrno = osGetLastError(); |
3519 rc = SQLITE_BUSY; | 3715 rc = SQLITE_BUSY; |
3520 } | 3716 } |
3521 | 3717 |
3522 OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n", | 3718 OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n", |
3523 pFile->hFile.h, (lockType == _SHM_UNLCK) ? "winUnlockFile" : | 3719 pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" : |
3524 "winLockFile", pFile->lastErrno, sqlite3ErrName(rc))); | 3720 "winLockFile", pFile->lastErrno, sqlite3ErrName(rc))); |
3525 | 3721 |
3526 return rc; | 3722 return rc; |
3527 } | 3723 } |
3528 | 3724 |
3529 /* Forward references to VFS methods */ | 3725 /* Forward references to VFS methods */ |
3530 static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*); | 3726 static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*); |
3531 static int winDelete(sqlite3_vfs *,const char*,int); | 3727 static int winDelete(sqlite3_vfs *,const char*,int); |
3532 | 3728 |
3533 /* | 3729 /* |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3591 int rc; /* Result code */ | 3787 int rc; /* Result code */ |
3592 struct winShmNode *pNew; /* Newly allocated winShmNode */ | 3788 struct winShmNode *pNew; /* Newly allocated winShmNode */ |
3593 int nName; /* Size of zName in bytes */ | 3789 int nName; /* Size of zName in bytes */ |
3594 | 3790 |
3595 assert( pDbFd->pShm==0 ); /* Not previously opened */ | 3791 assert( pDbFd->pShm==0 ); /* Not previously opened */ |
3596 | 3792 |
3597 /* Allocate space for the new sqlite3_shm object. Also speculatively | 3793 /* Allocate space for the new sqlite3_shm object. Also speculatively |
3598 ** allocate space for a new winShmNode and filename. | 3794 ** allocate space for a new winShmNode and filename. |
3599 */ | 3795 */ |
3600 p = sqlite3MallocZero( sizeof(*p) ); | 3796 p = sqlite3MallocZero( sizeof(*p) ); |
3601 if( p==0 ) return SQLITE_IOERR_NOMEM; | 3797 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT; |
3602 nName = sqlite3Strlen30(pDbFd->zPath); | 3798 nName = sqlite3Strlen30(pDbFd->zPath); |
3603 pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 ); | 3799 pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 ); |
3604 if( pNew==0 ){ | 3800 if( pNew==0 ){ |
3605 sqlite3_free(p); | 3801 sqlite3_free(p); |
3606 return SQLITE_IOERR_NOMEM; | 3802 return SQLITE_IOERR_NOMEM_BKPT; |
3607 } | 3803 } |
3608 pNew->zFilename = (char*)&pNew[1]; | 3804 pNew->zFilename = (char*)&pNew[1]; |
3609 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); | 3805 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); |
3610 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); | 3806 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); |
3611 | 3807 |
3612 /* Look to see if there is an existing winShmNode that can be used. | 3808 /* Look to see if there is an existing winShmNode that can be used. |
3613 ** If no matching winShmNode currently exists, create a new one. | 3809 ** If no matching winShmNode currently exists, create a new one. |
3614 */ | 3810 */ |
3615 winShmEnterMutex(); | 3811 winShmEnterMutex(); |
3616 for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){ | 3812 for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){ |
3617 /* TBD need to come up with better match here. Perhaps | 3813 /* TBD need to come up with better match here. Perhaps |
3618 ** use FILE_ID_BOTH_DIR_INFO Structure. | 3814 ** use FILE_ID_BOTH_DIR_INFO Structure. |
3619 */ | 3815 */ |
3620 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break; | 3816 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break; |
3621 } | 3817 } |
3622 if( pShmNode ){ | 3818 if( pShmNode ){ |
3623 sqlite3_free(pNew); | 3819 sqlite3_free(pNew); |
3624 }else{ | 3820 }else{ |
3625 pShmNode = pNew; | 3821 pShmNode = pNew; |
3626 pNew = 0; | 3822 pNew = 0; |
3627 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE; | 3823 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE; |
3628 pShmNode->pNext = winShmNodeList; | 3824 pShmNode->pNext = winShmNodeList; |
3629 winShmNodeList = pShmNode; | 3825 winShmNodeList = pShmNode; |
3630 | 3826 |
3631 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); | 3827 if( sqlite3GlobalConfig.bCoreMutex ){ |
3632 if( pShmNode->mutex==0 ){ | 3828 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
3633 rc = SQLITE_IOERR_NOMEM; | 3829 if( pShmNode->mutex==0 ){ |
3634 goto shm_open_err; | 3830 rc = SQLITE_IOERR_NOMEM_BKPT; |
| 3831 goto shm_open_err; |
| 3832 } |
3635 } | 3833 } |
3636 | 3834 |
3637 rc = winOpen(pDbFd->pVfs, | 3835 rc = winOpen(pDbFd->pVfs, |
3638 pShmNode->zFilename, /* Name of the file (UTF-8) */ | 3836 pShmNode->zFilename, /* Name of the file (UTF-8) */ |
3639 (sqlite3_file*)&pShmNode->hFile, /* File handle here */ | 3837 (sqlite3_file*)&pShmNode->hFile, /* File handle here */ |
3640 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, | 3838 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, |
3641 0); | 3839 0); |
3642 if( SQLITE_OK!=rc ){ | 3840 if( SQLITE_OK!=rc ){ |
3643 goto shm_open_err; | 3841 goto shm_open_err; |
3644 } | 3842 } |
3645 | 3843 |
3646 /* Check to see if another process is holding the dead-man switch. | 3844 /* Check to see if another process is holding the dead-man switch. |
3647 ** If not, truncate the file to zero length. | 3845 ** If not, truncate the file to zero length. |
3648 */ | 3846 */ |
3649 if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ | 3847 if( winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ |
3650 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); | 3848 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); |
3651 if( rc!=SQLITE_OK ){ | 3849 if( rc!=SQLITE_OK ){ |
3652 rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(), | 3850 rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(), |
3653 "winOpenShm", pDbFd->zPath); | 3851 "winOpenShm", pDbFd->zPath); |
3654 } | 3852 } |
3655 } | 3853 } |
3656 if( rc==SQLITE_OK ){ | 3854 if( rc==SQLITE_OK ){ |
3657 winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); | 3855 winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1); |
3658 rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); | 3856 rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1); |
3659 } | 3857 } |
3660 if( rc ) goto shm_open_err; | 3858 if( rc ) goto shm_open_err; |
3661 } | 3859 } |
3662 | 3860 |
3663 /* Make the new connection a child of the winShmNode */ | 3861 /* Make the new connection a child of the winShmNode */ |
3664 p->pShmNode = pShmNode; | 3862 p->pShmNode = pShmNode; |
3665 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) | 3863 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
3666 p->id = pShmNode->nextShmId++; | 3864 p->id = pShmNode->nextShmId++; |
3667 #endif | 3865 #endif |
3668 pShmNode->nRef++; | 3866 pShmNode->nRef++; |
3669 pDbFd->pShm = p; | 3867 pDbFd->pShm = p; |
3670 winShmLeaveMutex(); | 3868 winShmLeaveMutex(); |
3671 | 3869 |
3672 /* The reference count on pShmNode has already been incremented under | 3870 /* The reference count on pShmNode has already been incremented under |
3673 ** the cover of the winShmEnterMutex() mutex and the pointer from the | 3871 ** the cover of the winShmEnterMutex() mutex and the pointer from the |
3674 ** new (struct winShm) object to the pShmNode has been set. All that is | 3872 ** new (struct winShm) object to the pShmNode has been set. All that is |
3675 ** left to do is to link the new object into the linked list starting | 3873 ** left to do is to link the new object into the linked list starting |
3676 ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex | 3874 ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex |
3677 ** mutex. | 3875 ** mutex. |
3678 */ | 3876 */ |
3679 sqlite3_mutex_enter(pShmNode->mutex); | 3877 sqlite3_mutex_enter(pShmNode->mutex); |
3680 p->pNext = pShmNode->pFirst; | 3878 p->pNext = pShmNode->pFirst; |
3681 pShmNode->pFirst = p; | 3879 pShmNode->pFirst = p; |
3682 sqlite3_mutex_leave(pShmNode->mutex); | 3880 sqlite3_mutex_leave(pShmNode->mutex); |
3683 return SQLITE_OK; | 3881 return SQLITE_OK; |
3684 | 3882 |
3685 /* Jump here on any error */ | 3883 /* Jump here on any error */ |
3686 shm_open_err: | 3884 shm_open_err: |
3687 winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); | 3885 winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1); |
3688 winShmPurge(pDbFd->pVfs, 0); /* This call frees pShmNode if required */ | 3886 winShmPurge(pDbFd->pVfs, 0); /* This call frees pShmNode if required */ |
3689 sqlite3_free(p); | 3887 sqlite3_free(p); |
3690 sqlite3_free(pNew); | 3888 sqlite3_free(pNew); |
3691 winShmLeaveMutex(); | 3889 winShmLeaveMutex(); |
3692 return rc; | 3890 return rc; |
3693 } | 3891 } |
3694 | 3892 |
3695 /* | 3893 /* |
3696 ** Close a connection to shared-memory. Delete the underlying | 3894 ** Close a connection to shared-memory. Delete the underlying |
3697 ** storage if deleteFlag is true. | 3895 ** storage if deleteFlag is true. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3766 | 3964 |
3767 /* See if any siblings hold this same lock */ | 3965 /* See if any siblings hold this same lock */ |
3768 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ | 3966 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
3769 if( pX==p ) continue; | 3967 if( pX==p ) continue; |
3770 assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 ); | 3968 assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 ); |
3771 allMask |= pX->sharedMask; | 3969 allMask |= pX->sharedMask; |
3772 } | 3970 } |
3773 | 3971 |
3774 /* Unlock the system-level locks */ | 3972 /* Unlock the system-level locks */ |
3775 if( (mask & allMask)==0 ){ | 3973 if( (mask & allMask)==0 ){ |
3776 rc = winShmSystemLock(pShmNode, _SHM_UNLCK, ofst+WIN_SHM_BASE, n); | 3974 rc = winShmSystemLock(pShmNode, WINSHM_UNLCK, ofst+WIN_SHM_BASE, n); |
3777 }else{ | 3975 }else{ |
3778 rc = SQLITE_OK; | 3976 rc = SQLITE_OK; |
3779 } | 3977 } |
3780 | 3978 |
3781 /* Undo the local locks */ | 3979 /* Undo the local locks */ |
3782 if( rc==SQLITE_OK ){ | 3980 if( rc==SQLITE_OK ){ |
3783 p->exclMask &= ~mask; | 3981 p->exclMask &= ~mask; |
3784 p->sharedMask &= ~mask; | 3982 p->sharedMask &= ~mask; |
3785 } | 3983 } |
3786 }else if( flags & SQLITE_SHM_SHARED ){ | 3984 }else if( flags & SQLITE_SHM_SHARED ){ |
3787 u16 allShared = 0; /* Union of locks held by connections other than "p" */ | 3985 u16 allShared = 0; /* Union of locks held by connections other than "p" */ |
3788 | 3986 |
3789 /* Find out which shared locks are already held by sibling connections. | 3987 /* Find out which shared locks are already held by sibling connections. |
3790 ** If any sibling already holds an exclusive lock, go ahead and return | 3988 ** If any sibling already holds an exclusive lock, go ahead and return |
3791 ** SQLITE_BUSY. | 3989 ** SQLITE_BUSY. |
3792 */ | 3990 */ |
3793 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ | 3991 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
3794 if( (pX->exclMask & mask)!=0 ){ | 3992 if( (pX->exclMask & mask)!=0 ){ |
3795 rc = SQLITE_BUSY; | 3993 rc = SQLITE_BUSY; |
3796 break; | 3994 break; |
3797 } | 3995 } |
3798 allShared |= pX->sharedMask; | 3996 allShared |= pX->sharedMask; |
3799 } | 3997 } |
3800 | 3998 |
3801 /* Get shared locks at the system level, if necessary */ | 3999 /* Get shared locks at the system level, if necessary */ |
3802 if( rc==SQLITE_OK ){ | 4000 if( rc==SQLITE_OK ){ |
3803 if( (allShared & mask)==0 ){ | 4001 if( (allShared & mask)==0 ){ |
3804 rc = winShmSystemLock(pShmNode, _SHM_RDLCK, ofst+WIN_SHM_BASE, n); | 4002 rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, ofst+WIN_SHM_BASE, n); |
3805 }else{ | 4003 }else{ |
3806 rc = SQLITE_OK; | 4004 rc = SQLITE_OK; |
3807 } | 4005 } |
3808 } | 4006 } |
3809 | 4007 |
3810 /* Get the local shared locks */ | 4008 /* Get the local shared locks */ |
3811 if( rc==SQLITE_OK ){ | 4009 if( rc==SQLITE_OK ){ |
3812 p->sharedMask |= mask; | 4010 p->sharedMask |= mask; |
3813 } | 4011 } |
3814 }else{ | 4012 }else{ |
3815 /* Make sure no sibling connections hold locks that will block this | 4013 /* Make sure no sibling connections hold locks that will block this |
3816 ** lock. If any do, return SQLITE_BUSY right away. | 4014 ** lock. If any do, return SQLITE_BUSY right away. |
3817 */ | 4015 */ |
3818 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ | 4016 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
3819 if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){ | 4017 if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){ |
3820 rc = SQLITE_BUSY; | 4018 rc = SQLITE_BUSY; |
3821 break; | 4019 break; |
3822 } | 4020 } |
3823 } | 4021 } |
3824 | 4022 |
3825 /* Get the exclusive locks at the system level. Then if successful | 4023 /* Get the exclusive locks at the system level. Then if successful |
3826 ** also mark the local connection as being locked. | 4024 ** also mark the local connection as being locked. |
3827 */ | 4025 */ |
3828 if( rc==SQLITE_OK ){ | 4026 if( rc==SQLITE_OK ){ |
3829 rc = winShmSystemLock(pShmNode, _SHM_WRLCK, ofst+WIN_SHM_BASE, n); | 4027 rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, ofst+WIN_SHM_BASE, n); |
3830 if( rc==SQLITE_OK ){ | 4028 if( rc==SQLITE_OK ){ |
3831 assert( (p->sharedMask & mask)==0 ); | 4029 assert( (p->sharedMask & mask)==0 ); |
3832 p->exclMask |= mask; | 4030 p->exclMask |= mask; |
3833 } | 4031 } |
3834 } | 4032 } |
3835 } | 4033 } |
3836 sqlite3_mutex_leave(pShmNode->mutex); | 4034 sqlite3_mutex_leave(pShmNode->mutex); |
3837 OSTRACE(("SHM-LOCK pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x, rc=%s\n", | 4035 OSTRACE(("SHM-LOCK pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x, rc=%s\n", |
3838 osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask, | 4036 osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask, |
3839 sqlite3ErrName(rc))); | 4037 sqlite3ErrName(rc))); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3928 "winShmMap2", pDbFd->zPath); | 4126 "winShmMap2", pDbFd->zPath); |
3929 goto shmpage_out; | 4127 goto shmpage_out; |
3930 } | 4128 } |
3931 } | 4129 } |
3932 | 4130 |
3933 /* Map the requested memory region into this processes address space. */ | 4131 /* Map the requested memory region into this processes address space. */ |
3934 apNew = (struct ShmRegion *)sqlite3_realloc64( | 4132 apNew = (struct ShmRegion *)sqlite3_realloc64( |
3935 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) | 4133 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
3936 ); | 4134 ); |
3937 if( !apNew ){ | 4135 if( !apNew ){ |
3938 rc = SQLITE_IOERR_NOMEM; | 4136 rc = SQLITE_IOERR_NOMEM_BKPT; |
3939 goto shmpage_out; | 4137 goto shmpage_out; |
3940 } | 4138 } |
3941 pShmNode->aRegion = apNew; | 4139 pShmNode->aRegion = apNew; |
3942 | 4140 |
3943 while( pShmNode->nRegion<=iRegion ){ | 4141 while( pShmNode->nRegion<=iRegion ){ |
3944 HANDLE hMap = NULL; /* file-mapping handle */ | 4142 HANDLE hMap = NULL; /* file-mapping handle */ |
3945 void *pMap = 0; /* Mapped memory region */ | 4143 void *pMap = 0; /* Mapped memory region */ |
3946 | 4144 |
3947 #if SQLITE_OS_WINRT | 4145 #if SQLITE_OS_WINRT |
3948 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h, | 4146 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h, |
3949 NULL, PAGE_READWRITE, nByte, NULL | 4147 NULL, PAGE_READWRITE, nByte, NULL |
3950 ); | 4148 ); |
3951 #elif defined(SQLITE_WIN32_HAS_WIDE) | 4149 #elif defined(SQLITE_WIN32_HAS_WIDE) |
3952 hMap = osCreateFileMappingW(pShmNode->hFile.h, | 4150 hMap = osCreateFileMappingW(pShmNode->hFile.h, |
3953 NULL, PAGE_READWRITE, 0, nByte, NULL | 4151 NULL, PAGE_READWRITE, 0, nByte, NULL |
3954 ); | 4152 ); |
3955 #elif defined(SQLITE_WIN32_HAS_ANSI) | 4153 #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA |
3956 hMap = osCreateFileMappingA(pShmNode->hFile.h, | 4154 hMap = osCreateFileMappingA(pShmNode->hFile.h, |
3957 NULL, PAGE_READWRITE, 0, nByte, NULL | 4155 NULL, PAGE_READWRITE, 0, nByte, NULL |
3958 ); | 4156 ); |
3959 #endif | 4157 #endif |
3960 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n", | 4158 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n", |
3961 osGetCurrentProcessId(), pShmNode->nRegion, nByte, | 4159 osGetCurrentProcessId(), pShmNode->nRegion, nByte, |
3962 hMap ? "ok" : "failed")); | 4160 hMap ? "ok" : "failed")); |
3963 if( hMap ){ | 4161 if( hMap ){ |
3964 int iOffset = pShmNode->nRegion*szRegion; | 4162 int iOffset = pShmNode->nRegion*szRegion; |
3965 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; | 4163 int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4101 protect = PAGE_READWRITE; | 4299 protect = PAGE_READWRITE; |
4102 flags |= FILE_MAP_WRITE; | 4300 flags |= FILE_MAP_WRITE; |
4103 } | 4301 } |
4104 #endif | 4302 #endif |
4105 #if SQLITE_OS_WINRT | 4303 #if SQLITE_OS_WINRT |
4106 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); | 4304 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); |
4107 #elif defined(SQLITE_WIN32_HAS_WIDE) | 4305 #elif defined(SQLITE_WIN32_HAS_WIDE) |
4108 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, | 4306 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, |
4109 (DWORD)((nMap>>32) & 0xffffffff), | 4307 (DWORD)((nMap>>32) & 0xffffffff), |
4110 (DWORD)(nMap & 0xffffffff), NULL); | 4308 (DWORD)(nMap & 0xffffffff), NULL); |
4111 #elif defined(SQLITE_WIN32_HAS_ANSI) | 4309 #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA |
4112 pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect, | 4310 pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect, |
4113 (DWORD)((nMap>>32) & 0xffffffff), | 4311 (DWORD)((nMap>>32) & 0xffffffff), |
4114 (DWORD)(nMap & 0xffffffff), NULL); | 4312 (DWORD)(nMap & 0xffffffff), NULL); |
4115 #endif | 4313 #endif |
4116 if( pFd->hMap==NULL ){ | 4314 if( pFd->hMap==NULL ){ |
4117 pFd->lastErrno = osGetLastError(); | 4315 pFd->lastErrno = osGetLastError(); |
4118 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, | 4316 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
4119 "winMapfile1", pFd->zPath); | 4317 "winMapfile1", pFd->zPath); |
4120 /* Log the error, but continue normal operation using xRead/xWrite */ | 4318 /* Log the error, but continue normal operation using xRead/xWrite */ |
4121 OSTRACE(("MAP-FILE-CREATE pid=%lu, pFile=%p, rc=%s\n", | 4319 OSTRACE(("MAP-FILE-CREATE pid=%lu, pFile=%p, rc=%s\n", |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4262 winSectorSize, /* xSectorSize */ | 4460 winSectorSize, /* xSectorSize */ |
4263 winDeviceCharacteristics, /* xDeviceCharacteristics */ | 4461 winDeviceCharacteristics, /* xDeviceCharacteristics */ |
4264 winShmMap, /* xShmMap */ | 4462 winShmMap, /* xShmMap */ |
4265 winShmLock, /* xShmLock */ | 4463 winShmLock, /* xShmLock */ |
4266 winShmBarrier, /* xShmBarrier */ | 4464 winShmBarrier, /* xShmBarrier */ |
4267 winShmUnmap, /* xShmUnmap */ | 4465 winShmUnmap, /* xShmUnmap */ |
4268 winFetch, /* xFetch */ | 4466 winFetch, /* xFetch */ |
4269 winUnfetch /* xUnfetch */ | 4467 winUnfetch /* xUnfetch */ |
4270 }; | 4468 }; |
4271 | 4469 |
| 4470 /* |
| 4471 ** This vector defines all the methods that can operate on an |
| 4472 ** sqlite3_file for win32 without performing any locking. |
| 4473 */ |
| 4474 static const sqlite3_io_methods winIoNolockMethod = { |
| 4475 3, /* iVersion */ |
| 4476 winClose, /* xClose */ |
| 4477 winRead, /* xRead */ |
| 4478 winWrite, /* xWrite */ |
| 4479 winTruncate, /* xTruncate */ |
| 4480 winSync, /* xSync */ |
| 4481 winFileSize, /* xFileSize */ |
| 4482 winNolockLock, /* xLock */ |
| 4483 winNolockUnlock, /* xUnlock */ |
| 4484 winNolockCheckReservedLock, /* xCheckReservedLock */ |
| 4485 winFileControl, /* xFileControl */ |
| 4486 winSectorSize, /* xSectorSize */ |
| 4487 winDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 4488 winShmMap, /* xShmMap */ |
| 4489 winShmLock, /* xShmLock */ |
| 4490 winShmBarrier, /* xShmBarrier */ |
| 4491 winShmUnmap, /* xShmUnmap */ |
| 4492 winFetch, /* xFetch */ |
| 4493 winUnfetch /* xUnfetch */ |
| 4494 }; |
| 4495 |
| 4496 static winVfsAppData winAppData = { |
| 4497 &winIoMethod, /* pMethod */ |
| 4498 0, /* pAppData */ |
| 4499 0 /* bNoLock */ |
| 4500 }; |
| 4501 |
| 4502 static winVfsAppData winNolockAppData = { |
| 4503 &winIoNolockMethod, /* pMethod */ |
| 4504 0, /* pAppData */ |
| 4505 1 /* bNoLock */ |
| 4506 }; |
| 4507 |
4272 /**************************************************************************** | 4508 /**************************************************************************** |
4273 **************************** sqlite3_vfs methods **************************** | 4509 **************************** sqlite3_vfs methods **************************** |
4274 ** | 4510 ** |
4275 ** This division contains the implementation of methods on the | 4511 ** This division contains the implementation of methods on the |
4276 ** sqlite3_vfs object. | 4512 ** sqlite3_vfs object. |
4277 */ | 4513 */ |
4278 | 4514 |
4279 #if defined(__CYGWIN__) | 4515 #if defined(__CYGWIN__) |
4280 /* | 4516 /* |
4281 ** Convert a filename from whatever the underlying operating system | 4517 ** Convert a filename from whatever the underlying operating system |
4282 ** supports for filenames into UTF-8. Space to hold the result is | 4518 ** supports for filenames into UTF-8. Space to hold the result is |
4283 ** obtained from malloc and must be freed by the calling function. | 4519 ** obtained from malloc and must be freed by the calling function. |
4284 */ | 4520 */ |
4285 static char *winConvertToUtf8Filename(const void *zFilename){ | 4521 static char *winConvertToUtf8Filename(const void *zFilename){ |
4286 char *zConverted = 0; | 4522 char *zConverted = 0; |
4287 if( osIsNT() ){ | 4523 if( osIsNT() ){ |
4288 zConverted = winUnicodeToUtf8(zFilename); | 4524 zConverted = winUnicodeToUtf8(zFilename); |
4289 } | 4525 } |
4290 #ifdef SQLITE_WIN32_HAS_ANSI | 4526 #ifdef SQLITE_WIN32_HAS_ANSI |
4291 else{ | 4527 else{ |
4292 zConverted = sqlite3_win32_mbcs_to_utf8(zFilename); | 4528 zConverted = winMbcsToUtf8(zFilename, osAreFileApisANSI()); |
4293 } | 4529 } |
4294 #endif | 4530 #endif |
4295 /* caller will handle out of memory */ | 4531 /* caller will handle out of memory */ |
4296 return zConverted; | 4532 return zConverted; |
4297 } | 4533 } |
4298 #endif | 4534 #endif |
4299 | 4535 |
4300 /* | 4536 /* |
4301 ** Convert a UTF-8 filename into whatever form the underlying | 4537 ** Convert a UTF-8 filename into whatever form the underlying |
4302 ** operating system wants filenames in. Space to hold the result | 4538 ** operating system wants filenames in. Space to hold the result |
4303 ** is obtained from malloc and must be freed by the calling | 4539 ** is obtained from malloc and must be freed by the calling |
4304 ** function. | 4540 ** function. |
4305 */ | 4541 */ |
4306 static void *winConvertFromUtf8Filename(const char *zFilename){ | 4542 static void *winConvertFromUtf8Filename(const char *zFilename){ |
4307 void *zConverted = 0; | 4543 void *zConverted = 0; |
4308 if( osIsNT() ){ | 4544 if( osIsNT() ){ |
4309 zConverted = winUtf8ToUnicode(zFilename); | 4545 zConverted = winUtf8ToUnicode(zFilename); |
4310 } | 4546 } |
4311 #ifdef SQLITE_WIN32_HAS_ANSI | 4547 #ifdef SQLITE_WIN32_HAS_ANSI |
4312 else{ | 4548 else{ |
4313 zConverted = sqlite3_win32_utf8_to_mbcs(zFilename); | 4549 zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI()); |
4314 } | 4550 } |
4315 #endif | 4551 #endif |
4316 /* caller will handle out of memory */ | 4552 /* caller will handle out of memory */ |
4317 return zConverted; | 4553 return zConverted; |
4318 } | 4554 } |
4319 | 4555 |
4320 /* | 4556 /* |
4321 ** This function returns non-zero if the specified UTF-8 string buffer | 4557 ** This function returns non-zero if the specified UTF-8 string buffer |
4322 ** ends with a directory separator character or one was successfully | 4558 ** ends with a directory separator character or one was successfully |
4323 ** added to it. | 4559 ** added to it. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4358 */ | 4594 */ |
4359 SimulateIOError( return SQLITE_IOERR ); | 4595 SimulateIOError( return SQLITE_IOERR ); |
4360 | 4596 |
4361 /* Allocate a temporary buffer to store the fully qualified file | 4597 /* Allocate a temporary buffer to store the fully qualified file |
4362 ** name for the temporary file. If this fails, we cannot continue. | 4598 ** name for the temporary file. If this fails, we cannot continue. |
4363 */ | 4599 */ |
4364 nMax = pVfs->mxPathname; nBuf = nMax + 2; | 4600 nMax = pVfs->mxPathname; nBuf = nMax + 2; |
4365 zBuf = sqlite3MallocZero( nBuf ); | 4601 zBuf = sqlite3MallocZero( nBuf ); |
4366 if( !zBuf ){ | 4602 if( !zBuf ){ |
4367 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4603 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4368 return SQLITE_IOERR_NOMEM; | 4604 return SQLITE_IOERR_NOMEM_BKPT; |
4369 } | 4605 } |
4370 | 4606 |
4371 /* Figure out the effective temporary directory. First, check if one | 4607 /* Figure out the effective temporary directory. First, check if one |
4372 ** has been explicitly set by the application; otherwise, use the one | 4608 ** has been explicitly set by the application; otherwise, use the one |
4373 ** configured by the operating system. | 4609 ** configured by the operating system. |
4374 */ | 4610 */ |
4375 nDir = nMax - (nPre + 15); | 4611 nDir = nMax - (nPre + 15); |
4376 assert( nDir>0 ); | 4612 assert( nDir>0 ); |
4377 if( sqlite3_temp_directory ){ | 4613 if( sqlite3_temp_directory ){ |
4378 int nDirLen = sqlite3Strlen30(sqlite3_temp_directory); | 4614 int nDirLen = sqlite3Strlen30(sqlite3_temp_directory); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4416 /* If the path starts with a drive letter followed by the colon | 4652 /* If the path starts with a drive letter followed by the colon |
4417 ** character, assume it is already a native Win32 path; otherwise, | 4653 ** character, assume it is already a native Win32 path; otherwise, |
4418 ** it must be converted to a native Win32 path via the Cygwin API | 4654 ** it must be converted to a native Win32 path via the Cygwin API |
4419 ** prior to using it. | 4655 ** prior to using it. |
4420 */ | 4656 */ |
4421 if( winIsDriveLetterAndColon(zDir) ){ | 4657 if( winIsDriveLetterAndColon(zDir) ){ |
4422 zConverted = winConvertFromUtf8Filename(zDir); | 4658 zConverted = winConvertFromUtf8Filename(zDir); |
4423 if( !zConverted ){ | 4659 if( !zConverted ){ |
4424 sqlite3_free(zBuf); | 4660 sqlite3_free(zBuf); |
4425 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4661 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4426 return SQLITE_IOERR_NOMEM; | 4662 return SQLITE_IOERR_NOMEM_BKPT; |
4427 } | 4663 } |
4428 if( winIsDir(zConverted) ){ | 4664 if( winIsDir(zConverted) ){ |
4429 sqlite3_snprintf(nMax, zBuf, "%s", zDir); | 4665 sqlite3_snprintf(nMax, zBuf, "%s", zDir); |
4430 sqlite3_free(zConverted); | 4666 sqlite3_free(zConverted); |
4431 break; | 4667 break; |
4432 } | 4668 } |
4433 sqlite3_free(zConverted); | 4669 sqlite3_free(zConverted); |
4434 }else{ | 4670 }else{ |
4435 zConverted = sqlite3MallocZero( nMax+1 ); | 4671 zConverted = sqlite3MallocZero( nMax+1 ); |
4436 if( !zConverted ){ | 4672 if( !zConverted ){ |
4437 sqlite3_free(zBuf); | 4673 sqlite3_free(zBuf); |
4438 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4674 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4439 return SQLITE_IOERR_NOMEM; | 4675 return SQLITE_IOERR_NOMEM_BKPT; |
4440 } | 4676 } |
4441 if( cygwin_conv_path( | 4677 if( cygwin_conv_path( |
4442 osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir, | 4678 osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir, |
4443 zConverted, nMax+1)<0 ){ | 4679 zConverted, nMax+1)<0 ){ |
4444 sqlite3_free(zConverted); | 4680 sqlite3_free(zConverted); |
4445 sqlite3_free(zBuf); | 4681 sqlite3_free(zBuf); |
4446 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n")); | 4682 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n")); |
4447 return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno, | 4683 return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno, |
4448 "winGetTempname2", zDir); | 4684 "winGetTempname2", zDir); |
4449 } | 4685 } |
4450 if( winIsDir(zConverted) ){ | 4686 if( winIsDir(zConverted) ){ |
4451 /* At this point, we know the candidate directory exists and should | 4687 /* At this point, we know the candidate directory exists and should |
4452 ** be used. However, we may need to convert the string containing | 4688 ** be used. However, we may need to convert the string containing |
4453 ** its name into UTF-8 (i.e. if it is UTF-16 right now). | 4689 ** its name into UTF-8 (i.e. if it is UTF-16 right now). |
4454 */ | 4690 */ |
4455 char *zUtf8 = winConvertToUtf8Filename(zConverted); | 4691 char *zUtf8 = winConvertToUtf8Filename(zConverted); |
4456 if( !zUtf8 ){ | 4692 if( !zUtf8 ){ |
4457 sqlite3_free(zConverted); | 4693 sqlite3_free(zConverted); |
4458 sqlite3_free(zBuf); | 4694 sqlite3_free(zBuf); |
4459 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4695 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4460 return SQLITE_IOERR_NOMEM; | 4696 return SQLITE_IOERR_NOMEM_BKPT; |
4461 } | 4697 } |
4462 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); | 4698 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); |
4463 sqlite3_free(zUtf8); | 4699 sqlite3_free(zUtf8); |
4464 sqlite3_free(zConverted); | 4700 sqlite3_free(zConverted); |
4465 break; | 4701 break; |
4466 } | 4702 } |
4467 sqlite3_free(zConverted); | 4703 sqlite3_free(zConverted); |
4468 } | 4704 } |
4469 } | 4705 } |
4470 } | 4706 } |
4471 #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__) | 4707 #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__) |
4472 else if( osIsNT() ){ | 4708 else if( osIsNT() ){ |
4473 char *zMulti; | 4709 char *zMulti; |
4474 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) ); | 4710 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) ); |
4475 if( !zWidePath ){ | 4711 if( !zWidePath ){ |
4476 sqlite3_free(zBuf); | 4712 sqlite3_free(zBuf); |
4477 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4713 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4478 return SQLITE_IOERR_NOMEM; | 4714 return SQLITE_IOERR_NOMEM_BKPT; |
4479 } | 4715 } |
4480 if( osGetTempPathW(nMax, zWidePath)==0 ){ | 4716 if( osGetTempPathW(nMax, zWidePath)==0 ){ |
4481 sqlite3_free(zWidePath); | 4717 sqlite3_free(zWidePath); |
4482 sqlite3_free(zBuf); | 4718 sqlite3_free(zBuf); |
4483 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); | 4719 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); |
4484 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), | 4720 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), |
4485 "winGetTempname2", 0); | 4721 "winGetTempname2", 0); |
4486 } | 4722 } |
4487 zMulti = winUnicodeToUtf8(zWidePath); | 4723 zMulti = winUnicodeToUtf8(zWidePath); |
4488 if( zMulti ){ | 4724 if( zMulti ){ |
4489 sqlite3_snprintf(nMax, zBuf, "%s", zMulti); | 4725 sqlite3_snprintf(nMax, zBuf, "%s", zMulti); |
4490 sqlite3_free(zMulti); | 4726 sqlite3_free(zMulti); |
4491 sqlite3_free(zWidePath); | 4727 sqlite3_free(zWidePath); |
4492 }else{ | 4728 }else{ |
4493 sqlite3_free(zWidePath); | 4729 sqlite3_free(zWidePath); |
4494 sqlite3_free(zBuf); | 4730 sqlite3_free(zBuf); |
4495 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4731 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4496 return SQLITE_IOERR_NOMEM; | 4732 return SQLITE_IOERR_NOMEM_BKPT; |
4497 } | 4733 } |
4498 } | 4734 } |
4499 #ifdef SQLITE_WIN32_HAS_ANSI | 4735 #ifdef SQLITE_WIN32_HAS_ANSI |
4500 else{ | 4736 else{ |
4501 char *zUtf8; | 4737 char *zUtf8; |
4502 char *zMbcsPath = sqlite3MallocZero( nMax ); | 4738 char *zMbcsPath = sqlite3MallocZero( nMax ); |
4503 if( !zMbcsPath ){ | 4739 if( !zMbcsPath ){ |
4504 sqlite3_free(zBuf); | 4740 sqlite3_free(zBuf); |
4505 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4741 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4506 return SQLITE_IOERR_NOMEM; | 4742 return SQLITE_IOERR_NOMEM_BKPT; |
4507 } | 4743 } |
4508 if( osGetTempPathA(nMax, zMbcsPath)==0 ){ | 4744 if( osGetTempPathA(nMax, zMbcsPath)==0 ){ |
4509 sqlite3_free(zBuf); | 4745 sqlite3_free(zBuf); |
4510 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); | 4746 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); |
4511 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), | 4747 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), |
4512 "winGetTempname3", 0); | 4748 "winGetTempname3", 0); |
4513 } | 4749 } |
4514 zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath); | 4750 zUtf8 = winMbcsToUtf8(zMbcsPath, osAreFileApisANSI()); |
4515 if( zUtf8 ){ | 4751 if( zUtf8 ){ |
4516 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); | 4752 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8); |
4517 sqlite3_free(zUtf8); | 4753 sqlite3_free(zUtf8); |
4518 }else{ | 4754 }else{ |
4519 sqlite3_free(zBuf); | 4755 sqlite3_free(zBuf); |
4520 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); | 4756 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
4521 return SQLITE_IOERR_NOMEM; | 4757 return SQLITE_IOERR_NOMEM_BKPT; |
4522 } | 4758 } |
4523 } | 4759 } |
4524 #endif /* SQLITE_WIN32_HAS_ANSI */ | 4760 #endif /* SQLITE_WIN32_HAS_ANSI */ |
4525 #endif /* !SQLITE_OS_WINRT */ | 4761 #endif /* !SQLITE_OS_WINRT */ |
4526 | 4762 |
4527 /* | 4763 /* |
4528 ** Check to make sure the temporary directory ends with an appropriate | 4764 ** Check to make sure the temporary directory ends with an appropriate |
4529 ** separator. If it does not and there is not enough space left to add | 4765 ** separator. If it does not and there is not enough space left to add |
4530 ** one, fail. | 4766 ** one, fail. |
4531 */ | 4767 */ |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4594 attr = osGetFileAttributesA((char*)zConverted); | 4830 attr = osGetFileAttributesA((char*)zConverted); |
4595 #endif | 4831 #endif |
4596 } | 4832 } |
4597 return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY); | 4833 return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY); |
4598 } | 4834 } |
4599 | 4835 |
4600 /* | 4836 /* |
4601 ** Open a file. | 4837 ** Open a file. |
4602 */ | 4838 */ |
4603 static int winOpen( | 4839 static int winOpen( |
4604 sqlite3_vfs *pVfs, /* Used to get maximum path name length */ | 4840 sqlite3_vfs *pVfs, /* Used to get maximum path length and AppData */ |
4605 const char *zName, /* Name of the file (UTF-8) */ | 4841 const char *zName, /* Name of the file (UTF-8) */ |
4606 sqlite3_file *id, /* Write the SQLite file handle here */ | 4842 sqlite3_file *id, /* Write the SQLite file handle here */ |
4607 int flags, /* Open mode flags */ | 4843 int flags, /* Open mode flags */ |
4608 int *pOutFlags /* Status return flags */ | 4844 int *pOutFlags /* Status return flags */ |
4609 ){ | 4845 ){ |
4610 HANDLE h; | 4846 HANDLE h; |
4611 DWORD lastErrno = 0; | 4847 DWORD lastErrno = 0; |
4612 DWORD dwDesiredAccess; | 4848 DWORD dwDesiredAccess; |
4613 DWORD dwShareMode; | 4849 DWORD dwShareMode; |
4614 DWORD dwCreationDisposition; | 4850 DWORD dwCreationDisposition; |
4615 DWORD dwFlagsAndAttributes = 0; | 4851 DWORD dwFlagsAndAttributes = 0; |
4616 #if SQLITE_OS_WINCE | 4852 #if SQLITE_OS_WINCE |
4617 int isTemp = 0; | 4853 int isTemp = 0; |
4618 #endif | 4854 #endif |
| 4855 winVfsAppData *pAppData; |
4619 winFile *pFile = (winFile*)id; | 4856 winFile *pFile = (winFile*)id; |
4620 void *zConverted; /* Filename in OS encoding */ | 4857 void *zConverted; /* Filename in OS encoding */ |
4621 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ | 4858 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ |
4622 int cnt = 0; | 4859 int cnt = 0; |
4623 | 4860 |
4624 /* If argument zPath is a NULL pointer, this function is required to open | 4861 /* If argument zPath is a NULL pointer, this function is required to open |
4625 ** a temporary file. Use this buffer to store the file name in. | 4862 ** a temporary file. Use this buffer to store the file name in. |
4626 */ | 4863 */ |
4627 char *zTmpname = 0; /* For temporary filename, if necessary. */ | 4864 char *zTmpname = 0; /* For temporary filename, if necessary. */ |
4628 | 4865 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4703 ** sqlite3_uri_parameter(). | 4940 ** sqlite3_uri_parameter(). |
4704 */ | 4941 */ |
4705 assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) || | 4942 assert( (eType!=SQLITE_OPEN_MAIN_DB) || (flags & SQLITE_OPEN_URI) || |
4706 zUtf8Name[sqlite3Strlen30(zUtf8Name)+1]==0 ); | 4943 zUtf8Name[sqlite3Strlen30(zUtf8Name)+1]==0 ); |
4707 | 4944 |
4708 /* Convert the filename to the system encoding. */ | 4945 /* Convert the filename to the system encoding. */ |
4709 zConverted = winConvertFromUtf8Filename(zUtf8Name); | 4946 zConverted = winConvertFromUtf8Filename(zUtf8Name); |
4710 if( zConverted==0 ){ | 4947 if( zConverted==0 ){ |
4711 sqlite3_free(zTmpname); | 4948 sqlite3_free(zTmpname); |
4712 OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8Name)); | 4949 OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8Name)); |
4713 return SQLITE_IOERR_NOMEM; | 4950 return SQLITE_IOERR_NOMEM_BKPT; |
4714 } | 4951 } |
4715 | 4952 |
4716 if( winIsDir(zConverted) ){ | 4953 if( winIsDir(zConverted) ){ |
4717 sqlite3_free(zConverted); | 4954 sqlite3_free(zConverted); |
4718 sqlite3_free(zTmpname); | 4955 sqlite3_free(zTmpname); |
4719 OSTRACE(("OPEN name=%s, rc=SQLITE_CANTOPEN_ISDIR", zUtf8Name)); | 4956 OSTRACE(("OPEN name=%s, rc=SQLITE_CANTOPEN_ISDIR", zUtf8Name)); |
4720 return SQLITE_CANTOPEN_ISDIR; | 4957 return SQLITE_CANTOPEN_ISDIR; |
4721 } | 4958 } |
4722 | 4959 |
4723 if( isReadWrite ){ | 4960 if( isReadWrite ){ |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4830 *pOutFlags = SQLITE_OPEN_READWRITE; | 5067 *pOutFlags = SQLITE_OPEN_READWRITE; |
4831 }else{ | 5068 }else{ |
4832 *pOutFlags = SQLITE_OPEN_READONLY; | 5069 *pOutFlags = SQLITE_OPEN_READONLY; |
4833 } | 5070 } |
4834 } | 5071 } |
4835 | 5072 |
4836 OSTRACE(("OPEN file=%p, name=%s, access=%lx, pOutFlags=%p, *pOutFlags=%d, " | 5073 OSTRACE(("OPEN file=%p, name=%s, access=%lx, pOutFlags=%p, *pOutFlags=%d, " |
4837 "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ? | 5074 "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ? |
4838 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); | 5075 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); |
4839 | 5076 |
| 5077 pAppData = (winVfsAppData*)pVfs->pAppData; |
| 5078 |
4840 #if SQLITE_OS_WINCE | 5079 #if SQLITE_OS_WINCE |
4841 if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB | 5080 { |
4842 && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK | 5081 if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB |
4843 ){ | 5082 && ((pAppData==NULL) || !pAppData->bNoLock) |
4844 osCloseHandle(h); | 5083 && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK |
4845 sqlite3_free(zConverted); | 5084 ){ |
4846 sqlite3_free(zTmpname); | 5085 osCloseHandle(h); |
4847 OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc))); | 5086 sqlite3_free(zConverted); |
4848 return rc; | 5087 sqlite3_free(zTmpname); |
| 5088 OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc))); |
| 5089 return rc; |
| 5090 } |
4849 } | 5091 } |
4850 if( isTemp ){ | 5092 if( isTemp ){ |
4851 pFile->zDeleteOnClose = zConverted; | 5093 pFile->zDeleteOnClose = zConverted; |
4852 }else | 5094 }else |
4853 #endif | 5095 #endif |
4854 { | 5096 { |
4855 sqlite3_free(zConverted); | 5097 sqlite3_free(zConverted); |
4856 } | 5098 } |
4857 | 5099 |
4858 sqlite3_free(zTmpname); | 5100 sqlite3_free(zTmpname); |
4859 pFile->pMethod = &winIoMethod; | 5101 pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod; |
4860 pFile->pVfs = pVfs; | 5102 pFile->pVfs = pVfs; |
4861 pFile->h = h; | 5103 pFile->h = h; |
4862 if( isReadonly ){ | 5104 if( isReadonly ){ |
4863 pFile->ctrlFlags |= WINFILE_RDONLY; | 5105 pFile->ctrlFlags |= WINFILE_RDONLY; |
4864 } | 5106 } |
4865 if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ | 5107 if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ |
4866 pFile->ctrlFlags |= WINFILE_PSOW; | 5108 pFile->ctrlFlags |= WINFILE_PSOW; |
4867 } | 5109 } |
4868 pFile->lastErrno = NO_ERROR; | 5110 pFile->lastErrno = NO_ERROR; |
4869 pFile->zPath = zName; | 5111 pFile->zPath = zName; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4903 void *zConverted; | 5145 void *zConverted; |
4904 UNUSED_PARAMETER(pVfs); | 5146 UNUSED_PARAMETER(pVfs); |
4905 UNUSED_PARAMETER(syncDir); | 5147 UNUSED_PARAMETER(syncDir); |
4906 | 5148 |
4907 SimulateIOError(return SQLITE_IOERR_DELETE); | 5149 SimulateIOError(return SQLITE_IOERR_DELETE); |
4908 OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir)); | 5150 OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir)); |
4909 | 5151 |
4910 zConverted = winConvertFromUtf8Filename(zFilename); | 5152 zConverted = winConvertFromUtf8Filename(zFilename); |
4911 if( zConverted==0 ){ | 5153 if( zConverted==0 ){ |
4912 OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename)); | 5154 OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename)); |
4913 return SQLITE_IOERR_NOMEM; | 5155 return SQLITE_IOERR_NOMEM_BKPT; |
4914 } | 5156 } |
4915 if( osIsNT() ){ | 5157 if( osIsNT() ){ |
4916 do { | 5158 do { |
4917 #if SQLITE_OS_WINRT | 5159 #if SQLITE_OS_WINRT |
4918 WIN32_FILE_ATTRIBUTE_DATA sAttrData; | 5160 WIN32_FILE_ATTRIBUTE_DATA sAttrData; |
4919 memset(&sAttrData, 0, sizeof(sAttrData)); | 5161 memset(&sAttrData, 0, sizeof(sAttrData)); |
4920 if ( osGetFileAttributesExW(zConverted, GetFileExInfoStandard, | 5162 if ( osGetFileAttributesExW(zConverted, GetFileExInfoStandard, |
4921 &sAttrData) ){ | 5163 &sAttrData) ){ |
4922 attr = sAttrData.dwFileAttributes; | 5164 attr = sAttrData.dwFileAttributes; |
4923 }else{ | 5165 }else{ |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5011 void *zConverted; | 5253 void *zConverted; |
5012 UNUSED_PARAMETER(pVfs); | 5254 UNUSED_PARAMETER(pVfs); |
5013 | 5255 |
5014 SimulateIOError( return SQLITE_IOERR_ACCESS; ); | 5256 SimulateIOError( return SQLITE_IOERR_ACCESS; ); |
5015 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n", | 5257 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n", |
5016 zFilename, flags, pResOut)); | 5258 zFilename, flags, pResOut)); |
5017 | 5259 |
5018 zConverted = winConvertFromUtf8Filename(zFilename); | 5260 zConverted = winConvertFromUtf8Filename(zFilename); |
5019 if( zConverted==0 ){ | 5261 if( zConverted==0 ){ |
5020 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename)); | 5262 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename)); |
5021 return SQLITE_IOERR_NOMEM; | 5263 return SQLITE_IOERR_NOMEM_BKPT; |
5022 } | 5264 } |
5023 if( osIsNT() ){ | 5265 if( osIsNT() ){ |
5024 int cnt = 0; | 5266 int cnt = 0; |
5025 WIN32_FILE_ATTRIBUTE_DATA sAttrData; | 5267 WIN32_FILE_ATTRIBUTE_DATA sAttrData; |
5026 memset(&sAttrData, 0, sizeof(sAttrData)); | 5268 memset(&sAttrData, 0, sizeof(sAttrData)); |
5027 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, | 5269 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted, |
5028 GetFileExInfoStandard, | 5270 GetFileExInfoStandard, |
5029 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){} | 5271 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){} |
5030 if( rc ){ | 5272 if( rc ){ |
5031 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file | 5273 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5124 ** Turn a relative pathname into a full pathname. Write the full | 5366 ** Turn a relative pathname into a full pathname. Write the full |
5125 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname | 5367 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname |
5126 ** bytes in size. | 5368 ** bytes in size. |
5127 */ | 5369 */ |
5128 static int winFullPathname( | 5370 static int winFullPathname( |
5129 sqlite3_vfs *pVfs, /* Pointer to vfs object */ | 5371 sqlite3_vfs *pVfs, /* Pointer to vfs object */ |
5130 const char *zRelative, /* Possibly relative input path */ | 5372 const char *zRelative, /* Possibly relative input path */ |
5131 int nFull, /* Size of output buffer in bytes */ | 5373 int nFull, /* Size of output buffer in bytes */ |
5132 char *zFull /* Output buffer */ | 5374 char *zFull /* Output buffer */ |
5133 ){ | 5375 ){ |
| 5376 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__) |
| 5377 DWORD nByte; |
| 5378 void *zConverted; |
| 5379 char *zOut; |
| 5380 #endif |
| 5381 |
| 5382 /* If this path name begins with "/X:", where "X" is any alphabetic |
| 5383 ** character, discard the initial "/" from the pathname. |
| 5384 */ |
| 5385 if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){ |
| 5386 zRelative++; |
| 5387 } |
5134 | 5388 |
5135 #if defined(__CYGWIN__) | 5389 #if defined(__CYGWIN__) |
5136 SimulateIOError( return SQLITE_ERROR ); | 5390 SimulateIOError( return SQLITE_ERROR ); |
5137 UNUSED_PARAMETER(nFull); | 5391 UNUSED_PARAMETER(nFull); |
5138 assert( nFull>=pVfs->mxPathname ); | 5392 assert( nFull>=pVfs->mxPathname ); |
5139 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ | 5393 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ |
5140 /* | 5394 /* |
5141 ** NOTE: We are dealing with a relative path name and the data | 5395 ** NOTE: We are dealing with a relative path name and the data |
5142 ** directory has been set. Therefore, use it as the basis | 5396 ** directory has been set. Therefore, use it as the basis |
5143 ** for converting the relative path name to an absolute | 5397 ** for converting the relative path name to an absolute |
5144 ** one by prepending the data directory and a slash. | 5398 ** one by prepending the data directory and a slash. |
5145 */ | 5399 */ |
5146 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 ); | 5400 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 ); |
5147 if( !zOut ){ | 5401 if( !zOut ){ |
5148 return SQLITE_IOERR_NOMEM; | 5402 return SQLITE_IOERR_NOMEM_BKPT; |
5149 } | 5403 } |
5150 if( cygwin_conv_path( | 5404 if( cygwin_conv_path( |
5151 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) | | 5405 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) | |
5152 CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){ | 5406 CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){ |
5153 sqlite3_free(zOut); | 5407 sqlite3_free(zOut); |
5154 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, | 5408 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, |
5155 "winFullPathname1", zRelative); | 5409 "winFullPathname1", zRelative); |
5156 }else{ | 5410 }else{ |
5157 char *zUtf8 = winConvertToUtf8Filename(zOut); | 5411 char *zUtf8 = winConvertToUtf8Filename(zOut); |
5158 if( !zUtf8 ){ | 5412 if( !zUtf8 ){ |
5159 sqlite3_free(zOut); | 5413 sqlite3_free(zOut); |
5160 return SQLITE_IOERR_NOMEM; | 5414 return SQLITE_IOERR_NOMEM_BKPT; |
5161 } | 5415 } |
5162 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", | 5416 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", |
5163 sqlite3_data_directory, winGetDirSep(), zUtf8); | 5417 sqlite3_data_directory, winGetDirSep(), zUtf8); |
5164 sqlite3_free(zUtf8); | 5418 sqlite3_free(zUtf8); |
5165 sqlite3_free(zOut); | 5419 sqlite3_free(zOut); |
5166 } | 5420 } |
5167 }else{ | 5421 }else{ |
5168 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 ); | 5422 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 ); |
5169 if( !zOut ){ | 5423 if( !zOut ){ |
5170 return SQLITE_IOERR_NOMEM; | 5424 return SQLITE_IOERR_NOMEM_BKPT; |
5171 } | 5425 } |
5172 if( cygwin_conv_path( | 5426 if( cygwin_conv_path( |
5173 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A), | 5427 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A), |
5174 zRelative, zOut, pVfs->mxPathname+1)<0 ){ | 5428 zRelative, zOut, pVfs->mxPathname+1)<0 ){ |
5175 sqlite3_free(zOut); | 5429 sqlite3_free(zOut); |
5176 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, | 5430 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno, |
5177 "winFullPathname2", zRelative); | 5431 "winFullPathname2", zRelative); |
5178 }else{ | 5432 }else{ |
5179 char *zUtf8 = winConvertToUtf8Filename(zOut); | 5433 char *zUtf8 = winConvertToUtf8Filename(zOut); |
5180 if( !zUtf8 ){ | 5434 if( !zUtf8 ){ |
5181 sqlite3_free(zOut); | 5435 sqlite3_free(zOut); |
5182 return SQLITE_IOERR_NOMEM; | 5436 return SQLITE_IOERR_NOMEM_BKPT; |
5183 } | 5437 } |
5184 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8); | 5438 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8); |
5185 sqlite3_free(zUtf8); | 5439 sqlite3_free(zUtf8); |
5186 sqlite3_free(zOut); | 5440 sqlite3_free(zOut); |
5187 } | 5441 } |
5188 } | 5442 } |
5189 return SQLITE_OK; | 5443 return SQLITE_OK; |
5190 #endif | 5444 #endif |
5191 | 5445 |
5192 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__) | 5446 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__) |
5193 SimulateIOError( return SQLITE_ERROR ); | 5447 SimulateIOError( return SQLITE_ERROR ); |
5194 /* WinCE has no concept of a relative pathname, or so I am told. */ | 5448 /* WinCE has no concept of a relative pathname, or so I am told. */ |
5195 /* WinRT has no way to convert a relative path to an absolute one. */ | 5449 /* WinRT has no way to convert a relative path to an absolute one. */ |
5196 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ | 5450 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ |
5197 /* | 5451 /* |
5198 ** NOTE: We are dealing with a relative path name and the data | 5452 ** NOTE: We are dealing with a relative path name and the data |
5199 ** directory has been set. Therefore, use it as the basis | 5453 ** directory has been set. Therefore, use it as the basis |
5200 ** for converting the relative path name to an absolute | 5454 ** for converting the relative path name to an absolute |
5201 ** one by prepending the data directory and a backslash. | 5455 ** one by prepending the data directory and a backslash. |
5202 */ | 5456 */ |
5203 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", | 5457 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", |
5204 sqlite3_data_directory, winGetDirSep(), zRelative); | 5458 sqlite3_data_directory, winGetDirSep(), zRelative); |
5205 }else{ | 5459 }else{ |
5206 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative); | 5460 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative); |
5207 } | 5461 } |
5208 return SQLITE_OK; | 5462 return SQLITE_OK; |
5209 #endif | 5463 #endif |
5210 | 5464 |
5211 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__) | 5465 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__) |
5212 DWORD nByte; | |
5213 void *zConverted; | |
5214 char *zOut; | |
5215 | |
5216 /* If this path name begins with "/X:", where "X" is any alphabetic | |
5217 ** character, discard the initial "/" from the pathname. | |
5218 */ | |
5219 if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){ | |
5220 zRelative++; | |
5221 } | |
5222 | |
5223 /* It's odd to simulate an io-error here, but really this is just | 5466 /* It's odd to simulate an io-error here, but really this is just |
5224 ** using the io-error infrastructure to test that SQLite handles this | 5467 ** using the io-error infrastructure to test that SQLite handles this |
5225 ** function failing. This function could fail if, for example, the | 5468 ** function failing. This function could fail if, for example, the |
5226 ** current working directory has been unlinked. | 5469 ** current working directory has been unlinked. |
5227 */ | 5470 */ |
5228 SimulateIOError( return SQLITE_ERROR ); | 5471 SimulateIOError( return SQLITE_ERROR ); |
5229 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ | 5472 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){ |
5230 /* | 5473 /* |
5231 ** NOTE: We are dealing with a relative path name and the data | 5474 ** NOTE: We are dealing with a relative path name and the data |
5232 ** directory has been set. Therefore, use it as the basis | 5475 ** directory has been set. Therefore, use it as the basis |
5233 ** for converting the relative path name to an absolute | 5476 ** for converting the relative path name to an absolute |
5234 ** one by prepending the data directory and a backslash. | 5477 ** one by prepending the data directory and a backslash. |
5235 */ | 5478 */ |
5236 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", | 5479 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s", |
5237 sqlite3_data_directory, winGetDirSep(), zRelative); | 5480 sqlite3_data_directory, winGetDirSep(), zRelative); |
5238 return SQLITE_OK; | 5481 return SQLITE_OK; |
5239 } | 5482 } |
5240 zConverted = winConvertFromUtf8Filename(zRelative); | 5483 zConverted = winConvertFromUtf8Filename(zRelative); |
5241 if( zConverted==0 ){ | 5484 if( zConverted==0 ){ |
5242 return SQLITE_IOERR_NOMEM; | 5485 return SQLITE_IOERR_NOMEM_BKPT; |
5243 } | 5486 } |
5244 if( osIsNT() ){ | 5487 if( osIsNT() ){ |
5245 LPWSTR zTemp; | 5488 LPWSTR zTemp; |
5246 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0); | 5489 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0); |
5247 if( nByte==0 ){ | 5490 if( nByte==0 ){ |
5248 sqlite3_free(zConverted); | 5491 sqlite3_free(zConverted); |
5249 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), | 5492 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
5250 "winFullPathname1", zRelative); | 5493 "winFullPathname1", zRelative); |
5251 } | 5494 } |
5252 nByte += 3; | 5495 nByte += 3; |
5253 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); | 5496 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); |
5254 if( zTemp==0 ){ | 5497 if( zTemp==0 ){ |
5255 sqlite3_free(zConverted); | 5498 sqlite3_free(zConverted); |
5256 return SQLITE_IOERR_NOMEM; | 5499 return SQLITE_IOERR_NOMEM_BKPT; |
5257 } | 5500 } |
5258 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); | 5501 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); |
5259 if( nByte==0 ){ | 5502 if( nByte==0 ){ |
5260 sqlite3_free(zConverted); | 5503 sqlite3_free(zConverted); |
5261 sqlite3_free(zTemp); | 5504 sqlite3_free(zTemp); |
5262 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), | 5505 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
5263 "winFullPathname2", zRelative); | 5506 "winFullPathname2", zRelative); |
5264 } | 5507 } |
5265 sqlite3_free(zConverted); | 5508 sqlite3_free(zConverted); |
5266 zOut = winUnicodeToUtf8(zTemp); | 5509 zOut = winUnicodeToUtf8(zTemp); |
5267 sqlite3_free(zTemp); | 5510 sqlite3_free(zTemp); |
5268 } | 5511 } |
5269 #ifdef SQLITE_WIN32_HAS_ANSI | 5512 #ifdef SQLITE_WIN32_HAS_ANSI |
5270 else{ | 5513 else{ |
5271 char *zTemp; | 5514 char *zTemp; |
5272 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0); | 5515 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0); |
5273 if( nByte==0 ){ | 5516 if( nByte==0 ){ |
5274 sqlite3_free(zConverted); | 5517 sqlite3_free(zConverted); |
5275 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), | 5518 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
5276 "winFullPathname3", zRelative); | 5519 "winFullPathname3", zRelative); |
5277 } | 5520 } |
5278 nByte += 3; | 5521 nByte += 3; |
5279 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); | 5522 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); |
5280 if( zTemp==0 ){ | 5523 if( zTemp==0 ){ |
5281 sqlite3_free(zConverted); | 5524 sqlite3_free(zConverted); |
5282 return SQLITE_IOERR_NOMEM; | 5525 return SQLITE_IOERR_NOMEM_BKPT; |
5283 } | 5526 } |
5284 nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); | 5527 nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); |
5285 if( nByte==0 ){ | 5528 if( nByte==0 ){ |
5286 sqlite3_free(zConverted); | 5529 sqlite3_free(zConverted); |
5287 sqlite3_free(zTemp); | 5530 sqlite3_free(zTemp); |
5288 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), | 5531 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
5289 "winFullPathname4", zRelative); | 5532 "winFullPathname4", zRelative); |
5290 } | 5533 } |
5291 sqlite3_free(zConverted); | 5534 sqlite3_free(zConverted); |
5292 zOut = sqlite3_win32_mbcs_to_utf8(zTemp); | 5535 zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI()); |
5293 sqlite3_free(zTemp); | 5536 sqlite3_free(zTemp); |
5294 } | 5537 } |
5295 #endif | 5538 #endif |
5296 if( zOut ){ | 5539 if( zOut ){ |
5297 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut); | 5540 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut); |
5298 sqlite3_free(zOut); | 5541 sqlite3_free(zOut); |
5299 return SQLITE_OK; | 5542 return SQLITE_OK; |
5300 }else{ | 5543 }else{ |
5301 return SQLITE_IOERR_NOMEM; | 5544 return SQLITE_IOERR_NOMEM_BKPT; |
5302 } | 5545 } |
5303 #endif | 5546 #endif |
5304 } | 5547 } |
5305 | 5548 |
5306 #ifndef SQLITE_OMIT_LOAD_EXTENSION | 5549 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
5307 /* | 5550 /* |
5308 ** Interfaces for opening a shared library, finding entry points | 5551 ** Interfaces for opening a shared library, finding entry points |
5309 ** within the shared library, and closing the shared library. | 5552 ** within the shared library, and closing the shared library. |
5310 */ | 5553 */ |
5311 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ | 5554 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5366 osFreeLibrary((HANDLE)pHandle); | 5609 osFreeLibrary((HANDLE)pHandle); |
5367 OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle)); | 5610 OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle)); |
5368 } | 5611 } |
5369 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ | 5612 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ |
5370 #define winDlOpen 0 | 5613 #define winDlOpen 0 |
5371 #define winDlError 0 | 5614 #define winDlError 0 |
5372 #define winDlSym 0 | 5615 #define winDlSym 0 |
5373 #define winDlClose 0 | 5616 #define winDlClose 0 |
5374 #endif | 5617 #endif |
5375 | 5618 |
| 5619 /* State information for the randomness gatherer. */ |
| 5620 typedef struct EntropyGatherer EntropyGatherer; |
| 5621 struct EntropyGatherer { |
| 5622 unsigned char *a; /* Gather entropy into this buffer */ |
| 5623 int na; /* Size of a[] in bytes */ |
| 5624 int i; /* XOR next input into a[i] */ |
| 5625 int nXor; /* Number of XOR operations done */ |
| 5626 }; |
| 5627 |
| 5628 #if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) |
| 5629 /* Mix sz bytes of entropy into p. */ |
| 5630 static void xorMemory(EntropyGatherer *p, unsigned char *x, int sz){ |
| 5631 int j, k; |
| 5632 for(j=0, k=p->i; j<sz; j++){ |
| 5633 p->a[k++] ^= x[j]; |
| 5634 if( k>=p->na ) k = 0; |
| 5635 } |
| 5636 p->i = k; |
| 5637 p->nXor += sz; |
| 5638 } |
| 5639 #endif /* !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) */ |
5376 | 5640 |
5377 /* | 5641 /* |
5378 ** Write up to nBuf bytes of randomness into zBuf. | 5642 ** Write up to nBuf bytes of randomness into zBuf. |
5379 */ | 5643 */ |
5380 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ | 5644 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
5381 int n = 0; | 5645 #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) |
5382 UNUSED_PARAMETER(pVfs); | 5646 UNUSED_PARAMETER(pVfs); |
5383 #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) | |
5384 n = nBuf; | |
5385 memset(zBuf, 0, nBuf); | 5647 memset(zBuf, 0, nBuf); |
| 5648 return nBuf; |
5386 #else | 5649 #else |
5387 if( sizeof(SYSTEMTIME)<=nBuf-n ){ | 5650 EntropyGatherer e; |
| 5651 UNUSED_PARAMETER(pVfs); |
| 5652 memset(zBuf, 0, nBuf); |
| 5653 #if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE |
| 5654 rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */ |
| 5655 #endif /* defined(_MSC_VER) && _MSC_VER>=1400 */ |
| 5656 e.a = (unsigned char*)zBuf; |
| 5657 e.na = nBuf; |
| 5658 e.nXor = 0; |
| 5659 e.i = 0; |
| 5660 { |
5388 SYSTEMTIME x; | 5661 SYSTEMTIME x; |
5389 osGetSystemTime(&x); | 5662 osGetSystemTime(&x); |
5390 memcpy(&zBuf[n], &x, sizeof(x)); | 5663 xorMemory(&e, (unsigned char*)&x, sizeof(SYSTEMTIME)); |
5391 n += sizeof(x); | |
5392 } | 5664 } |
5393 if( sizeof(DWORD)<=nBuf-n ){ | 5665 { |
5394 DWORD pid = osGetCurrentProcessId(); | 5666 DWORD pid = osGetCurrentProcessId(); |
5395 memcpy(&zBuf[n], &pid, sizeof(pid)); | 5667 xorMemory(&e, (unsigned char*)&pid, sizeof(DWORD)); |
5396 n += sizeof(pid); | |
5397 } | 5668 } |
5398 #if SQLITE_OS_WINRT | 5669 #if SQLITE_OS_WINRT |
5399 if( sizeof(ULONGLONG)<=nBuf-n ){ | 5670 { |
5400 ULONGLONG cnt = osGetTickCount64(); | 5671 ULONGLONG cnt = osGetTickCount64(); |
5401 memcpy(&zBuf[n], &cnt, sizeof(cnt)); | 5672 xorMemory(&e, (unsigned char*)&cnt, sizeof(ULONGLONG)); |
5402 n += sizeof(cnt); | |
5403 } | 5673 } |
5404 #else | 5674 #else |
5405 if( sizeof(DWORD)<=nBuf-n ){ | 5675 { |
5406 DWORD cnt = osGetTickCount(); | 5676 DWORD cnt = osGetTickCount(); |
5407 memcpy(&zBuf[n], &cnt, sizeof(cnt)); | 5677 xorMemory(&e, (unsigned char*)&cnt, sizeof(DWORD)); |
5408 n += sizeof(cnt); | |
5409 } | 5678 } |
5410 #endif | 5679 #endif /* SQLITE_OS_WINRT */ |
5411 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ | 5680 { |
5412 LARGE_INTEGER i; | 5681 LARGE_INTEGER i; |
5413 osQueryPerformanceCounter(&i); | 5682 osQueryPerformanceCounter(&i); |
5414 memcpy(&zBuf[n], &i, sizeof(i)); | 5683 xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER)); |
5415 n += sizeof(i); | |
5416 } | 5684 } |
5417 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID | 5685 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
5418 if( sizeof(UUID)<=nBuf-n ){ | 5686 { |
5419 UUID id; | 5687 UUID id; |
5420 memset(&id, 0, sizeof(UUID)); | 5688 memset(&id, 0, sizeof(UUID)); |
5421 osUuidCreate(&id); | 5689 osUuidCreate(&id); |
5422 memcpy(&zBuf[n], &id, sizeof(UUID)); | 5690 xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); |
5423 n += sizeof(UUID); | |
5424 } | |
5425 if( sizeof(UUID)<=nBuf-n ){ | |
5426 UUID id; | |
5427 memset(&id, 0, sizeof(UUID)); | 5691 memset(&id, 0, sizeof(UUID)); |
5428 osUuidCreateSequential(&id); | 5692 osUuidCreateSequential(&id); |
5429 memcpy(&zBuf[n], &id, sizeof(UUID)); | 5693 xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); |
5430 n += sizeof(UUID); | |
5431 } | 5694 } |
5432 #endif | 5695 #endif /* !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID */ |
5433 #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */ | 5696 return e.nXor>nBuf ? nBuf : e.nXor; |
5434 return n; | 5697 #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */ |
5435 } | 5698 } |
5436 | 5699 |
5437 | 5700 |
5438 /* | 5701 /* |
5439 ** Sleep for a little while. Return the amount of time slept. | 5702 ** Sleep for a little while. Return the amount of time slept. |
5440 */ | 5703 */ |
5441 static int winSleep(sqlite3_vfs *pVfs, int microsec){ | 5704 static int winSleep(sqlite3_vfs *pVfs, int microsec){ |
5442 sqlite3_win32_sleep((microsec+999)/1000); | 5705 sqlite3_win32_sleep((microsec+999)/1000); |
5443 UNUSED_PARAMETER(pVfs); | 5706 UNUSED_PARAMETER(pVfs); |
5444 return ((microsec+999)/1000)*1000; | 5707 return ((microsec+999)/1000)*1000; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5540 ** int xGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ | 5803 ** int xGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
5541 ** assert(zBuf[0]=='\0'); | 5804 ** assert(zBuf[0]=='\0'); |
5542 ** return 0; | 5805 ** return 0; |
5543 ** } | 5806 ** } |
5544 ** | 5807 ** |
5545 ** However if an error message is supplied, it will be incorporated | 5808 ** However if an error message is supplied, it will be incorporated |
5546 ** by sqlite into the error message available to the user using | 5809 ** by sqlite into the error message available to the user using |
5547 ** sqlite3_errmsg(), possibly making IO errors easier to debug. | 5810 ** sqlite3_errmsg(), possibly making IO errors easier to debug. |
5548 */ | 5811 */ |
5549 static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ | 5812 static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
| 5813 DWORD e = osGetLastError(); |
5550 UNUSED_PARAMETER(pVfs); | 5814 UNUSED_PARAMETER(pVfs); |
5551 return winGetLastErrorMsg(osGetLastError(), nBuf, zBuf); | 5815 if( nBuf>0 ) winGetLastErrorMsg(e, nBuf, zBuf); |
| 5816 return e; |
5552 } | 5817 } |
5553 | 5818 |
5554 /* | 5819 /* |
5555 ** Initialize and deinitialize the operating system interface. | 5820 ** Initialize and deinitialize the operating system interface. |
5556 */ | 5821 */ |
5557 int sqlite3_os_init(void){ | 5822 int sqlite3_os_init(void){ |
5558 static sqlite3_vfs winVfs = { | 5823 static sqlite3_vfs winVfs = { |
5559 3, /* iVersion */ | 5824 3, /* iVersion */ |
5560 sizeof(winFile), /* szOsFile */ | 5825 sizeof(winFile), /* szOsFile */ |
5561 SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */ | 5826 SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */ |
5562 0, /* pNext */ | 5827 0, /* pNext */ |
5563 "win32", /* zName */ | 5828 "win32", /* zName */ |
5564 0, /* pAppData */ | 5829 &winAppData, /* pAppData */ |
5565 winOpen, /* xOpen */ | 5830 winOpen, /* xOpen */ |
5566 winDelete, /* xDelete */ | 5831 winDelete, /* xDelete */ |
5567 winAccess, /* xAccess */ | 5832 winAccess, /* xAccess */ |
5568 winFullPathname, /* xFullPathname */ | 5833 winFullPathname, /* xFullPathname */ |
5569 winDlOpen, /* xDlOpen */ | 5834 winDlOpen, /* xDlOpen */ |
5570 winDlError, /* xDlError */ | 5835 winDlError, /* xDlError */ |
5571 winDlSym, /* xDlSym */ | 5836 winDlSym, /* xDlSym */ |
5572 winDlClose, /* xDlClose */ | 5837 winDlClose, /* xDlClose */ |
5573 winRandomness, /* xRandomness */ | 5838 winRandomness, /* xRandomness */ |
5574 winSleep, /* xSleep */ | 5839 winSleep, /* xSleep */ |
5575 winCurrentTime, /* xCurrentTime */ | 5840 winCurrentTime, /* xCurrentTime */ |
5576 winGetLastError, /* xGetLastError */ | 5841 winGetLastError, /* xGetLastError */ |
5577 winCurrentTimeInt64, /* xCurrentTimeInt64 */ | 5842 winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
5578 winSetSystemCall, /* xSetSystemCall */ | 5843 winSetSystemCall, /* xSetSystemCall */ |
5579 winGetSystemCall, /* xGetSystemCall */ | 5844 winGetSystemCall, /* xGetSystemCall */ |
5580 winNextSystemCall, /* xNextSystemCall */ | 5845 winNextSystemCall, /* xNextSystemCall */ |
5581 }; | 5846 }; |
5582 #if defined(SQLITE_WIN32_HAS_WIDE) | 5847 #if defined(SQLITE_WIN32_HAS_WIDE) |
5583 static sqlite3_vfs winLongPathVfs = { | 5848 static sqlite3_vfs winLongPathVfs = { |
5584 3, /* iVersion */ | 5849 3, /* iVersion */ |
5585 sizeof(winFile), /* szOsFile */ | 5850 sizeof(winFile), /* szOsFile */ |
5586 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */ | 5851 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */ |
5587 0, /* pNext */ | 5852 0, /* pNext */ |
5588 "win32-longpath", /* zName */ | 5853 "win32-longpath", /* zName */ |
5589 0, /* pAppData */ | 5854 &winAppData, /* pAppData */ |
5590 winOpen, /* xOpen */ | 5855 winOpen, /* xOpen */ |
5591 winDelete, /* xDelete */ | 5856 winDelete, /* xDelete */ |
5592 winAccess, /* xAccess */ | 5857 winAccess, /* xAccess */ |
5593 winFullPathname, /* xFullPathname */ | 5858 winFullPathname, /* xFullPathname */ |
5594 winDlOpen, /* xDlOpen */ | 5859 winDlOpen, /* xDlOpen */ |
5595 winDlError, /* xDlError */ | 5860 winDlError, /* xDlError */ |
5596 winDlSym, /* xDlSym */ | 5861 winDlSym, /* xDlSym */ |
5597 winDlClose, /* xDlClose */ | 5862 winDlClose, /* xDlClose */ |
5598 winRandomness, /* xRandomness */ | 5863 winRandomness, /* xRandomness */ |
5599 winSleep, /* xSleep */ | 5864 winSleep, /* xSleep */ |
5600 winCurrentTime, /* xCurrentTime */ | 5865 winCurrentTime, /* xCurrentTime */ |
5601 winGetLastError, /* xGetLastError */ | 5866 winGetLastError, /* xGetLastError */ |
5602 winCurrentTimeInt64, /* xCurrentTimeInt64 */ | 5867 winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
5603 winSetSystemCall, /* xSetSystemCall */ | 5868 winSetSystemCall, /* xSetSystemCall */ |
5604 winGetSystemCall, /* xGetSystemCall */ | 5869 winGetSystemCall, /* xGetSystemCall */ |
5605 winNextSystemCall, /* xNextSystemCall */ | 5870 winNextSystemCall, /* xNextSystemCall */ |
| 5871 }; |
| 5872 #endif |
| 5873 static sqlite3_vfs winNolockVfs = { |
| 5874 3, /* iVersion */ |
| 5875 sizeof(winFile), /* szOsFile */ |
| 5876 SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */ |
| 5877 0, /* pNext */ |
| 5878 "win32-none", /* zName */ |
| 5879 &winNolockAppData, /* pAppData */ |
| 5880 winOpen, /* xOpen */ |
| 5881 winDelete, /* xDelete */ |
| 5882 winAccess, /* xAccess */ |
| 5883 winFullPathname, /* xFullPathname */ |
| 5884 winDlOpen, /* xDlOpen */ |
| 5885 winDlError, /* xDlError */ |
| 5886 winDlSym, /* xDlSym */ |
| 5887 winDlClose, /* xDlClose */ |
| 5888 winRandomness, /* xRandomness */ |
| 5889 winSleep, /* xSleep */ |
| 5890 winCurrentTime, /* xCurrentTime */ |
| 5891 winGetLastError, /* xGetLastError */ |
| 5892 winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 5893 winSetSystemCall, /* xSetSystemCall */ |
| 5894 winGetSystemCall, /* xGetSystemCall */ |
| 5895 winNextSystemCall, /* xNextSystemCall */ |
| 5896 }; |
| 5897 #if defined(SQLITE_WIN32_HAS_WIDE) |
| 5898 static sqlite3_vfs winLongPathNolockVfs = { |
| 5899 3, /* iVersion */ |
| 5900 sizeof(winFile), /* szOsFile */ |
| 5901 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */ |
| 5902 0, /* pNext */ |
| 5903 "win32-longpath-none", /* zName */ |
| 5904 &winNolockAppData, /* pAppData */ |
| 5905 winOpen, /* xOpen */ |
| 5906 winDelete, /* xDelete */ |
| 5907 winAccess, /* xAccess */ |
| 5908 winFullPathname, /* xFullPathname */ |
| 5909 winDlOpen, /* xDlOpen */ |
| 5910 winDlError, /* xDlError */ |
| 5911 winDlSym, /* xDlSym */ |
| 5912 winDlClose, /* xDlClose */ |
| 5913 winRandomness, /* xRandomness */ |
| 5914 winSleep, /* xSleep */ |
| 5915 winCurrentTime, /* xCurrentTime */ |
| 5916 winGetLastError, /* xGetLastError */ |
| 5917 winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 5918 winSetSystemCall, /* xSetSystemCall */ |
| 5919 winGetSystemCall, /* xGetSystemCall */ |
| 5920 winNextSystemCall, /* xNextSystemCall */ |
5606 }; | 5921 }; |
5607 #endif | 5922 #endif |
5608 | 5923 |
5609 /* Double-check that the aSyscall[] array has been constructed | 5924 /* Double-check that the aSyscall[] array has been constructed |
5610 ** correctly. See ticket [bb3a86e890c8e96ab] */ | 5925 ** correctly. See ticket [bb3a86e890c8e96ab] */ |
5611 assert( ArraySize(aSyscall)==80 ); | 5926 assert( ArraySize(aSyscall)==80 ); |
5612 | 5927 |
5613 /* get memory map allocation granularity */ | 5928 /* get memory map allocation granularity */ |
5614 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); | 5929 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
5615 #if SQLITE_OS_WINRT | 5930 #if SQLITE_OS_WINRT |
5616 osGetNativeSystemInfo(&winSysInfo); | 5931 osGetNativeSystemInfo(&winSysInfo); |
5617 #else | 5932 #else |
5618 osGetSystemInfo(&winSysInfo); | 5933 osGetSystemInfo(&winSysInfo); |
5619 #endif | 5934 #endif |
5620 assert( winSysInfo.dwAllocationGranularity>0 ); | 5935 assert( winSysInfo.dwAllocationGranularity>0 ); |
5621 assert( winSysInfo.dwPageSize>0 ); | 5936 assert( winSysInfo.dwPageSize>0 ); |
5622 | 5937 |
5623 sqlite3_vfs_register(&winVfs, 1); | 5938 sqlite3_vfs_register(&winVfs, 1); |
5624 | 5939 |
5625 #if defined(SQLITE_WIN32_HAS_WIDE) | 5940 #if defined(SQLITE_WIN32_HAS_WIDE) |
5626 sqlite3_vfs_register(&winLongPathVfs, 0); | 5941 sqlite3_vfs_register(&winLongPathVfs, 0); |
5627 #endif | 5942 #endif |
5628 | 5943 |
| 5944 sqlite3_vfs_register(&winNolockVfs, 0); |
| 5945 |
| 5946 #if defined(SQLITE_WIN32_HAS_WIDE) |
| 5947 sqlite3_vfs_register(&winLongPathNolockVfs, 0); |
| 5948 #endif |
| 5949 |
5629 return SQLITE_OK; | 5950 return SQLITE_OK; |
5630 } | 5951 } |
5631 | 5952 |
5632 int sqlite3_os_end(void){ | 5953 int sqlite3_os_end(void){ |
5633 #if SQLITE_OS_WINRT | 5954 #if SQLITE_OS_WINRT |
5634 if( sleepObj!=NULL ){ | 5955 if( sleepObj!=NULL ){ |
5635 osCloseHandle(sleepObj); | 5956 osCloseHandle(sleepObj); |
5636 sleepObj = NULL; | 5957 sleepObj = NULL; |
5637 } | 5958 } |
5638 #endif | 5959 #endif |
5639 return SQLITE_OK; | 5960 return SQLITE_OK; |
5640 } | 5961 } |
5641 | 5962 |
5642 CHROMIUM_SQLITE_API | 5963 CHROMIUM_SQLITE_API |
5643 void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE han
dle) { | 5964 void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE han
dle) { |
5644 winFile* winSQLite3File = (winFile*)file; | 5965 winFile* winSQLite3File = (winFile*)file; |
5645 memset(file, 0, sizeof(*file)); | 5966 memset(file, 0, sizeof(*file)); |
5646 winSQLite3File->pMethod = &winIoMethod; | 5967 winSQLite3File->pMethod = &winIoMethod; |
5647 winSQLite3File->h = handle; | 5968 winSQLite3File->h = handle; |
5648 } | 5969 } |
5649 | 5970 |
5650 #endif /* SQLITE_OS_WIN */ | 5971 #endif /* SQLITE_OS_WIN */ |
OLD | NEW |