Title: [256700] trunk

Diff

Modified: trunk/LayoutTests/ChangeLog (256699 => 256700)


--- trunk/LayoutTests/ChangeLog	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/LayoutTests/ChangeLog	2020-02-15 06:54:35 UTC (rev 256700)
@@ -1,3 +1,18 @@
+2020-02-14  Commit Queue  <commit-qu...@webkit.org>
+
+        Unreviewed, rolling out r256633.
+        https://bugs.webkit.org/show_bug.cgi?id=207807
+
+        4% memory regression in new Membuster, possibly some leaking
+        in WebKit Malloc? (Requested by yusukesuzuki on #webkit).
+
+        Reverted changeset:
+
+        "[Win] Implement NetworkCache::Data by using
+        FileSystem::MappedFileData"
+        https://bugs.webkit.org/show_bug.cgi?id=197684
+        https://trac.webkit.org/changeset/256633
+
 2020-02-14  Lauro Moura  <lmo...@igalia.com>
 
         [GTK] Layout test imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/event_timeupdate_noautoplay.html is flaky

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (256699 => 256700)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2020-02-15 06:54:35 UTC (rev 256700)
@@ -1161,20 +1161,7 @@
 
 http/tests/appcache [ Skip ]
 http/tests/blink/sendbeacon [ Skip ]
-
-# needs more investigation
-http/tests/cache/cancel-multiple-post-xhrs.html [ Failure ]
-
-# fails because of conversion to epoch behavior specific to Mac
-http/tests/cache/disk-cache/disk-cache-last-modified.html [ Failure ]
-
-# needs more investigation
-http/tests/cache/iframe-304-crash.html [ Failure ]
-http/tests/cache/network-error-during-revalidation.html [ Failure ]
-http/tests/cache/partitioned-cache-iframe.html [ Failure ]
-http/tests/cache/partitioned-cache.html [ Failure ]
-http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html [ Failure ]
-
+http/tests/cache [ Skip ]
 http/tests/cache-storage [ Skip ]
 http/tests/canvas [ Skip ]
 http/tests/contentdispositionattachmentsandbox [ Skip ]

Modified: trunk/Source/WTF/ChangeLog (256699 => 256700)


--- trunk/Source/WTF/ChangeLog	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/ChangeLog	2020-02-15 06:54:35 UTC (rev 256700)
@@ -1,3 +1,18 @@
+2020-02-14  Commit Queue  <commit-qu...@webkit.org>
+
+        Unreviewed, rolling out r256633.
+        https://bugs.webkit.org/show_bug.cgi?id=207807
+
+        4% memory regression in new Membuster, possibly some leaking
+        in WebKit Malloc? (Requested by yusukesuzuki on #webkit).
+
+        Reverted changeset:
+
+        "[Win] Implement NetworkCache::Data by using
+        FileSystem::MappedFileData"
+        https://bugs.webkit.org/show_bug.cgi?id=197684
+        https://trac.webkit.org/changeset/256633
+
 2020-02-14  Christopher Reid  <chris.r...@sony.com>
 
         [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData

Modified: trunk/Source/WTF/wtf/FileSystem.cpp (256699 => 256700)


--- trunk/Source/WTF/wtf/FileSystem.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/wtf/FileSystem.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -287,17 +287,17 @@
     unmapViewOfFile(m_fileData, m_fileSize);
 }
 
-MappedFileData::MappedFileData(const String& filePath, MappedFileMode mapMode, bool& success)
+#if HAVE(MMAP)
+
+MappedFileData::MappedFileData(const String& filePath, MappedFileMode mode, bool& success)
 {
-    auto fd = openFile(filePath, FileSystem::FileOpenMode::Read);
+    auto fd = openFile(filePath, FileOpenMode::Read);
 
-    success = mapFileHandle(fd, FileSystem::FileOpenMode::Read, mapMode);
+    success = mapFileHandle(fd, mode);
     closeFile(fd);
 }
 
-#if HAVE(MMAP)
-
-bool MappedFileData::mapFileHandle(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode mapMode)
+bool MappedFileData::mapFileHandle(PlatformFileHandle handle, MappedFileMode mode)
 {
     if (!isHandleValid(handle))
         return false;
@@ -324,22 +324,8 @@
         return true;
     }
 
-    int pageProtection = PROT_READ;
-    switch (openMode) {
-    case FileOpenMode::Read:
-        pageProtection = PROT_READ;
-        break;
-    case FileOpenMode::Write:
-        pageProtection = PROT_WRITE;
-        break;
-#if OS(DARWIN)
-    case FileOpenMode::EventsOnly:
-        ASSERT_NOT_REACHED();
-#endif
-    }
+    void* data = "" size, PROT_READ, MAP_FILE | (mode == MappedFileMode::Shared ? MAP_SHARED : MAP_PRIVATE), fd, 0);
 
-    void* data = "" size, pageProtection, MAP_FILE | (mapMode == MappedFileMode::Shared ? MAP_SHARED : MAP_PRIVATE), fd, 0);
-
     if (data == MAP_FAILED) {
         return false;
     }

