Title: [233461] trunk/Source
Revision
233461
Author
[email protected]
Date
2018-07-03 03:41:37 -0700 (Tue, 03 Jul 2018)

Log Message

[iOS] Add assert to catch improper use of WebCore::Timer in UI Process
<https://webkit.org/b/185330>
<rdar://problem/32816079>

Reviewed by Darin Adler.

Source/WebCore:

* platform/RuntimeApplicationChecks.cpp:
(WebCore::s_webKitProcessType): Add. Global to track process
type.
(WebCore::setWebKitProcessType): Implement new function that is
called when initializing Web, Network, and Storage processes.
(WebCore::isInNetworkProcess): Add.
(WebCore::isInStorageProcess): Add.
(WebCore::isInWebProcess): Add.
- Check value in s_webKitProcessType to determine which process
  is currently running.
* platform/RuntimeApplicationChecks.h:
(WebCore::isInNetworkProcess): Add.
(WebCore::isInStorageProcess): Add.
(WebCore::isInWebProcess):
- Make available for all platforms.

* platform/Timer.cpp:
(WebCore::TimerBase::TimerBase): Add assert and os_log_fault.
This catches the unwanted behavior on iOS using isAllowed().
(WebCore::TimerBase::isAllowed): Add implementation.
* platform/Timer.h:
(WebCore::TimerBase::isAllowed): Add declaration.

* platform/cocoa/RuntimeApplicationChecksCocoa.mm:
(WebCore::isInWebProcess): Delete.  Replace with method in
RuntimeApplicationChecks.cpp.

Source/WebKit:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::NetworkProcess):
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::StorageProcess):
* WebProcess/WebProcess.cpp:
(WebKit::m_nonVisibleProcessCleanupTimer):
- Call setWebKitProcessType() to se the global for the current
  process.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (233460 => 233461)


--- trunk/Source/WebCore/ChangeLog	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebCore/ChangeLog	2018-07-03 10:41:37 UTC (rev 233461)
@@ -1,3 +1,38 @@
+2018-07-03  David Kilzer  <[email protected]>
+
+        [iOS] Add assert to catch improper use of WebCore::Timer in UI Process
+        <https://webkit.org/b/185330>
+        <rdar://problem/32816079>
+
+        Reviewed by Darin Adler.
+
+        * platform/RuntimeApplicationChecks.cpp:
+        (WebCore::s_webKitProcessType): Add. Global to track process
+        type.
+        (WebCore::setWebKitProcessType): Implement new function that is
+        called when initializing Web, Network, and Storage processes.
+        (WebCore::isInNetworkProcess): Add.
+        (WebCore::isInStorageProcess): Add.
+        (WebCore::isInWebProcess): Add.
+        - Check value in s_webKitProcessType to determine which process
+          is currently running.
+        * platform/RuntimeApplicationChecks.h:
+        (WebCore::isInNetworkProcess): Add.
+        (WebCore::isInStorageProcess): Add.
+        (WebCore::isInWebProcess):
+        - Make available for all platforms.
+
+        * platform/Timer.cpp:
+        (WebCore::TimerBase::TimerBase): Add assert and os_log_fault.
+        This catches the unwanted behavior on iOS using isAllowed().
+        (WebCore::TimerBase::isAllowed): Add implementation.
+        * platform/Timer.h:
+        (WebCore::TimerBase::isAllowed): Add declaration.
+
+        * platform/cocoa/RuntimeApplicationChecksCocoa.mm:
+        (WebCore::isInWebProcess): Delete.  Replace with method in
+        RuntimeApplicationChecks.cpp.
+
 2018-07-02  Antti Koivisto  <[email protected]>
 
         Tighter limit for canvas memory use on iOS

Modified: trunk/Source/WebCore/platform/RuntimeApplicationChecks.cpp (233460 => 233461)


--- trunk/Source/WebCore/platform/RuntimeApplicationChecks.cpp	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebCore/platform/RuntimeApplicationChecks.cpp	2018-07-03 10:41:37 UTC (rev 233461)
@@ -46,6 +46,30 @@
     return pid;
 }
 
