Changeset 244678 in webkit


Ignore:
Timestamp:
Apr 25, 2019 11:06:10 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Make NetworkCache blobs safe for mmap instead of not using blobs
https://bugs.webkit.org/show_bug.cgi?id=197264
<rdar://problem/49564348>

Patch by Alex Christensen <achristensen@webkit.org> on 2019-04-25
Reviewed by Antti Koivisto.

This does what r244597 did for WKContentRuleLists but for the NetworkCache's blobs.
Those are the two cases where we were calling mmap and seeing crashes in apps with
default file protection of NSFileProtectionComplete.

  • NetworkProcess/cache/NetworkCacheBlobStorage.cpp:

(WebKit::NetworkCache::BlobStorage::add):

  • NetworkProcess/cache/NetworkCacheFileSystem.cpp:

(WebKit::NetworkCache::isSafeToUseMemoryMapForPath): Deleted.

  • NetworkProcess/cache/NetworkCacheFileSystem.h:
  • NetworkProcess/cache/NetworkCacheFileSystemCocoa.mm:

(WebKit::NetworkCache::isSafeToUseMemoryMapForPath):

  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::synchronize):
(WebKit::NetworkCache::Storage::mayContainBlob const):
(WebKit::NetworkCache::Storage::shouldStoreBodyAsBlob):
(WebKit::NetworkCache::estimateRecordsSize): Deleted.

  • NetworkProcess/cache/NetworkCacheStorage.h:
Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244675 r244678  
     12019-04-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Make NetworkCache blobs safe for mmap instead of not using blobs
     4        https://bugs.webkit.org/show_bug.cgi?id=197264
     5        <rdar://problem/49564348>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This does what r244597 did for WKContentRuleLists but for the NetworkCache's blobs.
     10        Those are the two cases where we were calling mmap and seeing crashes in apps with
     11        default file protection of NSFileProtectionComplete.
     12
     13        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
     14        (WebKit::NetworkCache::BlobStorage::add):
     15        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
     16        (WebKit::NetworkCache::isSafeToUseMemoryMapForPath): Deleted.
     17        * NetworkProcess/cache/NetworkCacheFileSystem.h:
     18        * NetworkProcess/cache/NetworkCacheFileSystemCocoa.mm:
     19        (WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
     20        * NetworkProcess/cache/NetworkCacheStorage.cpp:
     21        (WebKit::NetworkCache::Storage::Storage):
     22        (WebKit::NetworkCache::Storage::synchronize):
     23        (WebKit::NetworkCache::Storage::mayContainBlob const):
     24        (WebKit::NetworkCache::Storage::shouldStoreBodyAsBlob):
     25        (WebKit::NetworkCache::estimateRecordsSize): Deleted.
     26        * NetworkProcess/cache/NetworkCacheStorage.h:
     27
    1282019-04-25  Simon Fraser  <simon.fraser@apple.com>
    229
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp

    r240437 r244678  
    9494        return { data, hash };
    9595
    96     auto blobPath = FileSystem::fileSystemRepresentation(blobPathForHash(hash));
     96    String blobPathString = blobPathForHash(hash);
     97    makeSafeToUseMemoryMapForPath(blobPathString);
     98   
     99    auto blobPath = FileSystem::fileSystemRepresentation(blobPathString);
    97100    auto linkPath = FileSystem::fileSystemRepresentation(path);
    98101    unlink(linkPath.data());
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp

    r244597 r244678  
    147147
    148148#if !PLATFORM(IOS_FAMILY)
    149 bool isSafeToUseMemoryMapForPath(const String&)
    150 {
    151     return true;
    152 }
    153149void makeSafeToUseMemoryMapForPath(const String&)
    154150{
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.h

    r244597 r244678  
    4343void updateFileModificationTimeIfNeeded(const String& path);
    4444
    45 bool isSafeToUseMemoryMapForPath(const String&);
    4645void makeSafeToUseMemoryMapForPath(const String&);
    4746
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystemCocoa.mm

    r244597 r244678  
    3434
    3535#if PLATFORM(IOS_FAMILY)
    36 bool isSafeToUseMemoryMapForPath(const String& path)
     36static bool isSafeToUseMemoryMapForPath(const String& path)
    3737{
    38     // FIXME: For the network cache we should either use makeSafeToUseMemoryMapForPath instead of this
    39     // or we should listen to UIApplicationProtectedDataWillBecomeUnavailable and unmap files.
    4038    NSError *error = nil;
    4139    NSDictionary<NSFileAttributeKey, id> *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp

    r244645 r244678  
    229229    , m_mode(mode)
    230230    , m_salt(salt)
    231     , m_canUseBlobsForForBodyData(isSafeToUseMemoryMapForPath(baseDirectoryPath))
    232231    , m_readOperationTimeoutTimer(*this, &Storage::cancelAllReadOperations)
    233232    , m_writeOperationDispatchTimer(*this, &Storage::dispatchPendingWriteOperations)
     
    296295
    297296        // Most of the disk space usage is in blobs if we are using them. Approximate records file sizes to avoid expensive stat() calls.
    298         bool shouldComputeExactRecordsSize = !m_canUseBlobsForForBodyData;
    299297        size_t recordsSize = 0;
    300298        unsigned recordCount = 0;
     
    319317            ++recordCount;
    320318
    321             if (shouldComputeExactRecordsSize) {
    322                 long long fileSize = 0;
    323                 FileSystem::getFileSize(filePath, fileSize);
    324                 recordsSize += fileSize;
    325             }
    326 
    327319            recordFilter->add(hash);
    328320        });
    329321
    330         if (!shouldComputeExactRecordsSize)
    331             recordsSize = estimateRecordsSize(recordCount, blobCount);
     322        recordsSize = estimateRecordsSize(recordCount, blobCount);
    332323
    333324        m_blobStorage.synchronize();
     
    378369{
    379370    ASSERT(RunLoop::isMain());
    380     if (!m_canUseBlobsForForBodyData)
    381         return false;
    382371    return !m_blobFilter || m_blobFilter->mayContain(key.hash());
    383372}
     
    795784bool Storage::shouldStoreBodyAsBlob(const Data& bodyData)
    796785{
    797     if (!m_canUseBlobsForForBodyData)
    798         return false;
    799786    return bodyData.size() > maximumInlineBodySize;
    800787}
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h

    r243143 r244678  
    170170    const Mode m_mode;
    171171    const Salt m_salt;
    172     const bool m_canUseBlobsForForBodyData;
    173172
    174173    size_t m_capacity { std::numeric_limits<size_t>::max() };
Note: See TracChangeset for help on using the changeset viewer.