Modified: trunk/Source/WTF/wtf/FileSystem.h (256699 => 256700)


--- trunk/Source/WTF/wtf/FileSystem.h	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/wtf/FileSystem.h	2020-02-15 06:54:35 UTC (rev 256700)
@@ -84,11 +84,6 @@
 #endif
 };
 
-enum class FileAccessPermission : bool {
-    User,
-    All
-};
-
 enum class FileSeekOrigin {
     Beginning,
     Current,
@@ -136,7 +131,7 @@
 bool canExcludeFromBackup(); // Returns true if any file can ever be excluded from backup.
 bool excludeFromBackup(const String&); // Returns true if successful.
 
-WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter);
+WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter = String());
 
 WTF_EXPORT_PRIVATE CString fileSystemRepresentation(const String&);
 String stringFromFileSystemRepresentation(const char*);
@@ -145,7 +140,7 @@
 
 // Prefix is what the filename should be prefixed with, not the full path.
 WTF_EXPORT_PRIVATE String openTemporaryFile(const String& prefix, PlatformFileHandle&);
-WTF_EXPORT_PRIVATE PlatformFileHandle openFile(const String& path, FileOpenMode, FileAccessPermission = FileAccessPermission::All);
+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);
@@ -211,7 +206,6 @@
     MappedFileData(MappedFileData&&);
     WTF_EXPORT_PRIVATE MappedFileData(const String& filePath, MappedFileMode, bool& success);
     WTF_EXPORT_PRIVATE MappedFileData(PlatformFileHandle, MappedFileMode, bool& success);
-    WTF_EXPORT_PRIVATE MappedFileData(PlatformFileHandle, FileOpenMode, MappedFileMode, bool& success);
     WTF_EXPORT_PRIVATE ~MappedFileData();
     MappedFileData& operator=(MappedFileData&&);
 
@@ -222,22 +216,17 @@
     void* leakHandle() { return std::exchange(m_fileData, nullptr); }
 
 private:
-    WTF_EXPORT_PRIVATE bool mapFileHandle(PlatformFileHandle, FileOpenMode, MappedFileMode);
+    WTF_EXPORT_PRIVATE bool mapFileHandle(PlatformFileHandle, MappedFileMode);
 
     void* m_fileData { nullptr };
     unsigned m_fileSize { 0 };
 };
 
-inline MappedFileData::MappedFileData(PlatformFileHandle handle, MappedFileMode mapMode, bool& success)
+inline MappedFileData::MappedFileData(PlatformFileHandle handle, MappedFileMode mode, bool& success)
 {
-    success = mapFileHandle(handle, FileOpenMode::Read, mapMode);
+    success = mapFileHandle(handle, mode);
 }
 
-inline MappedFileData::MappedFileData(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode mapMode, bool& success)
-{
-    success = mapFileHandle(handle, openMode, mapMode);
-}
-
 inline MappedFileData::MappedFileData(MappedFileData&& other)
     : m_fileData(std::exchange(other.m_fileData, nullptr))
     , m_fileSize(std::exchange(other.m_fileSize, 0))

