mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
When running on Windows with an NT-based kernel, always use the LockFileEx/UnlockFileEx functions (with the correct flags).
FossilOrigin-Name: 3e7ba3ddb956056b8132ed383feed4f329c634e0
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Add\snew\sWin32\sAPIs\sused\sto\sthe\ssystem\scall\stable.\s\sAdd\serror\shandling\scode\sfor\sSetFilePointerEx.\s\sMake\ssure\sthe\slast\serror\snumber\sis\ssaved\sfrom\sthe\scall\sto\sGetFileInformationByHandleEx.
|
C When\srunning\son\sWindows\swith\san\sNT-based\skernel,\salways\suse\sthe\sLockFileEx/UnlockFileEx\sfunctions\s(with\sthe\scorrect\sflags).
|
||||||
D 2012-03-02T13:47:16.837
|
D 2012-03-02T22:38:49.501
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34
|
F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -167,7 +167,7 @@ F src/os.h c3a9db9e8e16f564e1a40cea1687dad69634262c
|
|||||||
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
||||||
F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
|
F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
|
||||||
F src/os_unix.c 0e3d2942d228d0366fb80a3640f35caf413b66d1
|
F src/os_unix.c 0e3d2942d228d0366fb80a3640f35caf413b66d1
|
||||||
F src/os_win.c 7378d50e4f8c3dafc0c11ca99615801c84329a4d
|
F src/os_win.c f6b9fa7a93d16779b0504d8c5d438fdd0ef022bb
|
||||||
F src/pager.c 3955b62cdb5bb64559607cb474dd12a6c8e1d4a5
|
F src/pager.c 3955b62cdb5bb64559607cb474dd12a6c8e1d4a5
|
||||||
F src/pager.h ef1eaf8593e78f73885c1dfac27ad83bee23bdc5
|
F src/pager.h ef1eaf8593e78f73885c1dfac27ad83bee23bdc5
|
||||||
F src/parse.y 1ddd71ae55f4b7cbb2672526ea4de023de0f519e
|
F src/parse.y 1ddd71ae55f4b7cbb2672526ea4de023de0f519e
|
||||||
@@ -991,7 +991,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
|||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
|
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
|
||||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||||
P cbf23b461f599d0b025c0f42dd3189cfa4e84bac
|
P a782d2dc3cd4ef49ed46b361cdd331be846c3d50
|
||||||
R f72d2ca1c8333360bf3d39a3248646ef
|
R 5657a63a45c0ba0c63e40023bb562ed0
|
||||||
U mistachkin
|
U mistachkin
|
||||||
Z bc3c857da09d5ea46a27e32ed356379b
|
Z a7d3129db9e33b537945aea438ba067d
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
a782d2dc3cd4ef49ed46b361cdd331be846c3d50
|
3e7ba3ddb956056b8132ed383feed4f329c634e0
|
||||||
118
src/os_win.c
118
src/os_win.c
@@ -1277,6 +1277,49 @@ static void logIoerr(int nRetry){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Lock a file region.
|
||||||
|
*/
|
||||||
|
static BOOL winLockFile(
|
||||||
|
HANDLE hFile,
|
||||||
|
DWORD flags,
|
||||||
|
DWORD offsetLow,
|
||||||
|
DWORD offsetHigh,
|
||||||
|
DWORD numBytesLow,
|
||||||
|
DWORD numBytesHigh
|
||||||
|
){
|
||||||
|
if( isNT() ){
|
||||||
|
OVERLAPPED ovlp;
|
||||||
|
memset(&ovlp, 0, sizeof(OVERLAPPED));
|
||||||
|
ovlp.Offset = offsetLow;
|
||||||
|
ovlp.OffsetHigh = offsetHigh;
|
||||||
|
return osLockFileEx(hFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
|
||||||
|
}else{
|
||||||
|
return osLockFile(hFile, offsetLow, offsetHigh, numBytesLow, numBytesHigh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Unlock a file region.
|
||||||
|
*/
|
||||||
|
static BOOL winUnlockFile(
|
||||||
|
HANDLE hFile,
|
||||||
|
DWORD offsetLow,
|
||||||
|
DWORD offsetHigh,
|
||||||
|
DWORD numBytesLow,
|
||||||
|
DWORD numBytesHigh
|
||||||
|
){
|
||||||
|
if( isNT() ){
|
||||||
|
OVERLAPPED ovlp;
|
||||||
|
memset(&ovlp, 0, sizeof(OVERLAPPED));
|
||||||
|
ovlp.Offset = offsetLow;
|
||||||
|
ovlp.OffsetHigh = offsetHigh;
|
||||||
|
return osUnlockFileEx(hFile, 0, numBytesLow, numBytesHigh, &ovlp);
|
||||||
|
}else{
|
||||||
|
return osUnlockFile(hFile, offsetLow, offsetHigh, numBytesLow, numBytesHigh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if SQLITE_OS_WINCE
|
#if SQLITE_OS_WINCE
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
** This section contains code for WinCE only.
|
** This section contains code for WinCE only.
|
||||||
@@ -1957,6 +2000,30 @@ static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
|
|||||||
# define LOCKFILE_FAIL_IMMEDIATELY 1
|
# define LOCKFILE_FAIL_IMMEDIATELY 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOCKFILE_EXCLUSIVE_LOCK
|
||||||
|
# define LOCKFILE_EXCLUSIVE_LOCK 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Historically, SQLite has used both the LockFile and LockFileEx functions.
|
||||||
|
** When the LockFile function was used, it was always expected to fail
|
||||||
|
** immediately if the lock could not be obtained. Also, it always expected to
|
||||||
|
** obtain an exclusive lock. These flags are used with the LockFileEx function
|
||||||
|
** and reflect those expectations; therefore, they should not be changed.
|
||||||
|
*/
|
||||||
|
#ifndef SQLITE_LOCKFILE_FLAGS
|
||||||
|
# define SQLITE_LOCKFILE_FLAGS (LOCKFILE_FAIL_IMMEDIATELY | \
|
||||||
|
LOCKFILE_EXCLUSIVE_LOCK)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Currently, SQLite never calls the LockFileEx function without wanting the
|
||||||
|
** call to fail immediately if the lock cannot be obtained.
|
||||||
|
*/
|
||||||
|
#ifndef SQLITE_LOCKFILEEX_FLAGS
|
||||||
|
# define SQLITE_LOCKFILEEX_FLAGS (LOCKFILE_FAIL_IMMEDIATELY)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Acquire a reader lock.
|
** Acquire a reader lock.
|
||||||
** Different API routines are called depending on whether or not this
|
** Different API routines are called depending on whether or not this
|
||||||
@@ -1965,19 +2032,16 @@ static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
|
|||||||
static int getReadLock(winFile *pFile){
|
static int getReadLock(winFile *pFile){
|
||||||
int res;
|
int res;
|
||||||
if( isNT() ){
|
if( isNT() ){
|
||||||
OVERLAPPED ovlp;
|
res = winLockFile(pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
|
||||||
ovlp.Offset = SHARED_FIRST;
|
SHARED_SIZE, 0);
|
||||||
ovlp.OffsetHigh = 0;
|
|
||||||
ovlp.hEvent = 0;
|
|
||||||
res = osLockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
|
|
||||||
0, SHARED_SIZE, 0, &ovlp);
|
|
||||||
}
|
}
|
||||||
#ifdef SQLITE_WIN32_HAS_ANSI
|
#ifdef SQLITE_WIN32_HAS_ANSI
|
||||||
else{
|
else{
|
||||||
int lk;
|
int lk;
|
||||||
sqlite3_randomness(sizeof(lk), &lk);
|
sqlite3_randomness(sizeof(lk), &lk);
|
||||||
pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
|
pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
|
||||||
res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
|
res = winLockFile(pFile->h, SQLITE_LOCKFILE_FLAGS,
|
||||||
|
SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if( res == 0 ){
|
if( res == 0 ){
|
||||||
@@ -1994,11 +2058,11 @@ static int unlockReadLock(winFile *pFile){
|
|||||||
int res;
|
int res;
|
||||||
DWORD lastErrno;
|
DWORD lastErrno;
|
||||||
if( isNT() ){
|
if( isNT() ){
|
||||||
res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
res = winUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||||
}
|
}
|
||||||
#ifdef SQLITE_WIN32_HAS_ANSI
|
#ifdef SQLITE_WIN32_HAS_ANSI
|
||||||
else{
|
else{
|
||||||
res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
|
res = winUnlockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
|
if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
|
||||||
@@ -2071,7 +2135,8 @@ static int winLock(sqlite3_file *id, int locktype){
|
|||||||
&& (pFile->locktype==RESERVED_LOCK))
|
&& (pFile->locktype==RESERVED_LOCK))
|
||||||
){
|
){
|
||||||
int cnt = 3;
|
int cnt = 3;
|
||||||
while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
|
while( cnt-->0 && (res = winLockFile(pFile->h, SQLITE_LOCKFILE_FLAGS,
|
||||||
|
PENDING_BYTE, 0, 1, 0))==0 ){
|
||||||
/* Try 3 times to get the pending lock. This is needed to work
|
/* Try 3 times to get the pending lock. This is needed to work
|
||||||
** around problems caused by indexing and/or anti-virus software on
|
** around problems caused by indexing and/or anti-virus software on
|
||||||
** Windows systems.
|
** Windows systems.
|
||||||
@@ -2103,7 +2168,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
|||||||
*/
|
*/
|
||||||
if( locktype==RESERVED_LOCK && res ){
|
if( locktype==RESERVED_LOCK && res ){
|
||||||
assert( pFile->locktype==SHARED_LOCK );
|
assert( pFile->locktype==SHARED_LOCK );
|
||||||
res = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
res = winLockFile(pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
|
||||||
if( res ){
|
if( res ){
|
||||||
newLocktype = RESERVED_LOCK;
|
newLocktype = RESERVED_LOCK;
|
||||||
}else{
|
}else{
|
||||||
@@ -2124,7 +2189,8 @@ static int winLock(sqlite3_file *id, int locktype){
|
|||||||
assert( pFile->locktype>=SHARED_LOCK );
|
assert( pFile->locktype>=SHARED_LOCK );
|
||||||
res = unlockReadLock(pFile);
|
res = unlockReadLock(pFile);
|
||||||
OSTRACE(("unreadlock = %d\n", res));
|
OSTRACE(("unreadlock = %d\n", res));
|
||||||
res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
res = winLockFile(pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
|
||||||
|
SHARED_SIZE, 0);
|
||||||
if( res ){
|
if( res ){
|
||||||
newLocktype = EXCLUSIVE_LOCK;
|
newLocktype = EXCLUSIVE_LOCK;
|
||||||
}else{
|
}else{
|
||||||
@@ -2138,7 +2204,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
|||||||
** release it now.
|
** release it now.
|
||||||
*/
|
*/
|
||||||
if( gotPendingLock && locktype==SHARED_LOCK ){
|
if( gotPendingLock && locktype==SHARED_LOCK ){
|
||||||
osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
|
winUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the state of the lock has held in the file descriptor then
|
/* Update the state of the lock has held in the file descriptor then
|
||||||
@@ -2172,9 +2238,9 @@ static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
|
|||||||
rc = 1;
|
rc = 1;
|
||||||
OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
|
OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
|
||||||
}else{
|
}else{
|
||||||
rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
rc = winLockFile(pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
|
||||||
if( rc ){
|
if( rc ){
|
||||||
osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
winUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||||
}
|
}
|
||||||
rc = !rc;
|
rc = !rc;
|
||||||
OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
|
OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
|
||||||
@@ -2204,7 +2270,7 @@ static int winUnlock(sqlite3_file *id, int locktype){
|
|||||||
pFile->locktype, pFile->sharedLockByte));
|
pFile->locktype, pFile->sharedLockByte));
|
||||||
type = pFile->locktype;
|
type = pFile->locktype;
|
||||||
if( type>=EXCLUSIVE_LOCK ){
|
if( type>=EXCLUSIVE_LOCK ){
|
||||||
osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
winUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||||
if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
|
if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
|
||||||
/* This should never happen. We should always be able to
|
/* This should never happen. We should always be able to
|
||||||
** reacquire the read lock */
|
** reacquire the read lock */
|
||||||
@@ -2213,13 +2279,13 @@ static int winUnlock(sqlite3_file *id, int locktype){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( type>=RESERVED_LOCK ){
|
if( type>=RESERVED_LOCK ){
|
||||||
osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
winUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||||
}
|
}
|
||||||
if( locktype==NO_LOCK && type>=SHARED_LOCK ){
|
if( locktype==NO_LOCK && type>=SHARED_LOCK ){
|
||||||
unlockReadLock(pFile);
|
unlockReadLock(pFile);
|
||||||
}
|
}
|
||||||
if( type>=PENDING_LOCK ){
|
if( type>=PENDING_LOCK ){
|
||||||
osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
|
winUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
|
||||||
}
|
}
|
||||||
pFile->locktype = (u8)locktype;
|
pFile->locktype = (u8)locktype;
|
||||||
return rc;
|
return rc;
|
||||||
@@ -2457,25 +2523,19 @@ static int winShmSystemLock(
|
|||||||
int ofst, /* Offset to first byte to be locked/unlocked */
|
int ofst, /* Offset to first byte to be locked/unlocked */
|
||||||
int nByte /* Number of bytes to lock or unlock */
|
int nByte /* Number of bytes to lock or unlock */
|
||||||
){
|
){
|
||||||
OVERLAPPED ovlp;
|
|
||||||
DWORD dwFlags;
|
|
||||||
int rc = 0; /* Result code form Lock/UnlockFileEx() */
|
int rc = 0; /* Result code form Lock/UnlockFileEx() */
|
||||||
|
|
||||||
/* Access to the winShmNode object is serialized by the caller */
|
/* Access to the winShmNode object is serialized by the caller */
|
||||||
assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
|
assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
|
||||||
|
|
||||||
/* Initialize the locking parameters */
|
|
||||||
dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
|
|
||||||
if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
|
|
||||||
|
|
||||||
memset(&ovlp, 0, sizeof(OVERLAPPED));
|
|
||||||
ovlp.Offset = ofst;
|
|
||||||
|
|
||||||
/* Release/Acquire the system-level lock */
|
/* Release/Acquire the system-level lock */
|
||||||
if( lockType==_SHM_UNLCK ){
|
if( lockType==_SHM_UNLCK ){
|
||||||
rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
|
rc = winUnlockFile(pFile->hFile.h, ofst, 0, nByte, 0);
|
||||||
}else{
|
}else{
|
||||||
rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
|
/* Initialize the locking parameters */
|
||||||
|
DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
|
||||||
|
if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
|
||||||
|
rc = winLockFile(pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( rc!= 0 ){
|
if( rc!= 0 ){
|
||||||
|
|||||||
Reference in New Issue
Block a user