/ Check-in [a782d2dc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add new Win32 APIs used to the system call table. Add error handling code for SetFilePointerEx. Make sure the last error number is saved from the call to GetFileInformationByHandleEx.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | winrt
Files: files | file ages | folders
SHA1: a782d2dc3cd4ef49ed46b361cdd331be846c3d50
User & Date: mistachkin 2012-03-02 13:47:16
Context
2012-03-02
22:38
When running on Windows with an NT-based kernel, always use the LockFileEx/UnlockFileEx functions (with the correct flags). check-in: 3e7ba3dd user: mistachkin tags: winrt
13:47
Add new Win32 APIs used to the system call table. Add error handling code for SetFilePointerEx. Make sure the last error number is saved from the call to GetFileInformationByHandleEx. check-in: a782d2dc user: mistachkin tags: winrt
00:00
Omit all ANSI APIs for winRT. check-in: cbf23b46 user: drh tags: winrt
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

620
621
622
623
624
625
626









































627
628
629
630
631
632
633
...
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
....
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
....
1604
1605
1606
1607
1608
1609
1610
1611


1612
1613









1614
1615
1616
1617
1618
1619
1620
....
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876

1877
1878
1879
1880
1881
1882
1883
....
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
....
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
        LPCSTR,LPBOOL))aSyscall[58].pCurrent)

  { "WriteFile",               (SYSCALL)WriteFile,               0 },

#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
        LPOVERLAPPED))aSyscall[59].pCurrent)










































}; /* End of the overrideable system calls */

/*
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
................................................................................
/*
** The following routine Suspends the thread for at least ms milliseconds.  This is equivalent
** to the win32 Sleep() interface.
*/
#if SQLITE_OS_WINRT
static HANDLE sleepObj;
static void portableSleep(int ms){
  WaitForSingleObjectEx(sleepObj, ms, FALSE);
}
#else
static void portableSleep(int ms){
  osSleep(ms); 
}
#endif

................................................................................

/*
** Acquire a lock on the handle h
*/
static void winceMutexAcquire(HANDLE h){
   DWORD dwErr;
   do {
     dwErr = WaitForSingleObject(h, INFINITE);
   } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
}
/*
** Release a lock acquired by winceMutexAcquire()
*/
#define winceMutexRelease(h) ReleaseMutex(h)

................................................................................
}
#else /* if SQLITE_OS_WINRT==1 */
/* 
** Same function as above, except that this implementation works for
** windowsRT.
*/
static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
  LARGE_INTEGER x;


  x.QuadPart = iOffset;
  return SetFilePointerEx(pFile->h, x, 0, FILE_BEGIN) ? 0 : 1;









}
#endif

/*
** Close a file.
**
** It is reported that an attempt to close a handle might sometimes
................................................................................
  int rc = SQLITE_OK;

  assert( id!=0 );
  SimulateIOError(return SQLITE_IOERR_FSTAT);
#if SQLITE_OS_WINRT
  {
    FILE_STANDARD_INFO info;
    if( GetFileInformationByHandleEx(pFile->h, FileStandardInfo,
                                     &info, sizeof(info)) ){
      *pSize = info.EndOfFile.QuadPart;
    }else{

      rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
                       "winFileSize", pFile->zPath);
    }
  }
#else
  {
    DWORD upperBits;
................................................................................
    winSetSystemCall,    /* xSetSystemCall */
    winGetSystemCall,    /* xGetSystemCall */
    winNextSystemCall,   /* xNextSystemCall */
  };

  /* Double-check that the aSyscall[] array has been constructed
  ** correctly.  See ticket [bb3a86e890c8e96ab] */
  assert( ArraySize(aSyscall)==60 );

#if SQLITE_OS_WINRT
  sleepObj = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, 
                                  EVENT_ALL_ACCESS);
#endif

#ifndef SQLITE_OMIT_WAL
  /* get memory map allocation granularity */
  memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  osGetSystemInfo(&winSysInfo);
................................................................................

  sqlite3_vfs_register(&winVfs, 1);
  return SQLITE_OK; 
}

int sqlite3_os_end(void){ 
#if SQLITE_OS_WINRT
  CloseHandle(sleepObj);
#endif
  return SQLITE_OK;
}

#endif /* SQLITE_OS_WIN */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







 







|
>
>

|
>
>
>
>
>
>
>
>
>







 







|



>







 







|


|







 







|





620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
....
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
....
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
....
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
....
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
....
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
        LPCSTR,LPBOOL))aSyscall[58].pCurrent)

  { "WriteFile",               (SYSCALL)WriteFile,               0 },

