OLD | NEW |
1 /* | 1 /* |
2 ** 2011 March 28 | 2 ** 2011 March 28 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
11 ************************************************************************* | 11 ************************************************************************* |
12 ** | 12 ** |
13 ** The code in this file implements a Tcl interface used to test error | 13 ** The code in this file implements a Tcl interface used to test error |
14 ** handling in the os_unix.c module. Wrapper functions that support fault | 14 ** handling in the os_unix.c module. Wrapper functions that support fault |
15 ** injection are registered as the low-level OS functions using the | 15 ** injection are registered as the low-level OS functions using the |
16 ** xSetSystemCall() method of the VFS. The Tcl interface is as follows: | 16 ** xSetSystemCall() method of the VFS. The Tcl interface is as follows: |
17 ** | 17 ** |
18 ** | 18 ** |
19 ** test_syscall install LIST | 19 ** test_syscall install LIST |
20 ** Install wrapper functions for all system calls in argument LIST. | 20 ** Install wrapper functions for all system calls in argument LIST. |
21 ** LIST must be a list consisting of zero or more of the following | 21 ** LIST must be a list consisting of zero or more of the following |
22 ** literal values: | 22 ** literal values: |
23 ** | 23 ** |
24 ** open close access getcwd stat fstat | 24 ** open close access getcwd stat fstat |
25 ** ftruncate fcntl read pread pread64 write | 25 ** ftruncate fcntl read pread pread64 write |
26 ** pwrite pwrite64 fchmod fallocate | 26 ** pwrite pwrite64 fchmod fallocate mmap |
27 ** | 27 ** |
28 ** test_syscall uninstall | 28 ** test_syscall uninstall |
29 ** Uninstall all wrapper functions. | 29 ** Uninstall all wrapper functions. |
30 ** | 30 ** |
31 ** test_syscall fault ?COUNT PERSIST? | 31 ** test_syscall fault ?COUNT PERSIST? |
32 ** If [test_syscall fault] is invoked without the two arguments, fault | 32 ** If [test_syscall fault] is invoked without the two arguments, fault |
33 ** injection is disabled. Otherwise, fault injection is configured to | 33 ** injection is disabled. Otherwise, fault injection is configured to |
34 ** cause a failure on the COUNT'th next call to a system call with a | 34 ** cause a failure on the COUNT'th next call to a system call with a |
35 ** wrapper function installed. A COUNT value of 1 means fail the next | 35 ** wrapper function installed. A COUNT value of 1 means fail the next |
36 ** system call. | 36 ** system call. |
(...skipping 23 matching lines...) Expand all Loading... |
60 ** | 60 ** |
61 ** With an argument, this command attempts to reset the system call named | 61 ** With an argument, this command attempts to reset the system call named |
62 ** by the parameter using the same method as [uninstall]. | 62 ** by the parameter using the same method as [uninstall]. |
63 ** | 63 ** |
64 ** test_syscall exists SYSTEM-CALL | 64 ** test_syscall exists SYSTEM-CALL |
65 ** Return true if the named system call exists. Or false otherwise. | 65 ** Return true if the named system call exists. Or false otherwise. |
66 ** | 66 ** |
67 ** test_syscall list | 67 ** test_syscall list |
68 ** Return a list of all system calls. The list is constructed using | 68 ** Return a list of all system calls. The list is constructed using |
69 ** the xNextSystemCall() VFS method. | 69 ** the xNextSystemCall() VFS method. |
| 70 ** |
| 71 ** test_syscall pagesize PGSZ |
| 72 ** If PGSZ is a power of two greater than 256, install a wrapper around |
| 73 ** OS function getpagesize() that reports the system page size as PGSZ. |
| 74 ** Or, if PGSZ is less than zero, remove any wrapper already installed. |
70 */ | 75 */ |
71 | 76 |
| 77 #include "sqliteInt.h" |
72 #include "sqlite3.h" | 78 #include "sqlite3.h" |
73 #include "tcl.h" | 79 #include "tcl.h" |
74 #include <stdlib.h> | 80 #include <stdlib.h> |
75 #include <string.h> | 81 #include <string.h> |
76 #include <assert.h> | 82 #include <assert.h> |
77 | 83 |
78 #include "sqliteInt.h" | |
79 #if SQLITE_OS_UNIX | 84 #if SQLITE_OS_UNIX |
80 | 85 |
81 /* From test1.c */ | 86 /* From main.c */ |
82 extern const char *sqlite3TestErrorName(int); | 87 extern const char *sqlite3ErrName(int); |
83 | 88 |
| 89 #include <sys/mman.h> |
84 #include <sys/types.h> | 90 #include <sys/types.h> |
85 #include <errno.h> | 91 #include <errno.h> |
86 | 92 |
87 static struct TestSyscallGlobal { | 93 static struct TestSyscallGlobal { |
88 int bPersist; /* 1 for persistent errors, 0 for transient */ | 94 int bPersist; /* 1 for persistent errors, 0 for transient */ |
89 int nCount; /* Fail after this many more calls */ | 95 int nCount; /* Fail after this many more calls */ |
90 int nFail; /* Number of failures that have occurred */ | 96 int nFail; /* Number of failures that have occurred */ |
91 } gSyscall = { 0, 0 }; | 97 int pgsz; |
| 98 sqlite3_syscall_ptr orig_getpagesize; |
| 99 } gSyscall = { 0, 0, 0, 0, 0 }; |
92 | 100 |
93 static int ts_open(const char *, int, int); | 101 static int ts_open(const char *, int, int); |
94 static int ts_close(int fd); | 102 static int ts_close(int fd); |
95 static int ts_access(const char *zPath, int mode); | 103 static int ts_access(const char *zPath, int mode); |
96 static char *ts_getcwd(char *zPath, size_t nPath); | 104 static char *ts_getcwd(char *zPath, size_t nPath); |
97 static int ts_stat(const char *zPath, struct stat *p); | 105 static int ts_stat(const char *zPath, struct stat *p); |
98 static int ts_fstat(int fd, struct stat *p); | 106 static int ts_fstat(int fd, struct stat *p); |
99 static int ts_ftruncate(int fd, off_t n); | 107 static int ts_ftruncate(int fd, off_t n); |
100 static int ts_fcntl(int fd, int cmd, ... ); | 108 static int ts_fcntl(int fd, int cmd, ... ); |
101 static int ts_read(int fd, void *aBuf, size_t nBuf); | 109 static int ts_read(int fd, void *aBuf, size_t nBuf); |
102 static int ts_pread(int fd, void *aBuf, size_t nBuf, off_t off); | 110 static int ts_pread(int fd, void *aBuf, size_t nBuf, off_t off); |
103 static int ts_pread64(int fd, void *aBuf, size_t nBuf, off_t off); | 111 static int ts_pread64(int fd, void *aBuf, size_t nBuf, off_t off); |
104 static int ts_write(int fd, const void *aBuf, size_t nBuf); | 112 static int ts_write(int fd, const void *aBuf, size_t nBuf); |
105 static int ts_pwrite(int fd, const void *aBuf, size_t nBuf, off_t off); | 113 static int ts_pwrite(int fd, const void *aBuf, size_t nBuf, off_t off); |
106 static int ts_pwrite64(int fd, const void *aBuf, size_t nBuf, off_t off); | 114 static int ts_pwrite64(int fd, const void *aBuf, size_t nBuf, off_t off); |
107 static int ts_fchmod(int fd, mode_t mode); | 115 static int ts_fchmod(int fd, mode_t mode); |
108 static int ts_fallocate(int fd, off_t off, off_t len); | 116 static int ts_fallocate(int fd, off_t off, off_t len); |
109 | 117 static void *ts_mmap(void *, size_t, int, int, int, off_t); |
| 118 static void *ts_mremap(void*, size_t, size_t, int, ...); |
110 | 119 |
111 struct TestSyscallArray { | 120 struct TestSyscallArray { |
112 const char *zName; | 121 const char *zName; |
113 sqlite3_syscall_ptr xTest; | 122 sqlite3_syscall_ptr xTest; |
114 sqlite3_syscall_ptr xOrig; | 123 sqlite3_syscall_ptr xOrig; |
115 int default_errno; /* Default value for errno following errors */ | 124 int default_errno; /* Default value for errno following errors */ |
116 int custom_errno; /* Current value for errno if error */ | 125 int custom_errno; /* Current value for errno if error */ |
117 } aSyscall[] = { | 126 } aSyscall[] = { |
118 /* 0 */ { "open", (sqlite3_syscall_ptr)ts_open, 0, EACCES, 0 }, | 127 /* 0 */ { "open", (sqlite3_syscall_ptr)ts_open, 0, EACCES, 0 }, |
119 /* 1 */ { "close", (sqlite3_syscall_ptr)ts_close, 0, 0, 0 }, | 128 /* 1 */ { "close", (sqlite3_syscall_ptr)ts_close, 0, 0, 0 }, |
120 /* 2 */ { "access", (sqlite3_syscall_ptr)ts_access, 0, 0, 0 }, | 129 /* 2 */ { "access", (sqlite3_syscall_ptr)ts_access, 0, 0, 0 }, |
121 /* 3 */ { "getcwd", (sqlite3_syscall_ptr)ts_getcwd, 0, 0, 0 }, | 130 /* 3 */ { "getcwd", (sqlite3_syscall_ptr)ts_getcwd, 0, 0, 0 }, |
122 /* 4 */ { "stat", (sqlite3_syscall_ptr)ts_stat, 0, 0, 0 }, | 131 /* 4 */ { "stat", (sqlite3_syscall_ptr)ts_stat, 0, 0, 0 }, |
123 /* 5 */ { "fstat", (sqlite3_syscall_ptr)ts_fstat, 0, 0, 0 }, | 132 /* 5 */ { "fstat", (sqlite3_syscall_ptr)ts_fstat, 0, 0, 0 }, |
124 /* 6 */ { "ftruncate", (sqlite3_syscall_ptr)ts_ftruncate, 0, EIO, 0 }, | 133 /* 6 */ { "ftruncate", (sqlite3_syscall_ptr)ts_ftruncate, 0, EIO, 0 }, |
125 /* 7 */ { "fcntl", (sqlite3_syscall_ptr)ts_fcntl, 0, EACCES, 0 }, | 134 /* 7 */ { "fcntl", (sqlite3_syscall_ptr)ts_fcntl, 0, EACCES, 0 }, |
126 /* 8 */ { "read", (sqlite3_syscall_ptr)ts_read, 0, 0, 0 }, | 135 /* 8 */ { "read", (sqlite3_syscall_ptr)ts_read, 0, 0, 0 }, |
127 /* 9 */ { "pread", (sqlite3_syscall_ptr)ts_pread, 0, 0, 0 }, | 136 /* 9 */ { "pread", (sqlite3_syscall_ptr)ts_pread, 0, 0, 0 }, |
128 /* 10 */ { "pread64", (sqlite3_syscall_ptr)ts_pread64, 0, 0, 0 }, | 137 /* 10 */ { "pread64", (sqlite3_syscall_ptr)ts_pread64, 0, 0, 0 }, |
129 /* 11 */ { "write", (sqlite3_syscall_ptr)ts_write, 0, 0, 0 }, | 138 /* 11 */ { "write", (sqlite3_syscall_ptr)ts_write, 0, 0, 0 }, |
130 /* 12 */ { "pwrite", (sqlite3_syscall_ptr)ts_pwrite, 0, 0, 0 }, | 139 /* 12 */ { "pwrite", (sqlite3_syscall_ptr)ts_pwrite, 0, 0, 0 }, |
131 /* 13 */ { "pwrite64", (sqlite3_syscall_ptr)ts_pwrite64, 0, 0, 0 }, | 140 /* 13 */ { "pwrite64", (sqlite3_syscall_ptr)ts_pwrite64, 0, 0, 0 }, |
132 /* 14 */ { "fchmod", (sqlite3_syscall_ptr)ts_fchmod, 0, 0, 0 }, | 141 /* 14 */ { "fchmod", (sqlite3_syscall_ptr)ts_fchmod, 0, 0, 0 }, |
133 /* 15 */ { "fallocate", (sqlite3_syscall_ptr)ts_fallocate, 0, 0, 0 }, | 142 /* 15 */ { "fallocate", (sqlite3_syscall_ptr)ts_fallocate, 0, 0, 0 }, |
| 143 /* 16 */ { "mmap", (sqlite3_syscall_ptr)ts_mmap, 0, 0, 0 }, |
| 144 /* 17 */ { "mremap", (sqlite3_syscall_ptr)ts_mremap, 0, 0, 0 }, |
134 { 0, 0, 0, 0, 0 } | 145 { 0, 0, 0, 0, 0 } |
135 }; | 146 }; |
136 | 147 |
137 #define orig_open ((int(*)(const char *, int, int))aSyscall[0].xOrig) | 148 #define orig_open ((int(*)(const char *, int, int))aSyscall[0].xOrig) |
138 #define orig_close ((int(*)(int))aSyscall[1].xOrig) | 149 #define orig_close ((int(*)(int))aSyscall[1].xOrig) |
139 #define orig_access ((int(*)(const char*,int))aSyscall[2].xOrig) | 150 #define orig_access ((int(*)(const char*,int))aSyscall[2].xOrig) |
140 #define orig_getcwd ((char*(*)(char*,size_t))aSyscall[3].xOrig) | 151 #define orig_getcwd ((char*(*)(char*,size_t))aSyscall[3].xOrig) |
141 #define orig_stat ((int(*)(const char*,struct stat*))aSyscall[4].xOrig) | 152 #define orig_stat ((int(*)(const char*,struct stat*))aSyscall[4].xOrig) |
142 #define orig_fstat ((int(*)(int,struct stat*))aSyscall[5].xOrig) | 153 #define orig_fstat ((int(*)(int,struct stat*))aSyscall[5].xOrig) |
143 #define orig_ftruncate ((int(*)(int,off_t))aSyscall[6].xOrig) | 154 #define orig_ftruncate ((int(*)(int,off_t))aSyscall[6].xOrig) |
144 #define orig_fcntl ((int(*)(int,int,...))aSyscall[7].xOrig) | 155 #define orig_fcntl ((int(*)(int,int,...))aSyscall[7].xOrig) |
145 #define orig_read ((ssize_t(*)(int,void*,size_t))aSyscall[8].xOrig) | 156 #define orig_read ((ssize_t(*)(int,void*,size_t))aSyscall[8].xOrig) |
146 #define orig_pread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].xOrig) | 157 #define orig_pread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].xOrig) |
147 #define orig_pread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].xOrig) | 158 #define orig_pread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].xOrig) |
148 #define orig_write ((ssize_t(*)(int,const void*,size_t))aSyscall[11].xOrig) | 159 #define orig_write ((ssize_t(*)(int,const void*,size_t))aSyscall[11].xOrig) |
149 #define orig_pwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ | 160 #define orig_pwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
150 aSyscall[12].xOrig) | 161 aSyscall[12].xOrig) |
151 #define orig_pwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ | 162 #define orig_pwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ |
152 aSyscall[13].xOrig) | 163 aSyscall[13].xOrig) |
153 #define orig_fchmod ((int(*)(int,mode_t))aSyscall[14].xOrig) | 164 #define orig_fchmod ((int(*)(int,mode_t))aSyscall[14].xOrig) |
154 #define orig_fallocate ((int(*)(int,off_t,off_t))aSyscall[15].xOrig) | 165 #define orig_fallocate ((int(*)(int,off_t,off_t))aSyscall[15].xOrig) |
| 166 #define orig_mmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[16].x
Orig) |
| 167 #define orig_mremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[17].xOri
g) |
155 | 168 |
156 /* | 169 /* |
157 ** This function is called exactly once from within each invocation of a | 170 ** This function is called exactly once from within each invocation of a |
158 ** system call wrapper in this file. It returns 1 if the function should | 171 ** system call wrapper in this file. It returns 1 if the function should |
159 ** fail, or 0 if it should succeed. | 172 ** fail, or 0 if it should succeed. |
160 */ | 173 */ |
161 static int tsIsFail(void){ | 174 static int tsIsFail(void){ |
162 gSyscall.nCount--; | 175 gSyscall.nCount--; |
163 if( gSyscall.nCount==0 || (gSyscall.nFail && gSyscall.bPersist) ){ | 176 if( gSyscall.nCount==0 || (gSyscall.nFail && gSyscall.bPersist) ){ |
164 gSyscall.nFail++; | 177 gSyscall.nFail++; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return -1; | 331 return -1; |
319 } | 332 } |
320 return orig_pread64(fd, aBuf, nBuf, off); | 333 return orig_pread64(fd, aBuf, nBuf, off); |
321 } | 334 } |
322 | 335 |
323 /* | 336 /* |
324 ** A wrapper around write(). | 337 ** A wrapper around write(). |
325 */ | 338 */ |
326 static int ts_write(int fd, const void *aBuf, size_t nBuf){ | 339 static int ts_write(int fd, const void *aBuf, size_t nBuf){ |
327 if( tsIsFailErrno("write") ){ | 340 if( tsIsFailErrno("write") ){ |
| 341 if( tsErrno("write")==EINTR ) orig_write(fd, aBuf, nBuf/2); |
328 return -1; | 342 return -1; |
329 } | 343 } |
330 return orig_write(fd, aBuf, nBuf); | 344 return orig_write(fd, aBuf, nBuf); |
331 } | 345 } |
332 | 346 |
333 /* | 347 /* |
334 ** A wrapper around pwrite(). | 348 ** A wrapper around pwrite(). |
335 */ | 349 */ |
336 static int ts_pwrite(int fd, const void *aBuf, size_t nBuf, off_t off){ | 350 static int ts_pwrite(int fd, const void *aBuf, size_t nBuf, off_t off){ |
337 if( tsIsFailErrno("pwrite") ){ | 351 if( tsIsFailErrno("pwrite") ){ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 ** posix_fallocate() returns zero on success, or an error number on | 383 ** posix_fallocate() returns zero on success, or an error number on |
370 ** failure. Note that errno is not set. | 384 ** failure. Note that errno is not set. |
371 */ | 385 */ |
372 static int ts_fallocate(int fd, off_t off, off_t len){ | 386 static int ts_fallocate(int fd, off_t off, off_t len){ |
373 if( tsIsFail() ){ | 387 if( tsIsFail() ){ |
374 return tsErrno("fallocate"); | 388 return tsErrno("fallocate"); |
375 } | 389 } |
376 return orig_fallocate(fd, off, len); | 390 return orig_fallocate(fd, off, len); |
377 } | 391 } |
378 | 392 |
| 393 static void *ts_mmap( |
| 394 void *pAddr, |
| 395 size_t nByte, |
| 396 int prot, |
| 397 int flags, |
| 398 int fd, |
| 399 off_t iOff |
| 400 ){ |
| 401 if( tsIsFailErrno("mmap") ){ |
| 402 return MAP_FAILED; |
| 403 } |
| 404 return orig_mmap(pAddr, nByte, prot, flags, fd, iOff); |
| 405 } |
| 406 |
| 407 static void *ts_mremap(void *a, size_t b, size_t c, int d, ...){ |
| 408 va_list ap; |
| 409 void *pArg; |
| 410 if( tsIsFailErrno("mremap") ){ |
| 411 return MAP_FAILED; |
| 412 } |
| 413 va_start(ap, d); |
| 414 pArg = va_arg(ap, void *); |
| 415 return orig_mremap(a, b, c, d, pArg); |
| 416 } |
| 417 |
379 static int test_syscall_install( | 418 static int test_syscall_install( |
380 void * clientData, | 419 void * clientData, |
381 Tcl_Interp *interp, | 420 Tcl_Interp *interp, |
382 int objc, | 421 int objc, |
383 Tcl_Obj *CONST objv[] | 422 Tcl_Obj *CONST objv[] |
384 ){ | 423 ){ |
385 sqlite3_vfs *pVfs; | 424 sqlite3_vfs *pVfs; |
386 int nElem; | 425 int nElem; |
387 int i; | 426 int i; |
388 Tcl_Obj **apElem; | 427 Tcl_Obj **apElem; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 int nFunc; | 498 int nFunc; |
460 char *zFunc = Tcl_GetStringFromObj(objv[2], &nFunc); | 499 char *zFunc = Tcl_GetStringFromObj(objv[2], &nFunc); |
461 rc = pVfs->xSetSystemCall(pVfs, Tcl_GetString(objv[2]), 0); | 500 rc = pVfs->xSetSystemCall(pVfs, Tcl_GetString(objv[2]), 0); |
462 for(i=0; rc==SQLITE_OK && aSyscall[i].zName; i++){ | 501 for(i=0; rc==SQLITE_OK && aSyscall[i].zName; i++){ |
463 if( strlen(aSyscall[i].zName)!=nFunc ) continue; | 502 if( strlen(aSyscall[i].zName)!=nFunc ) continue; |
464 if( memcmp(aSyscall[i].zName, zFunc, nFunc) ) continue; | 503 if( memcmp(aSyscall[i].zName, zFunc, nFunc) ) continue; |
465 aSyscall[i].xOrig = 0; | 504 aSyscall[i].xOrig = 0; |
466 } | 505 } |
467 } | 506 } |
468 if( rc!=SQLITE_OK ){ | 507 if( rc!=SQLITE_OK ){ |
469 Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3TestErrorName(rc), -1)); | 508 Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
470 return TCL_ERROR; | 509 return TCL_ERROR; |
471 } | 510 } |
472 | 511 |
473 Tcl_ResetResult(interp); | 512 Tcl_ResetResult(interp); |
474 return TCL_OK; | 513 return TCL_OK; |
475 } | 514 } |
476 | 515 |
477 static int test_syscall_exists( | 516 static int test_syscall_exists( |
478 void * clientData, | 517 void * clientData, |
479 Tcl_Interp *interp, | 518 Tcl_Interp *interp, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 if( objc!=2 ){ | 650 if( objc!=2 ){ |
612 Tcl_WrongNumArgs(interp, 2, objv, ""); | 651 Tcl_WrongNumArgs(interp, 2, objv, ""); |
613 return TCL_ERROR; | 652 return TCL_ERROR; |
614 } | 653 } |
615 | 654 |
616 pVfs = sqlite3_vfs_find(0); | 655 pVfs = sqlite3_vfs_find(0); |
617 Tcl_SetObjResult(interp, Tcl_NewStringObj(pVfs->zName, -1)); | 656 Tcl_SetObjResult(interp, Tcl_NewStringObj(pVfs->zName, -1)); |
618 return TCL_OK; | 657 return TCL_OK; |
619 } | 658 } |
620 | 659 |
| 660 static int ts_getpagesize(void){ |
| 661 return gSyscall.pgsz; |
| 662 } |
| 663 |
| 664 static int test_syscall_pagesize( |
| 665 void * clientData, |
| 666 Tcl_Interp *interp, |
| 667 int objc, |
| 668 Tcl_Obj *CONST objv[] |
| 669 ){ |
| 670 sqlite3_vfs *pVfs = sqlite3_vfs_find(0); |
| 671 int pgsz; |
| 672 if( objc!=3 ){ |
| 673 Tcl_WrongNumArgs(interp, 2, objv, "PGSZ"); |
| 674 return TCL_ERROR; |
| 675 } |
| 676 if( Tcl_GetIntFromObj(interp, objv[2], &pgsz) ){ |
| 677 return TCL_ERROR; |
| 678 } |
| 679 |
| 680 if( pgsz<0 ){ |
| 681 if( gSyscall.orig_getpagesize ){ |
| 682 pVfs->xSetSystemCall(pVfs, "getpagesize", gSyscall.orig_getpagesize); |
| 683 } |
| 684 }else{ |
| 685 if( pgsz<512 || (pgsz & (pgsz-1)) ){ |
| 686 Tcl_AppendResult(interp, "pgsz out of range", 0); |
| 687 return TCL_ERROR; |
| 688 } |
| 689 gSyscall.orig_getpagesize = pVfs->xGetSystemCall(pVfs, "getpagesize"); |
| 690 gSyscall.pgsz = pgsz; |
| 691 pVfs->xSetSystemCall( |
| 692 pVfs, "getpagesize", (sqlite3_syscall_ptr)ts_getpagesize |
| 693 ); |
| 694 } |
| 695 |
| 696 return TCL_OK; |
| 697 } |
| 698 |
621 static int test_syscall( | 699 static int test_syscall( |
622 void * clientData, | 700 void * clientData, |
623 Tcl_Interp *interp, | 701 Tcl_Interp *interp, |
624 int objc, | 702 int objc, |
625 Tcl_Obj *CONST objv[] | 703 Tcl_Obj *CONST objv[] |
626 ){ | 704 ){ |
627 struct SyscallCmd { | 705 struct SyscallCmd { |
628 const char *zName; | 706 const char *zName; |
629 Tcl_ObjCmdProc *xCmd; | 707 Tcl_ObjCmdProc *xCmd; |
630 } aCmd[] = { | 708 } aCmd[] = { |
631 { "fault", test_syscall_fault }, | 709 { "fault", test_syscall_fault }, |
632 { "install", test_syscall_install }, | 710 { "install", test_syscall_install }, |
633 { "uninstall", test_syscall_uninstall }, | 711 { "uninstall", test_syscall_uninstall }, |
634 { "reset", test_syscall_reset }, | 712 { "reset", test_syscall_reset }, |
635 { "errno", test_syscall_errno }, | 713 { "errno", test_syscall_errno }, |
636 { "exists", test_syscall_exists }, | 714 { "exists", test_syscall_exists }, |
637 { "list", test_syscall_list }, | 715 { "list", test_syscall_list }, |
638 { "defaultvfs", test_syscall_defaultvfs }, | 716 { "defaultvfs", test_syscall_defaultvfs }, |
| 717 { "pagesize", test_syscall_pagesize }, |
639 { 0, 0 } | 718 { 0, 0 } |
640 }; | 719 }; |
641 int iCmd; | 720 int iCmd; |
642 int rc; | 721 int rc; |
643 | 722 |
644 if( objc<2 ){ | 723 if( objc<2 ){ |
645 Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND ..."); | 724 Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND ..."); |
646 return TCL_ERROR; | 725 return TCL_ERROR; |
647 } | 726 } |
648 rc = Tcl_GetIndexFromObjStruct(interp, | 727 rc = Tcl_GetIndexFromObjStruct(interp, |
(...skipping 15 matching lines...) Expand all Loading... |
664 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ | 743 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ |
665 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xCmd, 0, 0); | 744 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xCmd, 0, 0); |
666 } | 745 } |
667 return TCL_OK; | 746 return TCL_OK; |
668 } | 747 } |
669 #else | 748 #else |
670 int SqlitetestSyscall_Init(Tcl_Interp *interp){ | 749 int SqlitetestSyscall_Init(Tcl_Interp *interp){ |
671 return TCL_OK; | 750 return TCL_OK; |
672 } | 751 } |
673 #endif | 752 #endif |
674 | |
OLD | NEW |