Title: [265139] trunk/Source
Revision
265139
Author
[email protected]
Date
2020-07-31 07:03:35 -0700 (Fri, 31 Jul 2020)

Log Message

[iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
https://bugs.webkit.org/show_bug.cgi?id=214965

Reviewed by Geoffrey Garen.

Source/WebCore/PAL:

Declare MobileGestalt queestion identifier.

* pal/spi/ios/MobileGestaltSPI.h:

Source/WebKit:

When the MobileGestalt cache is invalid, some MG queries will fail in the WebContent process, since it has no access to the daemon.
This can be fixed by issuing a temporary extension to the daemon, and having the WebContent process query all relevant MG values
while holding the extension. This will bring the values into the in-memory cache, which will be valid after the extension to the
daemon has been revoked. We will still attempt to rebuild the MG cache if invalid, but since we now have a workaround for when the
cache is invalid, we can do this on a secondary thread to avoid blocking the main thread. We also only attempt to rebuild once now,
instead of every time a WebContent process is started. Additionally, add IOKit property read access to "platform-name", since that
is needed by a MG query.

No new tests, since testing this depends on having an invalid cache, which is rare, and non-trivial to enforce in the test
environment.

* Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitialize):
(WebKit::WebProcessPool::platformInitializeWebProcess):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Modified Paths

Diff

Modified: trunk/Source/WebCore/PAL/ChangeLog (265138 => 265139)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-07-31 14:03:35 UTC (rev 265139)
@@ -1,3 +1,14 @@
+2020-07-31  Per Arne Vollan  <[email protected]>
+
+        [iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
+        https://bugs.webkit.org/show_bug.cgi?id=214965
+
+        Reviewed by Geoffrey Garen.
+
+        Declare MobileGestalt queestion identifier.
+
+        * pal/spi/ios/MobileGestaltSPI.h:
+
 2020-07-30  Jer Noble  <[email protected]>
 
         [Cocoa] Adopt -[AVContentKeyRequest willOutputBeObscuredDueToInsufficientExternalProtectionForDisplays:]

Modified: trunk/Source/WebCore/PAL/pal/spi/ios/MobileGestaltSPI.h (265138 => 265139)


--- trunk/Source/WebCore/PAL/pal/spi/ios/MobileGestaltSPI.h	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebCore/PAL/pal/spi/ios/MobileGestaltSPI.h	2020-07-31 14:03:35 UTC (rev 265139)
@@ -45,6 +45,7 @@
 static const CFStringRef kMGQDeviceName = CFSTR("DeviceName");
 static const CFStringRef kMGQDeviceClassNumber = CFSTR("DeviceClassNumber");
 static const CFStringRef kMGQHasExtendedColorDisplay = CFSTR("HasExtendedColorDisplay");
+static const CFStringRef kMGQDeviceCornerRadius = CFSTR("DeviceCornerRadius");
 
 typedef enum {
     MGDeviceClassInvalid = -1,

Modified: trunk/Source/WebKit/ChangeLog (265138 => 265139)


--- trunk/Source/WebKit/ChangeLog	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebKit/ChangeLog	2020-07-31 14:03:35 UTC (rev 265139)
@@ -1,3 +1,32 @@
+2020-07-31  Per Arne Vollan  <[email protected]>
+
+        [iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
+        https://bugs.webkit.org/show_bug.cgi?id=214965
+
+        Reviewed by Geoffrey Garen.
+
+        When the MobileGestalt cache is invalid, some MG queries will fail in the WebContent process, since it has no access to the daemon.
+        This can be fixed by issuing a temporary extension to the daemon, and having the WebContent process query all relevant MG values
+        while holding the extension. This will bring the values into the in-memory cache, which will be valid after the extension to the
+        daemon has been revoked. We will still attempt to rebuild the MG cache if invalid, but since we now have a workaround for when the
+        cache is invalid, we can do this on a secondary thread to avoid blocking the main thread. We also only attempt to rebuild once now,
+        instead of every time a WebContent process is started. Additionally, add IOKit property read access to "platform-name", since that
+        is needed by a MG query.
+
+        No new tests, since testing this depends on having an invalid cache, which is rare, and non-trivial to enforce in the test
+        environment.
+
+        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitialize):
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2020-07-31  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Mouse wheel events on horizontal scrollbar not correctly handled when AC mode is forced

Modified: trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb (265138 => 265139)


--- trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb	2020-07-31 14:03:35 UTC (rev 265139)
@@ -887,6 +887,7 @@
     (iokit-property "vendor-id")
     (iokit-property "udid-version") ;; <rdar://problem/52903475>
     (iokit-property "ui-pip") ;; <rdar://problem/48867037>
+    (iokit-property "platform-name")
 )
 
 ;; Read-only preferences and data
@@ -946,6 +947,10 @@
     (global-name "com.apple.containermanagerd")
 )
 
