-C Proposed\stemplate\spreprocessor\smagic\sfor\sactivating\smmap\sonly\son\splatforms\nwhere\swe\sknow\sit\sworks.
-D 2013-04-02T10:29:13.935
+C Add\stest\scases\sfor\serrors\sin\smmap()\sor\smremap()\sis\sos_unix.c.
+D 2013-04-02T12:04:09.729
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in df3e48659d80e1b7765785d8d66c86b320f72cc7
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F src/os.c 809d0707cec693e1b9b376ab229271ad74c3d35d
F src/os.h ae08bcc5f6ec6b339f4a2adf3931bb88cc14c3e4
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
-F src/os_unix.c d136eca0cff2f8a5ac2f45867d5e5153d60e377c
+F src/os_unix.c 42684a59b06b912b3ab80a8ad9f4295c0572a1f4
F src/os_win.c a2f41c9dfb9b065285ba94d4a40a31ca2e2b6ea3
F src/pager.c 46fa7d8b29e7fb8baa6111690d900c9111a5a397
F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1
F src/test_sqllog.c bc50e5afeb7fb50e77b4594e42302df9d05446aa
F src/test_stat.c d1569c7a4839f13e80187e2c26b2ab4da2d03935
F src/test_superlock.c 2b97936ca127d13962c3605dbc9a4ef269c424cd
-F src/test_syscall.c fe018f95049d4f24e036d1d649516b60689b4e57
+F src/test_syscall.c 7e8293e4e6971b0f44c7f7f37b1315a8cc9f6018
F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa
F src/test_thread.c e286f2173563f2a1747c24bcda6b9d030bf4f4e4
F src/test_vfs.c fb16b2d9938cf0c1afc5a423b55b952fcc024275
F test/misc7.test dd82ec9250b89178b96cd28b2aca70639d21e5b3
F test/misuse.test ba4fb5d1a6101d1c171ea38b3c613d0661c83054
F test/mmap1.test 9fb71daaca72f66fcc7a3b3a37fc3db99988b57a
+F test/mmap2.test bb0c97cdac0db06a5acdc6836eef9866815481b1
F test/multiplex.test e08cc7177bd6d85990ee1d71100bb6c684c02256
F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a
F test/multiplex3.test d228f59eac91839a977eac19f21d053f03e4d101
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
F test/speed1.test f2974a91d79f58507ada01864c0e323093065452
F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
-F test/speed1p.test c4a469f29f135f4d76c55b1f2a52f36e209466cc
+F test/speed1p.test b180e98609c7677382cf618c0ec9b69f789033a8
F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523
F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 793ba4e996426522eeaa86589a9e974fa1fc1522
-R 2b5ee6ceec98b53d533d4ea410a1bfc7
-U drh
-Z ead310385cbe70188969099b54288940
+P d96272f031102514b02bd839aac9e37618872200
+R 323dfbce5d7140c5ce46f22a5112dcc8
+U dan
+Z 3d1807f4fa3a8cf06a6141b170b215ce
-d96272f031102514b02bd839aac9e37618872200
\ No newline at end of file
+3098a3c1e7305033904a496ef534cb312a876fab
\ No newline at end of file
unixFile *pFd, /* File descriptor object */
i64 nNew /* Required mapping size */
){
+ const char *zErr = "mmap";
int h = pFd->h; /* File descriptor open on db file */
u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */
i64 nOrig = pFd->mmapOrigsize; /* Size of pOrig region in bytes */
assert( nNew<=pFd->mmapLimit );
assert( nNew>0 );
assert( pFd->mmapOrigsize>=pFd->mmapSize );
+ assert( MAP_FAILED!=0 );
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
#if HAVE_MREMAP
pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
+ zErr = "mremap";
#else
pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
if( pNew!=MAP_FAILED ){
if( pNew!=pReq ){
osMunmap(pNew, nNew - nReuse);
- pNew = MAP_FAILED;
+ pNew = 0;
}else{
pNew = pOrig;
}
** mapping and set pNew to NULL so that the code below will create a
** new mapping from scratch. */
if( pNew==MAP_FAILED ){
- pNew = 0;
osMunmap(pOrig, nReuse);
}
}
/* If pNew is still NULL, try to create an entirely new mapping. */
if( pNew==0 ){
pNew = osMmap(0, nNew, flags, MAP_SHARED, h, 0);
- if( pNew==MAP_FAILED ){
- pNew = 0;
- nNew = 0;
- unixLogError(SQLITE_OK, "mmap", pFd->zPath);
-
- /* If the mmap() above failed, assume that all subsequent mmap() calls
- ** will probably fail too. Fall back to using xRead/xWrite exclusively
- ** in this case. */
- pFd->mmapLimit = 0;
- }
}
+ if( pNew==MAP_FAILED ){
+ pNew = 0;
+ nNew = 0;
+ unixLogError(SQLITE_OK, zErr, pFd->zPath);
+
+ /* If the mmap() above failed, assume that all subsequent mmap() calls
+ ** will probably fail too. Fall back to using xRead/xWrite exclusively
+ ** in this case. */
+ pFd->mmapLimit = 0;
+ }
pFd->pMapRegion = (void *)pNew;
pFd->mmapSize = pFd->mmapOrigsize = nNew;
}
static int ts_fchmod(int fd, mode_t mode);
static int ts_fallocate(int fd, off_t off, off_t len);
static void *ts_mmap(void *, size_t, int, int, int, off_t);
-
+static void *ts_mremap(void*, size_t, size_t, int, ...);
struct TestSyscallArray {
const char *zName;
/* 14 */ { "fchmod", (sqlite3_syscall_ptr)ts_fchmod, 0, 0, 0 },
/* 15 */ { "fallocate", (sqlite3_syscall_ptr)ts_fallocate, 0, 0, 0 },
/* 16 */ { "mmap", (sqlite3_syscall_ptr)ts_mmap, 0, 0, 0 },
+ /* 17 */ { "mremap", (sqlite3_syscall_ptr)ts_mremap, 0, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
#define orig_fchmod ((int(*)(int,mode_t))aSyscall[14].xOrig)
#define orig_fallocate ((int(*)(int,off_t,off_t))aSyscall[15].xOrig)
#define orig_mmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[16].xOrig)
+#define orig_mremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[17].xOrig)
/*
** This function is called exactly once from within each invocation of a
return orig_mmap(pAddr, nByte, prot, flags, fd, iOff);
}
+static void *ts_mremap(void *a, size_t b, size_t c, int d, ...){
+ va_list ap;
+ void *pArg;
+ if( tsIsFailErrno("mremap") ){
+ return MAP_FAILED;
+ }
+ va_start(ap, d);
+ pArg = va_arg(ap, void *);
+ return orig_mremap(a, b, c, d, pArg);
+}
+
static int test_syscall_install(
void * clientData,
Tcl_Interp *interp,
--- /dev/null
+# 2013 March 20
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file tests the effect of the mmap() or mremap() system calls
+# returning an error on the library.
+#
+# If either mmap() or mremap() fails, SQLite should log an error
+# message, then continue accessing the database using read() and
+# write() exclusively.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix mmap2
+
+if {[test_syscall defaultvfs] != "unix"} {
+ finish_test
+ return
+}
+
+db close
+sqlite3_shutdown
+test_sqlite3_log xLog
+proc xLog {error_code msg} {
+ if {[string match os_unix.c* $msg]} {
+ lappend ::log $msg
+ }
+}
+
+foreach syscall {mmap mremap} {
+ test_syscall uninstall
+ if {[catch {test_syscall install $syscall}]} continue
+
+ for {set i 1} {$i < 20} {incr i} {
+ reset_db
+
+ test_syscall fault $i 1
+ test_syscall errno $syscall ENOMEM
+ set ::log ""
+
+ do_execsql_test 1.$syscall.$i.1 {
+ CREATE TABLE t1(a, b, UNIQUE(a, b));
+ INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ }
+
+ set nFail [test_syscall fault 0 0]
+
+ do_execsql_test 1.$syscall.$i.2 {
+ SELECT count(*) FROM t1;
+ PRAGMA integrity_check;
+ } {64 ok}
+
+ do_test 1.$syscall.$i.3 {
+ expr {$nFail==0 || $nFail==1}
+ } {1}
+
+ do_test 1.$syscall.$i.4.nFail=$nFail {
+ regexp ".*${syscall}.*" $::log
+ } [expr $nFail>0]
+ }
+}
+
+test_syscall uninstall
+finish_test
+
source $testdir/tester.tcl
speed_trial_init speed1
+sqlite3_memdebug_vfs_oom_test 0
+
# Set a uniform random seed
expr srand(0)
}
} {i2a i2b t1 t2}
-
# 50000 INSERTs on an unindexed table
#
set list {}