Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring of assertion code, v2 #19650

Conversation

pvollan
Copy link
Contributor

@pvollan pvollan commented Oct 27, 2023

5d6df46

Minor refactoring of assertion code, v2
https://bugs.webkit.org/show_bug.cgi?id=263797
rdar://117600174

Reviewed by Brent Fulgham.

This patch contains some minor refactoring of assertions code:

1) Let ProcessAndUIAssertion create method take an AuxiliaryProcessProxy reference, instead of a PID.
2) Let XPCConnectionTerminationWatchdog hold on to a weak AuxiliaryProcessProxy pointer, instead of an XPC connection.
3) Let ProcessThrottler::didConnectToProcess take an AuxiliaryProcessProxy reference, instead of a PID.

* Source/WebKit/Platform/cocoa/XPCUtilities.mm:
(WebKit::terminateWithReason):
* Source/WebKit/Platform/spi/Cocoa/ExtensionKitSPI.h:
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::didFinishLaunching):
* Source/WebKit/UIProcess/Cocoa/AuxiliaryProcessProxyCocoa.mm:
(WebKit::AuxiliaryProcessProxy::platformStartConnectionTerminationWatchdog):
(WebKit::AuxiliaryProcessProxy::extensionProcess const):
(WebKit::AuxiliaryProcessProxy::extensionProcess): Deleted.
* Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm:
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
* Source/WebKit/UIProcess/Cocoa/XPCConnectionTerminationWatchdog.h:
* Source/WebKit/UIProcess/Cocoa/XPCConnectionTerminationWatchdog.mm:
(WebKit::XPCConnectionTerminationWatchdog::startConnectionTerminationWatchdog):
(WebKit::XPCConnectionTerminationWatchdog::XPCConnectionTerminationWatchdog):
(WebKit::XPCConnectionTerminationWatchdog::watchdogTimerFired):
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::didFinishLaunching):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::didFinishLaunching):
* Source/WebKit/UIProcess/ProcessAssertion.h:
* Source/WebKit/UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::setThrottleState):
(WebKit::ProcessThrottler::updateThrottleStateIfNeeded):
(WebKit::ProcessThrottler::didConnectToProcess):
(WebKit::ProcessThrottler::didDisconnectFromProcess):
(WebKit::ProcessThrottler::sendPrepareToSuspendIPC):
(WebKit::ProcessThrottler::setShouldTakeNearSuspendedAssertion):
(WebKit::ProcessThrottler::isSuspended const):
(WebKit::ProcessThrottlerActivity::ProcessThrottlerActivity):
(WebKit::ProcessThrottlerActivity::invalidate):
* Source/WebKit/UIProcess/ProcessThrottler.h:
(WebKit::ProcessThrottler::isSuspended const): Deleted.
(WebKit::ProcessThrottlerActivity::ProcessThrottlerActivity): Deleted.
(WebKit::ProcessThrottlerActivity::invalidate): Deleted.
* Source/WebKit/UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::updateAudibleMediaAssertions):
* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didFinishLaunching):
(WebKit::WebProcessProxy::updateAudibleMediaAssertions):

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

6f8231b

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt   πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  tv-sim
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@pvollan pvollan requested a review from cdumez as a code owner October 27, 2023 20:00
@pvollan pvollan self-assigned this Oct 27, 2023
@pvollan pvollan added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Oct 27, 2023
@pvollan pvollan marked this pull request as draft October 27, 2023 20:01
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 27, 2023
@pvollan pvollan removed the merging-blocked Applied to prevent a change from being merged label Nov 1, 2023
@pvollan pvollan force-pushed the eng/Minor-refactoring-of-assertion-code-v2 branch from e20e1f2 to 6bc0f8e Compare November 1, 2023 21:59
@pvollan pvollan force-pushed the eng/Minor-refactoring-of-assertion-code-v2 branch from 6bc0f8e to 8963472 Compare November 1, 2023 22:03
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 1, 2023
@pvollan pvollan removed the merging-blocked Applied to prevent a change from being merged label Nov 1, 2023
@pvollan pvollan force-pushed the eng/Minor-refactoring-of-assertion-code-v2 branch from 8963472 to b19e985 Compare November 1, 2023 23:01
Copy link
Contributor

@brentfulgham brentfulgham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks fine, but I strongly recommend you restore the PID in the logging, as I've frequently needed this information to diagnose problem on users' devices from logs.

@@ -44,7 +44,7 @@ OBJC_CLASS WKRBSAssertionDelegate;

#if USE(EXTENSIONKIT_ASSERTIONS)
OBJC_CLASS _SEExtensionProcess;
OBJC_CLASS _SEGrant;
OBJC_PROTOCOL(_SEGrant);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

