WebKit Bugzilla
Attachment 370666 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]
WIP patch
map.diff (text/plain), 5.25 KB, created by
Fujii Hironori
on 2019-05-26 22:10:00 PDT
(
hide
)
Description:
WIP patch
Filename:
MIME Type:
Creator:
Fujii Hironori
Created:
2019-05-26 22:10:00 PDT
Size:
5.25 KB
patch
obsolete
>diff --git a/Source/WTF/wtf/FileSystem.cpp b/Source/WTF/wtf/FileSystem.cpp >index ba49b1e77a7..5237fb53886 100644 >--- a/Source/WTF/wtf/FileSystem.cpp >+++ b/Source/WTF/wtf/FileSystem.cpp >@@ -274,62 +274,6 @@ bool excludeFromBackup(const String&) > > #endif > >-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) { >- success = false; >- return; >- } >- >- struct stat fileStat; >- if (fstat(fd, &fileStat)) { >- close(fd); >- success = false; >- return; >- } >- >- unsigned size; >- if (!WTF::convertSafely(fileStat.st_size, size)) { >- close(fd); >- success = false; >- return; >- } >- >- if (!size) { >- close(fd); >- success = true; >- return; >- } >- >- void* data = mmap(0, size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); >- close(fd); >- >- if (data == MAP_FAILED) { >- success = false; >- return; >- } >- >- success = true; >- m_fileData = data; >- m_fileSize = size; >-#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 32fe76df400..32fb0eb3c94 100644 >--- a/Source/WTF/wtf/FileSystem.h >+++ b/Source/WTF/wtf/FileSystem.h >@@ -33,6 +33,7 @@ > #include <time.h> > #include <utility> > #include <wtf/Forward.h> >+#include <wtf/Noncopyable.h> > #include <wtf/OptionSet.h> > #include <wtf/Vector.h> > #include <wtf/WallTime.h> >@@ -192,6 +193,7 @@ WTF_EXPORT_PRIVATE bool isSafeToUseMemoryMapForPath(const String&); > WTF_EXPORT_PRIVATE void makeSafeToUseMemoryMapForPath(const String&); > > class MappedFileData { >+ WTF_MAKE_NONCOPYABLE(MappedFileData); > public: > MappedFileData() { } > MappedFileData(MappedFileData&&); >diff --git a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp b/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >index ad3c926153f..b6a5f08f1d5 100644 >--- a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >+++ b/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >@@ -508,5 +508,54 @@ String realPath(const String& filePath) > return result ? String::fromUTF8(result) : filePath; > } > >+MappedFileData::~MappedFileData() >+{ >+ if (!m_fileData) >+ return; >+ munmap(m_fileData, m_fileSize); >+} >+ >+MappedFileData::MappedFileData(const String& filePath, bool& success) >+{ >+ CString fsRep = fileSystemRepresentation(filePath); >+ int fd = !fsRep.isNull() ? open(fsRep.data(), O_RDONLY) : -1; >+ if (fd < 0) { >+ success = false; >+ return; >+ } >+ >+ struct stat fileStat; >+ if (fstat(fd, &fileStat)) { >+ close(fd); >+ success = false; >+ return; >+ } >+ >+ unsigned size; >+ if (!WTF::convertSafely(fileStat.st_size, size)) { >+ close(fd); >+ success = false; >+ return; >+ } >+ >+ if (!size) { >+ close(fd); >+ success = true; >+ return; >+ } >+ >+ void* data = mmap(0, size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); >+ close(fd); >+ >+ if (data == MAP_FAILED) { >+ success = false; >+ return; >+ } >+ >+ success = true; >+ m_fileData = data; >+ m_fileSize = size; >+} >+ > } // namespace FileSystemImpl > } // namespace WTF >diff --git a/Source/WTF/wtf/win/FileSystemWin.cpp b/Source/WTF/wtf/win/FileSystemWin.cpp >index e473157f228..5910da2f743 100644 >--- a/Source/WTF/wtf/win/FileSystemWin.cpp >+++ b/Source/WTF/wtf/win/FileSystemWin.cpp >@@ -588,5 +588,35 @@ 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; >+ } >+ 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/TestWebKitAPI/PlatformWin.cmake b/Tools/TestWebKitAPI/PlatformWin.cmake >index 4aa7cd95061..4636dcce18c 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
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
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198269
: 370666 |
373420
|
373645
|
373647
|
373649