diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 0149d3bf411b..ab7fe85df438 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -1021,9 +1021,7 @@ pref("identity.fxaccounts.remote.profile.uri", "https://profile.accounts.firefox pref("identity.fxaccounts.skipDeviceRegistration", true); // Enable mapped array buffer. -#ifndef XP_WIN pref("dom.mapped_arraybuffer.enabled", true); -#endif // SystemUpdate API pref("dom.system_update.enabled", true); diff --git a/dom/base/test/chrome.ini b/dom/base/test/chrome.ini index 576a25cea24d..e88449f57981 100644 --- a/dom/base/test/chrome.ini +++ b/dom/base/test/chrome.ini @@ -20,8 +20,6 @@ subsuite = clipboard [test_messagemanager_send_principal.html] skip-if = buildapp == 'mulet' [test_bug945152.html] -run-if = os == 'linux' [test_bug1008126.html] -run-if = os == 'linux' [test_sandboxed_blob_uri.html] [test_websocket_frame.html] diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index fe6b6f6b90f4..2420306b91db 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -2728,7 +2728,7 @@ XMLHttpRequestMainThread::Send(nsIVariant* aVariant, const Nullable mIsMappedArrayBuffer = false; if (mResponseType == XMLHttpRequestResponseType::Arraybuffer && - Preferences::GetBool("dom.mapped_arraybuffer.enabled", false)) { + Preferences::GetBool("dom.mapped_arraybuffer.enabled", true)) { nsCOMPtr uri; nsAutoCString scheme; @@ -3757,11 +3757,6 @@ nsresult ArrayBufferBuilder::mapToFileInPackage(const nsCString& aFile, nsIFile* aJarFile) { -#ifdef XP_WIN - // TODO: Bug 988813 - Support memory mapped array buffer for Windows platform. - MOZ_CRASH("Not implemented"); - return NS_ERROR_NOT_IMPLEMENTED; -#else nsresult rv; // Open Jar file to get related attributes of target file. @@ -3793,7 +3788,6 @@ ArrayBufferBuilder::mapToFileInPackage(const nsCString& aFile, } } return NS_ERROR_FAILURE; -#endif } /* static */ bool diff --git a/js/src/gc/Memory.cpp b/js/src/gc/Memory.cpp index 735e1080e2f8..e4024b6f26fa 100644 --- a/js/src/gc/Memory.cpp +++ b/js/src/gc/Memory.cpp @@ -280,6 +280,61 @@ GetPageFaultCount() return pmc.PageFaultCount; } +// On Windows the minimum size for a mapping is the allocation granularity +// (64KiB in practice), so mapping very small buffers is potentially wasteful. +void* +AllocateMappedContent(int fd, size_t offset, size_t length, size_t alignment) +{ + // The allocation granularity must be a whole multiple of the alignment and + // the caller must request an aligned offset to satisfy Windows' and the + // caller's alignment requirements. + if (allocGranularity % alignment != 0 || offset % alignment != 0) + return nullptr; + + // Make sure file exists and do sanity check for offset and size. + HANDLE hFile = reinterpret_cast(intptr_t(fd)); + MOZ_ASSERT(hFile != INVALID_HANDLE_VALUE); + + uint32_t fSizeHgh; + uint32_t fSizeLow = GetFileSize(hFile, LPDWORD(&fSizeHgh)); + if (fSizeLow == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) + return nullptr; + + uint64_t fSize = (uint64_t(fSizeHgh) << 32) + fSizeLow; + if (offset >= size_t(fSize) || length == 0 || length > fSize - offset) + return nullptr; + + uint64_t mapSize = length + offset; + HANDLE hMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, mapSize >> 32, mapSize, nullptr); + if (!hMap) + return nullptr; + + // MapViewOfFile requires the offset to be a whole multiple of the + // allocation granularity. + size_t alignOffset = offset - (offset % allocGranularity); + size_t alignLength = length + (offset % allocGranularity); + void* map = MapViewOfFile(hMap, FILE_MAP_COPY, 0, alignOffset, alignLength); + CloseHandle(hMap); + if (!map) + return nullptr; + + return reinterpret_cast(uintptr_t(map) + (offset - alignOffset)); +} + +void +DeallocateMappedContent(void* p, size_t /*length*/) +{ + if (!p) + return; + + // Calculate the address originally returned by MapViewOfFile. + // This is required because AllocateMappedContent returns a pointer that + // might be offset into the view, necessitated by the requirement that the + // beginning of a view must be aligned with the allocation granularity. + uintptr_t map = uintptr_t(p) - (uintptr_t(p) % allocGranularity); + MOZ_ALWAYS_TRUE(UnmapViewOfFile(reinterpret_cast(map))); +} + # else // Various APIs are unavailable. void* @@ -328,12 +383,10 @@ GetPageFaultCount() return 0; } -# endif - void* AllocateMappedContent(int fd, size_t offset, size_t length, size_t alignment) { - // TODO: Bug 988813 - Support memory mapped array buffer for Windows platform. + // Not implemented. return nullptr; } @@ -341,9 +394,11 @@ AllocateMappedContent(int fd, size_t offset, size_t length, size_t alignment) void DeallocateMappedContent(void* p, size_t length) { - // TODO: Bug 988813 - Support memory mapped array buffer for Windows platform. + // Not implemented. } +# endif + #elif defined(SOLARIS) #ifndef MAP_NOSYNC diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index a172036e25b5..7bfbb247cdad 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5053,8 +5053,8 @@ pref("dom.voicemail.enabled", false); // parameter omitted. pref("dom.voicemail.defaultServiceId", 0); -// Disable mapped array buffer by default. -pref("dom.mapped_arraybuffer.enabled", false); +// Enable mapped array buffer by default. +pref("dom.mapped_arraybuffer.enabled", true); // The tables used for Safebrowsing phishing and malware checks. pref("urlclassifier.malwareTable", "goog-malware-shavar,goog-unwanted-shavar,test-malware-simple,test-unwanted-simple");