Title: [294951] trunk/Source
Revision
294951
Author
cdu...@apple.com
Date
2022-05-27 13:52:05 -0700 (Fri, 27 May 2022)

Log Message

Start allocating shared memory with MAP_MEM_VM_SHARE again on newer OSes
https://bugs.webkit.org/show_bug.cgi?id=241014
<rdar://94032696>

Reviewed by Simon Fraser.

When we started doing memory attribution in the GPUProcess, we stopped using
the MAP_MEM_VM_SHARE flag when creating SharedMemory, because it was
incompatible with attribution. However, creating shared memory would fail
without the MAP_MEM_VM_SHARE flag under certain circumstances (due to size
restriction iirc), in which case we would fall back to using MAP_MEM_VM_SHARE
and fail memory attribution.

As of <rdar://73715428>, MAP_MEM_VM_SHARE is now compatible with memory
attribution so this patch starts using the flag again and unconditionally on
newer OSes.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp:
(WebKit::makeMemoryEntry):

Canonical link: https://commits.webkit.org/251059@main

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/PlatformHave.h (294950 => 294951)


--- trunk/Source/WTF/wtf/PlatformHave.h	2022-05-27 20:14:24 UTC (rev 294950)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2022-05-27 20:52:05 UTC (rev 294951)
@@ -1171,6 +1171,14 @@
 #define HAVE_SAFE_BROWSING_RESULT_DETAILS 1
 #endif
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000) \
+    || (PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000) \
+    || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000) \
+    || (PLATFORM(APPLETV) && __TV_OS_VERSION_MAX_ALLOWED >= 160000) \
+    || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 90000)
+#define HAVE_MEMORY_ATTRIBUTION_VM_SHARE_SUPPORT 1
+#endif
+
 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000)
 #define HAVE_SKADNETWORK_v4 1
 #endif

Modified: trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp (294950 => 294951)


--- trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp	2022-05-27 20:14:24 UTC (rev 294950)
+++ trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp	2022-05-27 20:52:05 UTC (rev 294951)
@@ -227,6 +227,17 @@
     memory_object_size_t memoryObjectSize = *roundedSize;
     mach_port_t port = MACH_PORT_NULL;
 
+#if HAVE(MEMORY_ATTRIBUTION_VM_SHARE_SUPPORT)
+    kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &memoryObjectSize, offset, machProtection(protection) | VM_PROT_IS_MASK | MAP_MEM_VM_SHARE, &port, parentEntry);
+    if (kr != KERN_SUCCESS) {
+#if RELEASE_LOG_DISABLED
+        LOG_ERROR("Failed to create a mach port for shared memory. %s (%x)", mach_error_string(kr), kr);
+#else
+        RELEASE_LOG_ERROR(VirtualMemory, "SharedMemory::makeMemoryEntry: Failed to create a mach port for shared memory. Error: %{public}s (%x)", mach_error_string(kr), kr);
+#endif
+        return { };
+    }
+#else
     // First try without MAP_MEM_VM_SHARE because it prevents memory ownership transfer. We only pass the MAP_MEM_VM_SHARE flag as a fallback.
     kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &memoryObjectSize, offset, machProtection(protection) | VM_PROT_IS_MASK, &port, parentEntry);
     if (kr != KERN_SUCCESS) {
@@ -241,6 +252,7 @@
             return { };
         }
     }
+#endif // HAVE(MEMORY_ATTRIBUTION_VM_SHARE_SUPPORT)
 
     RELEASE_ASSERT(memoryObjectSize >= size);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to