Modified: trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp (256699 => 256700)


--- trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -338,7 +338,7 @@
     return String::fromUTF8(tempPath.get());
 }
 
-PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission permission)
+PlatformFileHandle openFile(const String& path, FileOpenMode mode)
 {
     auto filename = fileSystemRepresentation(path);
     if (!validRepresentation(filename))
@@ -351,10 +351,8 @@
     else if (mode == FileOpenMode::Write) {
         if (g_file_test(filename.data(), static_cast<GFileTest>(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)))
             ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr));
-        else {
-            GFileCreateFlags permissionFlag = (permission == FileAccessPermission::All) ? G_FILE_CREATE_NONE : G_FILE_CREATE_PRIVATE;
-            ioStream = adoptGRef(g_file_create_readwrite(file.get(), permissionFlag, nullptr, nullptr));
-        }
+        else
+            ioStream = adoptGRef(g_file_create_readwrite(file.get(), G_FILE_CREATE_NONE, nullptr, nullptr));
     }
 
     return ioStream.leakRef();

Modified: trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp (256699 => 256700)


--- trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -79,7 +79,7 @@
     return unlinked;
 }
 
-PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission permission)
+PlatformFileHandle openFile(const String& path, FileOpenMode mode)
 {
     CString fsRep = fileSystemRepresentation(path);
 
@@ -87,27 +87,16 @@
         return invalidPlatformFileHandle;
 
     int platformFlag = 0;
-    switch (mode) {
-    case FileOpenMode::Read:
+    if (mode == FileOpenMode::Read)
         platformFlag |= O_RDONLY;
-        break;
-    case FileOpenMode::Write:
+    else if (mode == FileOpenMode::Write)
         platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC);
-        break;
 #if OS(DARWIN)
-    case FileOpenMode::EventsOnly:
+    else if (mode == FileOpenMode::EventsOnly)
         platformFlag |= O_EVTONLY;
-        break;
 #endif
-    }
 
-    int permissionFlag = 0;
-    if (permission == FileAccessPermission::User)
-        permissionFlag |= (S_IRUSR | S_IWUSR);
-    else if (permission == FileAccessPermission::All)
-        permissionFlag |= (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
-
-    return open(fsRep.data(), platformFlag, permissionFlag);
+    return open(fsRep.data(), platformFlag, 0666);
 }
 
 void closeFile(PlatformFileHandle& handle)

Modified: trunk/Source/WTF/wtf/win/FileSystemWin.cpp (256699 => 256700)


--- trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -421,7 +421,7 @@
     return proposedPath;
 }
 
-PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission)
+PlatformFileHandle openFile(const String& path, FileOpenMode mode)
 {
     DWORD desiredAccess = 0;
     DWORD creationDisposition = 0;
@@ -436,6 +436,8 @@
         desiredAccess = GENERIC_WRITE;
         creationDisposition = CREATE_ALWAYS;
         break;
+    default:
+        ASSERT_NOT_REACHED();
     }
 
     String destination = path;
@@ -547,14 +549,9 @@
     return entries;
 }
 
-bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
+bool getVolumeFreeSpace(const String&, uint64_t&)
 {
-    ULARGE_INTEGER freeBytesAvailableToCaller;
-    if (!GetDiskFreeSpaceExW(path.wideCharacters().data(), &freeBytesAvailableToCaller, nullptr, nullptr))
-        return false;
-
-    freeSpace = freeBytesAvailableToCaller.QuadPart;
-    return true;
+    return false;
 }
 
 Optional<int32_t> getFileDeviceId(const CString& fsFile)
@@ -606,8 +603,16 @@
     return UnmapViewOfFile(buffer);
 }
 