#endif
static Ref<ProcessAssertion> create(ProcessID, const String& reason, ProcessAssertionType, Mode = Mode::Async, const String& environmentIdentifier = emptyString(), CompletionHandler<void()>&& acquisisionHandler = nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Noticed an old typo here: acquisisionHandler -> aquisitionHandler

{
m_watchdogTimer.startOneShot(interval);
}

void XPCConnectionTerminationWatchdog::watchdogTimerFired()
{
terminateWithReason(m_xpcConnection.get(), ReasonCode::WatchdogTimerFired, "XPCConnectionTerminationWatchdog::watchdogTimerFired");
if (m_process && m_process->connection())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If m_process->connection() exists, is the result of xpcConnection() guaranteed to be a valid pointer? If so, why isn't it returning a reference?

It looks like methods such as Connection::getAuditToken() check this value for nullptr. I think we should check connection's validity here before using it to terminate, unless the terminateWithReason method expects the pointer might be nullptr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the implementation of xpc_connection_kill uses the passed in argument without nullptr checking, so this would create crashes in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch! I added a null check before calling xpc_connection_kill.

Thanks for reviewing!


void ProcessThrottler::didDisconnectFromProcess()
{
PROCESSTHROTTLER_RELEASE_LOG_WITH_PID("didDisconnectFromProcess:", m_processID);
PROCESSTHROTTLER_RELEASE_LOG("didDisconnectFromProcess:");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate the idea of losing this logging. Is there a way to determine the PID from the m_processProxy so we can keep this useful diagnostic information?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:
PROCESSTHROTTLER_RELEASE_LOG_WITH_PID("didDisconnectFromProcess:", m_processProxy ? m_processProxy->processID() : 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro PROCESSTHROTTLER_RELEASE_LOG actually logs the PID, so I believe we are good here.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 2, 2023
@pvollan pvollan removed the merging-blocked Applied to prevent a change from being merged label Nov 2, 2023
@pvollan pvollan force-pushed the eng/Minor-refactoring-of-assertion-code-v2 branch from b19e985 to 90fb10a Compare November 2, 2023 14:25
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 2, 2023
@pvollan pvollan removed the merging-blocked Applied to prevent a change from being merged label Nov 3, 2023
@pvollan pvollan force-pushed the eng/Minor-refactoring-of-assertion-code-v2 branch from 90fb10a to 6f8231b Compare November 3, 2023 19:09
@pvollan pvollan added the merge-queue Applied to send a pull request to merge-queue label Nov 3, 2023
@Ahmad-S792 Ahmad-S792 marked this pull request as ready for review November 3, 2023 22:05
https://bugs.webkit.org/show_bug.cgi?id=263797
rdar://117600174

Reviewed by Brent Fulgham.

This patch contains some minor refactoring of assertions code:

1) Let ProcessAndUIAssertion create method take an AuxiliaryProcessProxy reference, instead of a PID.
2) Let XPCConnectionTerminationWatchdog hold on to a weak AuxiliaryProcessProxy pointer, instead of an XPC connection.
3) Let ProcessThrottler::didConnectToProcess take an AuxiliaryProcessProxy reference, instead of a PID.

* Source/WebKit/Platform/cocoa/XPCUtilities.mm:
(WebKit::terminateWithReason):
* Source/WebKit/Platform/spi/Cocoa/ExtensionKitSPI.h:
* Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::didFinishLaunching):
* Source/WebKit/UIProcess/Cocoa/AuxiliaryProcessProxyCocoa.mm:
(WebKit::AuxiliaryProcessProxy::platformStartConnectionTerminationWatchdog):
(WebKit::AuxiliaryProcessProxy::extensionProcess const):
(WebKit::AuxiliaryProcessProxy::extensionProcess): Deleted.
* Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm:
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
* Source/WebKit/UIProcess/Cocoa/XPCConnectionTerminationWatchdog.h:
* Source/WebKit/UIProcess/Cocoa/XPCConnectionTerminationWatchdog.mm:
(WebKit::XPCConnectionTerminationWatchdog::startConnectionTerminationWatchdog):
(WebKit::XPCConnectionTerminationWatchdog::XPCConnectionTerminationWatchdog):
(WebKit::XPCConnectionTerminationWatchdog::watchdogTimerFired):
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::didFinishLaunching):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::didFinishLaunching):
* Source/WebKit/UIProcess/ProcessAssertion.h:
* Source/WebKit/UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::setThrottleState):
(WebKit::ProcessThrottler::updateThrottleStateIfNeeded):
(WebKit::ProcessThrottler::didConnectToProcess):
(WebKit::ProcessThrottler::didDisconnectFromProcess):
(WebKit::ProcessThrottler::sendPrepareToSuspendIPC):
(WebKit::ProcessThrottler::setShouldTakeNearSuspendedAssertion):
(WebKit::ProcessThrottler::isSuspended const):
(WebKit::ProcessThrottlerActivity::ProcessThrottlerActivity):
(WebKit::ProcessThrottlerActivity::invalidate):
* Source/WebKit/UIProcess/ProcessThrottler.h:
(WebKit::ProcessThrottler::isSuspended const): Deleted.
(WebKit::ProcessThrottlerActivity::ProcessThrottlerActivity): Deleted.
(WebKit::ProcessThrottlerActivity::invalidate): Deleted.
* Source/WebKit/UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::updateAudibleMediaAssertions):
* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didFinishLaunching):
(WebKit::WebProcessProxy::updateAudibleMediaAssertions):

Canonical link: https://commits.webkit.org/270212@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Minor-refactoring-of-assertion-code-v2 branch from 6f8231b to 5d6df46 Compare November 3, 2023 22:58
@webkit-commit-queue webkit-commit-queue merged commit 5d6df46 into WebKit:main Nov 3, 2023
@webkit-commit-queue
Copy link
Collaborator

Committed 270212@main (5d6df46): https://commits.webkit.org/270212@main

Reviewed commits have been landed. Closing PR #19650 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).
Projects
None yet
5 participants