/ Check-in [38558363]
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:Add additional VFS methods to retrieve system call pointers and to get a list of all changeable system calls.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | syscall-override
Files: files | file ages | folders
SHA1: 38558363494e3a736dcb091dd859e76b7ccd78b0
User & Date: drh 2011-03-02 19:06:42
Context
2011-03-04
15:43
Handle EINTR errors from open(). Closed-Leaf check-in: a7d176b2 user: drh tags: syscall-override
2011-03-02
19:06
Add additional VFS methods to retrieve system call pointers and to get a list of all changeable system calls. check-in: 38558363 user: drh tags: syscall-override
18:01
Add more system calls to the set that can be overridden in os_unix.c. Also merge in recent fixes from trunk. check-in: 80fac2a6 user: drh tags: syscall-override
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   372    372   #endif
   373    373   #define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent)
   374    374   
   375    375   }; /* End of the overrideable system calls */
   376    376   
   377    377   /*
   378    378   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   379         -** "unix" VFSes.
          379  +** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
          380  +** system call pointer, or SQLITE_NOTFOUND if there is no configurable
          381  +** system call named zName.
   380    382   */
   381    383   static int unixSetSystemCall(
   382    384     sqlite3_vfs *pNotUsed,     /* The VFS pointer.  Not used */
   383    385     const char *zName,         /* Name of system call to override */
   384    386     void *pNewFunc             /* Pointer to new system call value */
   385    387   ){
   386    388     int i;
   387         -  int rc = 0;
          389  +  int rc = SQLITE_NOTFOUND;
   388    390     if( zName==0 ){
   389    391       /* If no zName is given, restore all system calls to their default
   390    392       ** settings and return NULL
   391    393       */
   392    394       for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
   393    395         if( aSyscall[i].pDefault ){
   394    396           aSyscall[i].pCurrent = aSyscall[i].pDefault;
   395         -        rc = 1;
          397  +        rc = SQLITE_OK;
   396    398         }
   397    399       }
   398    400     }else{
   399    401       /* If zName is specified, operate on only the one system call
   400    402       ** specified.
   401    403       */
   402    404       for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
   403    405         if( strcmp(zName, aSyscall[i].zName)==0 ){
   404    406           if( aSyscall[i].pDefault==0 ){
   405    407             aSyscall[i].pDefault = aSyscall[i].pCurrent;
   406    408           }
   407         -        rc = 1;
          409  +        rc = SQLITE_OK;
   408    410           if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
   409    411           aSyscall[i].pCurrent = pNewFunc;
   410    412           break;
   411    413         }
   412    414       }
   413    415     }
   414    416     return rc;
   415    417   }
          418  +
          419  +/*
          420  +** Return the value of a system call.  Return NULL if zName is not a
          421  +** recognized system call name.  NULL is also returned if the system call
          422  +** is currently undefined.
          423  +*/
          424  +static void *unixGetSystemCall(sqlite3_vfs *pNotUsed, const char *zName){
          425  +  int i;
          426  +  for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          427  +    if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
          428  +  }
          429  +  return 0;
          430  +}
          431  +
          432  +/*
          433  +** Return the name of the first system call after zName.  If zName==NULL
          434  +** then return the name of the first system call.  Return NULL if zName
          435  +** is the last system call or if zName is not the name of a valid
          436  +** system call.
          437  +*/
          438  +static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
          439  +  int i;
          440  +  if( zName==0 ){
          441  +    i = -1;
          442  +  }else{
          443  +    for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){
          444  +      if( strcmp(zName, aSyscall[0].zName)==0 ) break;
          445  +    }
          446  +  }
          447  +  for(i++; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          448  +    if( aSyscall[0].pCurrent!=0 ) return aSyscall[0].zName;
          449  +  }
          450  +  return 0;
          451  +}
   416    452   
   417    453   
   418    454   /*
   419    455   ** Helper functions to obtain and relinquish the global mutex. The
   420    456   ** global mutex is used to protect the unixInodeInfo and
   421    457   ** vxworksFileId objects used by this file, all of which may be 
   422    458   ** shared by multiple threads.
................................................................................
  6493   6529       unixDlClose,          /* xDlClose */                    \
  6494   6530       unixRandomness,       /* xRandomness */                 \
  6495   6531       unixSleep,            /* xSleep */                      \
  6496   6532       unixCurrentTime,      /* xCurrentTime */                \
  6497   6533       unixGetLastError,     /* xGetLastError */               \
  6498   6534       unixCurrentTimeInt64, /* xCurrentTimeInt64 */           \
  6499   6535       unixSetSystemCall,    /* xSetSystemCall */              \
         6536  +    unixGetSystemCall,    /* xGetSystemCall */              \
         6537  +    unixNextSystemCall,   /* xNextSystemCall */             \
  6500   6538     }
  6501   6539   
  6502   6540     /*
  6503   6541     ** All default VFSes for unix are contained in the following array.
  6504   6542     **
  6505   6543     ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
  6506   6544     ** by the SQLite core when the VFS is registered.  So the following

Changes to src/os_win.c.

  2762   2762       winDlClose,          /* xDlClose */
  2763   2763       winRandomness,       /* xRandomness */
  2764   2764       winSleep,            /* xSleep */
  2765   2765       winCurrentTime,      /* xCurrentTime */
  2766   2766       winGetLastError,     /* xGetLastError */
  2767   2767       winCurrentTimeInt64, /* xCurrentTimeInt64 */
  2768   2768       0,                   /* xSetSystemCall */
         2769  +    0,                   /* xGetSystemCall */
         2770  +    0,                   /* xNextSystemCall */
  2769   2771     };
  2770   2772   
  2771   2773   #ifndef SQLITE_OMIT_WAL
  2772   2774     /* get memory map allocation granularity */
  2773   2775     memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  2774   2776     GetSystemInfo(&winSysInfo);
  2775   2777     assert(winSysInfo.dwAllocationGranularity > 0);

Changes to src/sqlite.h.in.

   921    921     */
   922    922     int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
   923    923     /*
   924    924     ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
   925    925     ** Those below are for version 3 and greater.
   926    926     */
   927    927     int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, void *pFunc);
          928  +  void *(*xGetSystemCall)(sqlite3_vfs*, const char *zName);
          929  +  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
   928    930     /*
   929    931     ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
   930    932     ** New fields may be appended in figure versions.  The iVersion
   931    933     ** value will increment whenever this happens. 
   932    934     */
   933    935   };
   934    936