Bug 47500

Summary: Need a way to pass HANDLEs between processes on Windows
Product: WebKit Reporter: Adam Roben (:aroben) <aroben>
Component: WebKit2Assignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: andersca
Priority: P2 Keywords: InRadar, PlatformOnly
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Windows XP   
Bug Depends on:    
Bug Blocks: 47499    

Description Adam Roben (:aroben) 2010-10-11 12:16:23 PDT
In order to implement WebKit2's SharedMemory class (bug 47499), we'll need a way to pass HANDLEs (specifically, those representing file-mapping objects) across processes.
Comment 1 Adam Roben (:aroben) 2010-10-11 12:25:14 PDT
In order to pass a HANDLE between processes, we'll need to call ::DuplicateHandle to copy the handle into the target process. But doing this requires knowing what the target process is, which is not known at argument-encoding time.

Anders suggests that we use CoreIPC::Attachment for this. Specifically, we'd:

A1) Make CoreIPC::Connection perform a handshake that exchanges process HANDLEs between the two ends of the connection (on Vista and newer we could perhaps use ::GetNamedPipeClientProcessId/::GetNamedPipeServerProcessId to simplify this)
A2) Use the process HANDLE received in the handshake to call ::DuplicateHandle when sending the message

I think another option that wouldn't require the handshake is:

B1) Call ::DuplicateHandle to duplicate the HANDLE in the source process at argument-encoding time
B2) Send both the HANDLE and the source process's PID in the message to the target process
B3) When the message is received in the target process, call ::DuplicateHandle to copy the handle into the target process and pass DUPLICATE_CLOSE_SOURCE to close the HANDLE the source process made in (B1)

I'm not positive that the ::DuplicateHandle call in (B3) will actually succeed, however. Maybe Windows doesn't allow it to be used like this.
Comment 2 Adam Roben (:aroben) 2010-10-11 12:26:02 PDT
<rdar://problem/8536804>
Comment 3 Adam Roben (:aroben) 2010-10-11 15:21:16 PDT

*** This bug has been marked as a duplicate of bug 47499 ***