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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 /* | 28 /* |
29 ** Compiling and using WAL mode requires several APIs that are only | 29 ** Compiling and using WAL mode requires several APIs that are only |
30 ** available in Windows platforms based on the NT kernel. | 30 ** available in Windows platforms based on the NT kernel. |
31 */ | 31 */ |
32 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) | 32 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL) |
33 # error "WAL mode requires support from the Windows NT kernel, compile\ | 33 # error "WAL mode requires support from the Windows NT kernel, compile\ |
34 with SQLITE_OMIT_WAL." | 34 with SQLITE_OMIT_WAL." |
35 #endif | 35 #endif |
36 | 36 |
| 37 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0 |
| 38 # error "Memory mapped files require support from the Windows NT kernel,\ |
| 39 compile with SQLITE_MAX_MMAP_SIZE=0." |
| 40 #endif |
| 41 |
37 /* | 42 /* |
38 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions | 43 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions |
39 ** based on the sub-platform)? | 44 ** based on the sub-platform)? |
40 */ | 45 */ |
41 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) | 46 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI) |
42 # define SQLITE_WIN32_HAS_ANSI | 47 # define SQLITE_WIN32_HAS_ANSI |
43 #endif | 48 #endif |
44 | 49 |
45 /* | 50 /* |
46 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions | 51 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 161 |
157 /* | 162 /* |
158 ** Returns the character that should be used as the directory separator. | 163 ** Returns the character that should be used as the directory separator. |
159 */ | 164 */ |
160 #ifndef winGetDirSep | 165 #ifndef winGetDirSep |
161 # define winGetDirSep() '\\' | 166 # define winGetDirSep() '\\' |
162 #endif | 167 #endif |
163 | 168 |
164 /* | 169 /* |
165 ** Do we need to manually define the Win32 file mapping APIs for use with WAL | 170 ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
166 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they | 171 ** mode or memory mapped files (e.g. these APIs are available in the Windows |
167 ** are not present in the header file)? | 172 ** CE SDK; however, they are not present in the header file)? |
168 */ | 173 */ |
169 #if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) | 174 #if SQLITE_WIN32_FILEMAPPING_API && \ |
| 175 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
170 /* | 176 /* |
171 ** Two of the file mapping APIs are different under WinRT. Figure out which | 177 ** Two of the file mapping APIs are different under WinRT. Figure out which |
172 ** set we need. | 178 ** set we need. |
173 */ | 179 */ |
174 #if SQLITE_OS_WINRT | 180 #if SQLITE_OS_WINRT |
175 WINBASEAPI HANDLE WINAPI CreateFileMappingFromApp(HANDLE, \ | 181 WINBASEAPI HANDLE WINAPI CreateFileMappingFromApp(HANDLE, \ |
176 LPSECURITY_ATTRIBUTES, ULONG, ULONG64, LPCWSTR); | 182 LPSECURITY_ATTRIBUTES, ULONG, ULONG64, LPCWSTR); |
177 | 183 |
178 WINBASEAPI LPVOID WINAPI MapViewOfFileFromApp(HANDLE, ULONG, ULONG64, SIZE_T); | 184 WINBASEAPI LPVOID WINAPI MapViewOfFileFromApp(HANDLE, ULONG, ULONG64, SIZE_T); |
179 #else | 185 #else |
180 #if defined(SQLITE_WIN32_HAS_ANSI) | 186 #if defined(SQLITE_WIN32_HAS_ANSI) |
181 WINBASEAPI HANDLE WINAPI CreateFileMappingA(HANDLE, LPSECURITY_ATTRIBUTES, \ | 187 WINBASEAPI HANDLE WINAPI CreateFileMappingA(HANDLE, LPSECURITY_ATTRIBUTES, \ |
182 DWORD, DWORD, DWORD, LPCSTR); | 188 DWORD, DWORD, DWORD, LPCSTR); |
183 #endif /* defined(SQLITE_WIN32_HAS_ANSI) */ | 189 #endif /* defined(SQLITE_WIN32_HAS_ANSI) */ |
184 | 190 |
185 #if defined(SQLITE_WIN32_HAS_WIDE) | 191 #if defined(SQLITE_WIN32_HAS_WIDE) |
186 WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE, LPSECURITY_ATTRIBUTES, \ | 192 WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE, LPSECURITY_ATTRIBUTES, \ |
187 DWORD, DWORD, DWORD, LPCWSTR); | 193 DWORD, DWORD, DWORD, LPCWSTR); |
188 #endif /* defined(SQLITE_WIN32_HAS_WIDE) */ | 194 #endif /* defined(SQLITE_WIN32_HAS_WIDE) */ |
189 | 195 |
190 WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T); | 196 WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T); |
191 #endif /* SQLITE_OS_WINRT */ | 197 #endif /* SQLITE_OS_WINRT */ |
192 | 198 |
193 /* | 199 /* |
194 ** This file mapping API is common to both Win32 and WinRT. | 200 ** These file mapping APIs are common to both Win32 and WinRT. |
195 */ | 201 */ |
| 202 |
| 203 WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T); |
196 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); | 204 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID); |
197 #endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */ | 205 #endif /* SQLITE_WIN32_FILEMAPPING_API */ |
198 | 206 |
199 /* | 207 /* |
200 ** Some Microsoft compilers lack this definition. | 208 ** Some Microsoft compilers lack this definition. |
201 */ | 209 */ |
202 #ifndef INVALID_FILE_ATTRIBUTES | 210 #ifndef INVALID_FILE_ATTRIBUTES |
203 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) | 211 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) |
204 #endif | 212 #endif |
205 | 213 |
206 #ifndef FILE_FLAG_MASK | 214 #ifndef FILE_FLAG_MASK |
207 # define FILE_FLAG_MASK (0xFF3C0000) | 215 # define FILE_FLAG_MASK (0xFF3C0000) |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) | 488 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) |
481 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, | 489 { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
482 #else | 490 #else |
483 { "CreateFileW", (SYSCALL)0, 0 }, | 491 { "CreateFileW", (SYSCALL)0, 0 }, |
484 #endif | 492 #endif |
485 | 493 |
486 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ | 494 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
487 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) | 495 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent) |
488 | 496 |
489 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ | 497 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \ |
490 !defined(SQLITE_OMIT_WAL)) | 498 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
491 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, | 499 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 }, |
492 #else | 500 #else |
493 { "CreateFileMappingA", (SYSCALL)0, 0 }, | 501 { "CreateFileMappingA", (SYSCALL)0, 0 }, |
494 #endif | 502 #endif |
495 | 503 |
496 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ | 504 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
497 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) | 505 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent) |
498 | 506 |
499 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ | 507 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ |
500 !defined(SQLITE_OMIT_WAL)) | 508 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
501 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, | 509 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
502 #else | 510 #else |
503 { "CreateFileMappingW", (SYSCALL)0, 0 }, | 511 { "CreateFileMappingW", (SYSCALL)0, 0 }, |
504 #endif | 512 #endif |
505 | 513 |
506 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ | 514 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
507 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent) | 515 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent) |
508 | 516 |
509 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) | 517 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) |
510 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 }, | 518 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 }, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 { "LockFileEx", (SYSCALL)LockFileEx, 0 }, | 838 { "LockFileEx", (SYSCALL)LockFileEx, 0 }, |
831 #else | 839 #else |
832 { "LockFileEx", (SYSCALL)0, 0 }, | 840 { "LockFileEx", (SYSCALL)0, 0 }, |
833 #endif | 841 #endif |
834 | 842 |
835 #ifndef osLockFileEx | 843 #ifndef osLockFileEx |
836 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ | 844 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
837 LPOVERLAPPED))aSyscall[48].pCurrent) | 845 LPOVERLAPPED))aSyscall[48].pCurrent) |
838 #endif | 846 #endif |
839 | 847 |
840 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)) | 848 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \ |
| 849 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)) |
841 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, | 850 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
842 #else | 851 #else |
843 { "MapViewOfFile", (SYSCALL)0, 0 }, | 852 { "MapViewOfFile", (SYSCALL)0, 0 }, |
844 #endif | 853 #endif |
845 | 854 |
846 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ | 855 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
847 SIZE_T))aSyscall[49].pCurrent) | 856 SIZE_T))aSyscall[49].pCurrent) |
848 | 857 |
849 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, | 858 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, |
850 | 859 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 | 909 |
901 #if !SQLITE_OS_WINCE | 910 #if !SQLITE_OS_WINCE |
902 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, | 911 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, |
903 #else | 912 #else |
904 { "UnlockFileEx", (SYSCALL)0, 0 }, | 913 { "UnlockFileEx", (SYSCALL)0, 0 }, |
905 #endif | 914 #endif |
906 | 915 |
907 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ | 916 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
908 LPOVERLAPPED))aSyscall[58].pCurrent) | 917 LPOVERLAPPED))aSyscall[58].pCurrent) |
909 | 918 |
910 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) | 919 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
911 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, | 920 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
912 #else | 921 #else |
913 { "UnmapViewOfFile", (SYSCALL)0, 0 }, | 922 { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
914 #endif | 923 #endif |
915 | 924 |
916 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent) | 925 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent) |
917 | 926 |
918 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, | 927 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, |
919 | 928 |
920 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ | 929 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 | 972 |
964 #if SQLITE_OS_WINRT | 973 #if SQLITE_OS_WINRT |
965 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 }, | 974 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 }, |
966 #else | 975 #else |
967 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 }, | 976 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 }, |
968 #endif | 977 #endif |
969 | 978 |
970 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ | 979 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \ |
971 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent) | 980 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent) |
972 | 981 |
973 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) | 982 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
974 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, | 983 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, |
975 #else | 984 #else |
976 { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, | 985 { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, |
977 #endif | 986 #endif |
978 | 987 |
979 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \ | 988 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \ |
980 SIZE_T))aSyscall[67].pCurrent) | 989 SIZE_T))aSyscall[67].pCurrent) |
981 | 990 |
982 #if SQLITE_OS_WINRT | 991 #if SQLITE_OS_WINRT |
983 { "CreateFile2", (SYSCALL)CreateFile2, 0 }, | 992 { "CreateFile2", (SYSCALL)CreateFile2, 0 }, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 #else | 1036 #else |
1028 { "OutputDebugStringW", (SYSCALL)0, 0 }, | 1037 { "OutputDebugStringW", (SYSCALL)0, 0 }, |
1029 #endif | 1038 #endif |
1030 | 1039 |
1031 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[73].pCurrent) | 1040 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[73].pCurrent) |
1032 | 1041 |
1033 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, | 1042 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
1034 | 1043 |
1035 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent) | 1044 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent) |
1036 | 1045 |
1037 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL) | 1046 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
1038 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, | 1047 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 }, |
1039 #else | 1048 #else |
1040 { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, | 1049 { "CreateFileMappingFromApp", (SYSCALL)0, 0 }, |
1041 #endif | 1050 #endif |
1042 | 1051 |
1043 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \ | 1052 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \ |
1044 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent) | 1053 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent) |
1045 | 1054 |
1046 /* | 1055 /* |
1047 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function" | 1056 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function" |
1048 ** is really just a macro that uses a compiler intrinsic (e.g. x64). | 1057 ** is really just a macro that uses a compiler intrinsic (e.g. x64). |
1049 ** So do not try to make this is into a redefinable interface. | 1058 ** So do not try to make this is into a redefinable interface. |
1050 */ | 1059 */ |
1051 #if defined(InterlockedCompareExchange) | 1060 #if defined(InterlockedCompareExchange) |
1052 { "InterlockedCompareExchange", (SYSCALL)0, 0 }, | 1061 { "InterlockedCompareExchange", (SYSCALL)0, 0 }, |
1053 | 1062 |
1054 #define osInterlockedCompareExchange InterlockedCompareExchange | 1063 #define osInterlockedCompareExchange InterlockedCompareExchange |
1055 #else | 1064 #else |
1056 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 }, | 1065 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 }, |
1057 | 1066 |
1058 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \ | 1067 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \ |
1059 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent) | 1068 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[76].pCurrent) |
1060 #endif /* defined(InterlockedCompareExchange) */ | 1069 #endif /* defined(InterlockedCompareExchange) */ |
1061 | 1070 |
| 1071 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 1072 { "UuidCreate", (SYSCALL)UuidCreate, 0 }, |
| 1073 #else |
| 1074 { "UuidCreate", (SYSCALL)0, 0 }, |
| 1075 #endif |
| 1076 |
| 1077 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[77].pCurrent) |
| 1078 |
| 1079 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 1080 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 }, |
| 1081 #else |
| 1082 { "UuidCreateSequential", (SYSCALL)0, 0 }, |
| 1083 #endif |
| 1084 |
| 1085 #define osUuidCreateSequential \ |
| 1086 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[78].pCurrent) |
| 1087 |
| 1088 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 |
| 1089 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, |
| 1090 #else |
| 1091 { "FlushViewOfFile", (SYSCALL)0, 0 }, |
| 1092 #endif |
| 1093 |
| 1094 #define osFlushViewOfFile \ |
| 1095 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent) |
| 1096 |
1062 }; /* End of the overrideable system calls */ | 1097 }; /* End of the overrideable system calls */ |
1063 | 1098 |
1064 /* | 1099 /* |
1065 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the | 1100 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
1066 ** "win32" VFSes. Return SQLITE_OK opon successfully updating the | 1101 ** "win32" VFSes. Return SQLITE_OK opon successfully updating the |
1067 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable | 1102 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
1068 ** system call named zName. | 1103 ** system call named zName. |
1069 */ | 1104 */ |
1070 static int winSetSystemCall( | 1105 static int winSetSystemCall( |
1071 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ | 1106 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 /* | 1224 /* |
1190 ** If a Win32 native heap has been configured, this function will attempt to | 1225 ** If a Win32 native heap has been configured, this function will attempt to |
1191 ** destroy and recreate it. If the Win32 native heap is not isolated and/or | 1226 ** destroy and recreate it. If the Win32 native heap is not isolated and/or |
1192 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will | 1227 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will |
1193 ** be returned and no changes will be made to the Win32 native heap. | 1228 ** be returned and no changes will be made to the Win32 native heap. |
1194 */ | 1229 */ |
1195 int sqlite3_win32_reset_heap(){ | 1230 int sqlite3_win32_reset_heap(){ |
1196 int rc; | 1231 int rc; |
1197 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ | 1232 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
1198 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ | 1233 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ |
1199 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) | 1234 MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); ) |
1200 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); ) | 1235 MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); ) |
1201 sqlite3_mutex_enter(pMaster); | 1236 sqlite3_mutex_enter(pMaster); |
1202 sqlite3_mutex_enter(pMem); | 1237 sqlite3_mutex_enter(pMem); |
1203 winMemAssertMagic(); | 1238 winMemAssertMagic(); |
1204 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ | 1239 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ |
1205 /* | 1240 /* |
1206 ** At this point, there should be no outstanding memory allocations on | 1241 ** At this point, there should be no outstanding memory allocations on |
1207 ** the heap. Also, since both the master and memsys locks are currently | 1242 ** the heap. Also, since both the master and memsys locks are currently |
1208 ** being held by us, no other function (i.e. from another thread) should | 1243 ** being held by us, no other function (i.e. from another thread) should |
1209 ** be able to even access the heap. Attempt to destroy and recreate our | 1244 ** be able to even access the heap. Attempt to destroy and recreate our |
1210 ** isolated Win32 native heap now. | 1245 ** isolated Win32 native heap now. |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1935 #endif | 1970 #endif |
1936 if( pError ){ | 1971 if( pError ){ |
1937 *pError = e; | 1972 *pError = e; |
1938 } | 1973 } |
1939 return 0; | 1974 return 0; |
1940 } | 1975 } |
1941 | 1976 |
1942 /* | 1977 /* |
1943 ** Log a I/O error retry episode. | 1978 ** Log a I/O error retry episode. |
1944 */ | 1979 */ |
1945 static void winLogIoerr(int nRetry){ | 1980 static void winLogIoerr(int nRetry, int lineno){ |
1946 if( nRetry ){ | 1981 if( nRetry ){ |
1947 sqlite3_log(SQLITE_IOERR, | 1982 sqlite3_log(SQLITE_NOTICE, |
1948 "delayed %dms for lock/sharing conflict", | 1983 "delayed %dms for lock/sharing conflict at line %d", |
1949 winIoerrRetryDelay*nRetry*(nRetry+1)/2 | 1984 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno |
1950 ); | 1985 ); |
1951 } | 1986 } |
1952 } | 1987 } |
1953 | 1988 |
1954 #if SQLITE_OS_WINCE | 1989 #if SQLITE_OS_WINCE |
1955 /************************************************************************* | 1990 /************************************************************************* |
1956 ** This section contains code for WinCE only. | 1991 ** This section contains code for WinCE only. |
1957 */ | 1992 */ |
1958 #if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API | 1993 #if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API |
1959 /* | 1994 /* |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 #define MX_CLOSE_ATTEMPT 3 | 2454 #define MX_CLOSE_ATTEMPT 3 |
2420 static int winClose(sqlite3_file *id){ | 2455 static int winClose(sqlite3_file *id){ |
2421 int rc, cnt = 0; | 2456 int rc, cnt = 0; |
2422 winFile *pFile = (winFile*)id; | 2457 winFile *pFile = (winFile*)id; |
2423 | 2458 |
2424 assert( id!=0 ); | 2459 assert( id!=0 ); |
2425 #ifndef SQLITE_OMIT_WAL | 2460 #ifndef SQLITE_OMIT_WAL |
2426 assert( pFile->pShm==0 ); | 2461 assert( pFile->pShm==0 ); |
2427 #endif | 2462 #endif |
2428 assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); | 2463 assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); |
2429 OSTRACE(("CLOSE file=%p\n", pFile->h)); | 2464 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n", |
| 2465 osGetCurrentProcessId(), pFile, pFile->h)); |
2430 | 2466 |
2431 #if SQLITE_MAX_MMAP_SIZE>0 | 2467 #if SQLITE_MAX_MMAP_SIZE>0 |
2432 winUnmapfile(pFile); | 2468 winUnmapfile(pFile); |
2433 #endif | 2469 #endif |
2434 | 2470 |
2435 do{ | 2471 do{ |
2436 rc = osCloseHandle(pFile->h); | 2472 rc = osCloseHandle(pFile->h); |
2437 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ | 2473 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ |
2438 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); | 2474 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); |
2439 #if SQLITE_OS_WINCE | 2475 #if SQLITE_OS_WINCE |
2440 #define WINCE_DELETION_ATTEMPTS 3 | 2476 #define WINCE_DELETION_ATTEMPTS 3 |
2441 winceDestroyLock(pFile); | 2477 winceDestroyLock(pFile); |
2442 if( pFile->zDeleteOnClose ){ | 2478 if( pFile->zDeleteOnClose ){ |
2443 int cnt = 0; | 2479 int cnt = 0; |
2444 while( | 2480 while( |
2445 osDeleteFileW(pFile->zDeleteOnClose)==0 | 2481 osDeleteFileW(pFile->zDeleteOnClose)==0 |
2446 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff | 2482 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff |
2447 && cnt++ < WINCE_DELETION_ATTEMPTS | 2483 && cnt++ < WINCE_DELETION_ATTEMPTS |
2448 ){ | 2484 ){ |
2449 sqlite3_win32_sleep(100); /* Wait a little before trying again */ | 2485 sqlite3_win32_sleep(100); /* Wait a little before trying again */ |
2450 } | 2486 } |
2451 sqlite3_free(pFile->zDeleteOnClose); | 2487 sqlite3_free(pFile->zDeleteOnClose); |
2452 } | 2488 } |
2453 #endif | 2489 #endif |
2454 if( rc ){ | 2490 if( rc ){ |
2455 pFile->h = NULL; | 2491 pFile->h = NULL; |
2456 } | 2492 } |
2457 OpenCounter(-1); | 2493 OpenCounter(-1); |
2458 OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed")); | 2494 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n", |
| 2495 osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed")); |
2459 return rc ? SQLITE_OK | 2496 return rc ? SQLITE_OK |
2460 : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), | 2497 : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), |
2461 "winClose", pFile->zPath); | 2498 "winClose", pFile->zPath); |
2462 } | 2499 } |
2463 | 2500 |
2464 /* | 2501 /* |
2465 ** Read data from a file into a buffer. Return SQLITE_OK if all | 2502 ** Read data from a file into a buffer. Return SQLITE_OK if all |
2466 ** bytes were read successfully and SQLITE_IOERR if anything goes | 2503 ** bytes were read successfully and SQLITE_IOERR if anything goes |
2467 ** wrong. | 2504 ** wrong. |
2468 */ | 2505 */ |
2469 static int winRead( | 2506 static int winRead( |
2470 sqlite3_file *id, /* File to read from */ | 2507 sqlite3_file *id, /* File to read from */ |
2471 void *pBuf, /* Write content into this buffer */ | 2508 void *pBuf, /* Write content into this buffer */ |
2472 int amt, /* Number of bytes to read */ | 2509 int amt, /* Number of bytes to read */ |
2473 sqlite3_int64 offset /* Begin reading at this offset */ | 2510 sqlite3_int64 offset /* Begin reading at this offset */ |
2474 ){ | 2511 ){ |
2475 #if !SQLITE_OS_WINCE | 2512 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
2476 OVERLAPPED overlapped; /* The offset for ReadFile. */ | 2513 OVERLAPPED overlapped; /* The offset for ReadFile. */ |
2477 #endif | 2514 #endif |
2478 winFile *pFile = (winFile*)id; /* file handle */ | 2515 winFile *pFile = (winFile*)id; /* file handle */ |
2479 DWORD nRead; /* Number of bytes actually read from file */ | 2516 DWORD nRead; /* Number of bytes actually read from file */ |
2480 int nRetry = 0; /* Number of retrys */ | 2517 int nRetry = 0; /* Number of retrys */ |
2481 | 2518 |
2482 assert( id!=0 ); | 2519 assert( id!=0 ); |
2483 assert( amt>0 ); | 2520 assert( amt>0 ); |
2484 assert( offset>=0 ); | 2521 assert( offset>=0 ); |
2485 SimulateIOError(return SQLITE_IOERR_READ); | 2522 SimulateIOError(return SQLITE_IOERR_READ); |
2486 OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", | 2523 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 2524 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
2487 pFile->h, pBuf, amt, offset, pFile->locktype)); | 2525 pFile->h, pBuf, amt, offset, pFile->locktype)); |
2488 | 2526 |
2489 #if SQLITE_MAX_MMAP_SIZE>0 | 2527 #if SQLITE_MAX_MMAP_SIZE>0 |
2490 /* Deal with as much of this read request as possible by transfering | 2528 /* Deal with as much of this read request as possible by transfering |
2491 ** data from the memory mapping using memcpy(). */ | 2529 ** data from the memory mapping using memcpy(). */ |
2492 if( offset<pFile->mmapSize ){ | 2530 if( offset<pFile->mmapSize ){ |
2493 if( offset+amt <= pFile->mmapSize ){ | 2531 if( offset+amt <= pFile->mmapSize ){ |
2494 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); | 2532 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
2495 OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); | 2533 OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 2534 osGetCurrentProcessId(), pFile, pFile->h)); |
2496 return SQLITE_OK; | 2535 return SQLITE_OK; |
2497 }else{ | 2536 }else{ |
2498 int nCopy = (int)(pFile->mmapSize - offset); | 2537 int nCopy = (int)(pFile->mmapSize - offset); |
2499 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy); | 2538 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy); |
2500 pBuf = &((u8 *)pBuf)[nCopy]; | 2539 pBuf = &((u8 *)pBuf)[nCopy]; |
2501 amt -= nCopy; | 2540 amt -= nCopy; |
2502 offset += nCopy; | 2541 offset += nCopy; |
2503 } | 2542 } |
2504 } | 2543 } |
2505 #endif | 2544 #endif |
2506 | 2545 |
2507 #if SQLITE_OS_WINCE | 2546 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
2508 if( winSeekFile(pFile, offset) ){ | 2547 if( winSeekFile(pFile, offset) ){ |
2509 OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h)); | 2548 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", |
| 2549 osGetCurrentProcessId(), pFile, pFile->h)); |
2510 return SQLITE_FULL; | 2550 return SQLITE_FULL; |
2511 } | 2551 } |
2512 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ | 2552 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ |
2513 #else | 2553 #else |
2514 memset(&overlapped, 0, sizeof(OVERLAPPED)); | 2554 memset(&overlapped, 0, sizeof(OVERLAPPED)); |
2515 overlapped.Offset = (LONG)(offset & 0xffffffff); | 2555 overlapped.Offset = (LONG)(offset & 0xffffffff); |
2516 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); | 2556 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
2517 while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) && | 2557 while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) && |
2518 osGetLastError()!=ERROR_HANDLE_EOF ){ | 2558 osGetLastError()!=ERROR_HANDLE_EOF ){ |
2519 #endif | 2559 #endif |
2520 DWORD lastErrno; | 2560 DWORD lastErrno; |
2521 if( winRetryIoerr(&nRetry, &lastErrno) ) continue; | 2561 if( winRetryIoerr(&nRetry, &lastErrno) ) continue; |
2522 pFile->lastErrno = lastErrno; | 2562 pFile->lastErrno = lastErrno; |
2523 OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h)); | 2563 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n", |
| 2564 osGetCurrentProcessId(), pFile, pFile->h)); |
2524 return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, | 2565 return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, |
2525 "winRead", pFile->zPath); | 2566 "winRead", pFile->zPath); |
2526 } | 2567 } |
2527 winLogIoerr(nRetry); | 2568 winLogIoerr(nRetry, __LINE__); |
2528 if( nRead<(DWORD)amt ){ | 2569 if( nRead<(DWORD)amt ){ |
2529 /* Unread parts of the buffer must be zero-filled */ | 2570 /* Unread parts of the buffer must be zero-filled */ |
2530 memset(&((char*)pBuf)[nRead], 0, amt-nRead); | 2571 memset(&((char*)pBuf)[nRead], 0, amt-nRead); |
2531 OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h)); | 2572 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n", |
| 2573 osGetCurrentProcessId(), pFile, pFile->h)); |
2532 return SQLITE_IOERR_SHORT_READ; | 2574 return SQLITE_IOERR_SHORT_READ; |
2533 } | 2575 } |
2534 | 2576 |
2535 OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h)); | 2577 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 2578 osGetCurrentProcessId(), pFile, pFile->h)); |
2536 return SQLITE_OK; | 2579 return SQLITE_OK; |
2537 } | 2580 } |
2538 | 2581 |
2539 /* | 2582 /* |
2540 ** Write data from a buffer into a file. Return SQLITE_OK on success | 2583 ** Write data from a buffer into a file. Return SQLITE_OK on success |
2541 ** or some other error code on failure. | 2584 ** or some other error code on failure. |
2542 */ | 2585 */ |
2543 static int winWrite( | 2586 static int winWrite( |
2544 sqlite3_file *id, /* File to write into */ | 2587 sqlite3_file *id, /* File to write into */ |
2545 const void *pBuf, /* The bytes to be written */ | 2588 const void *pBuf, /* The bytes to be written */ |
2546 int amt, /* Number of bytes to write */ | 2589 int amt, /* Number of bytes to write */ |
2547 sqlite3_int64 offset /* Offset into the file to begin writing at */ | 2590 sqlite3_int64 offset /* Offset into the file to begin writing at */ |
2548 ){ | 2591 ){ |
2549 int rc = 0; /* True if error has occurred, else false */ | 2592 int rc = 0; /* True if error has occurred, else false */ |
2550 winFile *pFile = (winFile*)id; /* File handle */ | 2593 winFile *pFile = (winFile*)id; /* File handle */ |
2551 int nRetry = 0; /* Number of retries */ | 2594 int nRetry = 0; /* Number of retries */ |
2552 | 2595 |
2553 assert( amt>0 ); | 2596 assert( amt>0 ); |
2554 assert( pFile ); | 2597 assert( pFile ); |
2555 SimulateIOError(return SQLITE_IOERR_WRITE); | 2598 SimulateIOError(return SQLITE_IOERR_WRITE); |
2556 SimulateDiskfullError(return SQLITE_FULL); | 2599 SimulateDiskfullError(return SQLITE_FULL); |
2557 | 2600 |
2558 OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", | 2601 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 2602 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
2559 pFile->h, pBuf, amt, offset, pFile->locktype)); | 2603 pFile->h, pBuf, amt, offset, pFile->locktype)); |
2560 | 2604 |
2561 #if !SQLITE_MMAP_READ_ONLY | 2605 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
2562 #if SQLITE_MAX_MMAP_SIZE>0 | |
2563 /* Deal with as much of this write request as possible by transfering | 2606 /* Deal with as much of this write request as possible by transfering |
2564 ** data from the memory mapping using memcpy(). */ | 2607 ** data from the memory mapping using memcpy(). */ |
2565 if( offset<pFile->mmapSize ){ | 2608 if( offset<pFile->mmapSize ){ |
2566 if( offset+amt <= pFile->mmapSize ){ | 2609 if( offset+amt <= pFile->mmapSize ){ |
2567 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); | 2610 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
2568 OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h)); | 2611 OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 2612 osGetCurrentProcessId(), pFile, pFile->h)); |
2569 return SQLITE_OK; | 2613 return SQLITE_OK; |
2570 }else{ | 2614 }else{ |
2571 int nCopy = (int)(pFile->mmapSize - offset); | 2615 int nCopy = (int)(pFile->mmapSize - offset); |
2572 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy); | 2616 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy); |
2573 pBuf = &((u8 *)pBuf)[nCopy]; | 2617 pBuf = &((u8 *)pBuf)[nCopy]; |
2574 amt -= nCopy; | 2618 amt -= nCopy; |
2575 offset += nCopy; | 2619 offset += nCopy; |
2576 } | 2620 } |
2577 } | 2621 } |
2578 #endif | 2622 #endif |
2579 #endif | |
2580 | 2623 |
2581 #if SQLITE_OS_WINCE | 2624 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
2582 rc = winSeekFile(pFile, offset); | 2625 rc = winSeekFile(pFile, offset); |
2583 if( rc==0 ){ | 2626 if( rc==0 ){ |
2584 #else | 2627 #else |
2585 { | 2628 { |
2586 #endif | 2629 #endif |
2587 #if !SQLITE_OS_WINCE | 2630 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
2588 OVERLAPPED overlapped; /* The offset for WriteFile. */ | 2631 OVERLAPPED overlapped; /* The offset for WriteFile. */ |
2589 #endif | 2632 #endif |
2590 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ | 2633 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ |
2591 int nRem = amt; /* Number of bytes yet to be written */ | 2634 int nRem = amt; /* Number of bytes yet to be written */ |
2592 DWORD nWrite; /* Bytes written by each WriteFile() call */ | 2635 DWORD nWrite; /* Bytes written by each WriteFile() call */ |
2593 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ | 2636 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ |
2594 | 2637 |
2595 #if !SQLITE_OS_WINCE | 2638 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
2596 memset(&overlapped, 0, sizeof(OVERLAPPED)); | 2639 memset(&overlapped, 0, sizeof(OVERLAPPED)); |
2597 overlapped.Offset = (LONG)(offset & 0xffffffff); | 2640 overlapped.Offset = (LONG)(offset & 0xffffffff); |
2598 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); | 2641 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
2599 #endif | 2642 #endif |
2600 | 2643 |
2601 while( nRem>0 ){ | 2644 while( nRem>0 ){ |
2602 #if SQLITE_OS_WINCE | 2645 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED) |
2603 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ | 2646 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ |
2604 #else | 2647 #else |
2605 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ | 2648 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ |
2606 #endif | 2649 #endif |
2607 if( winRetryIoerr(&nRetry, &lastErrno) ) continue; | 2650 if( winRetryIoerr(&nRetry, &lastErrno) ) continue; |
2608 break; | 2651 break; |
2609 } | 2652 } |
2610 assert( nWrite==0 || nWrite<=(DWORD)nRem ); | 2653 assert( nWrite==0 || nWrite<=(DWORD)nRem ); |
2611 if( nWrite==0 || nWrite>(DWORD)nRem ){ | 2654 if( nWrite==0 || nWrite>(DWORD)nRem ){ |
2612 lastErrno = osGetLastError(); | 2655 lastErrno = osGetLastError(); |
2613 break; | 2656 break; |
2614 } | 2657 } |
2615 #if !SQLITE_OS_WINCE | 2658 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED) |
2616 offset += nWrite; | 2659 offset += nWrite; |
2617 overlapped.Offset = (LONG)(offset & 0xffffffff); | 2660 overlapped.Offset = (LONG)(offset & 0xffffffff); |
2618 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); | 2661 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); |
2619 #endif | 2662 #endif |
2620 aRem += nWrite; | 2663 aRem += nWrite; |
2621 nRem -= nWrite; | 2664 nRem -= nWrite; |
2622 } | 2665 } |
2623 if( nRem>0 ){ | 2666 if( nRem>0 ){ |
2624 pFile->lastErrno = lastErrno; | 2667 pFile->lastErrno = lastErrno; |
2625 rc = 1; | 2668 rc = 1; |
2626 } | 2669 } |
2627 } | 2670 } |
2628 | 2671 |
2629 if( rc ){ | 2672 if( rc ){ |
2630 if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ) | 2673 if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ) |
2631 || ( pFile->lastErrno==ERROR_DISK_FULL )){ | 2674 || ( pFile->lastErrno==ERROR_DISK_FULL )){ |
2632 OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h)); | 2675 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n", |
| 2676 osGetCurrentProcessId(), pFile, pFile->h)); |
2633 return winLogError(SQLITE_FULL, pFile->lastErrno, | 2677 return winLogError(SQLITE_FULL, pFile->lastErrno, |
2634 "winWrite1", pFile->zPath); | 2678 "winWrite1", pFile->zPath); |
2635 } | 2679 } |
2636 OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h)); | 2680 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n", |
| 2681 osGetCurrentProcessId(), pFile, pFile->h)); |
2637 return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, | 2682 return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, |
2638 "winWrite2", pFile->zPath); | 2683 "winWrite2", pFile->zPath); |
2639 }else{ | 2684 }else{ |
2640 winLogIoerr(nRetry); | 2685 winLogIoerr(nRetry, __LINE__); |
2641 } | 2686 } |
2642 OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h)); | 2687 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 2688 osGetCurrentProcessId(), pFile, pFile->h)); |
2643 return SQLITE_OK; | 2689 return SQLITE_OK; |
2644 } | 2690 } |
2645 | 2691 |
2646 /* | 2692 /* |
2647 ** Truncate an open file to a specified size | 2693 ** Truncate an open file to a specified size |
2648 */ | 2694 */ |
2649 static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ | 2695 static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ |
2650 winFile *pFile = (winFile*)id; /* File handle object */ | 2696 winFile *pFile = (winFile*)id; /* File handle object */ |
2651 int rc = SQLITE_OK; /* Return code for this function */ | 2697 int rc = SQLITE_OK; /* Return code for this function */ |
2652 DWORD lastErrno; | 2698 DWORD lastErrno; |
2653 | 2699 |
2654 assert( pFile ); | 2700 assert( pFile ); |
2655 SimulateIOError(return SQLITE_IOERR_TRUNCATE); | 2701 SimulateIOError(return SQLITE_IOERR_TRUNCATE); |
2656 OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n", | 2702 OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n", |
2657 pFile->h, nByte, pFile->locktype)); | 2703 osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype)); |
2658 | 2704 |
2659 /* If the user has configured a chunk-size for this file, truncate the | 2705 /* If the user has configured a chunk-size for this file, truncate the |
2660 ** file so that it consists of an integer number of chunks (i.e. the | 2706 ** file so that it consists of an integer number of chunks (i.e. the |
2661 ** actual file size after the operation may be larger than the requested | 2707 ** actual file size after the operation may be larger than the requested |
2662 ** size). | 2708 ** size). |
2663 */ | 2709 */ |
2664 if( pFile->szChunk>0 ){ | 2710 if( pFile->szChunk>0 ){ |
2665 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; | 2711 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; |
2666 } | 2712 } |
2667 | 2713 |
(...skipping 11 matching lines...) Expand all Loading... |
2679 #if SQLITE_MAX_MMAP_SIZE>0 | 2725 #if SQLITE_MAX_MMAP_SIZE>0 |
2680 /* If the file was truncated to a size smaller than the currently | 2726 /* If the file was truncated to a size smaller than the currently |
2681 ** mapped region, reduce the effective mapping size as well. SQLite will | 2727 ** mapped region, reduce the effective mapping size as well. SQLite will |
2682 ** use read() and write() to access data beyond this point from now on. | 2728 ** use read() and write() to access data beyond this point from now on. |
2683 */ | 2729 */ |
2684 if( pFile->pMapRegion && nByte<pFile->mmapSize ){ | 2730 if( pFile->pMapRegion && nByte<pFile->mmapSize ){ |
2685 pFile->mmapSize = nByte; | 2731 pFile->mmapSize = nByte; |
2686 } | 2732 } |
2687 #endif | 2733 #endif |
2688 | 2734 |
2689 OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); | 2735 OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n", |
| 2736 osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc))); |
2690 return rc; | 2737 return rc; |
2691 } | 2738 } |
2692 | 2739 |
2693 #ifdef SQLITE_TEST | 2740 #ifdef SQLITE_TEST |
2694 /* | 2741 /* |
2695 ** Count the number of fullsyncs and normal syncs. This is used to test | 2742 ** Count the number of fullsyncs and normal syncs. This is used to test |
2696 ** that syncs and fullsyncs are occuring at the right times. | 2743 ** that syncs and fullsyncs are occuring at the right times. |
2697 */ | 2744 */ |
2698 int sqlite3_sync_count = 0; | 2745 int sqlite3_sync_count = 0; |
2699 int sqlite3_fullsync_count = 0; | 2746 int sqlite3_fullsync_count = 0; |
2700 #endif | 2747 #endif |
2701 | 2748 |
2702 /* | 2749 /* |
2703 ** Make sure all writes to a particular file are committed to disk. | 2750 ** Make sure all writes to a particular file are committed to disk. |
2704 */ | 2751 */ |
2705 static int winSync(sqlite3_file *id, int flags){ | 2752 static int winSync(sqlite3_file *id, int flags){ |
2706 #ifndef SQLITE_NO_SYNC | 2753 #ifndef SQLITE_NO_SYNC |
2707 /* | 2754 /* |
2708 ** Used only when SQLITE_NO_SYNC is not defined. | 2755 ** Used only when SQLITE_NO_SYNC is not defined. |
2709 */ | 2756 */ |
2710 BOOL rc; | 2757 BOOL rc; |
2711 #endif | 2758 #endif |
2712 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ | 2759 #if !defined(NDEBUG) || !defined(SQLITE_NO_SYNC) || \ |
2713 (defined(SQLITE_TEST) && defined(SQLITE_DEBUG)) | 2760 defined(SQLITE_HAVE_OS_TRACE) |
2714 /* | 2761 /* |
2715 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or | 2762 ** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or |
2716 ** OSTRACE() macros. | 2763 ** OSTRACE() macros. |
2717 */ | 2764 */ |
2718 winFile *pFile = (winFile*)id; | 2765 winFile *pFile = (winFile*)id; |
2719 #else | 2766 #else |
2720 UNUSED_PARAMETER(id); | 2767 UNUSED_PARAMETER(id); |
2721 #endif | 2768 #endif |
2722 | 2769 |
2723 assert( pFile ); | 2770 assert( pFile ); |
2724 /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */ | 2771 /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */ |
2725 assert((flags&0x0F)==SQLITE_SYNC_NORMAL | 2772 assert((flags&0x0F)==SQLITE_SYNC_NORMAL |
2726 || (flags&0x0F)==SQLITE_SYNC_FULL | 2773 || (flags&0x0F)==SQLITE_SYNC_FULL |
2727 ); | 2774 ); |
2728 | 2775 |
2729 /* Unix cannot, but some systems may return SQLITE_FULL from here. This | 2776 /* Unix cannot, but some systems may return SQLITE_FULL from here. This |
2730 ** line is to test that doing so does not cause any problems. | 2777 ** line is to test that doing so does not cause any problems. |
2731 */ | 2778 */ |
2732 SimulateDiskfullError( return SQLITE_FULL ); | 2779 SimulateDiskfullError( return SQLITE_FULL ); |
2733 | 2780 |
2734 OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n", | 2781 OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n", |
2735 pFile->h, flags, pFile->locktype)); | 2782 osGetCurrentProcessId(), pFile, pFile->h, flags, |
| 2783 pFile->locktype)); |
2736 | 2784 |
2737 #ifndef SQLITE_TEST | 2785 #ifndef SQLITE_TEST |
2738 UNUSED_PARAMETER(flags); | 2786 UNUSED_PARAMETER(flags); |
2739 #else | 2787 #else |
2740 if( (flags&0x0F)==SQLITE_SYNC_FULL ){ | 2788 if( (flags&0x0F)==SQLITE_SYNC_FULL ){ |
2741 sqlite3_fullsync_count++; | 2789 sqlite3_fullsync_count++; |
2742 } | 2790 } |
2743 sqlite3_sync_count++; | 2791 sqlite3_sync_count++; |
2744 #endif | 2792 #endif |
2745 | 2793 |
2746 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a | 2794 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
2747 ** no-op | 2795 ** no-op |
2748 */ | 2796 */ |
2749 #ifdef SQLITE_NO_SYNC | 2797 #ifdef SQLITE_NO_SYNC |
2750 OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h)); | 2798 OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 2799 osGetCurrentProcessId(), pFile, pFile->h)); |
2751 return SQLITE_OK; | 2800 return SQLITE_OK; |
2752 #else | 2801 #else |
| 2802 #if SQLITE_MAX_MMAP_SIZE>0 |
| 2803 if( pFile->pMapRegion ){ |
| 2804 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){ |
| 2805 OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " |
| 2806 "rc=SQLITE_OK\n", osGetCurrentProcessId(), |
| 2807 pFile, pFile->pMapRegion)); |
| 2808 }else{ |
| 2809 pFile->lastErrno = osGetLastError(); |
| 2810 OSTRACE(("SYNC-MMAP pid=%lu, pFile=%p, pMapRegion=%p, " |
| 2811 "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), |
| 2812 pFile, pFile->pMapRegion)); |
| 2813 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, |
| 2814 "winSync1", pFile->zPath); |
| 2815 } |
| 2816 } |
| 2817 #endif |
2753 rc = osFlushFileBuffers(pFile->h); | 2818 rc = osFlushFileBuffers(pFile->h); |
2754 SimulateIOError( rc=FALSE ); | 2819 SimulateIOError( rc=FALSE ); |
2755 if( rc ){ | 2820 if( rc ){ |
2756 OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h)); | 2821 OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| 2822 osGetCurrentProcessId(), pFile, pFile->h)); |
2757 return SQLITE_OK; | 2823 return SQLITE_OK; |
2758 }else{ | 2824 }else{ |
2759 pFile->lastErrno = osGetLastError(); | 2825 pFile->lastErrno = osGetLastError(); |
2760 OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h)); | 2826 OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n", |
| 2827 osGetCurrentProcessId(), pFile, pFile->h)); |
2761 return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, | 2828 return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, |
2762 "winSync", pFile->zPath); | 2829 "winSync2", pFile->zPath); |
2763 } | 2830 } |
2764 #endif | 2831 #endif |
2765 } | 2832 } |
2766 | 2833 |
2767 /* | 2834 /* |
2768 ** Determine the current size of a file in bytes | 2835 ** Determine the current size of a file in bytes |
2769 */ | 2836 */ |
2770 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ | 2837 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ |
2771 winFile *pFile = (winFile*)id; | 2838 winFile *pFile = (winFile*)id; |
2772 int rc = SQLITE_OK; | 2839 int rc = SQLITE_OK; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2941 | 3008 |
2942 /* If there is already a lock of this type or more restrictive on the | 3009 /* If there is already a lock of this type or more restrictive on the |
2943 ** OsFile, do nothing. Don't use the end_lock: exit path, as | 3010 ** OsFile, do nothing. Don't use the end_lock: exit path, as |
2944 ** sqlite3OsEnterMutex() hasn't been called yet. | 3011 ** sqlite3OsEnterMutex() hasn't been called yet. |
2945 */ | 3012 */ |
2946 if( pFile->locktype>=locktype ){ | 3013 if( pFile->locktype>=locktype ){ |
2947 OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h)); | 3014 OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h)); |
2948 return SQLITE_OK; | 3015 return SQLITE_OK; |
2949 } | 3016 } |
2950 | 3017 |
| 3018 /* Do not allow any kind of write-lock on a read-only database |
| 3019 */ |
| 3020 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){ |
| 3021 return SQLITE_IOERR_LOCK; |
| 3022 } |
| 3023 |
2951 /* Make sure the locking sequence is correct | 3024 /* Make sure the locking sequence is correct |
2952 */ | 3025 */ |
2953 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK ); | 3026 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK ); |
2954 assert( locktype!=PENDING_LOCK ); | 3027 assert( locktype!=PENDING_LOCK ); |
2955 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK ); | 3028 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK ); |
2956 | 3029 |
2957 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or | 3030 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or |
2958 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of | 3031 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of |
2959 ** the PENDING_LOCK byte is temporary. | 3032 ** the PENDING_LOCK byte is temporary. |
2960 */ | 3033 */ |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3070 winFile *pFile = (winFile*)id; | 3143 winFile *pFile = (winFile*)id; |
3071 | 3144 |
3072 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); | 3145 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); |
3073 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut)); | 3146 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut)); |
3074 | 3147 |
3075 assert( id!=0 ); | 3148 assert( id!=0 ); |
3076 if( pFile->locktype>=RESERVED_LOCK ){ | 3149 if( pFile->locktype>=RESERVED_LOCK ){ |
3077 res = 1; | 3150 res = 1; |
3078 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res)); | 3151 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res)); |
3079 }else{ | 3152 }else{ |
3080 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0)
; | 3153 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0); |
3081 if( res ){ | 3154 if( res ){ |
3082 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0); | 3155 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0); |
3083 } | 3156 } |
3084 res = !res; | 3157 res = !res; |
3085 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res)); | 3158 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res)); |
3086 } | 3159 } |
3087 *pResOut = res; | 3160 *pResOut = res; |
3088 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n", | 3161 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n", |
3089 pFile->h, pResOut, *pResOut)); | 3162 pFile->h, pResOut, *pResOut)); |
3090 return SQLITE_OK; | 3163 return SQLITE_OK; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3310 ** | 3383 ** |
3311 ** Function winShmMutexHeld() is used to assert() that the global mutex | 3384 ** Function winShmMutexHeld() is used to assert() that the global mutex |
3312 ** is held when required. This function is only used as part of assert() | 3385 ** is held when required. This function is only used as part of assert() |
3313 ** statements. e.g. | 3386 ** statements. e.g. |
3314 ** | 3387 ** |
3315 ** winShmEnterMutex() | 3388 ** winShmEnterMutex() |
3316 ** assert( winShmMutexHeld() ); | 3389 ** assert( winShmMutexHeld() ); |
3317 ** winShmLeaveMutex() | 3390 ** winShmLeaveMutex() |
3318 */ | 3391 */ |
3319 static void winShmEnterMutex(void){ | 3392 static void winShmEnterMutex(void){ |
3320 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); | 3393 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
3321 } | 3394 } |
3322 static void winShmLeaveMutex(void){ | 3395 static void winShmLeaveMutex(void){ |
3323 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); | 3396 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
3324 } | 3397 } |
3325 #ifndef NDEBUG | 3398 #ifndef NDEBUG |
3326 static int winShmMutexHeld(void) { | 3399 static int winShmMutexHeld(void) { |
3327 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); | 3400 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1)); |
3328 } | 3401 } |
3329 #endif | 3402 #endif |
3330 | 3403 |
3331 /* | 3404 /* |
3332 ** Object used to represent a single file opened and mmapped to provide | 3405 ** Object used to represent a single file opened and mmapped to provide |
3333 ** shared memory. When multiple threads all reference the same | 3406 ** shared memory. When multiple threads all reference the same |
3334 ** log-summary, each thread has its own winFile object, but they all | 3407 ** log-summary, each thread has its own winFile object, but they all |
3335 ** point to a single instance of this object. In other words, each | 3408 ** point to a single instance of this object. In other words, each |
3336 ** log-summary is opened only once per process. | 3409 ** log-summary is opened only once per process. |
3337 ** | 3410 ** |
(...skipping 22 matching lines...) Expand all Loading... |
3360 int nRegion; /* Size of array apRegion */ | 3433 int nRegion; /* Size of array apRegion */ |
3361 struct ShmRegion { | 3434 struct ShmRegion { |
3362 HANDLE hMap; /* File handle from CreateFileMapping */ | 3435 HANDLE hMap; /* File handle from CreateFileMapping */ |
3363 void *pMap; | 3436 void *pMap; |
3364 } *aRegion; | 3437 } *aRegion; |
3365 DWORD lastErrno; /* The Windows errno from the last I/O error */ | 3438 DWORD lastErrno; /* The Windows errno from the last I/O error */ |
3366 | 3439 |
3367 int nRef; /* Number of winShm objects pointing to this */ | 3440 int nRef; /* Number of winShm objects pointing to this */ |
3368 winShm *pFirst; /* All winShm objects pointing to this */ | 3441 winShm *pFirst; /* All winShm objects pointing to this */ |
3369 winShmNode *pNext; /* Next in list of all winShmNode objects */ | 3442 winShmNode *pNext; /* Next in list of all winShmNode objects */ |
3370 #ifdef SQLITE_DEBUG | 3443 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
3371 u8 nextShmId; /* Next available winShm.id value */ | 3444 u8 nextShmId; /* Next available winShm.id value */ |
3372 #endif | 3445 #endif |
3373 }; | 3446 }; |
3374 | 3447 |
3375 /* | 3448 /* |
3376 ** A global array of all winShmNode objects. | 3449 ** A global array of all winShmNode objects. |
3377 ** | 3450 ** |
3378 ** The winShmMutexHeld() must be true while reading or writing this list. | 3451 ** The winShmMutexHeld() must be true while reading or writing this list. |
3379 */ | 3452 */ |
3380 static winShmNode *winShmNodeList = 0; | 3453 static winShmNode *winShmNodeList = 0; |
(...skipping 10 matching lines...) Expand all Loading... |
3391 ** | 3464 ** |
3392 ** All other fields are read/write. The winShm.pShmNode->mutex must be held | 3465 ** All other fields are read/write. The winShm.pShmNode->mutex must be held |
3393 ** while accessing any read/write fields. | 3466 ** while accessing any read/write fields. |
3394 */ | 3467 */ |
3395 struct winShm { | 3468 struct winShm { |
3396 winShmNode *pShmNode; /* The underlying winShmNode object */ | 3469 winShmNode *pShmNode; /* The underlying winShmNode object */ |
3397 winShm *pNext; /* Next winShm with the same winShmNode */ | 3470 winShm *pNext; /* Next winShm with the same winShmNode */ |
3398 u8 hasMutex; /* True if holding the winShmNode mutex */ | 3471 u8 hasMutex; /* True if holding the winShmNode mutex */ |
3399 u16 sharedMask; /* Mask of shared locks held */ | 3472 u16 sharedMask; /* Mask of shared locks held */ |
3400 u16 exclMask; /* Mask of exclusive locks held */ | 3473 u16 exclMask; /* Mask of exclusive locks held */ |
3401 #ifdef SQLITE_DEBUG | 3474 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
3402 u8 id; /* Id of this connection with its winShmNode */ | 3475 u8 id; /* Id of this connection with its winShmNode */ |
3403 #endif | 3476 #endif |
3404 }; | 3477 }; |
3405 | 3478 |
3406 /* | 3479 /* |
3407 ** Constants used for locking | 3480 ** Constants used for locking |
3408 */ | 3481 */ |
3409 #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | 3482 #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
3410 #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ | 3483 #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
3411 | 3484 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 } | 3655 } |
3583 if( rc==SQLITE_OK ){ | 3656 if( rc==SQLITE_OK ){ |
3584 winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); | 3657 winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1); |
3585 rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); | 3658 rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1); |
3586 } | 3659 } |
3587 if( rc ) goto shm_open_err; | 3660 if( rc ) goto shm_open_err; |
3588 } | 3661 } |
3589 | 3662 |
3590 /* Make the new connection a child of the winShmNode */ | 3663 /* Make the new connection a child of the winShmNode */ |
3591 p->pShmNode = pShmNode; | 3664 p->pShmNode = pShmNode; |
3592 #ifdef SQLITE_DEBUG | 3665 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
3593 p->id = pShmNode->nextShmId++; | 3666 p->id = pShmNode->nextShmId++; |
3594 #endif | 3667 #endif |
3595 pShmNode->nRef++; | 3668 pShmNode->nRef++; |
3596 pDbFd->pShm = p; | 3669 pDbFd->pShm = p; |
3597 winShmLeaveMutex(); | 3670 winShmLeaveMutex(); |
3598 | 3671 |
3599 /* The reference count on pShmNode has already been incremented under | 3672 /* The reference count on pShmNode has already been incremented under |
3600 ** the cover of the winShmEnterMutex() mutex and the pointer from the | 3673 ** the cover of the winShmEnterMutex() mutex and the pointer from the |
3601 ** new (struct winShm) object to the pShmNode has been set. All that is | 3674 ** new (struct winShm) object to the pShmNode has been set. All that is |
3602 ** left to do is to link the new object into the linked list starting | 3675 ** left to do is to link the new object into the linked list starting |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3770 /* | 3843 /* |
3771 ** Implement a memory barrier or memory fence on shared memory. | 3844 ** Implement a memory barrier or memory fence on shared memory. |
3772 ** | 3845 ** |
3773 ** All loads and stores begun before the barrier must complete before | 3846 ** All loads and stores begun before the barrier must complete before |
3774 ** any load or store begun after the barrier. | 3847 ** any load or store begun after the barrier. |
3775 */ | 3848 */ |
3776 static void winShmBarrier( | 3849 static void winShmBarrier( |
3777 sqlite3_file *fd /* Database holding the shared memory */ | 3850 sqlite3_file *fd /* Database holding the shared memory */ |
3778 ){ | 3851 ){ |
3779 UNUSED_PARAMETER(fd); | 3852 UNUSED_PARAMETER(fd); |
3780 /* MemoryBarrier(); // does not work -- do not know why not */ | 3853 sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ |
3781 winShmEnterMutex(); | 3854 winShmEnterMutex(); /* Also mutex, for redundancy */ |
3782 winShmLeaveMutex(); | 3855 winShmLeaveMutex(); |
3783 } | 3856 } |
3784 | 3857 |
3785 /* | 3858 /* |
3786 ** This function is called to obtain a pointer to region iRegion of the | 3859 ** This function is called to obtain a pointer to region iRegion of the |
3787 ** shared-memory associated with the database file fd. Shared-memory regions | 3860 ** shared-memory associated with the database file fd. Shared-memory regions |
3788 ** are numbered starting from zero. Each shared-memory region is szRegion | 3861 ** are numbered starting from zero. Each shared-memory region is szRegion |
3789 ** bytes in size. | 3862 ** bytes in size. |
3790 ** | 3863 ** |
3791 ** If an error occurs, an error code is returned and *pp is set to NULL. | 3864 ** If an error occurs, an error code is returned and *pp is set to NULL. |
(...skipping 10 matching lines...) Expand all Loading... |
3802 ** memory and SQLITE_OK returned. | 3875 ** memory and SQLITE_OK returned. |
3803 */ | 3876 */ |
3804 static int winShmMap( | 3877 static int winShmMap( |
3805 sqlite3_file *fd, /* Handle open on database file */ | 3878 sqlite3_file *fd, /* Handle open on database file */ |
3806 int iRegion, /* Region to retrieve */ | 3879 int iRegion, /* Region to retrieve */ |
3807 int szRegion, /* Size of regions */ | 3880 int szRegion, /* Size of regions */ |
3808 int isWrite, /* True to extend file if necessary */ | 3881 int isWrite, /* True to extend file if necessary */ |
3809 void volatile **pp /* OUT: Mapped memory */ | 3882 void volatile **pp /* OUT: Mapped memory */ |
3810 ){ | 3883 ){ |
3811 winFile *pDbFd = (winFile*)fd; | 3884 winFile *pDbFd = (winFile*)fd; |
3812 winShm *p = pDbFd->pShm; | 3885 winShm *pShm = pDbFd->pShm; |
3813 winShmNode *pShmNode; | 3886 winShmNode *pShmNode; |
3814 int rc = SQLITE_OK; | 3887 int rc = SQLITE_OK; |
3815 | 3888 |
3816 if( !p ){ | 3889 if( !pShm ){ |
3817 rc = winOpenSharedMemory(pDbFd); | 3890 rc = winOpenSharedMemory(pDbFd); |
3818 if( rc!=SQLITE_OK ) return rc; | 3891 if( rc!=SQLITE_OK ) return rc; |
3819 p = pDbFd->pShm; | 3892 pShm = pDbFd->pShm; |
3820 } | 3893 } |
3821 pShmNode = p->pShmNode; | 3894 pShmNode = pShm->pShmNode; |
3822 | 3895 |
3823 sqlite3_mutex_enter(pShmNode->mutex); | 3896 sqlite3_mutex_enter(pShmNode->mutex); |
3824 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); | 3897 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); |
3825 | 3898 |
3826 if( pShmNode->nRegion<=iRegion ){ | 3899 if( pShmNode->nRegion<=iRegion ){ |
3827 struct ShmRegion *apNew; /* New aRegion[] array */ | 3900 struct ShmRegion *apNew; /* New aRegion[] array */ |
3828 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */ | 3901 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */ |
3829 sqlite3_int64 sz; /* Current size of wal-index file */ | 3902 sqlite3_int64 sz; /* Current size of wal-index file */ |
3830 | 3903 |
3831 pShmNode->szRegion = szRegion; | 3904 pShmNode->szRegion = szRegion; |
(...skipping 19 matching lines...) Expand all Loading... |
3851 if( !isWrite ) goto shmpage_out; | 3924 if( !isWrite ) goto shmpage_out; |
3852 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); | 3925 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); |
3853 if( rc!=SQLITE_OK ){ | 3926 if( rc!=SQLITE_OK ){ |
3854 rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(), | 3927 rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(), |
3855 "winShmMap2", pDbFd->zPath); | 3928 "winShmMap2", pDbFd->zPath); |
3856 goto shmpage_out; | 3929 goto shmpage_out; |
3857 } | 3930 } |
3858 } | 3931 } |
3859 | 3932 |
3860 /* Map the requested memory region into this processes address space. */ | 3933 /* Map the requested memory region into this processes address space. */ |
3861 apNew = (struct ShmRegion *)sqlite3_realloc( | 3934 apNew = (struct ShmRegion *)sqlite3_realloc64( |
3862 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) | 3935 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
3863 ); | 3936 ); |
3864 if( !apNew ){ | 3937 if( !apNew ){ |
3865 rc = SQLITE_IOERR_NOMEM; | 3938 rc = SQLITE_IOERR_NOMEM; |
3866 goto shmpage_out; | 3939 goto shmpage_out; |
3867 } | 3940 } |
3868 pShmNode->aRegion = apNew; | 3941 pShmNode->aRegion = apNew; |
3869 | 3942 |
3870 while( pShmNode->nRegion<=iRegion ){ | 3943 while( pShmNode->nRegion<=iRegion ){ |
3871 HANDLE hMap = NULL; /* file-mapping handle */ | 3944 HANDLE hMap = NULL; /* file-mapping handle */ |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4016 | 4089 |
4017 if( nMap==0 && pFd->mmapSize>0 ){ | 4090 if( nMap==0 && pFd->mmapSize>0 ){ |
4018 winUnmapfile(pFd); | 4091 winUnmapfile(pFd); |
4019 } | 4092 } |
4020 if( nMap!=pFd->mmapSize ){ | 4093 if( nMap!=pFd->mmapSize ){ |
4021 void *pNew = 0; | 4094 void *pNew = 0; |
4022 DWORD protect = PAGE_READONLY; | 4095 DWORD protect = PAGE_READONLY; |
4023 DWORD flags = FILE_MAP_READ; | 4096 DWORD flags = FILE_MAP_READ; |
4024 | 4097 |
4025 winUnmapfile(pFd); | 4098 winUnmapfile(pFd); |
4026 #if !SQLITE_MMAP_READ_ONLY | 4099 #ifdef SQLITE_MMAP_READWRITE |
4027 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ | 4100 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ |
4028 protect = PAGE_READWRITE; | 4101 protect = PAGE_READWRITE; |
4029 flags |= FILE_MAP_WRITE; | 4102 flags |= FILE_MAP_WRITE; |
4030 } | 4103 } |
4031 #endif | 4104 #endif |
4032 #if SQLITE_OS_WINRT | 4105 #if SQLITE_OS_WINRT |
4033 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); | 4106 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); |
4034 #elif defined(SQLITE_WIN32_HAS_WIDE) | 4107 #elif defined(SQLITE_WIN32_HAS_WIDE) |
4035 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, | 4108 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, |
4036 (DWORD)((nMap>>32) & 0xffffffff), | 4109 (DWORD)((nMap>>32) & 0xffffffff), |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4725 dwDesiredAccess, | 4798 dwDesiredAccess, |
4726 dwShareMode, NULL, | 4799 dwShareMode, NULL, |
4727 dwCreationDisposition, | 4800 dwCreationDisposition, |
4728 dwFlagsAndAttributes, | 4801 dwFlagsAndAttributes, |
4729 NULL))==INVALID_HANDLE_VALUE && | 4802 NULL))==INVALID_HANDLE_VALUE && |
4730 winRetryIoerr(&cnt, &lastErrno) ){ | 4803 winRetryIoerr(&cnt, &lastErrno) ){ |
4731 /* Noop */ | 4804 /* Noop */ |
4732 } | 4805 } |
4733 } | 4806 } |
4734 #endif | 4807 #endif |
4735 winLogIoerr(cnt); | 4808 winLogIoerr(cnt, __LINE__); |
4736 | 4809 |
4737 OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name, | 4810 OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name, |
4738 dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); | 4811 dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok")); |
4739 | 4812 |
4740 if( h==INVALID_HANDLE_VALUE ){ | 4813 if( h==INVALID_HANDLE_VALUE ){ |
4741 pFile->lastErrno = lastErrno; | 4814 pFile->lastErrno = lastErrno; |
4742 winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name); | 4815 winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name); |
4743 sqlite3_free(zConverted); | 4816 sqlite3_free(zConverted); |
4744 sqlite3_free(zTmpname); | 4817 sqlite3_free(zTmpname); |
4745 if( isReadWrite && !isExclusive ){ | 4818 if( isReadWrite && !isExclusive ){ |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4909 if ( !winRetryIoerr(&cnt, &lastErrno) ){ | 4982 if ( !winRetryIoerr(&cnt, &lastErrno) ){ |
4910 rc = SQLITE_ERROR; /* No more retries. */ | 4983 rc = SQLITE_ERROR; /* No more retries. */ |
4911 break; | 4984 break; |
4912 } | 4985 } |
4913 } while(1); | 4986 } while(1); |
4914 } | 4987 } |
4915 #endif | 4988 #endif |
4916 if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ | 4989 if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ |
4917 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); | 4990 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename); |
4918 }else{ | 4991 }else{ |
4919 winLogIoerr(cnt); | 4992 winLogIoerr(cnt, __LINE__); |
4920 } | 4993 } |
4921 sqlite3_free(zConverted); | 4994 sqlite3_free(zConverted); |
4922 OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc))); | 4995 OSTRACE(("DELETE name=%s, rc=%s\n", zFilename, sqlite3ErrName(rc))); |
4923 return rc; | 4996 return rc; |
4924 } | 4997 } |
4925 | 4998 |
4926 /* | 4999 /* |
4927 ** Check the existence and status of a file. | 5000 ** Check the existence and status of a file. |
4928 */ | 5001 */ |
4929 static int winAccess( | 5002 static int winAccess( |
(...skipping 29 matching lines...) Expand all Loading... |
4959 ** as if it does not exist. | 5032 ** as if it does not exist. |
4960 */ | 5033 */ |
4961 if( flags==SQLITE_ACCESS_EXISTS | 5034 if( flags==SQLITE_ACCESS_EXISTS |
4962 && sAttrData.nFileSizeHigh==0 | 5035 && sAttrData.nFileSizeHigh==0 |
4963 && sAttrData.nFileSizeLow==0 ){ | 5036 && sAttrData.nFileSizeLow==0 ){ |
4964 attr = INVALID_FILE_ATTRIBUTES; | 5037 attr = INVALID_FILE_ATTRIBUTES; |
4965 }else{ | 5038 }else{ |
4966 attr = sAttrData.dwFileAttributes; | 5039 attr = sAttrData.dwFileAttributes; |
4967 } | 5040 } |
4968 }else{ | 5041 }else{ |
4969 winLogIoerr(cnt); | 5042 winLogIoerr(cnt, __LINE__); |
4970 if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ | 5043 if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){ |
4971 sqlite3_free(zConverted); | 5044 sqlite3_free(zConverted); |
4972 return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", | 5045 return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", |
4973 zFilename); | 5046 zFilename); |
4974 }else{ | 5047 }else{ |
4975 attr = INVALID_FILE_ATTRIBUTES; | 5048 attr = INVALID_FILE_ATTRIBUTES; |
4976 } | 5049 } |
4977 } | 5050 } |
4978 } | 5051 } |
4979 #ifdef SQLITE_WIN32_HAS_ANSI | 5052 #ifdef SQLITE_WIN32_HAS_ANSI |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5300 #define winDlClose 0 | 5373 #define winDlClose 0 |
5301 #endif | 5374 #endif |
5302 | 5375 |
5303 | 5376 |
5304 /* | 5377 /* |
5305 ** Write up to nBuf bytes of randomness into zBuf. | 5378 ** Write up to nBuf bytes of randomness into zBuf. |
5306 */ | 5379 */ |
5307 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ | 5380 static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ |
5308 int n = 0; | 5381 int n = 0; |
5309 UNUSED_PARAMETER(pVfs); | 5382 UNUSED_PARAMETER(pVfs); |
5310 #if defined(SQLITE_TEST) | 5383 #if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) |
5311 n = nBuf; | 5384 n = nBuf; |
5312 memset(zBuf, 0, nBuf); | 5385 memset(zBuf, 0, nBuf); |
5313 #else | 5386 #else |
5314 if( sizeof(SYSTEMTIME)<=nBuf-n ){ | 5387 if( sizeof(SYSTEMTIME)<=nBuf-n ){ |
5315 SYSTEMTIME x; | 5388 SYSTEMTIME x; |
5316 osGetSystemTime(&x); | 5389 osGetSystemTime(&x); |
5317 memcpy(&zBuf[n], &x, sizeof(x)); | 5390 memcpy(&zBuf[n], &x, sizeof(x)); |
5318 n += sizeof(x); | 5391 n += sizeof(x); |
5319 } | 5392 } |
5320 if( sizeof(DWORD)<=nBuf-n ){ | 5393 if( sizeof(DWORD)<=nBuf-n ){ |
(...skipping 13 matching lines...) Expand all Loading... |
5334 memcpy(&zBuf[n], &cnt, sizeof(cnt)); | 5407 memcpy(&zBuf[n], &cnt, sizeof(cnt)); |
5335 n += sizeof(cnt); | 5408 n += sizeof(cnt); |
5336 } | 5409 } |
5337 #endif | 5410 #endif |
5338 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ | 5411 if( sizeof(LARGE_INTEGER)<=nBuf-n ){ |
5339 LARGE_INTEGER i; | 5412 LARGE_INTEGER i; |
5340 osQueryPerformanceCounter(&i); | 5413 osQueryPerformanceCounter(&i); |
5341 memcpy(&zBuf[n], &i, sizeof(i)); | 5414 memcpy(&zBuf[n], &i, sizeof(i)); |
5342 n += sizeof(i); | 5415 n += sizeof(i); |
5343 } | 5416 } |
| 5417 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID |
| 5418 if( sizeof(UUID)<=nBuf-n ){ |
| 5419 UUID id; |
| 5420 memset(&id, 0, sizeof(UUID)); |
| 5421 osUuidCreate(&id); |
| 5422 memcpy(&zBuf[n], &id, sizeof(UUID)); |
| 5423 n += sizeof(UUID); |
| 5424 } |
| 5425 if( sizeof(UUID)<=nBuf-n ){ |
| 5426 UUID id; |
| 5427 memset(&id, 0, sizeof(UUID)); |
| 5428 osUuidCreateSequential(&id); |
| 5429 memcpy(&zBuf[n], &id, sizeof(UUID)); |
| 5430 n += sizeof(UUID); |
| 5431 } |
5344 #endif | 5432 #endif |
| 5433 #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */ |
5345 return n; | 5434 return n; |
5346 } | 5435 } |
5347 | 5436 |
5348 | 5437 |
5349 /* | 5438 /* |
5350 ** Sleep for a little while. Return the amount of time slept. | 5439 ** Sleep for a little while. Return the amount of time slept. |
5351 */ | 5440 */ |
5352 static int winSleep(sqlite3_vfs *pVfs, int microsec){ | 5441 static int winSleep(sqlite3_vfs *pVfs, int microsec){ |
5353 sqlite3_win32_sleep((microsec+999)/1000); | 5442 sqlite3_win32_sleep((microsec+999)/1000); |
5354 UNUSED_PARAMETER(pVfs); | 5443 UNUSED_PARAMETER(pVfs); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5512 winGetLastError, /* xGetLastError */ | 5601 winGetLastError, /* xGetLastError */ |
5513 winCurrentTimeInt64, /* xCurrentTimeInt64 */ | 5602 winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
5514 winSetSystemCall, /* xSetSystemCall */ | 5603 winSetSystemCall, /* xSetSystemCall */ |
5515 winGetSystemCall, /* xGetSystemCall */ | 5604 winGetSystemCall, /* xGetSystemCall */ |
5516 winNextSystemCall, /* xNextSystemCall */ | 5605 winNextSystemCall, /* xNextSystemCall */ |
5517 }; | 5606 }; |
5518 #endif | 5607 #endif |
5519 | 5608 |
5520 /* Double-check that the aSyscall[] array has been constructed | 5609 /* Double-check that the aSyscall[] array has been constructed |
5521 ** correctly. See ticket [bb3a86e890c8e96ab] */ | 5610 ** correctly. See ticket [bb3a86e890c8e96ab] */ |
5522 assert( ArraySize(aSyscall)==77 ); | 5611 assert( ArraySize(aSyscall)==80 ); |
5523 | 5612 |
5524 /* get memory map allocation granularity */ | 5613 /* get memory map allocation granularity */ |
5525 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); | 5614 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
5526 #if SQLITE_OS_WINRT | 5615 #if SQLITE_OS_WINRT |
5527 osGetNativeSystemInfo(&winSysInfo); | 5616 osGetNativeSystemInfo(&winSysInfo); |
5528 #else | 5617 #else |
5529 osGetSystemInfo(&winSysInfo); | 5618 osGetSystemInfo(&winSysInfo); |
5530 #endif | 5619 #endif |
5531 assert( winSysInfo.dwAllocationGranularity>0 ); | 5620 assert( winSysInfo.dwAllocationGranularity>0 ); |
5532 assert( winSysInfo.dwPageSize>0 ); | 5621 assert( winSysInfo.dwPageSize>0 ); |
(...skipping 10 matching lines...) Expand all Loading... |
5543 int sqlite3_os_end(void){ | 5632 int sqlite3_os_end(void){ |
5544 #if SQLITE_OS_WINRT | 5633 #if SQLITE_OS_WINRT |
5545 if( sleepObj!=NULL ){ | 5634 if( sleepObj!=NULL ){ |
5546 osCloseHandle(sleepObj); | 5635 osCloseHandle(sleepObj); |
5547 sleepObj = NULL; | 5636 sleepObj = NULL; |
5548 } | 5637 } |
5549 #endif | 5638 #endif |
5550 return SQLITE_OK; | 5639 return SQLITE_OK; |
5551 } | 5640 } |
5552 | 5641 |
5553 CHROMIUM_SQLITE_API | |
5554 void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE han
dle) { | |
5555 winFile* winSQLite3File = (winFile*)file; | |
5556 memset(file, 0, sizeof(*file)); | |
5557 winSQLite3File->pMethod = &winIoMethod; | |
5558 winSQLite3File->h = handle; | |
5559 } | |
5560 | |
5561 #endif /* SQLITE_OS_WIN */ | 5642 #endif /* SQLITE_OS_WIN */ |
OLD | NEW |