diff --git a/src/sqlite3.c b/src/sqlite3.c index a610bf7e85d621c9f6b1172d96ddd474780f5b3d..35ee1bd614a47cb39253fcf405ed94a52bfe26c9 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -37138,7 +37138,24 @@ static pid_t randomnessPid = 0; ** which always has the same well-defined interface. */ static int posixOpen(const char *zFile, int flags, int mode){ - return open(zFile, flags, mode); + int fd = open(zFile, flags, mode); +#ifdef FDSAN_ENABLE + if ( fd > 0 && fdsan_get_owner_tag(fd) == 0 ) { + fdsan_exchange_owner_tag(fd, 0, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); + } +#endif + return fd; +} + +/* +** Change close to posixClose, use fdsan_close_with_tag when fdsan enable. +*/ +static int posixClose(int fd) { +#ifdef FDSAN_ENABLE + return fdsan_close_with_tag(fd, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); +#else + return close(fd); +#endif } /* Forward reference */ @@ -37159,7 +37176,7 @@ static struct unix_syscall { { "open", (sqlite3_syscall_ptr)posixOpen, 0 }, #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent) - { "close", (sqlite3_syscall_ptr)close, 0 }, + { "close", (sqlite3_syscall_ptr)posixClose, 0 }, #define osClose ((int(*)(int))aSyscall[1].pCurrent) { "access", (sqlite3_syscall_ptr)access, 0 }, @@ -37455,20 +37472,11 @@ static int robust_open(const char *z, int f, mode_t m){ if( errno==EINTR ) continue; break; } -#ifdef FDSAN_ENABLE - if( fdsan_get_owner_tag(fd)==0 ){ - fdsan_exchange_owner_tag(fd, 0, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); - } -#endif if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; if( (f & (O_EXCL|O_CREAT))==(O_EXCL|O_CREAT) ){ (void)osUnlink(z); } -#ifdef FDSAN_ENABLE - fdsan_close_with_tag(fd, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); -#else osClose(fd); -#endif sqlite3_log(SQLITE_WARNING, "attempt to open \"%s\" as file descriptor %d", z, fd); fd = -1; @@ -38067,13 +38075,7 @@ static int unixLogErrorAtLine( ** and move on. */ static void robust_close(unixFile *pFile, int h, int lineno){ - int rc; -#ifdef FDSAN_ENABLE - rc = fdsan_close_with_tag(h, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); -#else - rc = osClose(h); -#endif - if( rc ){ + if( osClose(h) ){ unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close", pFile ? pFile->zPath : 0, lineno); } @@ -40192,21 +40194,18 @@ static int unixRead( case EDEVERR: #endif #ifdef LOG_DUMP - sqlite3_log(SQLITE_IOERR_CORRUPTFS, "unixRead-EDEVERR, fd: [%d], amt[%d], got[%d], offset[%lld]", pFile->h, amt, got, offset); + sqlite3_log(SQLITE_IOERR_CORRUPTFS, "unixRead-EDEVERR, fd:[%d], amt[%d], got[%d], offset[%lld]", pFile->h, amt, got, offset); #endif return SQLITE_IOERR_CORRUPTFS; } #ifdef LOG_DUMP - sqlite3_log(SQLITE_IOERR_READ, "unixRead-got<0, fd: [%d], amt[%d], got[%d], offset[%lld]", pFile->h, amt, got, offset); + sqlite3_log(SQLITE_IOERR_READ, "unixRead-got<0, fd: [%d], amt[%d], got[%d], offset[%lld]", pFile->h, amt, got, offset); #endif return SQLITE_IOERR_READ; }else{ storeLastErrno(pFile, 0); /* not a system error */ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[got], 0, amt-got); -#ifdef LOG_DUMP - sqlite3_log(SQLITE_IOERR_SHORT_READ, "unixRead-got>=0, fd: [%d], amt[%d], got[%d], offset[%lld]", pFile->h, amt, got, offset); -#endif return SQLITE_IOERR_SHORT_READ; } } @@ -40595,12 +40594,6 @@ static int unixSync(sqlite3_file *id, int flags){ HAVE_FULLFSYNC, isFullsync)); rc = osOpenDirectory(pFile->zPath, &dirfd); if( rc==SQLITE_OK ){ -#ifdef FDSAN_ENABLE - // FDSAN_OWNER_TYPE_FILE is used because files and directories are not distinguished. - if( fdsan_get_owner_tag(dirfd)==0 ){ - fdsan_exchange_owner_tag(dirfd, 0, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); - } -#endif full_fsync(dirfd, 0, 0); robust_close(pFile, dirfd, __LINE__); }else{ @@ -40726,14 +40719,14 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){ if( err && err!=EINVAL ){ #ifdef LOG_DUMP sqlite3_log(SQLITE_IOERR_WRITE, - "fcntlSizeHint-fallocate, fd[%d], bufSize[%lld], nSize[%lld] err[%d]", - pFile->h, - buf.st_size, - nSize, - err); + "fcntlSizeHint-fallocate, fd[%d], bufSize[%lld], nSize[%lld] err[%d]", + pFile->h, + buf.st_size, + nSize, + err); #endif - return SQLITE_IOERR_WRITE; - } + return SQLITE_IOERR_WRITE; + } #else /* If the OS does not have posix_fallocate(), fake it. Write a ** single byte to the last byte in each block that falls entirely @@ -43266,12 +43259,6 @@ static int unixDelete( int fd; rc = osOpenDirectory(zPath, &fd); if( rc==SQLITE_OK ){ -#ifdef FDSAN_ENABLE - // FDSAN_OWNER_TYPE_FILE is used because files and directories are not distinguished. - if( fdsan_get_owner_tag(fd)==0 ){ - fdsan_exchange_owner_tag(fd, 0, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, SQLITE_FDSAN_TAG)); - } -#endif if( full_fsync(fd,0,0) ){ rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); } @@ -44215,7 +44202,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){ if( len<0 ){ storeLastErrno(pFile, errno); #ifdef LOG_DUMP - sqlite3_log(SQLITE_IOERR_LOCK, "proxyConchLock tries 2, pFile fd[%d], conchFile fd[%d], lastErrno[%d]", pFile->h, conchFile->h, errno); + sqlite3_log(SQLITE_IOERR_LOCK, "proxyConchLock tries 2, pFile fd[%d], conchFile fd[%d], lastErrno[%d]", pFile->h, conchFile->h, errno); #endif return SQLITE_IOERR_LOCK; } @@ -44292,7 +44279,7 @@ static int proxyTakeConch(unixFile *pFile){ /* I/O error: lastErrno set by seekAndRead */ storeLastErrno(pFile, conchFile->lastErrno); #ifdef LOG_DUMP - sqlite3_log(SQLITE_IOERR_READ, "proxyTakeConch fd:[%d], pFile fd[%d], conchFile fd[%d], lastErrno[%d]", pFile->h, conchFile->h, conchFile->lastErrno); + sqlite3_log(SQLITE_IOERR_READ, "proxyTakeConch pFile fd[%d], conchFile fd[%d], lastErrno[%d]", pFile->h, conchFile->h, conchFile->lastErrno); #endif rc = SQLITE_IOERR_READ; goto end_takeconch; @@ -67316,12 +67303,12 @@ SQLITE_PRIVATE int sqlite3WalCheckpoint( } #ifdef LOG_DUMP sqlite3_log(SQLITE_NOTICE, - "checkpoint res[%d], szPage[%u], minFrame[%u], readOnly[%u], exclusiveMode[%d]", - rc, - pWal->szPage, - pWal->minFrame, - pWal->readOnly, - pWal->exclusiveMode); + "checkpoint res[%d], szPage[%u], minFrame[%u], readOnly[%u], exclusiveMode[%d]", + rc, + pWal->szPage, + pWal->minFrame, + pWal->readOnly, + pWal->exclusiveMode); #endif WALTRACE(("WAL%p: checkpoint %s\n", pWal, rc ? "failed" : "ok")); #ifdef SQLITE_ENABLE_SETLK_TIMEOUT