-bool MappedFileData::mapFileHandle(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode)
+MappedFileData::MappedFileData(const String& filePath, MappedFileMode mode, bool& success)
 {
+    auto file = CreateFile(filePath.wideCharacters().data(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+
+    success = mapFileHandle(file, mode);
+    closeFile(file);
+}
+
+bool MappedFileData::mapFileHandle(PlatformFileHandle handle, MappedFileMode)
+{
     if (!isHandleValid(handle))
         return false;
 
@@ -620,24 +625,11 @@
         return true;
     }
 
-    DWORD pageProtection = PAGE_READONLY;
-    DWORD desiredAccess = FILE_MAP_READ;
-    switch (openMode) {
-    case FileOpenMode::Read:
-        pageProtection = PAGE_READONLY;
-        desiredAccess = FILE_MAP_READ;
-        break;
-    case FileOpenMode::Write:
-        pageProtection = PAGE_READWRITE;
-        desiredAccess = FILE_MAP_WRITE;
-        break;
-    }
-
-    auto mapping = CreateFileMapping(handle, nullptr, pageProtection, 0, 0, nullptr);
+    auto mapping = CreateFileMapping(handle, nullptr, PAGE_READONLY, 0, 0, nullptr);
     if (!mapping)
         return false;
 
-    m_fileData = MapViewOfFile(mapping, desiredAccess, 0, 0, size);
+    m_fileData = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, size);
     CloseHandle(mapping);
     if (!m_fileData)
         return false;

Modified: trunk/Source/WTF/wtf/win/PathWalker.cpp (256699 => 256700)


--- trunk/Source/WTF/wtf/win/PathWalker.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WTF/wtf/win/PathWalker.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -32,7 +32,7 @@
 
 PathWalker::PathWalker(const String& directory, const String& pattern)
 {
-    String path = makeString(directory, '\\', pattern);
+    String path = directory + "\\" + pattern;
     m_handle = ::FindFirstFileW(path.wideCharacters().data(), &m_data);
 }
 

Modified: trunk/Source/WebKit/ChangeLog (256699 => 256700)


--- trunk/Source/WebKit/ChangeLog	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/ChangeLog	2020-02-15 06:54:35 UTC (rev 256700)
@@ -1,3 +1,18 @@
+2020-02-14  Commit Queue  <commit-qu...@webkit.org>
+
+        Unreviewed, rolling out r256633.
+        https://bugs.webkit.org/show_bug.cgi?id=207807
+
+        4% memory regression in new Membuster, possibly some leaking
+        in WebKit Malloc? (Requested by yusukesuzuki on #webkit).
+
+        Reverted changeset:
+
+        "[Win] Implement NetworkCache::Data by using
+        FileSystem::MappedFileData"
+        https://bugs.webkit.org/show_bug.cgi?id=197684
+        https://trac.webkit.org/changeset/256633
+
 2020-02-14  Jon Lee  <jon...@apple.com>
 
         Mask WebGL strings

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -453,11 +453,8 @@
     auto isNewEntry = m_sessionStorageQuotaManagers.ensure(sessionID, [defaultQuota, defaultThirdPartyQuota, &cacheRootPath] {
         return makeUnique<SessionStorageQuotaManager>(cacheRootPath, defaultQuota, defaultThirdPartyQuota);
     }).isNewEntry;
-    if (isNewEntry) {
+    if (isNewEntry)
         SandboxExtension::consumePermanently(cacheRootPathHandle);
-        if (!cacheRootPath.isEmpty())
-            postStorageTask(createCrossThreadTask(*this, &NetworkProcess::ensurePathExists, cacheRootPath));
-    }
 }
 
 void NetworkProcess::removeSessionStorageQuotaManager(PAL::SessionID sessionID)

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -28,6 +28,7 @@
 
 #include <fcntl.h>
 #include <wtf/CryptographicallyRandomNumber.h>
+#include <wtf/FileSystem.h>
 
 #if !OS(WINDOWS)
 #include <sys/mman.h>
@@ -38,23 +39,26 @@
 namespace WebKit {
 namespace NetworkCache {
 
+#if !OS(WINDOWS)
 Data Data::mapToFile(const String& path) const
 {
-    auto handle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write, FileSystem::FileAccessPermission::User);
-    if (!FileSystem::truncateFile(handle, m_size)) {
-        FileSystem::closeFile(handle);
+    int fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
+    if (fd < 0)
         return { };
+
+    if (ftruncate(fd, m_size) < 0) {
+        close(fd);
+        return { };
     }
     
     FileSystem::makeSafeToUseMemoryMapForPath(path);
-    bool success;
-    FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::Write, FileSystem::MappedFileMode::Shared, success);
-    if (!success) {
-        FileSystem::closeFile(handle);
+
+    void* map = mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    if (map == MAP_FAILED) {
+        close(fd);
         return { };
     }
 
-    void* map = const_cast<void*>(mappedFile.data());
     uint8_t* mapData = static_cast<uint8_t*>(map);
     apply([&mapData](const uint8_t* bytes, size_t bytesSize) {
         memcpy(mapData, bytes, bytesSize);
@@ -62,23 +66,52 @@
         return true;
     });
 
-#if OS(WINDOWS)
-    DWORD oldProtection;
-    VirtualProtect(map, m_size, FILE_MAP_READ, &oldProtection);
-    FlushViewOfFile(map, m_size);
-#else
     // Drop the write permission.
     mprotect(map, m_size, PROT_READ);
 
     // Flush (asynchronously) to file, turning this into clean memory.
     msync(map, m_size, MS_ASYNC);
-#endif
 
-    return Data::adoptMap(WTFMove(mappedFile), handle);
+    return Data::adoptMap(map, m_size, fd);
 }
+#else
+Data Data::mapToFile(const String& path) const
+{
+    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
+    if (!FileSystem::isHandleValid(file))
+        return { };
+    if (FileSystem::writeToFile(file, reinterpret_cast<const char*>(data()), size()) < 0)
+        return { };
+    return Data(Vector<uint8_t>(m_buffer));
+}
+#endif
 
+#if !OS(WINDOWS)
 Data mapFile(const char* path)
 {
+    int fd = open(path, O_RDONLY, 0);
+    if (fd < 0)
+        return { };
+    struct stat stat;
+    if (fstat(fd, &stat) < 0) {
+        close(fd);
+        return { };
+    }
+    size_t size = stat.st_size;
+    if (!size) {
+        close(fd);
+        return Data::empty();
+    }
+
+    return adoptAndMapFile(fd, 0, size);
+}
+#endif
+
+Data mapFile(const String& path)
+{
+#if !OS(WINDOWS)
+    return mapFile(FileSystem::fileSystemRepresentation(path).data());
+#else
     auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
     if (!FileSystem::isHandleValid(file))
         return { };
@@ -86,28 +119,31 @@
     if (!FileSystem::getFileSize(file, size))
         return { };
     return adoptAndMapFile(file, 0, size);
+#endif
 }
 
-Data mapFile(const String& path)
+#if !OS(WINDOWS)
+Data adoptAndMapFile(int fd, size_t offset, size_t size)
 {
-    return mapFile(FileSystem::fileSystemRepresentation(path).data());
-}
-
-Data adoptAndMapFile(FileSystem::PlatformFileHandle handle, size_t offset, size_t size)
-{
     if (!size) {
-        FileSystem::closeFile(handle);
+        close(fd);
         return Data::empty();
     }
-    bool success;
-    FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::Read, FileSystem::MappedFileMode::Private, success);
-    if (!success) {
-        FileSystem::closeFile(handle);
+
+    void* map = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, offset);
+    if (map == MAP_FAILED) {
+        close(fd);
         return { };
     }
 
-    return Data::adoptMap(WTFMove(mappedFile), handle);
+    return Data::adoptMap(map, size, fd);
 }
+#else
+Data adoptAndMapFile(FileSystem::PlatformFileHandle file, size_t offset, size_t size)
+{
+    return Data(file, offset, size);
+}
+#endif
 
 SHA1::Digest computeSHA1(const Data& data, const Salt& salt)
 {
@@ -143,25 +179,40 @@
 
 Optional<Salt> readOrMakeSalt(const String& path)
 {
-    if (fileExists(path)) {
-        auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
-        Salt salt;
-        auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size());
-        FileSystem::closeFile(file);
-        if (bytesRead != salt.size())
+#if !OS(WINDOWS)
+    auto cpath = FileSystem::fileSystemRepresentation(path);
+    auto fd = open(cpath.data(), O_RDONLY, 0);
+    Salt salt;
+    auto bytesRead = read(fd, salt.data(), salt.size());
+    close(fd);
+    if (bytesRead != static_cast<ssize_t>(salt.size())) {
+        salt = makeSalt();
+
+        unlink(cpath.data());
+        fd = open(cpath.data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
+        bool success = write(fd, salt.data(), salt.size()) == static_cast<ssize_t>(salt.size());
+        close(fd);
+        if (!success)
             return { };
-
-        return salt;
     }
-
-    Salt salt = makeSalt();
-    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write, FileSystem::FileAccessPermission::User);
-    bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size();
+    return salt;
+#else
+    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
+    Salt salt;
+    auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size());
     FileSystem::closeFile(file);
-    if (!success)
-        return { };
+    if (bytesRead != salt.size()) {
+        salt = makeSalt();
 
+        FileSystem::deleteFile(path);
+        file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
+        bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size();
+        FileSystem::closeFile(file);
+        if (!success)
+            return { };
+    }
     return salt;
+#endif
 }
 
 } // namespace NetworkCache

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h	2020-02-15 06:54:35 UTC (rev 256700)
@@ -39,11 +39,6 @@
 #include <WebCore/GRefPtrSoup.h>
 #endif
 
-#if USE(CURL)
-#include <wtf/Box.h>
-#include <wtf/Variant.h>
-#endif
-
 namespace WebKit {
 
 class SharedMemory;
@@ -58,7 +53,9 @@
     ~Data() { }
 
     static Data empty();
-    static Data adoptMap(FileSystem::MappedFileData&&, FileSystem::PlatformFileHandle);
+#if !OS(WINDOWS)
+    static Data adoptMap(void* map, size_t, int fd);
+#endif
 
 #if PLATFORM(COCOA)
     enum class Backing { Buffer, Map };
@@ -65,9 +62,10 @@
     Data(OSObjectPtr<dispatch_data_t>&&, Backing = Backing::Buffer);
 #endif
 #if USE(SOUP)
-    Data(GRefPtr<SoupBuffer>&&, FileSystem::PlatformFileHandle fd = FileSystem::invalidPlatformFileHandle);
-#elif USE(CURL)
-    Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&&);
+    Data(GRefPtr<SoupBuffer>&&, int fd = -1);
+#elif OS(WINDOWS)
+    explicit Data(Vector<uint8_t>&&);
+    Data(FileSystem::PlatformFileHandle, size_t offset, size_t);
 #endif
     bool isNull() const;
     bool isEmpty() const { return !m_size; }
@@ -96,10 +94,10 @@
 #endif
 #if USE(SOUP)
     mutable GRefPtr<SoupBuffer> m_buffer;
-    FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle };
+    int m_fileDescriptor { -1 };
 #endif
