From: drh Date: Wed, 2 Mar 2011 18:01:10 +0000 (+0000) Subject: Add more system calls to the set that can be overridden in os_unix.c. X-Git-Tag: version-3.7.6~112^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e562be52cf0dae1e3e3f204159860001abdd03d1;p=thirdparty%2Fsqlite.git Add more system calls to the set that can be overridden in os_unix.c. Also merge in recent fixes from trunk. FossilOrigin-Name: 80fac2a6e07221bb67613af84ab9dda3e18b5ceb --- e562be52cf0dae1e3e3f204159860001abdd03d1 diff --cc manifest index db71d0c060,7bf2741a7b..8febb8aa67 --- a/manifest +++ b/manifest @@@ -1,8 -1,8 +1,8 @@@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 - C Proof-of-concept\sprototype\sfor\sthe\sproposed\sxSetSystemCall\sextension\smethod\non\sthe\sVFS. - D 2011-03-02T15:09:07.461 -C Fix\sbugs\sin\s[7b6e30e6a7]\sthat\sonly\sshow\sup\son\sMac. -D 2011-03-02T17:54:32.411 ++C Add\smore\ssystem\scalls\sto\sthe\sset\sthat\scan\sbe\soverridden\sin\sos_unix.c.\nAlso\smerge\sin\srecent\sfixes\sfrom\strunk. ++D 2011-03-02T18:01:10.609 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@@ -164,8 -165,8 +165,8 @@@ F src/os.c 22ac61d06e72a0dac90040014733 F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 2e452c9f2ca507623ad351c33a8a8b27849b1863 - F src/os_unix.c 34f0341ab45ba2708714c8e3f7bd35c7ccb5e34d -F src/os_unix.c 54cd8b64e342984cb9a565d8bbd3d4ed4f6679ad -F src/os_win.c 9abdcdd925416d854eabb0996c96debd92abfef5 ++F src/os_unix.c a13aa2394c337a51f818b33e8abb5922bcd25cbb +F src/os_win.c c2df806a8510ec8c2c2c30fb78b3a25bc1b2f325 F src/pager.c 6aa906b60a59664ba58d3f746164bb010d407ce1 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 @@@ -912,18 -913,14 +913,14 @@@ F tool/speedtest2.tcl ee2149167303ba8e9 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f - P 7b6e30e6a712311d4ef275253b085b85e6e17116 - R b432d469c6ed4dca97f566fa093fcbff - T *bgcolor * #a8d3c0 - T *branch * syscall-override - T *sym-syscall-override * - T -sym-trunk * -P 24602557fc3295fe2836d269175f12ec680ac011 -R e01d9f9e8e2dad85147f5fc5ffb976eb ++P 92b5a76abc53290e1bb87b6b55bc64bb1b331dfc ec55e8c6bb4f2419b3813aa2fd1a20d8f5016159 ++R 3565d6dc7b759fbd44b8dfd37d76ad07 U drh - Z 9b09403dc20dd3b2e37d470a4feaa93c -Z c84f9d0b8eefba981fbaf57340fff3b5 ++Z d880c71a14ae5250c2798782141ecbce -----BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.10 (Darwin) +Version: GnuPG v1.4.6 (GNU/Linux) - iD8DBQFNbl2aoxKgR168RlERAnuDAJ9BNtRHzGqMMOlHR9sjdCvks/uYWQCgiUgt - CkJFrHO5mCcgtbaMpvVY+k0= - =K2zl -iEYEARECAAYFAk1uhFgACgkQoxKgR168RlFREQCfT9Vnfu+FKv7ziCX9Y4ICLtOr -MgsAnjKkrrgDNYH+MAY+dZUejwVsARq0 -=k7I4 ++iD8DBQFNboXpoxKgR168RlERAi5qAJ48oWmqxPjfRV4pFj4iAbQCs6u9fQCeNLi2 ++M/sSIPhA4/GCd6qHTyrGyKQ= ++=Ttvh -----END PGP SIGNATURE----- diff --cc manifest.uuid index ee6de5d921,eb42b9f72d..3647910982 --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - 92b5a76abc53290e1bb87b6b55bc64bb1b331dfc -ec55e8c6bb4f2419b3813aa2fd1a20d8f5016159 ++80fac2a6e07221bb67613af84ab9dda3e18b5ceb diff --cc src/os_unix.c index d2263addc6,40e4b89cd6..18ec658701 --- a/src/os_unix.c +++ b/src/os_unix.c @@@ -313,59 -277,18 +313,106 @@@ static struct unix_syscall ** DJGPP. But it is DOS - what did you expect? */ #ifdef __DJGPP__ -# define fcntl(A,B,C) 0 + { "fstat", 0, 0 }, +#define osFstat(a,b,c) 0 +#else + { "fstat", (void*)fstat, 0 }, +#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent) #endif -/* -** The threadid macro resolves to the thread-id or to 0. Used for -** testing and debugging only. -*/ -#if SQLITE_THREADSAFE -#define threadid pthread_self() + { "ftruncate", (void*)ftruncate, 0 }, +#define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent) + - { "fcntl", (void*)fcntl, 0 }, ++ { "fcntl", (void*)fcntl, 0 }, +#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) - }; ++ ++ { "read", (void*)read, 0 }, ++#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) ++ ++#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE) ++ { "pread", (void*)pread, 0 }, + #else -#define threadid 0 ++ { "pread", (void*)0, 0 }, ++#endif ++#define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) ++ ++#if defined(USE_PREAD64) ++ { "pread64", (void*)pread64, 0 }, ++#else ++ { "pread64", (void*)0, 0 }, + #endif ++#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) ++ ++ { "write", (void*)write, 0 }, ++#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) ++ ++#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE) ++ { "pwrite", (void*)pwrite, 0 }, ++#else ++ { "pwrite", (void*)0, 0 }, ++#endif ++#define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ ++ aSyscall[12].pCurrent) ++ ++#if defined(USE_PREAD64) ++ { "pwrite64", (void*)pwrite64, 0 }, ++#else ++ { "pwrite64", (void*)0, 0 }, ++#endif ++#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ ++ aSyscall[13].pCurrent) ++ ++ { "fchmod", (void*)fchmod, 0 }, ++#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) ++ ++#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE ++ { "fallocate", (void*)posix_fallocate, 0 }, ++#else ++ { "fallocate", (void*)0, 0 }, ++#endif ++#define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent) ++ ++}; /* End of the overrideable system calls */ + +/* +** This is the xSetSystemCall() method of sqlite3_vfs for all of the +** "unix" VFSes. +*/ +static int unixSetSystemCall( + sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ + const char *zName, /* Name of system call to override */ + void *pNewFunc /* Pointer to new system call value */ +){ + int i; + int rc = 0; + if( zName==0 ){ + /* If no zName is given, restore all system calls to their default + ** settings and return NULL + */ + for(i=0; ifsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){ -- do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR ); ++ do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR ); if( rc!=1 ){ pFile->lastErrno = errno; return SQLITE_IOERR; @@@ -2783,10 -2705,10 +2830,10 @@@ static int seekAndRead(unixFile *id, sq #endif TIMER_START; #if defined(USE_PREAD) -- do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); ++ do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); SimulateIOError( got = -1 ); #elif defined(USE_PREAD64) -- do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); ++ do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR); SimulateIOError( got = -1 ); #else newOffset = lseek(id->h, offset, SEEK_SET); @@@ -2799,7 -2721,7 +2846,7 @@@ } return -1; } -- do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); ++ do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); #endif TIMER_END; if( got<0 ){ @@@ -2861,9 -2783,9 +2908,9 @@@ static int seekAndWrite(unixFile *id, i #endif TIMER_START; #if defined(USE_PREAD) -- do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); ++ do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); #elif defined(USE_PREAD64) -- do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); ++ do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR); #else newOffset = lseek(id->h, offset, SEEK_SET); if( newOffset!=offset ){ @@@ -2874,7 -2796,7 +2921,7 @@@ } return -1; } -- do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); ++ do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); #endif TIMER_END; if( got<0 ){ @@@ -3237,7 -3159,7 +3284,7 @@@ static int fcntlSizeHint(unixFile *pFil #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE int rc; do{ -- rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size; ++ rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size; }while( rc<0 && errno=EINTR ); if( rc ) return SQLITE_IOERR_WRITE; #else @@@ -5115,7 -5037,7 +5162,7 @@@ static int unixRandomness(sqlite3_vfs * assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); nBuf = sizeof(t) + sizeof(pid); }else{ -- do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); ++ do{ nBuf = osRead(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); robust_close(0, fd, __LINE__); } } @@@ -5638,7 -5560,7 +5685,7 @@@ static int proxyBreakConchLock(unixFil goto end_breaklock; } /* read the conch content */ -- readLen = pread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0); ++ readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0); if( readLenh, tBuf, PROXY_MAXCONCHLEN, 0); ++ int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0); if( len<0 ){ pFile->lastErrno = errno; return SQLITE_IOERR_LOCK; @@@ -5884,17 -5806,16 +5931,16 @@@ static int proxyTakeConch(unixFile *pFi */ if( rc==SQLITE_OK && createConch ){ struct stat buf; - int rc; - int err = fstat(pFile->h, &buf); + int err = osFstat(pFile->h, &buf); if( err==0 ){ mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | S_IROTH|S_IWOTH); /* try to match the database file R/W permissions, ignore failure */ #ifndef SQLITE_PROXY_DEBUG -- fchmod(conchFile->h, cmode); ++ osFchmod(conchFile->h, cmode); #else do{ -- rc = fchmod(conchFile->h, cmode); ++ rc = osFchmod(conchFile->h, cmode); }while( rc==(-1) && errno==EINTR ); if( rc!=0 ){ int code = errno; @@@ -5917,10 -5838,10 +5963,10 @@@ OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h)); if( rc==SQLITE_OK && pFile->openFlags ){ if( pFile->h>=0 ){ - robust_close(pFile, pFile->h, __LINE__) ){ + robust_close(pFile, pFile->h, __LINE__); } pFile->h = -1; - int fd = open(pCtx->dbPath, pFile->openFlags, + int fd = osOpen(pCtx->dbPath, pFile->openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS); OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); if( fd>=0 ){