+#if !PLATFORM(WIN)
+static WebKitProcessType s_webKitProcessType { WebKitProcessType::UIProcess };
+
+void setWebKitProcessType(WebKitProcessType type)
+{
+    s_webKitProcessType = type;
+}
+
+bool isInNetworkProcess()
+{
+    return s_webKitProcessType == WebKitProcessType::NetworkProcess;
+}
+
+bool isInStorageProcess()
+{
+    return s_webKitProcessType == WebKitProcessType::StorageProcess;
+}
+
+bool isInWebProcess()
+{
+    return s_webKitProcessType == WebKitProcessType::WebProcess;
+}
+#endif
+
 int presentingApplicationPID()
 {
     const auto& pid = presentingApplicationPIDOverride();

Modified: trunk/Source/WebCore/platform/RuntimeApplicationChecks.h (233460 => 233461)


--- trunk/Source/WebCore/platform/RuntimeApplicationChecks.h	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebCore/platform/RuntimeApplicationChecks.h	2018-07-03 10:41:37 UTC (rev 233461)
@@ -33,15 +33,19 @@
 WEBCORE_EXPORT int presentingApplicationPID();
 
 #if PLATFORM(WIN)
+inline bool isInNetworkProcess() { return false; }
+inline bool isInStorageProcess() { return false; }
 inline bool isInWebProcess() { return false; }
-#elif !PLATFORM(COCOA)
-inline bool isInWebProcess() { return true; }
+#else
+enum class WebKitProcessType { UIProcess = 0, NetworkProcess, StorageProcess, WebProcess };
+WEBCORE_EXPORT void setWebKitProcessType(WebKitProcessType);
+bool isInNetworkProcess();
+bool isInStorageProcess();
+bool isInWebProcess();
 #endif
 
 #if PLATFORM(COCOA)
 
-bool isInWebProcess();
-
 WEBCORE_EXPORT void setApplicationBundleIdentifier(const String&);
 String applicationBundleIdentifier();
 

Modified: trunk/Source/WebCore/platform/Timer.cpp (233460 => 233461)


--- trunk/Source/WebCore/platform/Timer.cpp	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebCore/platform/Timer.cpp	2018-07-03 10:41:37 UTC (rev 233461)
@@ -27,6 +27,8 @@
 #include "config.h"
 #include "Timer.h"
 
+#include "Logging.h"
+#include "RuntimeApplicationChecks.h"
 #include "SharedTimer.h"
 #include "ThreadGlobalData.h"
 #include "ThreadTimers.h"
@@ -33,9 +35,14 @@
 #include <limits.h>
 #include <limits>
 #include <math.h>
+#include <wtf/Compiler.h>
 #include <wtf/MainThread.h>
 #include <wtf/Vector.h>
 
+#if USE(WEB_THREAD)
+#include "WebCoreThread.h"
+#endif
+
 namespace WebCore {
 
 class TimerHeapReference;
@@ -186,6 +193,14 @@
 
 TimerBase::TimerBase()
 {
+#if PLATFORM(IOS)
+    if (UNLIKELY(!isAllowed())) {
+#define WEBCORE_TIMERBASE_ASSERTION_MESSAGE "WebCore::Timer should not be used in UI Process."
+        ASSERT_WITH_MESSAGE(false, WEBCORE_TIMERBASE_ASSERTION_MESSAGE);
+        RELEASE_LOG_FAULT(Threading, WEBCORE_TIMERBASE_ASSERTION_MESSAGE);
+#undef WEBCORE_TIMERBASE_ASSERTION_MESSAGE
+    }
+#endif
 }
 
 TimerBase::~TimerBase()
@@ -242,6 +257,23 @@
         checkHeapIndex();
 }
 
+bool TimerBase::isAllowed()
+{
+#if PLATFORM(IOS)
+    if (isInWebProcess() || isInNetworkProcess() || isInStorageProcess())
+        return true;
+
+#if USE(WEB_THREAD)
+    if (WebThreadIsEnabled() && (WebThreadIsCurrent() || WebThreadIsLocked()))
+        return true;
+#endif
+
+    return false;
+#else
+    return true;
+#endif
+}
+
 void TimerBase::heapDecreaseKey()
 {
     ASSERT(static_cast<bool>(m_nextFireTime));

Modified: trunk/Source/WebCore/platform/Timer.h (233460 => 233461)


--- trunk/Source/WebCore/platform/Timer.h	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebCore/platform/Timer.h	2018-07-03 10:41:37 UTC (rev 233461)
@@ -78,6 +78,8 @@
     void checkConsistency() const;
     void checkHeapIndex() const;
 
+    static bool isAllowed();
+
     void setNextFireTime(MonotonicTime);
 
     bool inHeap() const { return m_heapIndex != -1; }

Modified: trunk/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm (233460 => 233461)


--- trunk/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm	2018-07-03 10:41:37 UTC (rev 233461)
@@ -65,14 +65,6 @@
     applicationBundleIdentifierOverride() = bundleIdentifier;
 }
 
-bool isInWebProcess()
-{
-    static bool mainBundleIsWebProcess = [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.WebKit.WebContent.Development"]
-        || [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.WebKit.WebContent"]
-        || [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.WebProcess"];
-    return mainBundleIsWebProcess;
-}
-
 static bool applicationBundleIsEqualTo(const String& bundleIdentifierString)
 {
     return applicationBundleIdentifier() == bundleIdentifierString;

Modified: trunk/Source/WebKit/ChangeLog (233460 => 233461)


--- trunk/Source/WebKit/ChangeLog	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebKit/ChangeLog	2018-07-03 10:41:37 UTC (rev 233461)
@@ -1,3 +1,20 @@
+2018-07-03  David Kilzer  <[email protected]>
+
+        [iOS] Add assert to catch improper use of WebCore::Timer in UI Process
+        <https://webkit.org/b/185330>
+        <rdar://problem/32816079>
+
+        Reviewed by Darin Adler.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::NetworkProcess):
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::StorageProcess):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::m_nonVisibleProcessCleanupTimer):
+        - Call setWebKitProcessType() to se the global for the current
+          process.
+
 2018-07-03  Frederic Wang  <[email protected]>
 
         [iOS] Animations with Bézier timing function not suspended on UI process when animation-play-state is set to "paused"

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (233460 => 233461)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2018-07-03 10:41:37 UTC (rev 233461)
@@ -128,6 +128,8 @@
         for (auto& webProcessConnection : webProcessConnections)
             webProcessConnection->setOnLineState(isOnLine);
     });
