Bug 220529 - Reimplement WebCore::isInWebProcess() family as cross-platform by using AuxiliaryProcessInitializationParameters.processType
Summary: Reimplement WebCore::isInWebProcess() family as cross-platform by using Auxil...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Fujii Hironori
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-01-11 18:48 PST by Fujii Hironori
Modified: 2021-01-13 13:06 PST (History)
5 users (show)

See Also:


Attachments
WIP patch (15.45 KB, patch)
2021-01-11 18:49 PST, Fujii Hironori
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
WIP patch (15.68 KB, patch)
2021-01-11 19:04 PST, Fujii Hironori
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (19.49 KB, patch)
2021-01-11 19:54 PST, Fujii Hironori
don.olmstead: review+
achristensen: commit-queue-
Details | Formatted Diff | Diff
Patch (27.69 KB, patch)
2021-01-12 13:45 PST, Fujii Hironori
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (27.76 KB, patch)
2021-01-12 13:50 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (27.83 KB, patch)
2021-01-12 16:31 PST, Fujii Hironori
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (28.89 KB, patch)
2021-01-12 16:50 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (20.88 KB, patch)
2021-01-12 17:18 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch for landing (20.83 KB, patch)
2021-01-13 12:30 PST, Fujii Hironori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fujii Hironori 2021-01-11 18:48:34 PST
Reimplement WebCore::isInWebProcess() families as cross-platform by using AuxiliaryProcessInitializationParameters.processType

I'm going to reimplement the following functions.

 WebCore::isInWebProcess()
 WebCore::isInGPUProcess()
 WebCore::isInNetworkProcess()
Comment 1 Fujii Hironori 2021-01-11 18:49:18 PST
Created attachment 417425 [details]
WIP patch
Comment 2 Fujii Hironori 2021-01-11 19:04:19 PST
Created attachment 417426 [details]
WIP patch
Comment 3 Fujii Hironori 2021-01-11 19:54:41 PST
Created attachment 417428 [details]
Patch
Comment 4 Alex Christensen 2021-01-12 11:33:42 PST
Comment on attachment 417428 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417428&action=review

> Source/WebCore/platform/RuntimeApplicationChecks.cpp:63
> +static ProcessType s_processType = ProcessType::Invalid;

static Optional<AuxiliaryProcessType> auxiliaryProcessType;

