Skip to content

Commit 272972f

Browse files
Partition object identifiers into WebContent process and GPU process domains
https://bugs.webkit.org/show_bug.cgi?id=328652 rdar://190831206 Reviewed by Youenn Fablet. GPU process creates VideoFrame instances when camera captures them. These are offered to WebContent process, and the offer uses identifiers to reference these. WebContent process would like to also create VideoFrame instances and pass identifiers to GPU process. Currently this is done with synchronous messages, so that GPU process allocates the identifier. Mark all identifiers allocated by GPUP with top bit == 1. This guarantees that GPUP can allocate identifiers in its own timeline, and WCP in its own. The IPC test converted the GPU process identifiers with Number(), which loses precision for identifiers with the top bit set. Pass the BigInt identifiers as is. The IPC test library checked identifiers against the int64_t range even though they are serialized as uint64_t. Check them against the uint64_t range. * LayoutTests/ipc/cocoa/legacy-cdm-session-avcontentkeysession-destruction-race.html: * LayoutTests/ipc/coreipc.js: (CoreIPC.serializeIdentifier): * Source/WTF/wtf/ObjectIdentifier.cpp: (WTF::initializeObjectIdentifierDomain): (WTF::ObjectIdentifierMainThreadAccessTraits::generateIdentifierInternal): (WTF::ObjectIdentifierThreadSafeAccessTraits::generateIdentifierInternal): * Source/WTF/wtf/ObjectIdentifier.h: * Source/WebKit/GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm: (GPU_SERVICE_INITIALIZER): * Source/WebKit/Shared/AuxiliaryProcessMain.h: (WebKit::AuxiliaryProcessMainBase::run): * Source/WebKit/Shared/ObjectIdentifierDomains.h: Added. * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/324813@main
1 parent 8f621b6 commit 272972f

8 files changed

Lines changed: 85 additions & 9 deletions

File tree

‎LayoutTests/ipc/cocoa/legacy-cdm-session-avcontentkeysession-destruction-race.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@
5050

