WebKit Bugzilla
Attachment 373647 Details for
Bug 198269
: Implement MappedFileData for Windows
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for landing
bug-198269-20190708112457.patch (text/plain), 12.35 KB, created by
Christopher Reid
on 2019-07-08 11:24:58 PDT
(
hide
)
Description:
Patch for landing
Filename:
MIME Type:
Creator:
Christopher Reid
Created:
2019-07-08 11:24:58 PDT
Size:
12.35 KB
patch
obsolete
>Subversion Revision: 247011 >diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt >index 91c4c75db86606ddea4b9772f1343c344f8c90d3..ba0dac40e7b1ee51df35a05c888f51da228f32f4 100644 >--- a/Source/JavaScriptCore/CMakeLists.txt >+++ b/Source/JavaScriptCore/CMakeLists.txt >@@ -224,7 +224,7 @@ add_custom_command( > if (WTF_OS_MAC_OS_X) > execute_process(COMMAND bash -c "date +'%s'" OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE) > else () >- set(BUILD_TIME 0) >+ string(TIMESTAMP BUILD_TIME "%s") # might not work for incremental builds > endif () > > file(WRITE ${JavaScriptCore_DERIVED_SOURCES_DIR}/BytecodeCacheVersion.h "#define JSC_BYTECODE_CACHE_VERSION ${BUILD_TIME}\n") >diff --git a/Source/JavaScriptCore/jsc.cpp b/Source/JavaScriptCore/jsc.cpp >index d4fa222c721cf4a7e71ad4786f984111241e1852..d82fdf6881e79fe842d89d97367381f8407a5c27 100644 >--- a/Source/JavaScriptCore/jsc.cpp >+++ b/Source/JavaScriptCore/jsc.cpp >@@ -85,6 +85,7 @@ > #include <type_traits> > #include <wtf/Box.h> > #include <wtf/CommaPrinter.h> >+#include <wtf/FileSystem.h> > #include <wtf/MainThread.h> > #include <wtf/MemoryPressureHandler.h> > #include <wtf/MonotonicTime.h> >@@ -1003,7 +1004,6 @@ public: > > void commitCachedBytecode() const override > { >-#if OS(DARWIN) > if (!cacheEnabled() || !m_cachedBytecode || !m_cachedBytecode->hasUpdates()) > return; > >@@ -1012,32 +1012,31 @@ public: > }); > > String filename = cachePath(); >- int fd = open(filename.utf8().data(), O_CREAT | O_WRONLY | O_TRUNC | O_EXLOCK | O_NONBLOCK, 0666); >- if (fd == -1) >+ //int fd = open(filename.utf8().data(), O_CREAT | O_WRONLY | O_TRUNC | O_EXLOCK | O_NONBLOCK, 0666); >+ auto lockMode = OptionSet<FileSystem::FileLockMode>(FileSystem::FileLockMode::Exclusive) | FileSystem::FileLockMode::Nonblocking; >+ auto fd = FileSystem::openAndLockFile(filename, FileSystem::FileOpenMode::Write, lockMode); // O_TRUNC? >+ if (!FileSystem::isHandleValid(fd)) > return; > > auto closeFD = makeScopeExit([&] { >- close(fd); >+ FileSystem::closeFile(fd); > }); > >- struct stat sb; >- int res = fstat(fd, &sb); >- size_t size = static_cast<size_t>(sb.st_size); >- if (res || size != m_cachedBytecode->size()) { >+ long long size; >+ if (!FileSystem::getFileSize(fd, size) || size != m_cachedBytecode->size()) { > // The bytecode cache has already been updated > return; > } > >- if (ftruncate(fd, m_cachedBytecode->sizeForUpdate())) >+ if (!FileSystem::truncateFile(fd, m_cachedBytecode->sizeForUpdate())) // FileSystemGlib doesn't have truncateFile > return; > > m_cachedBytecode->commitUpdates([&] (off_t offset, const void* data, size_t size) { >- off_t result = lseek(fd, offset, SEEK_SET); >+ long long result = FileSystem::seekFile(fd, offset, FileSystem::FileSeekOrigin::Beginning); > ASSERT_UNUSED(result, result != -1); >- size_t bytesWritten = static_cast<size_t>(write(fd, data, size)); >+ size_t bytesWritten = static_cast<size_t>(FileSystem::writeToFile(fd, static_cast<const char*>(data), size)); > ASSERT_UNUSED(bytesWritten, bytesWritten == size); > }); >-#endif > } > > private: >@@ -1046,14 +1045,12 @@ private: > if (!cacheEnabled()) > return static_cast<const char*>(nullptr); > const char* cachePath = Options::diskCachePath(); >- String filename = sourceOrigin().string(); >- filename.replace('/', '_'); >- return makeString(cachePath, '/', source().toString().hash(), '-', filename, ".bytecode-cache"); >+ String filename = FileSystem::encodeForFileName(sourceOrigin().string()); >+ return FileSystem::pathByAppendingComponent(cachePath, makeString(source().toString().hash(), '-', filename, ".bytecode-cache")); > } > > void loadBytecode() const > { >-#if OS(DARWIN) > if (!cacheEnabled()) > return; > >@@ -1061,24 +1058,30 @@ private: > if (filename.isNull()) > return; > >- int fd = open(filename.utf8().data(), O_RDONLY | O_SHLOCK | O_NONBLOCK); >- if (fd == -1) >+ // int fd = open(filename.utf8().data(), O_RDONLY | O_SHLOCK | O_NONBLOCK); >+ auto lockMode = OptionSet<FileSystem::FileLockMode>(FileSystem::FileLockMode::Shared) | FileSystem::FileLockMode::Nonblocking; >+ auto fd = FileSystem::openAndLockFile(filename, FileSystem::FileOpenMode::Read, lockMode); >+ if (!FileSystem::isHandleValid(fd)) > return; > > auto closeFD = makeScopeExit([&] { >- close(fd); >+ FileSystem::closeFile(fd); > }); > >- struct stat sb; >- int res = fstat(fd, &sb); >- size_t size = static_cast<size_t>(sb.st_size); >- if (res || !size) >+ long long size; >+ if (!FileSystem::getFileSize(fd, size)) > return; > >- void* buffer = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0); >+#if !OS(WINDOWS) >+ void* buffer = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0); // Need to switch over to MappedFileData > if (buffer == MAP_FAILED) > return; > m_cachedBytecode = CachedBytecode::create(buffer, size); >+#else >+ MallocPtr<uint8_t> bytecode = MallocPtr<uint8_t>::malloc(size); >+ FileSystem::readFromFile(fd, reinterpret_cast<char*>(bytecode.get()), size); >+ m_cachedBytecode = CachedBytecode::create(WTFMove(bytecode), size, {}); >+ > #endif > } > >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index c2f305e77004e1ea1a65c6b9cf0ceb352aaf78a2..9381e7e0310141e3e71b7353abb1e7d2f05b34d7 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,18 @@ >+2019-07-03 Christopher Reid <chris.reid@sony.com> >+ >+ Implement MappedFileData for Windows >+ https://bugs.webkit.org/show_bug.cgi?id=198269 >+ >+ Reviewed by Darin Adler. >+ >+ Original patch by Fujii Hironori. >+ >+ Add Windows implementations for MappedFileData constructor and destructor. >+ >+ * wtf/FileSystem.cpp: >+ * wtf/FileSystem.h: >+ * wtf/win/FileSystemWin.cpp: >+ > 2019-07-01 Philippe Normand <pnormand@igalia.com> > > [GStreamer] Cannot play Bert's Bytes radio stream from http://radio.dos.nl/ >diff --git a/Source/WTF/wtf/FileSystem.cpp b/Source/WTF/wtf/FileSystem.cpp >index ba49b1e77a7a41749ab40235304e9f5bf4daffa8..975429bad09f171587c63f933a1e7ca2d9657e9d 100644 >--- a/Source/WTF/wtf/FileSystem.cpp >+++ b/Source/WTF/wtf/FileSystem.cpp >@@ -274,21 +274,17 @@ bool excludeFromBackup(const String&) > > #endif > >+#if HAVE(MMAP) >+ > MappedFileData::~MappedFileData() > { >-#if !OS(WINDOWS) > if (!m_fileData) > return; > munmap(m_fileData, m_fileSize); >-#endif > } > > MappedFileData::MappedFileData(const String& filePath, bool& success) > { >-#if OS(WINDOWS) >- // FIXME: Implement mapping >- success = false; >-#else > CString fsRep = fileSystemRepresentation(filePath); > int fd = !fsRep.isNull() ? open(fsRep.data(), O_RDONLY) : -1; > if (fd < 0) { >@@ -327,9 +323,10 @@ MappedFileData::MappedFileData(const String& filePath, bool& success) > success = true; > m_fileData = data; > m_fileSize = size; >-#endif > } > >+#endif >+ > PlatformFileHandle openAndLockFile(const String& path, FileOpenMode openMode, OptionSet<FileLockMode> lockMode) > { > auto handle = openFile(path, openMode); >diff --git a/Source/WTF/wtf/FileSystem.h b/Source/WTF/wtf/FileSystem.h >index 32fe76df400072cfb7499b7fd48a3a3b148b2a4a..52ed8074a511ee15a942e9c4708556e8b585d229 100644 >--- a/Source/WTF/wtf/FileSystem.h >+++ b/Source/WTF/wtf/FileSystem.h >@@ -138,7 +138,7 @@ WTF_EXPORT_PRIVATE PlatformFileHandle openFile(const String& path, FileOpenMode) > WTF_EXPORT_PRIVATE void closeFile(PlatformFileHandle&); > // Returns the resulting offset from the beginning of the file if successful, -1 otherwise. > WTF_EXPORT_PRIVATE long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin); >-bool truncateFile(PlatformFileHandle, long long offset); >+WTF_EXPORT_PRIVATE bool truncateFile(PlatformFileHandle, long long offset); > // Returns number of bytes actually read if successful, -1 otherwise. > WTF_EXPORT_PRIVATE int writeToFile(PlatformFileHandle, const char* data, int length); > // Returns number of bytes actually written if successful, -1 otherwise. >diff --git a/Source/WTF/wtf/UUID.cpp b/Source/WTF/wtf/UUID.cpp >index 85968bf59116d13cad92396f339f204fe1dc2151..15ca00a710b97c69025eb5015d00171e89a3a45d 100644 >--- a/Source/WTF/wtf/UUID.cpp >+++ b/Source/WTF/wtf/UUID.cpp >@@ -66,8 +66,8 @@ String createCanonicalUUIDString() > > String bootSessionUUIDString() > { >- static LazyNeverDestroyed<String> bootSessionUUID; > #if OS(DARWIN) >+ static LazyNeverDestroyed<String> bootSessionUUID; > static std::once_flag onceKey; > std::call_once(onceKey, [] { > size_t uuidLength = 37; >@@ -76,8 +76,10 @@ String bootSessionUUIDString() > return; > bootSessionUUID.construct(static_cast<const char*>(uuid), uuidLength - 1); > }); >-#endif > return bootSessionUUID; >+#else >+ return String(); >+#endif > } > > } // namespace WTF >diff --git a/Source/WTF/wtf/win/FileSystemWin.cpp b/Source/WTF/wtf/win/FileSystemWin.cpp >index e473157f228c8b3e87c4c379aa06941c8aa20f93..8fe01715cd49f6c3c725e67d8e0313c1bb88a654 100644 >--- a/Source/WTF/wtf/win/FileSystemWin.cpp >+++ b/Source/WTF/wtf/win/FileSystemWin.cpp >@@ -470,6 +470,17 @@ long long seekFile(PlatformFileHandle handle, long long offset, FileSeekOrigin o > return largeOffset.QuadPart; > } > >+bool truncateFile(PlatformFileHandle handle, long long offset) >+{ >+ LARGE_INTEGER largeOffset; >+ largeOffset.QuadPart = offset; >+ >+ FILE_END_OF_FILE_INFO eofInfo; >+ eofInfo.EndOfFile = largeOffset; >+ >+ return SetFileInformationByHandle(handle, FileEndOfFileInfo, &eofInfo, sizeof(FILE_END_OF_FILE_INFO)); >+} >+ > int writeToFile(PlatformFileHandle handle, const char* data, int length) > { > if (!isHandleValid(handle)) >@@ -588,5 +599,44 @@ bool deleteNonEmptyDirectory(const String& directoryPath) > return !SHFileOperation(&deleteOperation); > } > >+MappedFileData::~MappedFileData() >+{ >+ if (!m_fileData) >+ return; >+ UnmapViewOfFile(m_fileData); >+} >+ >+MappedFileData::MappedFileData(const String& filePath, bool& success) >+{ >+ success = false; >+ auto file = CreateFile(filePath.wideCharacters().data(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); >+ if (file == INVALID_HANDLE_VALUE) >+ return; >+ >+ long long size; >+ if (!getFileSize(file, size) || size > std::numeric_limits<size_t>::max() || size > std::numeric_limits<decltype(m_fileSize)>::max()) { >+ CloseHandle(file); >+ return; >+ } >+ >+ if (!size) { >+ CloseHandle(file); >+ success = true; >+ return; >+ } >+ >+ auto mapping = CreateFileMapping(file, nullptr, PAGE_READONLY, 0, 0, nullptr); >+ CloseHandle(file); >+ if (!mapping) >+ return; >+ >+ m_fileData = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, size); >+ CloseHandle(mapping); >+ if (!m_fileData) >+ return; >+ m_fileSize = size; >+ success = true; >+} >+ > } // namespace FileSystemImpl > } // namespace WTF >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index bdf9bb358040f6727b85d23e80f6e062f654fef5..4578d5f290043e5998a8666f2c187d3d4013b249 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,12 @@ >+2019-07-03 Christopher Reid <chris.reid@sony.com> >+ >+ Implement MappedFileData for Windows >+ https://bugs.webkit.org/show_bug.cgi?id=198269 >+ >+ Reviewed by Darin Adler. >+ >+ * TestWebKitAPI/PlatformWin.cmake: >+ > 2019-07-01 Philippe Normand <pnormand@igalia.com> > > Unreviewed, GTK a11y tests fix after r246958 >diff --git a/Tools/TestWebKitAPI/PlatformWin.cmake b/Tools/TestWebKitAPI/PlatformWin.cmake >index 0c48cf04fe541e52aa27db78e5747778e2a178ac..349334826fa34db28ae2d8260fc5ae4d524dc0ef 100644 >--- a/Tools/TestWebKitAPI/PlatformWin.cmake >+++ b/Tools/TestWebKitAPI/PlatformWin.cmake >@@ -17,7 +17,6 @@ set(test_main_SOURCES > ) > > # TestWTF >-list(REMOVE_ITEM TestWTF_SOURCES Tests/WTF/FileSystem.cpp) > list(APPEND TestWTF_SOURCES > ${test_main_SOURCES} > win/UtilitiesWin.cpp >warning: LF will be replaced by CRLF in Source/WTF/ChangeLog. >The file will have its original line endings in your working directory >warning: LF will be replaced by CRLF in Tools/ChangeLog. >The file will have its original line endings in your working directory
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
chris.reid
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198269
:
370666
|
373420
|
373645
|
373647
|
373649