-#if USE(CURL)
-    Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>> m_buffer;
+#if OS(WINDOWS)
+    Vector<uint8_t> m_buffer;
 #endif
     mutable const uint8_t* m_data { nullptr };
     size_t m_size { 0 };
@@ -108,8 +106,17 @@
 
 Data concatenate(const Data&, const Data&);
 bool bytesEqual(const Data&, const Data&);
+#if !OS(WINDOWS)
+Data adoptAndMapFile(int, size_t offset, size_t);
+#else
 Data adoptAndMapFile(FileSystem::PlatformFileHandle, size_t offset, size_t);
+#endif
+#if USE(GLIB) && !PLATFORM(WIN)
+Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t);
+#endif
+#if !OS(WINDOWS)
 Data mapFile(const char* path);
+#endif
 Data mapFile(const String& path);
 
 using Salt = std::array<uint8_t, 8>;

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm	2020-02-15 06:54:35 UTC (rev 256700)
@@ -92,13 +92,11 @@
     return { adoptOSObject(dispatch_data_create_concat(a.dispatchData(), b.dispatchData())) };
 }
 
-Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd)
+Data Data::adoptMap(void* map, size_t size, int fd)
 {
-    size_t size = mappedFile.size();
-    void* map = mappedFile.leakHandle();
     ASSERT(map);
     ASSERT(map != MAP_FAILED);
-    FileSystem::closeFile(fd);
+    close(fd);
     auto bodyMap = adoptOSObject(dispatch_data_create(map, size, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [map, size] {
         munmap(map, size);
     }));

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -30,42 +30,40 @@
 namespace NetworkCache {
 
 Data::Data(const uint8_t* data, size_t size)
-    : m_buffer(Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>>::create(Vector<uint8_t>(size)))
-    , m_size(size)
 {
-    memcpy(WTF::get<Vector<uint8_t>>(*m_buffer).data(), data, size);
+    m_buffer.resize(size);
+    m_size = size;
+    memcpy(m_buffer.data(), data, size);
 }
 
-Data::Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&& data)
-    : m_buffer(Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>>::create(WTFMove(data)))
-    , m_isMap(WTF::holds_alternative<FileSystem::MappedFileData>(*m_buffer))
+Data::Data(FileSystem::PlatformFileHandle file, size_t offset, size_t size)
 {
-    m_size = WTF::switchOn(*m_buffer,
-        [](const Vector<uint8_t>& buffer) -> size_t { return buffer.size(); },
-        [](const FileSystem::MappedFileData& mappedFile) -> size_t { return mappedFile.size(); }
-    );
+    m_buffer.resize(size);
+    m_size = size;
+    FileSystem::seekFile(file, offset, FileSystem::FileSeekOrigin::Beginning);
+    FileSystem::readFromFile(file, reinterpret_cast<char*>(m_buffer.data()), size);
+    FileSystem::closeFile(file);
 }
 
+Data::Data(Vector<uint8_t>&& buffer)
+    : m_buffer(WTFMove(buffer))
+{
+    m_size = m_buffer.size();
+}
+
 Data Data::empty()
 {
-    Vector<uint8_t> buffer;
-    return { WTFMove(buffer) };
+    return { };
 }
 
 const uint8_t* Data::data() const
 {
-    if (!m_buffer)
-        return nullptr;
-
-    return WTF::switchOn(*m_buffer,
-        [](const Vector<uint8_t>& buffer) -> const uint8_t* { return buffer.data(); },
-        [](const FileSystem::MappedFileData& mappedFile) -> const uint8_t* { return static_cast<const uint8_t*>(mappedFile.data()); }
-    );
+    return m_buffer.data();
 }
 
 bool Data::isNull() const
 {
-    return !m_buffer;
+    return m_buffer.isEmpty();
 }
 
 bool Data::apply(const Function<bool(const uint8_t*, size_t)>& applier) const
@@ -73,24 +71,16 @@
     if (isEmpty())
         return false;
 
-    return applier(reinterpret_cast<const uint8_t*>(data()), size());
+    return applier(reinterpret_cast<const uint8_t*>(m_buffer.data()), m_buffer.size());
 }
 
 Data Data::subrange(size_t offset, size_t size) const
 {
-    if (!m_buffer)
-        return { };
-
-    return { data() + offset, size };
+    return { m_buffer.data() + offset, size };
 }
 
 Data concatenate(const Data& a, const Data& b)
 {
-    if (a.isNull())
-        return b;
-    if (b.isNull())
-        return a;
-
     Vector<uint8_t> buffer(a.size() + b.size());
     memcpy(buffer.data(), a.data(), a.size());
     memcpy(buffer.data() + a.size(), b.data(), b.size());
@@ -97,13 +87,5 @@
     return Data(WTFMove(buffer));
 }
 
-Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd)
-{
-    ASSERT(mappedFile.data());
-    FileSystem::closeFile(fd);
-
-    return { WTFMove(mappedFile) };
-}
-
 } // namespace NetworkCache
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -48,11 +48,11 @@
     m_buffer = adoptGRef(soup_buffer_new_with_owner(copiedData, size, copiedData, fastFree));
 }
 
-Data::Data(GRefPtr<SoupBuffer>&& buffer, FileSystem::PlatformFileHandle fd)
+Data::Data(GRefPtr<SoupBuffer>&& buffer, int fd)
     : m_buffer(buffer)
     , m_fileDescriptor(fd)
     , m_size(buffer ? buffer->length : 0)
-    , m_isMap(m_size && FileSystem::isHandleValid(fd))
+    , m_isMap(m_size && fd != -1)
 {
 }
 
@@ -108,12 +108,12 @@
     ~MapWrapper()
     {
         munmap(map, size);
-        FileSystem::closeFile(fileDescriptor);
+        close(fileDescriptor);
     }
 
     void* map;
     size_t size;
-    FileSystem::PlatformFileHandle fileDescriptor;
+    int fileDescriptor;
 };
 
 static void deleteMapWrapper(MapWrapper* wrapper)
@@ -121,10 +121,8 @@
     delete wrapper;
 }
 
-Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd)
+Data Data::adoptMap(void* map, size_t size, int fd)
 {
-    size_t size = mappedFile.size();
-    void* map = mappedFile.leakHandle();
     ASSERT(map);
     ASSERT(map != MAP_FAILED);
     MapWrapper* wrapper = new MapWrapper { map, size, fd };
@@ -132,14 +130,21 @@
     return { WTFMove(buffer), fd };
 }
 
+#if USE(GLIB) && !PLATFORM(WIN)
+Data adoptAndMapFile(GFileIOStream* stream, size_t offset, size_t size)
+{
+    GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(stream));
+    int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream));
+    return adoptAndMapFile(fd, offset, size);
+}
+#endif
+
 RefPtr<SharedMemory> Data::tryCreateSharedMemory() const
 {
     if (isNull() || !isMap())
         return nullptr;
 
-    GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_fileDescriptor));
-    int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream));
-    return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, fd);
+    return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, m_fileDescriptor);
 }
 
 } // namespace NetworkCache

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp (256699 => 256700)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2020-02-15 04:25:05 UTC (rev 256699)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2020-02-15 06:54:35 UTC (rev 256700)
@@ -53,13 +53,48 @@
 namespace WebKit {
 namespace NetworkCache {
 
+#if !OS(WINDOWS)
+static DirectoryEntryType directoryEntryType(uint8_t dtype)
+{
+    switch (dtype) {
+    case DT_DIR:
+        return DirectoryEntryType::Directory;
+    case DT_REG:
+        return DirectoryEntryType::File;
+    default:
+        ASSERT_NOT_REACHED();
+        return DirectoryEntryType::File;
+    }
+    return DirectoryEntryType::File;
+}
+#endif
+
 void traverseDirectory(const String& path, const Function<void (const String&, DirectoryEntryType)>& function)
 {
-    auto entries = FileSystem::listDirectory(path, "*"_s);
+#if !OS(WINDOWS)
+    DIR* dir = opendir(FileSystem::fileSystemRepresentation(path).data());
+    if (!dir)
+        return;
+    dirent* dp;
+    while ((dp = readdir(dir))) {
+        if (dp->d_type != DT_DIR && dp->d_type != DT_REG)
+            continue;
+        const char* name = dp->d_name;
+        if (!strcmp(name, ".") || !strcmp(name, ".."))
+            continue;
+        auto nameString = String::fromUTF8(name);
+        if (nameString.isNull())
+            continue;
+        function(nameString, directoryEntryType(dp->d_type));
+    }
+    closedir(dir);
+#else
+    auto entries = FileSystem::listDirectory(path);
     for (auto& entry : entries) {
         auto type = FileSystem::fileIsDirectory(entry, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File;
-        function(FileSystem::pathGetFileName(entry), type);
+        function(entry, type);
     }
+#endif
 }
 
 void deleteDirectoryRecursively(const String& path)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to