OLD | NEW |
| (Empty) |
1 From 0b346776e7a4d775932a18970801fa48d7a5ce11 Mon Sep 17 00:00:00 2001 | |
2 From: Scott Hess <shess@chromium.org> | |
3 Date: Wed, 5 Aug 2015 16:44:32 -0700 | |
4 Subject: [PATCH 12/12] Allow read-only memory mapping. | |
5 | |
6 In memory-mapped I/O mode, SQLite writes pages by using memcpy() from | |
7 the staging memory into the underlying memory-mapped file. This allows | |
8 anyone in the process to also write into that space. Modify SQLite to | |
9 map things read-only. | |
10 | |
11 TODO: Upstream. | |
12 | |
13 BUG=489784 | |
14 --- | |
15 third_party/sqlite/src/src/os_unix.c | 4 ++++ | |
16 third_party/sqlite/src/src/os_win.c | 4 ++++ | |
17 2 files changed, 8 insertions(+) | |
18 | |
19 diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/o
s_unix.c | |
20 index 75b71dc..eaa97cf 100644 | |
21 --- a/third_party/sqlite/src/src/os_unix.c | |
22 +++ b/third_party/sqlite/src/src/os_unix.c | |
23 @@ -3341,6 +3341,7 @@ static int unixWrite( | |
24 } | |
25 #endif | |
26 | |
27 +#if !SQLITE_MMAP_READ_ONLY | |
28 #if SQLITE_MAX_MMAP_SIZE>0 | |
29 /* Deal with as much of this write request as possible by transfering | |
30 ** data from the memory mapping using memcpy(). */ | |
31 @@ -3357,6 +3358,7 @@ static int unixWrite( | |
32 } | |
33 } | |
34 #endif | |
35 +#endif | |
36 | |
37 while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){ | |
38 amt -= wrote; | |
39 @@ -4743,7 +4745,9 @@ static void unixRemapfile( | |
40 assert( pFd->mmapSizeActual>=pFd->mmapSize ); | |
41 assert( MAP_FAILED!=0 ); | |
42 | |
43 +#if !SQLITE_MMAP_READ_ONLY | |
44 if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; | |
45 +#endif | |
46 | |
47 if( pOrig ){ | |
48 #if HAVE_MREMAP | |
49 diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os
_win.c | |
50 index 9320bfc..2e757f8 100644 | |
51 --- a/third_party/sqlite/src/src/os_win.c | |
52 +++ b/third_party/sqlite/src/src/os_win.c | |
53 @@ -2558,6 +2558,7 @@ static int winWrite( | |
54 OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n", | |
55 pFile->h, pBuf, amt, offset, pFile->locktype)); | |
56 | |
57 +#if !SQLITE_MMAP_READ_ONLY | |
58 #if SQLITE_MAX_MMAP_SIZE>0 | |
59 /* Deal with as much of this write request as possible by transfering | |
60 ** data from the memory mapping using memcpy(). */ | |
61 @@ -2575,6 +2576,7 @@ static int winWrite( | |
62 } | |
63 } | |
64 #endif | |
65 +#endif | |
66 | |
67 #if SQLITE_OS_WINCE | |
68 rc = winSeekFile(pFile, offset); | |
69 @@ -4021,10 +4023,12 @@ static int winMapfile(winFile *pFd, sqlite3_int64 nByte)
{ | |
70 DWORD flags = FILE_MAP_READ; | |
71 | |
72 winUnmapfile(pFd); | |
73 +#if !SQLITE_MMAP_READ_ONLY | |
74 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ | |
75 protect = PAGE_READWRITE; | |
76 flags |= FILE_MAP_WRITE; | |
77 } | |
78 +#endif | |
79 #if SQLITE_OS_WINRT | |
80 pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); | |
81 #elif defined(SQLITE_WIN32_HAS_WIDE) | |
82 -- | |
83 2.4.5 | |
84 | |
OLD | NEW |