+(deny mach-lookup (with telemetry-backtrace)
+    (global-name "com.apple.mobilegestalt.xpc")
+)
+
 (allow mach-lookup
     (require-all
         (extension "com.apple.webkit.extension.mach")
@@ -957,6 +962,7 @@
             "com.apple.iphone.axserver-systemwide"
             "com.apple.lsd.mapdb"
             "com.apple.mobileassetd.v2"
+            "com.apple.mobilegestalt.xpc"
             "com.apple.nehelper"
             "com.apple.nesessionmanager.content-filter"
             "com.apple.osanalytics.osanalyticshelper"

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (265138 => 265139)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-07-31 14:03:35 UTC (rev 265139)
@@ -160,7 +160,8 @@
 #endif
 
     encoder << containerManagerExtensionHandle;
-    
+    encoder << mobileGestaltExtensionHandle;
+
 #if PLATFORM(IOS_FAMILY)
     encoder << diagnosticsExtensionHandles;
     encoder << dynamicMachExtensionHandles;
@@ -428,6 +429,12 @@
         return false;
     parameters.containerManagerExtensionHandle = WTFMove(*containerManagerExtensionHandle);
 
+    Optional<Optional<SandboxExtension::Handle>> mobileGestaltExtensionHandle;
+    decoder >> mobileGestaltExtensionHandle;
+    if (!mobileGestaltExtensionHandle)
+        return false;
+    parameters.mobileGestaltExtensionHandle = WTFMove(*mobileGestaltExtensionHandle);
+
 #if PLATFORM(IOS_FAMILY)
     Optional<SandboxExtension::HandleArray> diagnosticsExtensionHandles;
     decoder >> diagnosticsExtensionHandles;

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (265138 => 265139)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-07-31 14:03:35 UTC (rev 265139)
@@ -204,6 +204,7 @@
 #endif
 
     Optional<SandboxExtension::Handle> containerManagerExtensionHandle;
+    Optional<SandboxExtension::Handle> mobileGestaltExtensionHandle;
 
 #if PLATFORM(IOS_FAMILY)
     SandboxExtension::HandleArray diagnosticsExtensionHandles;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (265138 => 265139)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-07-31 14:03:35 UTC (rev 265139)
@@ -165,6 +165,14 @@
         installMemoryPressureHandler();
 
     setLegacyCustomProtocolManagerClient(makeUnique<LegacyCustomProtocolManagerClient>());
+
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
+    if (!_MGCacheValid()) {
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            [adoptNS([[objc_getClass("MobileGestaltHelperProxy") alloc] init]) proxyRebuildCache];
+        });
+    }
+#endif
 }
 
 #if PLATFORM(IOS_FAMILY)
@@ -447,8 +455,11 @@
 #endif
 
 #if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
-    if (!_MGCacheValid())
-        [adoptNS([[objc_getClass("MobileGestaltHelperProxy") alloc] init]) proxyRebuildCache];
+    if (!_MGCacheValid()) {
+        SandboxExtension::Handle handle;
+        SandboxExtension::createHandleForMachLookup("com.apple.mobilegestalt.xpc"_s, WTF::nullopt, handle);
+        parameters.mobileGestaltExtensionHandle = WTFMove(handle);
+    }
 #endif
 
 #if PLATFORM(IOS_FAMILY) && ENABLE(CFPREFS_DIRECT_MODE)

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (265138 => 265139)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-07-31 10:57:19 UTC (rev 265138)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-07-31 14:03:35 UTC (rev 265139)
@@ -109,6 +109,7 @@
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <UIKit/UIAccessibility.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
+#import <pal/spi/ios/MobileGestaltSPI.h>
 #endif
 
 #if PLATFORM(IOS_FAMILY) && USE(APPLE_INTERNAL_SDK)
@@ -202,6 +203,26 @@
 
 void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
 {
+    if (parameters.mobileGestaltExtensionHandle) {
+        if (auto extension = SandboxExtension::create(WTFMove(*parameters.mobileGestaltExtensionHandle))) {
+            bool ok = extension->consume();
+            ASSERT_UNUSED(ok, ok);
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
+            MGGetFloat32Answer(kMGQMainScreenScale, 0);
+            MGGetSInt32Answer(kMGQMainScreenPitch, 0);
+            MGGetSInt32Answer(kMGQMainScreenClass, MGScreenClassPad2);
+            MGGetBoolAnswer(kMGQAppleInternalInstallCapability);
+            MGGetBoolAnswer(kMGQiPadCapability);
+            auto deviceName = adoptCF(MGCopyAnswer(kMGQDeviceName, nullptr));
+            MGGetSInt32Answer(kMGQDeviceClassNumber, MGDeviceClassInvalid);
+            MGGetBoolAnswer(kMGQHasExtendedColorDisplay);
+            MGGetFloat32Answer(kMGQDeviceCornerRadius, 0);
+#endif
+            ok = extension->revoke();
+            ASSERT_UNUSED(ok, ok);
+        }
+    }
+
 #if HAVE(LSDATABASECONTEXT)
     // FIXME: Remove this entire section when the selector observeDatabaseChange4WebKit is present
     auto context = [NSClassFromString(@"LSDatabaseContext") sharedDatabaseContext];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to