blob: acb20c9e51e4c9c2d9801557c95e07c696702f58 [file] [log] [blame]
From 0b346776e7a4d775932a18970801fa48d7a5ce11 Mon Sep 17 00:00:00 2001
From: Scott Hess <shess@chromium.org>
Date: Wed, 5 Aug 2015 16:44:32 -0700
Subject: [PATCH 12/12] Allow read-only memory mapping.
In memory-mapped I/O mode, SQLite writes pages by using memcpy() from
the staging memory into the underlying memory-mapped file. This allows
anyone in the process to also write into that space. Modify SQLite to
map things read-only.
TODO: Upstream.
BUG=489784
---
third_party/sqlite/src/src/os_unix.c | 4 ++++
third_party/sqlite/src/src/os_win.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/os_unix.c
index 75b71dc..eaa97cf 100644
--- a/third_party/sqlite/src/src/os_unix.c
+++ b/third_party/sqlite/src/src/os_unix.c
@@ -3341,6 +3341,7 @@ static int unixWrite(
}
#endif
+#if !SQLITE_MMAP_READ_ONLY
#if SQLITE_MAX_MMAP_SIZE>0
/* Deal with as much of this write request as possible by transfering
** data from the memory mapping using memcpy(). */
@@ -3357,6 +3358,7 @@ static int unixWrite(
}
}
#endif
+#endif
while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
amt -= wrote;
@@ -4743,7 +4745,9 @@ static void unixRemapfile(
assert( pFd->mmapSizeActual>=pFd->mmapSize );
assert( MAP_FAILED!=0 );
+#if !SQLITE_MMAP_READ_ONLY
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
+#endif
if( pOrig ){
#if HAVE_MREMAP
diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os_win.c
index 9320bfc..2e757f8 100644
--- a/third_party/sqlite/src/src/os_win.c
+++ b/third_party/sqlite/src/src/os_win.c
@@ -2558,6 +2558,7 @@ static int winWrite(
OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
pFile->h, pBuf, amt, offset, pFile->locktype));
+#if !SQLITE_MMAP_READ_ONLY
#if SQLITE_MAX_MMAP_SIZE>0
/* Deal with as much of this write request as possible by transfering
** data from the memory mapping using memcpy(). */
@@ -2575,6 +2576,7 @@ static int winWrite(
}
}
#endif
+#endif
#if SQLITE_OS_WINCE
rc = winSeekFile(pFile, offset);
@@ -4021,10 +4023,12 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte){
DWORD flags = FILE_MAP_READ;
winUnmapfile(pFd);
+#if !SQLITE_MMAP_READ_ONLY
if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
protect = PAGE_READWRITE;
flags |= FILE_MAP_WRITE;
}
+#endif
#if SQLITE_OS_WINRT
pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL);
#elif defined(SQLITE_WIN32_HAS_WIDE)
--
2.4.5