/ Check-in [38df8fc1]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:When compiled for WinRT, avoid using MapViewOfFile and GetFileAttributes. Also, reset the private 'sleep' event handle when the VFS is cleaned up.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | winrt
Files: files | file ages | folders
SHA1: 38df8fc1b49d55b61cb168a61134b4a314a62f21
User & Date: mistachkin 2012-03-03 13:15:25
Context
2012-03-04
02:56
When creating the event used to sleep on WinRT, request the minimum access rights required for the desired operations on it (i.e. SYNCHRONIZE). check-in: ed603d75 user: mistachkin tags: winrt
2012-03-03
13:15
When compiled for WinRT, avoid using MapViewOfFile and GetFileAttributes. Also, reset the private 'sleep' event handle when the VFS is cleaned up. check-in: 38df8fc1 user: mistachkin tags: winrt
2012-03-02
23:53
When compiled for WinRT, avoid using the FORMAT_MESSAGE_ALLOCATE_BUFFER flag to FormatMessage (i.e. because LocalFree is unavailable). check-in: 9eb331be user: mistachkin tags: winrt
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

661
662
663
664
665
666
667





668
669
670
671
672
673
674
....
2992
2993
2994
2995
2996
2997
2998





2999
3000
3001

3002
3003
3004
3005
3006
3007
3008
....
3415
3416
3417
3418
3419
3420
3421
3422
3423







3424

3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
....
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
....
3851
3852
3853
3854
3855
3856
3857

3858
3859
3860
3861
3862
  { "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
................................................................................
      );
      OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
               (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
               hMap ? "ok" : "failed"));
      if( hMap ){
        int iOffset = pShmNode->nRegion*szRegion;
        int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;





        pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
            0, iOffset - iOffsetShift, szRegion + iOffsetShift
        );

        OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
                 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
                 szRegion, pMap ? "ok" : "failed"));
      }
      if( !pMap ){
        pShmNode->lastErrno = osGetLastError();
        rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno,
................................................................................
  UNUSED_PARAMETER(syncDir);

  SimulateIOError(return SQLITE_IOERR_DELETE);
  zConverted = convertUtf8Filename(zFilename);
  if( zConverted==0 ){
    return SQLITE_IOERR_NOMEM;
  }
  if( isNT() ){
    rc = 1;







    while( osGetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&

         (rc = osDeleteFileW(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){}
    rc = rc ? SQLITE_OK : SQLITE_ERROR;
  }
#ifdef SQLITE_WIN32_HAS_ANSI
  else{
    rc = 1;
    while( osGetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         (rc = osDeleteFileA(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){}
    rc = rc ? SQLITE_OK : SQLITE_ERROR;
  }
#endif
  if( rc ){
    rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
................................................................................
    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
................................................................................
  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 */







>
>
>
>
>







 







>
>
>
>
>



>







 







<
|
>
>
>
>
>
>
>

>





<







 







|







 







>





661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
....
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
....
3426
3427
3428
3429
3430
3431
3432

3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447

3448
3449
3450
3451
3452
3453
3454
....
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
....
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
  { "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

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

#define osMapViewOfFileEx ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,SIZE_T, \
        LPVOID))aSyscall[65].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
................................................................................
      );
      OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
               (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
               hMap ? "ok" : "failed"));
      if( hMap ){
        int iOffset = pShmNode->nRegion*szRegion;
        int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
#if SQLITE_OS_WINRT
        pMap = osMapViewOfFileEx(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
            0, iOffset - iOffsetShift, szRegion + iOffsetShift, NULL
        );
#else
        pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
            0, iOffset - iOffsetShift, szRegion + iOffsetShift
        );
#endif
        OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
                 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
                 szRegion, pMap ? "ok" : "failed"));
      }
      if( !pMap ){
        pShmNode->lastErrno = osGetLastError();
        rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno,
................................................................................
  UNUSED_PARAMETER(syncDir);

  SimulateIOError(return SQLITE_IOERR_DELETE);
  zConverted = convertUtf8Filename(zFilename);
  if( zConverted==0 ){
    return SQLITE_IOERR_NOMEM;
  }

  rc = 1;
  if( isNT() ){
#if SQLITE_OS_WINRT
    WIN32_FILE_ATTRIBUTE_DATA sAttrData;
    memset(&sAttrData, 0, sizeof(sAttrData));
    while( osGetFileAttributesExW(zConverted, GetFileExInfoStandard,
                                  &sAttrData) &&
#else
    while( osGetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&
#endif
         (rc = osDeleteFileW(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){}
    rc = rc ? SQLITE_OK : SQLITE_ERROR;
  }
#ifdef SQLITE_WIN32_HAS_ANSI
  else{

    while( osGetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         (rc = osDeleteFileA(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){}
    rc = rc ? SQLITE_OK : SQLITE_ERROR;
  }
#endif
  if( rc ){
    rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
................................................................................
    winSetSystemCall,    /* xSetSystemCall */
    winGetSystemCall,    /* xGetSystemCall */
    winNextSystemCall,   /* xNextSystemCall */
  };

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

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

#ifndef SQLITE_OMIT_WAL
................................................................................
  sqlite3_vfs_register(&winVfs, 1);
  return SQLITE_OK; 
}

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

#endif /* SQLITE_OS_WIN */