Bug 988831 - support memory mapped files in Windows. r=ehoogeveen

--HG--
extra : rebase_source : faf8d37b0d4d517b8a859b3fa57f8cd7f914de8f
This commit is contained in:
Benjamin Dahse 2016-06-30 14:32:13 +02:00
Родитель 0642c8d7d3
Коммит 2400e065d1
5 изменённых файлов: 62 добавлений и 17 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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]

Просмотреть файл

@ -2728,7 +2728,7 @@ XMLHttpRequestMainThread::Send(nsIVariant* aVariant, const Nullable<RequestBody>
mIsMappedArrayBuffer = false;
if (mResponseType == XMLHttpRequestResponseType::Arraybuffer &&
Preferences::GetBool("dom.mapped_arraybuffer.enabled", false)) {
Preferences::GetBool("dom.mapped_arraybuffer.enabled", true)) {
nsCOMPtr<nsIURI> 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

Просмотреть файл

@ -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<HANDLE>(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<void*>(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<void*>(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

Просмотреть файл

@ -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");