Skip to content

Commit

Permalink
Guard against thread safety issues related to assertions
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268758
rdar://122321271

Reviewed by Chris Dumez.

Guard against thread safety issues related to assertions, since they are usually acquired on a non-main thread.

* Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm:
(WebKit::ProcessAssertion::acquireSync):
(WebKit::ProcessAssertion::~ProcessAssertion):
* Source/WebKit/UIProcess/ProcessAssertion.h:

Canonical link: https://commits.webkit.org/274122@main
  • Loading branch information
pvollan committed Feb 6, 2024
1 parent 153d8bb commit 1395822
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ static ASCIILiteral runningBoardDomainForAssertionType(ProcessAssertionType asse
}
}

#if USE(EXTENSIONKIT)
Lock ProcessAssertion::s_capabilityLock;
#endif

ProcessAssertion::ProcessAssertion(pid_t pid, const String& reason, ProcessAssertionType assertionType, const String& environmentIdentifier)
: m_assertionType(assertionType)
, m_pid(pid)
Expand Down Expand Up @@ -465,6 +469,7 @@ static ASCIILiteral runningBoardDomainForAssertionType(ProcessAssertionType asse
{
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::acquireSync Trying to take RBS assertion '%{public}s' for process with PID=%d", this, m_reason.utf8().data(), m_pid);
#if USE(EXTENSIONKIT)
Locker locker { s_capabilityLock };
if (m_process && m_capability) {
NSError *error = nil;
m_grant = [m_process grantCapability:m_capability->platformCapability().get() error:&error];
Expand Down Expand Up @@ -500,6 +505,7 @@ static ASCIILiteral runningBoardDomainForAssertionType(ProcessAssertionType asse
}

#if USE(EXTENSIONKIT)
Locker locker { s_capabilityLock };
[m_grant invalidateWithError:nil];
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/UIProcess/ProcessAssertion.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ class ProcessAssertion : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr<
Function<void()> m_prepareForInvalidationHandler;
Function<void()> m_invalidationHandler;
#if USE(EXTENSIONKIT)
static Lock s_capabilityLock;
std::optional<AssertionCapability> m_capability;
RetainPtr<_SEGrant> m_grant;
RetainPtr<_SEGrant> m_grant WTF_GUARDED_BY_LOCK(s_capabilityLock);
RetainPtr<_SEExtensionProcess> m_process;
#endif
};
Expand Down

0 comments on commit 1395822

Please sign in to comment.