haikuwebkit/Source/WebCore/platform/ProcessIdentifier.cpp

55 lines
1.9 KiB
C++
Raw Permalink Normal View History

Add a ProcessIdentifier, vended from the UI process, to each child process https://bugs.webkit.org/show_bug.cgi?id=181155 Reviewed by Brent Fulgham. Source/WebCore: No new tests (Not yet testable) More than once we've needed to create an identifier for an object that is unique across all processes no matter which process it came from. Sometimes we have an object or proxy object to the UI, Storage, or Network process that allows us to augment a process-unique identifier to be globally unique. Due to multiple sessions even this isn't good enough. Other times we have to create more hair-brained solutions. In upcoming MessagePort work (Next step is https://bugs.webkit.org/show_bug.cgi?id=181172) there was no truly workable solution for this. By introducing a new ProcessIdentifier to each WK2 child processes that is guaranteed to be unique over the run of a given UI process, we can easily create an object in any process and identify it uniquely across all processes. Obviously "process identifier" brings to mind a processes PID but that isn't good enough. The number of PIDs on the system is fairly low and they are global across all processes on the system. It is easy to see how a given UI process that runs for long enough (such as a web browser that the user rarely quits) will start to run in to recycled PIDs, therefore breaking the uniqueness guarantee that is required. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * platform/Process.cpp: Added. (WebCore::Process::setIdentifier): Sets the process-wise identifier (to be used during WK2 child process initialization) (WebCore::Process::identifier): Get the process-wide identifier. * platform/Process.h: Added. Source/WebKit: * Shared/ChildProcess.cpp: (WebKit::ChildProcess::initialize): Set the process-wide identifier if the initialization parameters have it. Cocoa ASSERTS it exists; non-Cocoa platforms will have to figure this out soon. * Shared/ChildProcess.h: * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm: (WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): * UIProcess/ChildProcessProxy.cpp: (WebKit::ChildProcessProxy::getLaunchOptions): * UIProcess/ChildProcessProxy.h: (WebKit::ChildProcessProxy::coreProcessIdentifier const): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): Canonical link: https://commits.webkit.org/197032@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-29 05:56:29 +00:00
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ProcessIdentifier.h"
Add a ProcessIdentifier, vended from the UI process, to each child process https://bugs.webkit.org/show_bug.cgi?id=181155 Reviewed by Brent Fulgham. Source/WebCore: No new tests (Not yet testable) More than once we've needed to create an identifier for an object that is unique across all processes no matter which process it came from. Sometimes we have an object or proxy object to the UI, Storage, or Network process that allows us to augment a process-unique identifier to be globally unique. Due to multiple sessions even this isn't good enough. Other times we have to create more hair-brained solutions. In upcoming MessagePort work (Next step is https://bugs.webkit.org/show_bug.cgi?id=181172) there was no truly workable solution for this. By introducing a new ProcessIdentifier to each WK2 child processes that is guaranteed to be unique over the run of a given UI process, we can easily create an object in any process and identify it uniquely across all processes. Obviously "process identifier" brings to mind a processes PID but that isn't good enough. The number of PIDs on the system is fairly low and they are global across all processes on the system. It is easy to see how a given UI process that runs for long enough (such as a web browser that the user rarely quits) will start to run in to recycled PIDs, therefore breaking the uniqueness guarantee that is required. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * platform/Process.cpp: Added. (WebCore::Process::setIdentifier): Sets the process-wise identifier (to be used during WK2 child process initialization) (WebCore::Process::identifier): Get the process-wide identifier. * platform/Process.h: Added. Source/WebKit: * Shared/ChildProcess.cpp: (WebKit::ChildProcess::initialize): Set the process-wide identifier if the initialization parameters have it. Cocoa ASSERTS it exists; non-Cocoa platforms will have to figure this out soon. * Shared/ChildProcess.h: * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm: (WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): * UIProcess/ChildProcessProxy.cpp: (WebKit::ChildProcessProxy::getLaunchOptions): * UIProcess/ChildProcessProxy.h: (WebKit::ChildProcessProxy::coreProcessIdentifier const): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): Canonical link: https://commits.webkit.org/197032@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-29 05:56:29 +00:00
#include <wtf/MainThread.h>
namespace WebCore {
namespace Process {
Remove WTF::Optional synonym for std::optional, using that class template directly instead https://bugs.webkit.org/show_bug.cgi?id=226433 Reviewed by Chris Dumez. Source/JavaScriptCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): Use auto instead of Optional<>. Also use * instead of value() and nest the definition of the local inside an if statement in the case where it's an optional. * inspector/scripts/tests/expected/*: Regenerated these results. Source/WebCore: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebCore/PAL: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebDriver: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKit: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * Scripts/webkit/tests: Regenerated expected results, by running the command "python Scripts/webkit/messages_unittest.py -r". (How am I supposed to know to do that?) Source/WebKitLegacy/ios: * WebCoreSupport/WebChromeClientIOS.h: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/mac: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WebKitLegacy/win: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Source/WTF: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. * wtf/Optional.h: Remove WTF::Optional. Tools: * <many files>: Let the do-webcore-rename script rename Optional<> to std::optional<>. Canonical link: https://commits.webkit.org/238290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-30 16:11:40 +00:00
static std::optional<ProcessIdentifier> globalIdentifier;
Add a ProcessIdentifier, vended from the UI process, to each child process https://bugs.webkit.org/show_bug.cgi?id=181155 Reviewed by Brent Fulgham. Source/WebCore: No new tests (Not yet testable) More than once we've needed to create an identifier for an object that is unique across all processes no matter which process it came from. Sometimes we have an object or proxy object to the UI, Storage, or Network process that allows us to augment a process-unique identifier to be globally unique. Due to multiple sessions even this isn't good enough. Other times we have to create more hair-brained solutions. In upcoming MessagePort work (Next step is https://bugs.webkit.org/show_bug.cgi?id=181172) there was no truly workable solution for this. By introducing a new ProcessIdentifier to each WK2 child processes that is guaranteed to be unique over the run of a given UI process, we can easily create an object in any process and identify it uniquely across all processes. Obviously "process identifier" brings to mind a processes PID but that isn't good enough. The number of PIDs on the system is fairly low and they are global across all processes on the system. It is easy to see how a given UI process that runs for long enough (such as a web browser that the user rarely quits) will start to run in to recycled PIDs, therefore breaking the uniqueness guarantee that is required. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * platform/Process.cpp: Added. (WebCore::Process::setIdentifier): Sets the process-wise identifier (to be used during WK2 child process initialization) (WebCore::Process::identifier): Get the process-wide identifier. * platform/Process.h: Added. Source/WebKit: * Shared/ChildProcess.cpp: (WebKit::ChildProcess::initialize): Set the process-wide identifier if the initialization parameters have it. Cocoa ASSERTS it exists; non-Cocoa platforms will have to figure this out soon. * Shared/ChildProcess.h: * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm: (WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): * UIProcess/ChildProcessProxy.cpp: (WebKit::ChildProcessProxy::getLaunchOptions): * UIProcess/ChildProcessProxy.h: (WebKit::ChildProcessProxy::coreProcessIdentifier const): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): Canonical link: https://commits.webkit.org/197032@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-29 05:56:29 +00:00
void setIdentifier(ProcessIdentifier processIdentifier)
{
ASSERT(isUIThread());
Add a ProcessIdentifier, vended from the UI process, to each child process https://bugs.webkit.org/show_bug.cgi?id=181155 Reviewed by Brent Fulgham. Source/WebCore: No new tests (Not yet testable) More than once we've needed to create an identifier for an object that is unique across all processes no matter which process it came from. Sometimes we have an object or proxy object to the UI, Storage, or Network process that allows us to augment a process-unique identifier to be globally unique. Due to multiple sessions even this isn't good enough. Other times we have to create more hair-brained solutions. In upcoming MessagePort work (Next step is https://bugs.webkit.org/show_bug.cgi?id=181172) there was no truly workable solution for this. By introducing a new ProcessIdentifier to each WK2 child processes that is guaranteed to be unique over the run of a given UI process, we can easily create an object in any process and identify it uniquely across all processes. Obviously "process identifier" brings to mind a processes PID but that isn't good enough. The number of PIDs on the system is fairly low and they are global across all processes on the system. It is easy to see how a given UI process that runs for long enough (such as a web browser that the user rarely quits) will start to run in to recycled PIDs, therefore breaking the uniqueness guarantee that is required. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * platform/Process.cpp: Added. (WebCore::Process::setIdentifier): Sets the process-wise identifier (to be used during WK2 child process initialization) (WebCore::Process::identifier): Get the process-wide identifier. * platform/Process.h: Added. Source/WebKit: * Shared/ChildProcess.cpp: (WebKit::ChildProcess::initialize): Set the process-wide identifier if the initialization parameters have it. Cocoa ASSERTS it exists; non-Cocoa platforms will have to figure this out soon. * Shared/ChildProcess.h: * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm: (WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): * UIProcess/ChildProcessProxy.cpp: (WebKit::ChildProcessProxy::getLaunchOptions): * UIProcess/ChildProcessProxy.h: (WebKit::ChildProcessProxy::coreProcessIdentifier const): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): Canonical link: https://commits.webkit.org/197032@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-29 05:56:29 +00:00
globalIdentifier = processIdentifier;
}
ProcessIdentifier identifier()
{
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
if (!globalIdentifier)
Make sure WTF::generateObjectIdentifier() internal counter does not get duplicated https://bugs.webkit.org/show_bug.cgi?id=193848 Reviewed by Youenn Fablet. Source/WebCore: * dom/Document.cpp: * dom/MessageChannel.cpp: (WebCore::MessageChannel::MessageChannel): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::contextIdentifier const): * history/HistoryItem.cpp: (WebCore::HistoryItem::HistoryItem): * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::registerTemporaryServiceWorkerClient): * page/DOMWindow.cpp: (WebCore::DOMWindow::DOMWindow): * platform/Process.cpp: (WebCore::Process::identifier): * workers/service/ServiceWorkerJobData.cpp: (WebCore::ServiceWorkerJobData::ServiceWorkerJobData): * workers/service/server/RegistrationDatabase.cpp: (WebCore::RegistrationDatabase::importRecords): * workers/service/server/SWServer.cpp: (WebCore::SWServer::Connection::Connection): (WebCore::SWServer::updateWorker): * workers/service/server/SWServerRegistration.cpp: (WebCore::generateServiceWorkerRegistrationIdentifier): * workers/service/server/SWServerToContextConnection.cpp: (WebCore::generateServerToContextConnectionIdentifier): Source/WebKit: * Platform/IPC/Connection.cpp: (IPC::Connection::Connection): * UIProcess/ChildProcessProxy.h: * UIProcess/UserContent/WebUserContentControllerProxy.cpp: (WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy): * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::restoreFromState): * UIProcess/WebProcessPool.cpp: * WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp: (WebKit::UserMediaPermissionRequestManager::addDeviceChangeObserver): Source/WTF: Move WTF::generateObjectIdentifier()'s internal counter out-of-line so make sure it never gets duplicated at each call site. This has caused some hard-to-debug issues with duplicate identifiers such as Bug 193761. Also move it to ObjectIdentifier and rename it to generate() as this make call sites nicer when they have a typedef for the ObjectIdentifier<T> type. * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/ObjectIdentifier.cpp: Copied from Source/WebCore/platform/Process.cpp. (WTF::ObjectIdentifierBase::generateIdentifierInternal): (WTF::ObjectIdentifierBase::generateThreadSafeIdentifierInternal): * wtf/ObjectIdentifier.h: (WTF::ObjectIdentifier::generate): (WTF::ObjectIdentifier::generateThreadSafe): Canonical link: https://commits.webkit.org/208459@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240661 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-01-29 17:50:53 +00:00
globalIdentifier = ProcessIdentifier::generate();
Add a ProcessIdentifier, vended from the UI process, to each child process https://bugs.webkit.org/show_bug.cgi?id=181155 Reviewed by Brent Fulgham. Source/WebCore: No new tests (Not yet testable) More than once we've needed to create an identifier for an object that is unique across all processes no matter which process it came from. Sometimes we have an object or proxy object to the UI, Storage, or Network process that allows us to augment a process-unique identifier to be globally unique. Due to multiple sessions even this isn't good enough. Other times we have to create more hair-brained solutions. In upcoming MessagePort work (Next step is https://bugs.webkit.org/show_bug.cgi?id=181172) there was no truly workable solution for this. By introducing a new ProcessIdentifier to each WK2 child processes that is guaranteed to be unique over the run of a given UI process, we can easily create an object in any process and identify it uniquely across all processes. Obviously "process identifier" brings to mind a processes PID but that isn't good enough. The number of PIDs on the system is fairly low and they are global across all processes on the system. It is easy to see how a given UI process that runs for long enough (such as a web browser that the user rarely quits) will start to run in to recycled PIDs, therefore breaking the uniqueness guarantee that is required. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * platform/Process.cpp: Added. (WebCore::Process::setIdentifier): Sets the process-wise identifier (to be used during WK2 child process initialization) (WebCore::Process::identifier): Get the process-wide identifier. * platform/Process.h: Added. Source/WebKit: * Shared/ChildProcess.cpp: (WebKit::ChildProcess::initialize): Set the process-wide identifier if the initialization parameters have it. Cocoa ASSERTS it exists; non-Cocoa platforms will have to figure this out soon. * Shared/ChildProcess.h: * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm: (WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): * UIProcess/ChildProcessProxy.cpp: (WebKit::ChildProcessProxy::getLaunchOptions): * UIProcess/ChildProcessProxy.h: (WebKit::ChildProcessProxy::coreProcessIdentifier const): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): Canonical link: https://commits.webkit.org/197032@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-29 05:56:29 +00:00
});
return *globalIdentifier;
}
} // namespace Process
} // namespace WebCore