Bug 181155

Summary: Add a ProcessIdentifier, vended from the UI process, to each child process
Product: WebKit Reporter: Brady Eidson <beidson>
Component: WebKit2Assignee: Brady Eidson <beidson>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, bfulgham, cdumez, commit-queue, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=193944
Bug Depends on:    
Bug Blocks: 181172    
Attachments:
Description Flags
Patch
none
Patch none

Description Brady Eidson 2017-12-25 22:38:48 PST
Add a ProcessIdentifier, vended from the UI process, to each child process

This will make it painless to guarantee globally unique object identifiers no matter which process generates an object identifier as long as the process identifier is included in the mix.
Comment 1 Brady Eidson 2017-12-26 21:46:23 PST
Created attachment 330209 [details]
Patch
Comment 2 Brent Fulgham 2017-12-28 13:39:58 PST
Comment on attachment 330209 [details]
Patch

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

Looks good! I had a few idle thoughts, but nothing you need to address before landing. r=me.

> Source/WebCore/ChangeLog:4
> +        https://bugs.webkit.org/show_bug.cgi?id=181155

Yes, please.

> Source/WebCore/platform/Process.cpp:46
> +    static bool hasInitialized;

Don't we usually prefer a dispatch_once for this kind of initialization? Maybe we don't for cross-platform code.

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^ {
        globalIdentifier = generateObjectIdentifier<ProcessIdentifierType>();
    });

> Source/WebKit/Shared/ChildProcess.cpp:73
> +#endif

I think 'processIdentifier' is guaranteed to exist (on all platforms), since you default initialize it in the ChildProcessProxy, and always add it to the init parameters in getLaunchOptions.

> Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm:90
> +    if (processIdentifierString.isEmpty())

Should this assert? It would be super weird if this ever failed, wouldn't it?
Comment 3 Brady Eidson 2017-12-28 19:50:07 PST
(In reply to Brent Fulgham from comment #2)
> Comment on attachment 330209 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=330209&action=review
> 
> Looks good! I had a few idle thoughts, but nothing you need to address
> before landing. r=me.
> 
> > Source/WebCore/ChangeLog:4
> > +        https://bugs.webkit.org/show_bug.cgi?id=181155
> 
> Yes, please.
> 
> > Source/WebCore/platform/Process.cpp:46
> > +    static bool hasInitialized;
> 
> Don't we usually prefer a dispatch_once for this kind of initialization?
> Maybe we don't for cross-platform code.

Right, cross platform. That said I totally remembered std::once_flag and std::call_once since I uploaded this - Will use that instead.

> 
>     static dispatch_once_t onceToken;
>     dispatch_once(&onceToken, ^ {
>         globalIdentifier = generateObjectIdentifier<ProcessIdentifierType>();
>     });
> 
> > Source/WebKit/Shared/ChildProcess.cpp:73
> > +#endif
> 
> I think 'processIdentifier' is guaranteed to exist (on all platforms), since
> you default initialize it in the ChildProcessProxy, and always add it to the
> init parameters in getLaunchOptions.

It's always added to LaunchOptions in ChildProcessProxy in the UI process, that is true.
Unfortunately:
 - In the child process itself the code that populates ChildProcessInitializationParameters is platform-specific, and I can only write the Cocoa port
 - WK1 is still a thing.

> 
> > Source/WebKit/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm:90
> > +    if (processIdentifierString.isEmpty())
> 
> Should this assert? It would be super weird if this ever failed, wouldn't it?

That's handled in XPCServiceInitializer where the delegates to populate these things are called.

e.g.:
    if (!delegate.getProcessIdentifier(processIdentifier))
        exit(EXIT_FAILURE);
Comment 4 Brady Eidson 2017-12-28 20:03:28 PST
Created attachment 330244 [details]
Patch
Comment 5 WebKit Commit Bot 2017-12-28 21:56:33 PST
Comment on attachment 330244 [details]
Patch

Clearing flags on attachment: 330244

Committed r226308: <https://trac.webkit.org/changeset/226308>
Comment 6 WebKit Commit Bot 2017-12-28 21:56:34 PST
All reviewed patches have been landed.  Closing bug.
Comment 7 Radar WebKit Bug Importer 2018-01-02 13:18:23 PST
<rdar://problem/36261367>