haikuwebkit/Source/WebCore/platform/ProcessIdentifier.h

42 lines
1.7 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.
*/
#pragma once
#include <wtf/ObjectIdentifier.h>
namespace WebCore {
enum ProcessIdentifierType { };
using ProcessIdentifier = ObjectIdentifier<ProcessIdentifierType>;
namespace Process {
WEBCORE_EXPORT void setIdentifier(ProcessIdentifier);
WEBCORE_EXPORT ProcessIdentifier identifier();
} // namespace Process
} // namespace WebCore