+
+    WebCore::setWebKitProcessType(WebKitProcessType::NetworkProcess);
 }
 
 NetworkProcess::~NetworkProcess()

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.cpp (233460 => 233461)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2018-07-03 10:41:37 UTC (rev 233461)
@@ -40,6 +40,7 @@
 #include <WebCore/FileSystem.h>
 #include <WebCore/IDBKeyData.h>
 #include <WebCore/NotImplemented.h>
+#include <WebCore/RuntimeApplicationChecks.h>
 #include <WebCore/SWServerWorker.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/ServiceWorkerClientIdentifier.h>
@@ -72,6 +73,8 @@
     // Make sure the UTF8Encoding encoding and the text encoding maps have been built on the main thread before a background thread needs it.
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=135365 - Need a more explicit way of doing this besides accessing the UTF8Encoding.
     UTF8Encoding();
+
+    WebCore::setWebKitProcessType(WebKitProcessType::StorageProcess);
 }
 
 StorageProcess::~StorageProcess()

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (233460 => 233461)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-07-03 10:22:54 UTC (rev 233460)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-07-03 10:41:37 UTC (rev 233461)
@@ -209,6 +209,8 @@
     });
     
     Gigacage::disableDisablingPrimitiveGigacageIfShouldBeEnabled();
+
+    WebCore::setWebKitProcessType(WebKitProcessType::WebProcess);
 }
 
 WebProcess::~WebProcess()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to