5151
for (let i = 0; i < 3; i++) {
5252
let sessA;
53-
CoreIPC.GPU.RemoteLegacyCDMProxy.CreateSession(Number(cdmId), { logIdentifier: 1n },
53+
CoreIPC.GPU.RemoteLegacyCDMProxy.CreateSession(cdmId, { logIdentifier: 1n },
5454
(r,_,t) => { sessA = t.identifier.parsedValue?.optionalValue?.parsedValue; });
5555
if (sessA === undefined)
5656
break;
5757

58-
CoreIPC.GPU.RemoteLegacyCDMSessionProxy.GenerateKeyRequest(Number(sessA),
58+
CoreIPC.GPU.RemoteLegacyCDMSessionProxy.GenerateKeyRequest(sessA,
5959
{ mimeType: "video/mp4", initData: initSB, mediaKeysHashSalt: "x" }, ()=>{});
6060

6161
// Creates AVContentKeySession + bg delegate queue + fires didProvideContentKeyRequest
6262
// (bg thread takes RefPtr parent).
63-
CoreIPC.GPU.RemoteLegacyCDMSessionProxy.Update(Number(sessA), { update: certSB }, ()=>{});
63+
CoreIPC.GPU.RemoteLegacyCDMSessionProxy.Update(sessA, { update: certSB }, ()=>{});
6464

6565
// Drop the only main-thread RefPtr; bg's `parent` may become last owner.
6666
CoreIPC.GPU.RemoteLegacyCDMFactoryProxy.RemoveSession(0, { identifier: sessA }, ()=>{});
@@ -69,7 +69,7 @@
6969
let burst = [];
7070
for (let k = 0; k < 32; k++) {
7171
let s;
72-
CoreIPC.GPU.RemoteLegacyCDMProxy.CreateSession(Number(cdmId), { logIdentifier: BigInt(100 + k) },
72+
CoreIPC.GPU.RemoteLegacyCDMProxy.CreateSession(cdmId, { logIdentifier: BigInt(100 + k) },
7373
(r,_,t) => { s = t.identifier.parsedValue?.optionalValue?.parsedValue; });
7474
if (s !== undefined)
7575
burst.push(s);

‎LayoutTests/ipc/coreipc.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export class ArgumentSerializer {
614614
if (typeof argument != 'number' && typeof argument != 'bigint') {
615615
throw new SerializationError(`Identifier of type ${ argumentDefinition.type } is not a number`);
616616
}
617-
if (argument < MIN_INT64 || argument > MAX_INT64) {
617+
if (argument < MIN_UINT || argument > MAX_UINT64) {
618618
throw new SerializationError(`Identifier value (${ argumentDefinition.name }) of type ${ argumentDefinition.type } is out-of-bounds.`);
619619
}
620620
// magic object identifier for WebGL hotpatches

‎Source/WTF/wtf/ObjectIdentifier.cpp‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,28 @@
2828

2929
#include <atomic>
3030
#include <wtf/MainThread.h>
31+
#include <wtf/MathExtras.h>
3132
#include <wtf/PrintStream.h>
3233
#include <wtf/text/TextStream.h>
3334

3435
namespace WTF {
3536

37+
static uint64_t currentMainThreadIdentifier;
38+
static std::atomic<uint64_t> currentThreadSafeIdentifier;
39+
40+
void initializeObjectIdentifierDomain(ObjectIdentifierDomain domain)
41+
{
42+
ASSERT(!currentMainThreadIdentifier);
43+
ASSERT(!currentThreadSafeIdentifier);
44+
currentMainThreadIdentifier = static_cast<uint64_t>(domain);
45+
ASSERT(ctz(currentMainThreadIdentifier) >= 60); // 1 identifier per ns, 2^60 identifiers, 1e18ns. 1e16 ns/year that is still scale of 100 years.
46+
currentThreadSafeIdentifier = currentMainThreadIdentifier;
47+
}
48+
3649
uint64_t ObjectIdentifierMainThreadAccessTraits::generateIdentifierInternal()
3750
{
3851
ASSERT(isMainThread()); // You should use AtomicObjectIdentifier if you're hitting this assertion.
39-
static uint64_t current = 0;
40-
return ++current;
52+
return ++currentMainThreadIdentifier;
4153
}
4254

4355
void printInternal(PrintStream& out, const ObjectIdentifierGenericBase& identifier)
@@ -47,8 +59,7 @@ void printInternal(PrintStream& out, const ObjectIdentifierGenericBase& identifi
4759

4860
uint64_t ObjectIdentifierThreadSafeAccessTraits::generateIdentifierInternal()
4961
{
50-
static std::atomic<uint64_t> current;
51-
return ++current;
62+
return ++currentThreadSafeIdentifier;
5263
}
5364

5465
} // namespace WTF

‎Source/WTF/wtf/ObjectIdentifier.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ namespace WTF {
3434

3535
class PrintStream;
3636

37+
// Type to mark the object identifier domains. Each domain can generate
38+
// identifiers in isolation with respective to other domains and the identifiers
39+
// are guaranteed to be unique. Use for example:
40+
// constexpr ObjectIdentifierDomain gpuProcessObjectIdentifierDomain { static_cast<uint64_t>(1) << 63 };
41+
enum class ObjectIdentifierDomain : uint64_t {
42+
};
43+
44+
// Initializes the process to produce unique identifiers among process domains.
45+
// By default, the process in the default domain.
46+
WTF_EXPORT_PRIVATE void initializeObjectIdentifierDomain(ObjectIdentifierDomain);
47+
3748
struct ObjectIdentifierThreadSafeAccessTraits {
3849
WTF_EXPORT_PRIVATE static uint64_t generateIdentifierInternal();
3950
};
@@ -194,3 +205,4 @@ using WTF::AtomicObjectIdentifier;
194205
using WTF::ObjectIdentifierGenericBase;
195206
using WTF::ObjectIdentifierGeneric;
196207
using WTF::ObjectIdentifier;
208+
using WTF::ObjectIdentifierDomain;

‎Source/WebKit/GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#import "XPCServiceEntryPoint.h"
3232

3333
#if ENABLE(GPU_PROCESS)
34+
#import "ObjectIdentifierDomains.h"
3435

3536
namespace WebKit {
3637

@@ -52,6 +53,7 @@ void GPU_SERVICE_INITIALIZER(xpc_connection_t connection, xpc_object_t initializ
5253
{
5354
WebKit::disableJSC([&] {
5455
#if ENABLE(GPU_PROCESS)
56+
WTF::initializeObjectIdentifierDomain(WebKit::gpuProcessObjectIdentifierDomain);
5557
WebKit::XPCServiceInitializer<WebKit::GPUProcess, WebKit::GPUServiceInitializerDelegate>(connection, initializerMessage);
5658
#endif // ENABLE(GPU_PROCESS)
5759
});

‎Source/WebKit/Shared/AuxiliaryProcessMain.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include <wtf/RunLoop.h>
3535
#include <wtf/RuntimeApplicationChecks.h>
3636

37+
#if ENABLE(GPU_PROCESS)
38+
#include "ObjectIdentifierDomains.h"
39+
#endif
40+
3741
namespace WebKit {
3842

3943
class AuxiliaryProcessMainCommon {
@@ -70,6 +74,10 @@ class AuxiliaryProcessMainBase : public AuxiliaryProcessMainCommon {
7074
if (!parseCommandLine(argc, argv))
7175
return EXIT_FAILURE;
7276

77+
#if ENABLE(GPU_PROCESS)
78+
if (AuxiliaryProcessType::processType == WTF::AuxiliaryProcessType::GPU)
79+
WTF::initializeObjectIdentifierDomain(gpuProcessObjectIdentifierDomain);
80+
#endif
7381
InitializeWebKit2();
7482

7583
initializeAuxiliaryProcess(WTF::move(m_parameters));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2024 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
#include <wtf/ObjectIdentifier.h>
29+
30+
namespace WebKit {
31+
32+
#if ENABLE(GPU_PROCESS)
33+
34+
// Identifiers generated by any type of process and GPU processes are guaranteed
35+
// to be unique between said processes and the GPU processes.
36+
constexpr ObjectIdentifierDomain gpuProcessObjectIdentifierDomain { static_cast<uint64_t>(1) << 63 };
37+
38+
#endif
39+
40+
}
41+

‎Source/WebKit/WebKit.xcodeproj/project.pbxproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7172,6 +7172,7 @@
71727172
7B904169254AFEA7006EEB8C /* RemoteGraphicsContextGL.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGL.cpp; sourceTree = "<group>"; };
71737173
7B90416A254AFEA7006EEB8C /* RemoteGraphicsContextGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteGraphicsContextGL.h; sourceTree = "<group>"; };
71747174
7B90416D2550108C006EEB8C /* RemoteGraphicsContextGLFunctionsGenerated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteGraphicsContextGLFunctionsGenerated.h; sourceTree = "<group>"; };
7175+
7B98A6D82C9452F40054BC62 /* ObjectIdentifierDomains.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObjectIdentifierDomains.h; sourceTree = "<group>"; };
71757176
7B9FC59628A28D13007570E7 /* PlatformUnifiedSource1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformUnifiedSource1.cpp; sourceTree = "<group>"; };
71767177
7B9FC59D28A28F88007570E7 /* libWebKitPlatform.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWebKitPlatform.a; sourceTree = BUILT_PRODUCTS_DIR; };
71777178
7B9FC5A228A2A0B5007570E7 /* WebKitPlatform.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WebKitPlatform.xcconfig; sourceTree = "<group>"; };
@@ -10613,6 +10614,7 @@
1061310614
5CD1E0011234567890ABCDEF /* NetworkStorageSession.h */,
1061410615
FA45FA392E4545E500057B45 /* NodeHitTestResult.h */,
1061510616
FA45FA3B2E45462200057B45 /* NodeHitTestResult.serialization.in */,
10617+
7B98A6D82C9452F40054BC62 /* ObjectIdentifierDomains.h */,
1061610618
8657EE3928EDB8C500FF9B40 /* Pasteboard.serialization.in */,
1061710619
2A0F3D0230200A0100AB01F0 /* PDFAccessibilityDisplayModeState.h */,
1061810620
2A0F3D0330200A0100AB01F0 /* PDFAccessibilityDisplayModeState.serialization.in */,

0 commit comments

Comments
 (0)