bool QSharedMemoryPrivate::create(int size) { QString function = QLatin1String("QSharedMemory::create"); if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); return false; } // Create the file mapping. #if defined(Q_OS_WINPHONE) Q_UNIMPLEMENTED(); Q_UNUSED(size) hand = 0; #elif defined(Q_OS_WINRT) hand = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, size, (PCWSTR)nativeKey.utf16()); #else hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16()); #endif setErrorString(function); // hand is valid when it already exists unlike unix so explicitly check if (error == QSharedMemory::AlreadyExists || !hand) return false; return true; }
HANDLE QSharedMemoryPrivate::handle() { if (!hand) { QString function = QLatin1String("QSharedMemory::handle"); if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); return 0; } #if defined(Q_OS_WINPHONE) Q_UNIMPLEMENTED(); hand = 0; #elif defined(Q_OS_WINRT) hand = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, (PCWSTR)nativeKey.utf16()); #elif defined(Q_OS_WINCE) // This works for opening a mapping too, but always opens it with read/write access in // attach as it seems. hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)nativeKey.utf16()); #else hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16()); #endif if (!hand) { setErrorString(function); return 0; } } return hand; }
void* mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle) { void *ptr; int mflags = 0; HANDLE file, mapping; int prot = mono_mmap_win_prot_from_flags (flags); mflags = FILE_MAP_READ; if (flags & MONO_MMAP_WRITE) mflags = FILE_MAP_COPY; file = (HANDLE) _get_osfhandle (fd); mapping = CreateFileMappingFromApp (file, NULL, prot, length, NULL); if (mapping == NULL) return NULL; ptr = MapViewOfFileFromApp (mapping, mflags, offset, length); if (ptr == NULL) { CloseHandle (mapping); return NULL; } *ret_handle = (void*)mapping; return ptr; }