#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
        LPOVERLAPPED))aSyscall[59].pCurrent)

#if !SQLITE_OS_WINCE
  { "CreateEventEx",           (SYSCALL)CreateEventEx,           0 },

#define osCreateEventEx ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCTSTR, \
        DWORD,DWORD))aSyscall[60].pCurrent)
#else
  { "CreateEventEx",           (SYSCALL)0,                       0 },
#endif

  { "WaitForSingleObject",     (SYSCALL)WaitForSingleObject,     0 },

#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
        DWORD))aSyscall[61].pCurrent)

#if !SQLITE_OS_WINCE
  { "WaitForSingleObjectEx",   (SYSCALL)WaitForSingleObjectEx,   0 },

#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
        BOOL))aSyscall[62].pCurrent)
#else
  { "WaitForSingleObjectEx",   (SYSCALL)0,                       0 },
#endif

#if !SQLITE_OS_WINCE
  { "SetFilePointerEx",        (SYSCALL)SetFilePointerEx,        0 },

#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
        PLARGE_INTEGER,DWORD))aSyscall[63].pCurrent)
#else
  { "SetFilePointerEx",        (SYSCALL)0,                       0 },
#endif

#if !SQLITE_OS_WINCE
  { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },

#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
        FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[64].pCurrent)
#else
  { "GetFileInformationByHandleEx", (SYSCALL)0,                  0 },
#endif

}; /* End of the overrideable system calls */

/*
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
................................................................................
/*
** The following routine Suspends the thread for at least ms milliseconds.  This is equivalent
** to the win32 Sleep() interface.
*/
#if SQLITE_OS_WINRT
static HANDLE sleepObj;
static void portableSleep(int ms){
  osWaitForSingleObjectEx(sleepObj, ms, FALSE);
}
#else
static void portableSleep(int ms){
  osSleep(ms); 
}
#endif

................................................................................

/*
** Acquire a lock on the handle h
*/
static void winceMutexAcquire(HANDLE h){
   DWORD dwErr;
   do {
     dwErr = osWaitForSingleObject(h, INFINITE);
   } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
}
/*
** Release a lock acquired by winceMutexAcquire()
*/
#define winceMutexRelease(h) ReleaseMutex(h)

................................................................................
}
#else /* if SQLITE_OS_WINRT==1 */
/* 
** Same function as above, except that this implementation works for
** windowsRT.
*/
static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
  LARGE_INTEGER x;                /* The new offset */
  BOOL bRet;                      /* Value returned by SetFilePointerEx() */

  x.QuadPart = iOffset;
  bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);

  if(!bRet){
    pFile->lastErrno = osGetLastError();
    winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
             "seekWinFile", pFile->zPath);
    return 1;
  }

  return 0;
}
#endif

/*
** Close a file.
**
** It is reported that an attempt to close a handle might sometimes
................................................................................
  int rc = SQLITE_OK;

  assert( id!=0 );
  SimulateIOError(return SQLITE_IOERR_FSTAT);
#if SQLITE_OS_WINRT
  {
    FILE_STANDARD_INFO info;
    if( osGetFileInformationByHandleEx(pFile->h, FileStandardInfo,
                                     &info, sizeof(info)) ){
      *pSize = info.EndOfFile.QuadPart;
    }else{
      pFile->lastErrno = osGetLastError();
      rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
                       "winFileSize", pFile->zPath);
    }
  }
#else
  {
    DWORD upperBits;
................................................................................
    winSetSystemCall,    /* xSetSystemCall */
    winGetSystemCall,    /* xGetSystemCall */
    winNextSystemCall,   /* xNextSystemCall */
  };

  /* Double-check that the aSyscall[] array has been constructed
  ** correctly.  See ticket [bb3a86e890c8e96ab] */
  assert( ArraySize(aSyscall)==65 );

#if SQLITE_OS_WINRT
  sleepObj = osCreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, 
                                  EVENT_ALL_ACCESS);
#endif

#ifndef SQLITE_OMIT_WAL
  /* get memory map allocation granularity */
  memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  osGetSystemInfo(&winSysInfo);
................................................................................

  sqlite3_vfs_register(&winVfs, 1);
  return SQLITE_OK; 
}

int sqlite3_os_end(void){ 
#if SQLITE_OS_WINRT
  osCloseHandle(sleepObj);
#endif
  return SQLITE_OK;
}

#endif /* SQLITE_OS_WIN */