From 3a4728e169ef59896f8f1c7f1c9a3abc814c83cf Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 15 Dec 2011 13:29:30 +0000 Subject: Symbian - Fix QFile::map with non page aligned offsets Although it is not documented, RFileMap native API requires the offset into the file to be a multiple of the page size. Round down the offset requested by the user to the page size. Add back the difference before returning the base address to the user. e.g. if the offset passed to QFile::map was 5000: The offset passed to RFileMap will be 4096 The address returned to the user will be the RFileMap::Base() + 904 The modified address is used to key the hash of file mappings, so that QFile::unmap() can be passed the modified address without needing changes. Reviewed-by: mread Task-number: ou1cimx#953054 --- src/corelib/io/qfsfileengine_unix.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 4961722..781a5f0 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -1058,22 +1058,24 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla TInt nativeMapError = KErrNone; RFileMap mapping; TUint mode(EFileMapRemovableMedia); + TUint64 nativeOffset = offset & ~(mapping.PageSizeInBytes() - 1); + //If the file was opened for write or read/write, then open the map for read/write if (openMode & QIODevice::WriteOnly) mode |= EFileMapWrite; if (symbianFile.SubSessionHandle()) { - nativeMapError = mapping.Open(symbianFile, offset, size, mode); + nativeMapError = mapping.Open(symbianFile, nativeOffset, size, mode); } else { //map file by name if we don't have a native handle QString fn = QFileSystemEngine::absoluteName(fileEntry).nativeFilePath(); TUint filemode = EFileShareReadersOrWriters | EFileRead; if (openMode & QIODevice::WriteOnly) filemode |= EFileWrite; - nativeMapError = mapping.Open(qt_s60GetRFs(), qt_QString2TPtrC(fn), filemode, offset, size, mode); + nativeMapError = mapping.Open(qt_s60GetRFs(), qt_QString2TPtrC(fn), filemode, nativeOffset, size, mode); } if (nativeMapError == KErrNone) { QScopedResource ptr(mapping); //will call Close if adding to mapping throws an exception - uchar *address = mapping.Base(); + uchar *address = mapping.Base() + (offset - nativeOffset); maps[address] = mapping; ptr.take(); return address; -- cgit v0.12