mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Merge updates from trunk.
FossilOrigin-Name: 00990020d07d7c87b922cdbfa5373298a86bb4b3
This commit is contained in:
432
src/os_win.c
432
src/os_win.c
@@ -76,6 +76,10 @@
|
||||
# define NTDDI_WINBLUE 0x06030000
|
||||
#endif
|
||||
|
||||
#ifndef NTDDI_WINTHRESHOLD
|
||||
# define NTDDI_WINTHRESHOLD 0x06040000
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Check to see if the GetVersionEx[AW] functions are deprecated on the
|
||||
** target system. GetVersionEx was first deprecated in Win8.1.
|
||||
@@ -88,6 +92,19 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Check to see if the CreateFileMappingA function is supported on the
|
||||
** target system. It is unavailable when using "mincore.lib" on Win10.
|
||||
** When compiling for Windows 10, always assume "mincore.lib" is in use.
|
||||
*/
|
||||
#ifndef SQLITE_WIN32_CREATEFILEMAPPINGA
|
||||
# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINTHRESHOLD
|
||||
# define SQLITE_WIN32_CREATEFILEMAPPINGA 0
|
||||
# else
|
||||
# define SQLITE_WIN32_CREATEFILEMAPPINGA 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This constant should already be defined (in the "WinDef.h" SDK file).
|
||||
*/
|
||||
@@ -327,11 +344,23 @@ struct winFile {
|
||||
# define SQLITE_WIN32_HEAP_CREATE (TRUE)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is cache size used in the calculation of the initial size of the
|
||||
* Win32-specific heap. It cannot be negative.
|
||||
*/
|
||||
#ifndef SQLITE_WIN32_CACHE_SIZE
|
||||
# if SQLITE_DEFAULT_CACHE_SIZE>=0
|
||||
# define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
|
||||
# else
|
||||
# define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The initial size of the Win32-specific heap. This value may be zero.
|
||||
*/
|
||||
#ifndef SQLITE_WIN32_HEAP_INIT_SIZE
|
||||
# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
|
||||
# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
|
||||
(SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
|
||||
#endif
|
||||
|
||||
@@ -494,8 +523,9 @@ static struct win_syscall {
|
||||
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
|
||||
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
|
||||
|
||||
#if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
|
||||
(!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
|
||||
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
|
||||
(!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \
|
||||
SQLITE_WIN32_CREATEFILEMAPPINGA
|
||||
{ "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
|
||||
#else
|
||||
{ "CreateFileMappingA", (SYSCALL)0, 0 },
|
||||
@@ -725,8 +755,7 @@ static struct win_syscall {
|
||||
|
||||
#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
|
||||
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \
|
||||
SQLITE_WIN32_GETVERSIONEX
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX
|
||||
{ "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
|
||||
#else
|
||||
{ "GetVersionExA", (SYSCALL)0, 0 },
|
||||
@@ -736,7 +765,7 @@ static struct win_syscall {
|
||||
LPOSVERSIONINFOA))aSyscall[34].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
|
||||
defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
|
||||
SQLITE_WIN32_GETVERSIONEX
|
||||
{ "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
|
||||
#else
|
||||
{ "GetVersionExW", (SYSCALL)0, 0 },
|
||||
@@ -1205,7 +1234,7 @@ int sqlite3_win32_compact_heap(LPUINT pnLargest){
|
||||
if( lastErrno==NO_ERROR ){
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
|
||||
(void*)hHeap);
|
||||
rc = SQLITE_NOMEM;
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
}else{
|
||||
sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
|
||||
osGetLastError(), (void*)hHeap);
|
||||
@@ -1277,6 +1306,12 @@ void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
|
||||
int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
|
||||
if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
|
||||
assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zBuf ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI)
|
||||
if( nMin>0 ){
|
||||
memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
|
||||
@@ -1347,7 +1382,7 @@ DWORD sqlite3Win32Wait(HANDLE hObject){
|
||||
** the LockFileEx() API.
|
||||
*/
|
||||
|
||||
#if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX
|
||||
#if !SQLITE_WIN32_GETVERSIONEX
|
||||
# define osIsNT() (1)
|
||||
#elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
|
||||
# define osIsNT() (1)
|
||||
@@ -1368,7 +1403,7 @@ int sqlite3_win32_is_nt(void){
|
||||
** kernel.
|
||||
*/
|
||||
return 1;
|
||||
#elif defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX
|
||||
#elif SQLITE_WIN32_GETVERSIONEX
|
||||
if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI)
|
||||
OSVERSIONINFOA sInfo;
|
||||
@@ -1525,7 +1560,7 @@ static int winMemInit(void *pAppData){
|
||||
"failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu",
|
||||
osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize,
|
||||
dwMaximumSize);
|
||||
return SQLITE_NOMEM;
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
pWinMemData->bOwned = TRUE;
|
||||
assert( pWinMemData->bOwned );
|
||||
@@ -1535,7 +1570,7 @@ static int winMemInit(void *pAppData){
|
||||
if( !pWinMemData->hHeap ){
|
||||
sqlite3_log(SQLITE_NOMEM,
|
||||
"failed to GetProcessHeap (%lu)", osGetLastError());
|
||||
return SQLITE_NOMEM;
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
pWinMemData->bOwned = FALSE;
|
||||
assert( !pWinMemData->bOwned );
|
||||
@@ -1602,147 +1637,244 @@ void sqlite3MemSetDefault(void){
|
||||
#endif /* SQLITE_WIN32_MALLOC */
|
||||
|
||||
/*
|
||||
** Convert a UTF-8 string to Microsoft Unicode (UTF-16?).
|
||||
** Convert a UTF-8 string to Microsoft Unicode.
|
||||
**
|
||||
** Space to hold the returned string is obtained from malloc.
|
||||
** Space to hold the returned string is obtained from sqlite3_malloc().
|
||||
*/
|
||||
static LPWSTR winUtf8ToUnicode(const char *zFilename){
|
||||
static LPWSTR winUtf8ToUnicode(const char *zText){
|
||||
int nChar;
|
||||
LPWSTR zWideFilename;
|
||||
LPWSTR zWideText;
|
||||
|
||||
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
|
||||
nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0);
|
||||
if( nChar==0 ){
|
||||
return 0;
|
||||
}
|
||||
zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) );
|
||||
if( zWideFilename==0 ){
|
||||
zWideText = sqlite3MallocZero( nChar*sizeof(WCHAR) );
|
||||
if( zWideText==0 ){
|
||||
return 0;
|
||||
}
|
||||
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
|
||||
nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText,
|
||||
nChar);
|
||||
if( nChar==0 ){
|
||||
sqlite3_free(zWideFilename);
|
||||
zWideFilename = 0;
|
||||
sqlite3_free(zWideText);
|
||||
zWideText = 0;
|
||||
}
|
||||
return zWideFilename;
|
||||
return zWideText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert Microsoft Unicode to UTF-8. Space to hold the returned string is
|
||||
** obtained from sqlite3_malloc().
|
||||
** Convert a Microsoft Unicode string to UTF-8.
|
||||
**
|
||||
** Space to hold the returned string is obtained from sqlite3_malloc().
|
||||
*/
|
||||
static char *winUnicodeToUtf8(LPCWSTR zWideFilename){
|
||||
static char *winUnicodeToUtf8(LPCWSTR zWideText){
|
||||
int nByte;
|
||||
char *zFilename;
|
||||
char *zText;
|
||||
|
||||
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
|
||||
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0);
|
||||
if( nByte == 0 ){
|
||||
return 0;
|
||||
}
|
||||
zFilename = sqlite3MallocZero( nByte );
|
||||
if( zFilename==0 ){
|
||||
zText = sqlite3MallocZero( nByte );
|
||||
if( zText==0 ){
|
||||
return 0;
|
||||
}
|
||||
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
|
||||
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte,
|
||||
0, 0);
|
||||
if( nByte == 0 ){
|
||||
sqlite3_free(zFilename);
|
||||
zFilename = 0;
|
||||
sqlite3_free(zText);
|
||||
zText = 0;
|
||||
}
|
||||
return zFilename;
|
||||
return zText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert an ANSI string to Microsoft Unicode, based on the
|
||||
** current codepage settings for file apis.
|
||||
** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM
|
||||
** code page.
|
||||
**
|
||||
** Space to hold the returned string is obtained
|
||||
** from sqlite3_malloc.
|
||||
** Space to hold the returned string is obtained from sqlite3_malloc().
|
||||
*/
|
||||
static LPWSTR winMbcsToUnicode(const char *zFilename){
|
||||
static LPWSTR winMbcsToUnicode(const char *zText, int useAnsi){
|
||||
int nByte;
|
||||
LPWSTR zMbcsFilename;
|
||||
int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||
LPWSTR zMbcsText;
|
||||
int codepage = useAnsi ? CP_ACP : CP_OEMCP;
|
||||
|
||||
nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
|
||||
nByte = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
|
||||
0)*sizeof(WCHAR);
|
||||
if( nByte==0 ){
|
||||
return 0;
|
||||
}
|
||||
zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) );
|
||||
if( zMbcsFilename==0 ){
|
||||
zMbcsText = sqlite3MallocZero( nByte*sizeof(WCHAR) );
|
||||
if( zMbcsText==0 ){
|
||||
return 0;
|
||||
}
|
||||
nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename,
|
||||
nByte = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText,
|
||||
nByte);
|
||||
if( nByte==0 ){
|
||||
sqlite3_free(zMbcsFilename);
|
||||
zMbcsFilename = 0;
|
||||
sqlite3_free(zMbcsText);
|
||||
zMbcsText = 0;
|
||||
}
|
||||
return zMbcsFilename;
|
||||
return zMbcsText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert Microsoft Unicode to multi-byte character string, based on the
|
||||
** user's ANSI codepage.
|
||||
** Convert a Microsoft Unicode string to a multi-byte character string,
|
||||
** using the ANSI or OEM code page.
|
||||
**
|
||||
** Space to hold the returned string is obtained from
|
||||
** sqlite3_malloc().
|
||||
** Space to hold the returned string is obtained from sqlite3_malloc().
|
||||
*/
|
||||
static char *winUnicodeToMbcs(LPCWSTR zWideFilename){
|
||||
static char *winUnicodeToMbcs(LPCWSTR zWideText, int useAnsi){
|
||||
int nByte;
|
||||
char *zFilename;
|
||||
int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||
char *zText;
|
||||
int codepage = useAnsi ? CP_ACP : CP_OEMCP;
|
||||
|
||||
nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
|
||||
nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, 0, 0, 0, 0);
|
||||
if( nByte == 0 ){
|
||||
return 0;
|
||||
}
|
||||
zFilename = sqlite3MallocZero( nByte );
|
||||
if( zFilename==0 ){
|
||||
zText = sqlite3MallocZero( nByte );
|
||||
if( zText==0 ){
|
||||
return 0;
|
||||
}
|
||||
nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename,
|
||||
nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, zText,
|
||||
nByte, 0, 0);
|
||||
if( nByte == 0 ){
|
||||
sqlite3_free(zFilename);
|
||||
zFilename = 0;
|
||||
sqlite3_free(zText);
|
||||
zText = 0;
|
||||
}
|
||||
return zFilename;
|
||||
return zText;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert multibyte character string to UTF-8. Space to hold the
|
||||
** returned string is obtained from sqlite3_malloc().
|
||||
** Convert a multi-byte character string to UTF-8.
|
||||
**
|
||||
** Space to hold the returned string is obtained from sqlite3_malloc().
|
||||
*/
|
||||
char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){
|
||||
char *zFilenameUtf8;
|
||||
static char *winMbcsToUtf8(const char *zText, int useAnsi){
|
||||
char *zTextUtf8;
|
||||
LPWSTR zTmpWide;
|
||||
|
||||
zTmpWide = winMbcsToUnicode(zFilename);
|
||||
zTmpWide = winMbcsToUnicode(zText, useAnsi);
|
||||
if( zTmpWide==0 ){
|
||||
return 0;
|
||||
}
|
||||
zFilenameUtf8 = winUnicodeToUtf8(zTmpWide);
|
||||
zTextUtf8 = winUnicodeToUtf8(zTmpWide);
|
||||
sqlite3_free(zTmpWide);
|
||||
return zFilenameUtf8;
|
||||
return zTextUtf8;
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert UTF-8 to multibyte character string. Space to hold the
|
||||
** returned string is obtained from sqlite3_malloc().
|
||||
** Convert a UTF-8 string to a multi-byte character string.
|
||||
**
|
||||
** Space to hold the returned string is obtained from sqlite3_malloc().
|
||||
*/
|
||||
char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){
|
||||
char *zFilenameMbcs;
|
||||
static char *winUtf8ToMbcs(const char *zText, int useAnsi){
|
||||
char *zTextMbcs;
|
||||
LPWSTR zTmpWide;
|
||||
|
||||
zTmpWide = winUtf8ToUnicode(zFilename);
|
||||
zTmpWide = winUtf8ToUnicode(zText);
|
||||
if( zTmpWide==0 ){
|
||||
return 0;
|
||||
}
|
||||
zFilenameMbcs = winUnicodeToMbcs(zTmpWide);
|
||||
zTextMbcs = winUnicodeToMbcs(zTmpWide, useAnsi);
|
||||
sqlite3_free(zTmpWide);
|
||||
return zFilenameMbcs;
|
||||
return zTextMbcs;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a public wrapper for the winUtf8ToUnicode() function.
|
||||
*/
|
||||
LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zText ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
return winUtf8ToUnicode(zText);
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a public wrapper for the winUnicodeToUtf8() function.
|
||||
*/
|
||||
char *sqlite3_win32_unicode_to_utf8(LPCWSTR zWideText){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zWideText ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
return winUnicodeToUtf8(zWideText);
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a public wrapper for the winMbcsToUtf8() function.
|
||||
*/
|
||||
char *sqlite3_win32_mbcs_to_utf8(const char *zText){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zText ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
return winMbcsToUtf8(zText, osAreFileApisANSI());
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a public wrapper for the winMbcsToUtf8() function.
|
||||
*/
|
||||
char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zText ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
return winMbcsToUtf8(zText, useAnsi);
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a public wrapper for the winUtf8ToMbcs() function.
|
||||
*/
|
||||
char *sqlite3_win32_utf8_to_mbcs(const char *zText){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zText ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
return winUtf8ToMbcs(zText, osAreFileApisANSI());
|
||||
}
|
||||
|
||||
/*
|
||||
** This is a public wrapper for the winUtf8ToMbcs() function.
|
||||
*/
|
||||
char *sqlite3_win32_utf8_to_mbcs_v2(const char *zText, int useAnsi){
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !zText ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
return winUtf8ToMbcs(zText, useAnsi);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1772,7 +1904,7 @@ int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
|
||||
if( zValue && zValue[0] ){
|
||||
zValueUtf8 = winUnicodeToUtf8(zValue);
|
||||
if ( zValueUtf8==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
sqlite3_free(*ppDirectory);
|
||||
@@ -1844,7 +1976,7 @@ static int winGetLastErrorMsg(DWORD lastErrno, int nBuf, char *zBuf){
|
||||
if( dwLen > 0 ){
|
||||
/* allocate a buffer and convert to UTF8 */
|
||||
sqlite3BeginBenignMalloc();
|
||||
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
|
||||
zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
|
||||
sqlite3EndBenignMalloc();
|
||||
/* free the system buffer allocated by FormatMessage */
|
||||
osLocalFree(zTemp);
|
||||
@@ -2053,7 +2185,7 @@ static int winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
zName = winUtf8ToUnicode(zFilename);
|
||||
if( zName==0 ){
|
||||
/* out of memory */
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
|
||||
/* Initialize the local lockdata */
|
||||
@@ -3244,7 +3376,7 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
|
||||
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case SQLITE_LAST_ERRNO: {
|
||||
case SQLITE_FCNTL_LAST_ERRNO: {
|
||||
*(int*)pArg = (int)pFile->lastErrno;
|
||||
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
|
||||
return SQLITE_OK;
|
||||
@@ -3602,12 +3734,12 @@ static int winOpenSharedMemory(winFile *pDbFd){
|
||||
** allocate space for a new winShmNode and filename.
|
||||
*/
|
||||
p = sqlite3MallocZero( sizeof(*p) );
|
||||
if( p==0 ) return SQLITE_IOERR_NOMEM;
|
||||
if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
|
||||
nName = sqlite3Strlen30(pDbFd->zPath);
|
||||
pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
|
||||
if( pNew==0 ){
|
||||
sqlite3_free(p);
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
pNew->zFilename = (char*)&pNew[1];
|
||||
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
|
||||
@@ -3634,7 +3766,7 @@ static int winOpenSharedMemory(winFile *pDbFd){
|
||||
|
||||
pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
|
||||
if( pShmNode->mutex==0 ){
|
||||
rc = SQLITE_IOERR_NOMEM;
|
||||
rc = SQLITE_IOERR_NOMEM_BKPT;
|
||||
goto shm_open_err;
|
||||
}
|
||||
|
||||
@@ -3939,7 +4071,7 @@ static int winShmMap(
|
||||
pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
|
||||
);
|
||||
if( !apNew ){
|
||||
rc = SQLITE_IOERR_NOMEM;
|
||||
rc = SQLITE_IOERR_NOMEM_BKPT;
|
||||
goto shmpage_out;
|
||||
}
|
||||
pShmNode->aRegion = apNew;
|
||||
@@ -3956,7 +4088,7 @@ static int winShmMap(
|
||||
hMap = osCreateFileMappingW(pShmNode->hFile.h,
|
||||
NULL, PAGE_READWRITE, 0, nByte, NULL
|
||||
);
|
||||
#elif defined(SQLITE_WIN32_HAS_ANSI)
|
||||
#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
|
||||
hMap = osCreateFileMappingA(pShmNode->hFile.h,
|
||||
NULL, PAGE_READWRITE, 0, nByte, NULL
|
||||
);
|
||||
@@ -4112,7 +4244,7 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
|
||||
pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
|
||||
(DWORD)((nMap>>32) & 0xffffffff),
|
||||
(DWORD)(nMap & 0xffffffff), NULL);
|
||||
#elif defined(SQLITE_WIN32_HAS_ANSI)
|
||||
#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
|
||||
pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect,
|
||||
(DWORD)((nMap>>32) & 0xffffffff),
|
||||
(DWORD)(nMap & 0xffffffff), NULL);
|
||||
@@ -4293,7 +4425,7 @@ static char *winConvertToUtf8Filename(const void *zFilename){
|
||||
}
|
||||
#ifdef SQLITE_WIN32_HAS_ANSI
|
||||
else{
|
||||
zConverted = sqlite3_win32_mbcs_to_utf8(zFilename);
|
||||
zConverted = winMbcsToUtf8(zFilename, osAreFileApisANSI());
|
||||
}
|
||||
#endif
|
||||
/* caller will handle out of memory */
|
||||
@@ -4314,7 +4446,7 @@ static void *winConvertFromUtf8Filename(const char *zFilename){
|
||||
}
|
||||
#ifdef SQLITE_WIN32_HAS_ANSI
|
||||
else{
|
||||
zConverted = sqlite3_win32_utf8_to_mbcs(zFilename);
|
||||
zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
|
||||
}
|
||||
#endif
|
||||
/* caller will handle out of memory */
|
||||
@@ -4369,7 +4501,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
zBuf = sqlite3MallocZero( nBuf );
|
||||
if( !zBuf ){
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
|
||||
/* Figure out the effective temporary directory. First, check if one
|
||||
@@ -4427,7 +4559,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
if( !zConverted ){
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( winIsDir(zConverted) ){
|
||||
sqlite3_snprintf(nMax, zBuf, "%s", zDir);
|
||||
@@ -4440,7 +4572,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
if( !zConverted ){
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( cygwin_conv_path(
|
||||
osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
|
||||
@@ -4461,7 +4593,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
sqlite3_free(zConverted);
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
|
||||
sqlite3_free(zUtf8);
|
||||
@@ -4479,7 +4611,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
if( !zWidePath ){
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( osGetTempPathW(nMax, zWidePath)==0 ){
|
||||
sqlite3_free(zWidePath);
|
||||
@@ -4497,7 +4629,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
sqlite3_free(zWidePath);
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
#ifdef SQLITE_WIN32_HAS_ANSI
|
||||
@@ -4507,7 +4639,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
if( !zMbcsPath ){
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( osGetTempPathA(nMax, zMbcsPath)==0 ){
|
||||
sqlite3_free(zBuf);
|
||||
@@ -4515,14 +4647,14 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
|
||||
"winGetTempname3", 0);
|
||||
}
|
||||
zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
|
||||
zUtf8 = winMbcsToUtf8(zMbcsPath, osAreFileApisANSI());
|
||||
if( zUtf8 ){
|
||||
sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
|
||||
sqlite3_free(zUtf8);
|
||||
}else{
|
||||
sqlite3_free(zBuf);
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_WIN32_HAS_ANSI */
|
||||
@@ -4714,7 +4846,7 @@ static int winOpen(
|
||||
if( zConverted==0 ){
|
||||
sqlite3_free(zTmpname);
|
||||
OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8Name));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
|
||||
if( winIsDir(zConverted) ){
|
||||
@@ -4914,7 +5046,7 @@ static int winDelete(
|
||||
zConverted = winConvertFromUtf8Filename(zFilename);
|
||||
if( zConverted==0 ){
|
||||
OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( osIsNT() ){
|
||||
do {
|
||||
@@ -5022,7 +5154,7 @@ static int winAccess(
|
||||
zConverted = winConvertFromUtf8Filename(zFilename);
|
||||
if( zConverted==0 ){
|
||||
OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( osIsNT() ){
|
||||
int cnt = 0;
|
||||
@@ -5149,7 +5281,7 @@ static int winFullPathname(
|
||||
*/
|
||||
char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
|
||||
if( !zOut ){
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( cygwin_conv_path(
|
||||
(osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
|
||||
@@ -5161,7 +5293,7 @@ static int winFullPathname(
|
||||
char *zUtf8 = winConvertToUtf8Filename(zOut);
|
||||
if( !zUtf8 ){
|
||||
sqlite3_free(zOut);
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
|
||||
sqlite3_data_directory, winGetDirSep(), zUtf8);
|
||||
@@ -5171,7 +5303,7 @@ static int winFullPathname(
|
||||
}else{
|
||||
char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
|
||||
if( !zOut ){
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( cygwin_conv_path(
|
||||
(osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A),
|
||||
@@ -5183,7 +5315,7 @@ static int winFullPathname(
|
||||
char *zUtf8 = winConvertToUtf8Filename(zOut);
|
||||
if( !zUtf8 ){
|
||||
sqlite3_free(zOut);
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
|
||||
sqlite3_free(zUtf8);
|
||||
@@ -5243,7 +5375,7 @@ static int winFullPathname(
|
||||
}
|
||||
zConverted = winConvertFromUtf8Filename(zRelative);
|
||||
if( zConverted==0 ){
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
if( osIsNT() ){
|
||||
LPWSTR zTemp;
|
||||
@@ -5257,7 +5389,7 @@ static int winFullPathname(
|
||||
zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
|
||||
if( zTemp==0 ){
|
||||
sqlite3_free(zConverted);
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
|
||||
if( nByte==0 ){
|
||||
@@ -5283,7 +5415,7 @@ static int winFullPathname(
|
||||
zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
|
||||
if( zTemp==0 ){
|
||||
sqlite3_free(zConverted);
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
|
||||
if( nByte==0 ){
|
||||
@@ -5293,7 +5425,7 @@ static int winFullPathname(
|
||||
"winFullPathname4", zRelative);
|
||||
}
|
||||
sqlite3_free(zConverted);
|
||||
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
|
||||
zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
|
||||
sqlite3_free(zTemp);
|
||||
}
|
||||
#endif
|
||||
@@ -5302,7 +5434,7 @@ static int winFullPathname(
|
||||
sqlite3_free(zOut);
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -5377,65 +5509,85 @@ static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
|
||||
#define winDlClose 0
|
||||
#endif
|
||||
|
||||
/* State information for the randomness gatherer. */
|
||||
typedef struct EntropyGatherer EntropyGatherer;
|
||||
struct EntropyGatherer {
|
||||
unsigned char *a; /* Gather entropy into this buffer */
|
||||
int na; /* Size of a[] in bytes */
|
||||
int i; /* XOR next input into a[i] */
|
||||
int nXor; /* Number of XOR operations done */
|
||||
};
|
||||
|
||||
#if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
|
||||
/* Mix sz bytes of entropy into p. */
|
||||
static void xorMemory(EntropyGatherer *p, unsigned char *x, int sz){
|
||||
int j, k;
|
||||
for(j=0, k=p->i; j<sz; j++){
|
||||
p->a[k++] ^= x[j];
|
||||
if( k>=p->na ) k = 0;
|
||||
}
|
||||
p->i = k;
|
||||
p->nXor += sz;
|
||||
}
|
||||
#endif /* !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) */
|
||||
|
||||
/*
|
||||
** Write up to nBuf bytes of randomness into zBuf.
|
||||
*/
|
||||
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
||||
int n = 0;
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
#if defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
|
||||
n = nBuf;
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
memset(zBuf, 0, nBuf);
|
||||
return nBuf;
|
||||
#else
|
||||
if( sizeof(SYSTEMTIME)<=nBuf-n ){
|
||||
EntropyGatherer e;
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
memset(zBuf, 0, nBuf);
|
||||
#if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
|
||||
rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
|
||||
#endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
|
||||
e.a = (unsigned char*)zBuf;
|
||||
e.na = nBuf;
|
||||
e.nXor = 0;
|
||||
e.i = 0;
|
||||
{
|
||||
SYSTEMTIME x;
|
||||
osGetSystemTime(&x);
|
||||
memcpy(&zBuf[n], &x, sizeof(x));
|
||||
n += sizeof(x);
|
||||
xorMemory(&e, (unsigned char*)&x, sizeof(SYSTEMTIME));
|
||||
}
|
||||
if( sizeof(DWORD)<=nBuf-n ){
|
||||
{
|
||||
DWORD pid = osGetCurrentProcessId();
|
||||
memcpy(&zBuf[n], &pid, sizeof(pid));
|
||||
n += sizeof(pid);
|
||||
xorMemory(&e, (unsigned char*)&pid, sizeof(DWORD));
|
||||
}
|
||||
#if SQLITE_OS_WINRT
|
||||
if( sizeof(ULONGLONG)<=nBuf-n ){
|
||||
{
|
||||
ULONGLONG cnt = osGetTickCount64();
|
||||
memcpy(&zBuf[n], &cnt, sizeof(cnt));
|
||||
n += sizeof(cnt);
|
||||
xorMemory(&e, (unsigned char*)&cnt, sizeof(ULONGLONG));
|
||||
}
|
||||
#else
|
||||
if( sizeof(DWORD)<=nBuf-n ){
|
||||
{
|
||||
DWORD cnt = osGetTickCount();
|
||||
memcpy(&zBuf[n], &cnt, sizeof(cnt));
|
||||
n += sizeof(cnt);
|
||||
xorMemory(&e, (unsigned char*)&cnt, sizeof(DWORD));
|
||||
}
|
||||
#endif
|
||||
if( sizeof(LARGE_INTEGER)<=nBuf-n ){
|
||||
#endif /* SQLITE_OS_WINRT */
|
||||
{
|
||||
LARGE_INTEGER i;
|
||||
osQueryPerformanceCounter(&i);
|
||||
memcpy(&zBuf[n], &i, sizeof(i));
|
||||
n += sizeof(i);
|
||||
xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER));
|
||||
}
|
||||
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
|
||||
if( sizeof(UUID)<=nBuf-n ){
|
||||
{
|
||||
UUID id;
|
||||
memset(&id, 0, sizeof(UUID));
|
||||
osUuidCreate(&id);
|
||||
memcpy(&zBuf[n], &id, sizeof(UUID));
|
||||
n += sizeof(UUID);
|
||||
}
|
||||
if( sizeof(UUID)<=nBuf-n ){
|
||||
UUID id;
|
||||
xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
|
||||
memset(&id, 0, sizeof(UUID));
|
||||
osUuidCreateSequential(&id);
|
||||
memcpy(&zBuf[n], &id, sizeof(UUID));
|
||||
n += sizeof(UUID);
|
||||
xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
|
||||
}
|
||||
#endif
|
||||
#endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
|
||||
return n;
|
||||
#endif /* !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID */
|
||||
return e.nXor>nBuf ? nBuf : e.nXor;
|
||||
#endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
|
||||
}
|
||||
|
||||
|
||||
@@ -5551,8 +5703,10 @@ static int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
|
||||
** sqlite3_errmsg(), possibly making IO errors easier to debug.
|
||||
*/
|
||||
static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
||||
DWORD e = osGetLastError();
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
return winGetLastErrorMsg(osGetLastError(), nBuf, zBuf);
|
||||
if( nBuf>0 ) winGetLastErrorMsg(e, nBuf, zBuf);
|
||||
return e;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user