Title: [279835] trunk/Source/WebKit
Revision
279835
Author
[email protected]
Date
2021-07-12 10:26:01 -0700 (Mon, 12 Jul 2021)

Log Message

Regression(r279601) ProcessAssertion may get destroyed on a background thread
https://bugs.webkit.org/show_bug.cgi?id=227875
<rdar://76972252>

Reviewed by Geoffrey Garen.

r279601 added an internal WorkQueue to ProcessAssertion, so that we could acquire the RunningBoard assertion
asynchronously on the background queue. When dispatching to the background queue, we capture |protectedThis|,
which means that ProcessAssertion may now get destroyed on the background queue. ProcessAssertion is a main
thread object and destroying it on a non-main thread can lead to crashes.

* UIProcess/ProcessAssertion.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::~ProcessAssertion):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279834 => 279835)


--- trunk/Source/WebKit/ChangeLog	2021-07-12 17:23:13 UTC (rev 279834)
+++ trunk/Source/WebKit/ChangeLog	2021-07-12 17:26:01 UTC (rev 279835)
@@ -1,3 +1,21 @@
+2021-07-12  Chris Dumez  <[email protected]>
+
+        Regression(r279601) ProcessAssertion may get destroyed on a background thread
+        https://bugs.webkit.org/show_bug.cgi?id=227875
+        <rdar://76972252>
+
+        Reviewed by Geoffrey Garen.
+
+        r279601 added an internal WorkQueue to ProcessAssertion, so that we could acquire the RunningBoard assertion
+        asynchronously on the background queue. When dispatching to the background queue, we capture |protectedThis|,
+        which means that ProcessAssertion may now get destroyed on the background queue. ProcessAssertion is a main
+        thread object and destroying it on a non-main thread can lead to crashes.
+
+        * UIProcess/ProcessAssertion.h:
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+        (WebKit::ProcessAssertion::~ProcessAssertion):
+
 2021-07-12  Jer Noble  <[email protected]>
 
         [Cocoa] Incorrect deprecation declaration for -[WKWebView closeAllMediaPresentations:]

Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.h (279834 => 279835)


--- trunk/Source/WebKit/UIProcess/ProcessAssertion.h	2021-07-12 17:23:13 UTC (rev 279834)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.h	2021-07-12 17:26:01 UTC (rev 279835)
@@ -54,7 +54,7 @@
     FinishTaskUninterruptable,
 };
 
-class ProcessAssertion : public ThreadSafeRefCounted<ProcessAssertion>, public CanMakeWeakPtr<ProcessAssertion, WeakPtrFactoryInitialization::Eager> {
+class ProcessAssertion : public ThreadSafeRefCounted<ProcessAssertion, WTF::DestructionThread::MainRunLoop>, public CanMakeWeakPtr<ProcessAssertion, WeakPtrFactoryInitialization::Eager> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     enum class Mode : bool { Sync, Async };

Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (279834 => 279835)


--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2021-07-12 17:23:13 UTC (rev 279834)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2021-07-12 17:26:01 UTC (rev 279835)
@@ -321,6 +321,7 @@
     , m_pid(pid)
     , m_reason(reason)
 {
+    ASSERT(isMainRunLoop());
     NSString *runningBoardAssertionName = runningBoardNameForAssertionType(assertionType);
     ASSERT(runningBoardAssertionName);
     if (!pid) {
@@ -365,6 +366,7 @@
 
 ProcessAssertion::~ProcessAssertion()
 {
+    ASSERT(isMainRunLoop());
     RELEASE_LOG(ProcessSuspension, "%p - ~ProcessAssertion: Releasing process assertion '%{public}s' for process with PID=%d", this, m_reason.utf8().data(), m_pid);
 
     if (m_rbsAssertion) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to