summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qsharedmemory_win.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-03-15 12:33:35 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-07 20:38:57 +0000
commita2cef41a3199b7bdaa64c911c7a2e7d0b0daecd4 (patch)
tree45a7ff001198601fe2483dc552d3855064493d3a /src/corelib/kernel/qsharedmemory_win.cpp
parent9ad1c6d835eac2938f1e6137dd420e274dcbef6e (diff)
Extend QSharedMemory to work with qsizetype for sizes
This allows larger than 2G memory segments to be allocated. Fixes: QTBUG-76995 Change-Id: I95309eeea511fadb28724c7592298c2fcc6f1d1a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/kernel/qsharedmemory_win.cpp')
-rw-r--r--src/corelib/kernel/qsharedmemory_win.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/corelib/kernel/qsharedmemory_win.cpp b/src/corelib/kernel/qsharedmemory_win.cpp
index cbf31bcb2f..549fc13b2d 100644
--- a/src/corelib/kernel/qsharedmemory_win.cpp
+++ b/src/corelib/kernel/qsharedmemory_win.cpp
@@ -122,7 +122,7 @@ bool QSharedMemoryPrivate::cleanHandle()
return true;
}
-bool QSharedMemoryPrivate::create(int size)
+bool QSharedMemoryPrivate::create(qsizetype size)
{
const QLatin1String function("QSharedMemory::create");
if (nativeKey.isEmpty()) {
@@ -132,8 +132,14 @@ bool QSharedMemoryPrivate::create(int size)
}
// Create the file mapping.
- hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size,
- reinterpret_cast<const wchar_t*>(nativeKey.utf16()));
+ DWORD high, low;
+ if constexpr (sizeof(qsizetype) == 8)
+ high = DWORD(quint64(size) >> 32);
+ else
+ high = 0;
+ low = DWORD(size_t(size) & 0xffffffff);
+ hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, high, low,
+ reinterpret_cast<const wchar_t *>(nativeKey.utf16()));
setErrorString(function);
// hand is valid when it already exists unlike unix so explicitly check
@@ -160,7 +166,7 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
errorString = QSharedMemory::tr("%1: size query failed").arg(QLatin1String("QSharedMemory::attach: "));
return false;
}
- size = info.RegionSize;
+ size = qsizetype(info.RegionSize);
return true;
}