From 3905c6f00d9d11e01d6e211565d5ed58a59fc2d8 Mon Sep 17 00:00:00 2001 From: Simon Sasburg Date: Mon, 21 Jul 2014 19:28:43 +0100 Subject: Add QFileDevice::MemoryMapFlags::MapPrivateOption flag. Passing this flag to QFileDevice::map() will allow writes to the mapped memory without modifying the file that was mapped. These writes will be lost when the memory is unmapped. Change-Id: I7d46b044fc370585de8c06fdb4059f1f1be12d7d Reviewed-by: Thiago Macieira Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qfsfileengine_unix.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/corelib/io/qfsfileengine_unix.cpp') diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 064a1a511f..f9c6c8ab98 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -713,6 +713,12 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla if (openMode & QIODevice::ReadOnly) access |= PROT_READ; if (openMode & QIODevice::WriteOnly) access |= PROT_WRITE; + int sharemode = MAP_SHARED; + if (flags & QFileDevice::MapPrivateOption) { + sharemode = MAP_PRIVATE; + access |= PROT_WRITE; + } + #if defined(Q_OS_INTEGRITY) int pageSize = sysconf(_SC_PAGESIZE); #else @@ -730,7 +736,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla realOffset &= ~(QT_OFF_T(pageSize - 1)); void *mapAddress = QT_MMAP((void*)0, realSize, - access, MAP_SHARED, nativeHandle(), realOffset); + access, sharemode, nativeHandle(), realOffset); if (MAP_FAILED != mapAddress) { uchar *address = extra + static_cast(mapAddress); maps[address] = QPair(extra, realSize); -- cgit v1.2.3