> Source/WebCore/platform/RuntimeApplicationChecks.h:35
> +enum class ProcessType : uint8_t {

AuxiliaryProcessType.
Remove Invalid.

> Source/WebKit/Shared/AuxiliaryProcess.h:48
>      enum class ProcessType : uint8_t {

Let's remove this duplicate enum.
Comment 5 Fujii Hironori 2021-01-12 13:26:14 PST
Comment on attachment 417428 [details]
Patch

Thank you for the review. I will revise the patch.
Comment 6 Fujii Hironori 2021-01-12 13:45:40 PST
Created attachment 417488 [details]
Patch
Comment 7 Fujii Hironori 2021-01-12 13:50:07 PST
Created attachment 417489 [details]
Patch
Comment 8 Alex Christensen 2021-01-12 13:53:28 PST
Comment on attachment 417489 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417489&action=review

> Source/WebCore/platform/RuntimeApplicationChecks.cpp:70
> +Optional<AuxiliaryProcessType> auxiliaryProcessType()

If this returns a const Optional<AuxiliaryProcessType>& you can have a function scoped static variable instead of using possibly uninitialized memory if you call checkAuxiliaryProcessType from the UI process.
Comment 9 Fujii Hironori 2021-01-12 16:18:01 PST
Comment on attachment 417489 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417489&action=review

>> Source/WebCore/platform/RuntimeApplicationChecks.cpp:70
>> +Optional<AuxiliaryProcessType> auxiliaryProcessType()
> 
> If this returns a const Optional<AuxiliaryProcessType>& you can have a function scoped static variable instead of using possibly uninitialized memory if you call checkAuxiliaryProcessType from the UI process.

It isn't uninitialized memory.
And, becasue Optional has a constexpr ctor, I think ctor isn't executed at runtime.
Here is the function-scope version.

const Optional<AuxiliaryProcessType>& auxiliaryProcessType()
{
    static AuxiliaryProcessType s_auxiliaryProcessType;
    return s_auxiliaryProcessType;
}

I think there is no difference.

Returning Optional<AuxiliaryProcessType>& requires dereferencing in caller side.
Returning Optional<AuxiliaryProcessType> requires dereferencing in callee side.
I didn't check disassemble code, but I expect returning Optional<AuxiliaryProcessType> is slightly efficient.
Comment 10 Fujii Hironori 2021-01-12 16:27:41 PST
Comment on attachment 417489 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417489&action=review

> Source/WebCore/platform/RuntimeApplicationChecks.cpp:63
> +static AuxiliaryProcessType s_auxiliaryProcessType;

Oops. I fotgot to replace the type. I got your idea. It's uninitialized.
Comment 11 Fujii Hironori 2021-01-12 16:31:01 PST
Created attachment 417496 [details]
Patch
Comment 12 Fujii Hironori 2021-01-12 16:50:24 PST
Created attachment 417497 [details]
Patch
Comment 13 Chris Dumez 2021-01-12 16:59:13 PST
Comment on attachment 417497 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417497&action=review

> Source/WebCore/platform/RuntimeApplicationChecks.cpp:65
> +    static Optional<AuxiliaryProcessType> s_auxiliaryProcessType;

I don't think we use prefixes for such static variables usually.

> Source/WebKit/Shared/AuxiliaryProcessMain.h:45
> +    AuxiliaryProcessInitializationParameters& m_parameters;

While this may currently be safe (I have not look deeply enough to verify), this looks dangerous and I wish we did not introduce such a fragile design that could very easily lead to use-after-free.
Comment 14 Fujii Hironori 2021-01-12 17:14:34 PST
Comment on attachment 417497 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417497&action=review

>> Source/WebCore/platform/RuntimeApplicationChecks.cpp:65
>> +    static Optional<AuxiliaryProcessType> s_auxiliaryProcessType;
> 
> I don't think we use prefixes for such static variables usually.

Will fix.

>> Source/WebKit/Shared/AuxiliaryProcessMain.h:45
>> +    AuxiliaryProcessInitializationParameters& m_parameters;
> 
> While this may currently be safe (I have not look deeply enough to verify), this looks dangerous and I wish we did not introduce such a fragile design that could very easily lead to use-after-free.

I agree. I will change the patch look more sane.
I will redesign AuxiliaryProcessMain in another bug ticket later. BTW, it is non-cocoa code.
Comment 15 Fujii Hironori 2021-01-12 17:18:55 PST
Created attachment 417501 [details]
Patch
Comment 16 Alex Christensen 2021-01-13 08:28:40 PST
Comment on attachment 417501 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417501&action=review

> Source/WebCore/platform/RuntimeApplicationChecks.h:29
> +#include <wtf/Optional.h>

I don't think this is needed.
Comment 17 Fujii Hironori 2021-01-13 12:30:05 PST
Created attachment 417552 [details]
Patch for landing
Comment 18 Fujii Hironori 2021-01-13 12:42:16 PST
Comment on attachment 417501 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417501&action=review

>> Source/WebCore/platform/RuntimeApplicationChecks.h:29
>> +#include <wtf/Optional.h>
> 
> I don't think this is needed.

Fixed. Thank you.
Comment 19 EWS 2021-01-13 13:05:40 PST
Committed r271452: <https://trac.webkit.org/changeset/271452>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417552 [details].
Comment 20 Radar WebKit Bug Importer 2021-01-13 13:06:16 PST
<rdar://problem/73163290>