Diff
Modified: trunk/Source/WebKit/ChangeLog (239259 => 239260)
--- trunk/Source/WebKit/ChangeLog 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/ChangeLog 2018-12-16 19:39:38 UTC (rev 239260)
@@ -1,3 +1,31 @@
+2018-12-16 Adrian Perez de Castro <[email protected]>
+
+ Unify SharedMemory factory functions
+ https://bugs.webkit.org/show_bug.cgi?id=192714
+
+ Reviewed by Darin Adler.
+
+ This unifies SharedMemory so in the following way, across platforms:
+
+ - SharedMemory::create() is removed, to avoid ambiguity.
+ - SharedMemory::allocate() always allocates a new block of shared memory.
+ - SharedMemory::wrapMap() always creates a SharedMemory object which refers to an
+ existing region of memory resulting from memory-mapping a file.
+
+ * NetworkProcess/cache/NetworkCacheDataCocoa.mm:
+ (WebKit::NetworkCache::Data::tryCreateSharedMemory const): Use SharedMemory::wrapMap().
+ * Platform/SharedMemory.h: Remove the definition of SharedMemory::create(), and make
+ SharedMemory::wrapMap() available on OS(DARWIN) as well.
+ * Platform/cocoa/SharedMemoryCocoa.cpp:
+ (WebKit::SharedMemory::wrapMap): Renamed from ::create().
+ * Platform/unix/SharedMemoryUnix.cpp:
+ (WebKit::SharedMemory::allocate): Renamed from ::create().
+ * Platform/win/SharedMemoryWin.cpp:
+ (WebKit::SharedMemory::allocate): Renamed from ::create()
+ * UIProcess/API/APIContentRuleListStore.cpp:
+ (API::createExtension): Use NetworkCache::Data::tryCreateSharedMemory() instead of
+ SharedMemory::create().
+
2018-12-15 Chris Fleizach <[email protected]>
[meta][WebKit] Remove using namespace WebCore and WebKit in the global scope for unified source builds
Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm (239259 => 239260)
--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm 2018-12-16 19:39:38 UTC (rev 239260)
@@ -108,7 +108,7 @@
if (isNull() || !isMap())
return nullptr;
- return SharedMemory::create(const_cast<uint8_t*>(data()), m_size, SharedMemory::Protection::ReadOnly);
+ return SharedMemory::wrapMap(const_cast<uint8_t*>(data()), m_size, SharedMemory::Protection::ReadOnly);
}
}
Modified: trunk/Source/WebKit/Platform/SharedMemory.h (239259 => 239260)
--- trunk/Source/WebKit/Platform/SharedMemory.h 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/Platform/SharedMemory.h 2018-12-16 19:39:38 UTC (rev 239260)
@@ -94,6 +94,8 @@
static RefPtr<SharedMemory> map(const Handle&, Protection);
#if USE(UNIX_DOMAIN_SOCKETS)
static RefPtr<SharedMemory> wrapMap(void*, size_t, int fileDescriptor);
+#elif OS(DARWIN)
+ static RefPtr<SharedMemory> wrapMap(void*, size_t, Protection);
#endif
#if OS(WINDOWS)
static RefPtr<SharedMemory> adopt(HANDLE, size_t, Protection);
Modified: trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp (239259 => 239260)
--- trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp 2018-12-16 19:39:38 UTC (rev 239260)
@@ -157,7 +157,7 @@
return WTF::MachSendRight::adopt(port);
}
-RefPtr<SharedMemory> SharedMemory::create(void* data, size_t size, Protection protection)
+RefPtr<SharedMemory> SharedMemory::wrapMap(void* data, size_t size, Protection protection)
{
ASSERT(size);
Modified: trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp (239259 => 239260)
--- trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp 2018-12-16 19:39:38 UTC (rev 239260)
@@ -148,7 +148,7 @@
return fileDescriptor;
}
-RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection protection)
+RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
{
int fileDescriptor = createSharedMemory();
if (fileDescriptor == -1) {
@@ -163,7 +163,7 @@
}
}
- void* data = "" size, accessModeMMap(protection), MAP_SHARED, fileDescriptor, 0);
+ void* data = "" size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
if (data == MAP_FAILED) {
closeWithRetry(fileDescriptor);
return nullptr;
@@ -176,11 +176,6 @@
return instance;
}
-RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
-{
- return SharedMemory::create(nullptr, size, SharedMemory::Protection::ReadWrite);
-}
-
RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection)
{
ASSERT(!handle.isNull());
Modified: trunk/Source/WebKit/Platform/win/SharedMemoryWin.cpp (239259 => 239260)
--- trunk/Source/WebKit/Platform/win/SharedMemoryWin.cpp 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/Platform/win/SharedMemoryWin.cpp 2018-12-16 19:39:38 UTC (rev 239260)
@@ -132,16 +132,11 @@
RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
{
- return SharedMemory::create(nullptr, size, SharedMemory::Protection::ReadWrite);
-}
-
-RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection protection)
-{
- HANDLE handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, 0, protectAttribute(protection), 0, size, 0);
+ HANDLE handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, 0, protectAttribute(SharedMemory::Protection::ReadWrite), 0, size, 0);
if (!handle)
return nullptr;
- void* baseAddress = ::MapViewOfFileEx(handle, FILE_MAP_ALL_ACCESS, 0, 0, size, address);
+ void* baseAddress = ::MapViewOfFileEx(handle, FILE_MAP_ALL_ACCESS, 0, 0, size, nullptr);
if (!baseAddress) {
::CloseHandle(handle);
return nullptr;
Modified: trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp (239259 => 239260)
--- trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp 2018-12-16 12:05:46 UTC (rev 239259)
+++ trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp 2018-12-16 19:39:38 UTC (rev 239260)
@@ -369,7 +369,11 @@
static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier, const ContentRuleListMetaData& metaData, const WebKit::NetworkCache::Data& fileData)
{
- auto sharedMemory = WebKit::SharedMemory::create(const_cast<uint8_t*>(fileData.data()), fileData.size(), WebKit::SharedMemory::Protection::ReadOnly);
+ // Content extensions are always compiled to files, and at this point the file
+ // has been already mapped, therefore tryCreateSharedMemory() cannot fail.
+ auto sharedMemory = fileData.tryCreateSharedMemory();
+ ASSERT(sharedMemory);
+
const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + metaData.sourceSize;
auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData(
WTFMove(sharedMemory),