bool Open(const PrivateIPDLInterface&, MessageChannel* aOpenerChannel, ProcessHandle aOtherProcess, Transport::Mode aOpenerMode, ProtocolId aProtocol, ProtocolId aChildProtocol) { bool isParent = (Transport::MODE_SERVER == aOpenerMode); ProcessHandle thisHandle = GetCurrentProcessHandle(); ProcessHandle parentHandle = isParent ? thisHandle : aOtherProcess; ProcessHandle childHandle = !isParent ? thisHandle : aOtherProcess; ProcessId parentId = GetProcId(parentHandle); ProcessId childId = GetProcId(childHandle); if (!parentId || !childId) { return false; } TransportDescriptor parentSide, childSide; if (!CreateTransport(parentHandle, childHandle, &parentSide, &childSide)) { return false; } Message* parentMsg = new ChannelOpened(parentSide, childId, aProtocol); Message* childMsg = new ChannelOpened(childSide, parentId, aChildProtocol); nsAutoPtr<Message> messageForUs(isParent ? parentMsg : childMsg); nsAutoPtr<Message> messageForOtherSide(!isParent ? parentMsg : childMsg); if (!aOpenerChannel->Echo(messageForUs.forget()) || !aOpenerChannel->Send(messageForOtherSide.forget())) { CloseDescriptor(parentSide); CloseDescriptor(childSide); return false; } return true; }
CrossProcessMutexHandle CrossProcessMutex::ShareToProcess(ProcessHandle aHandle) { HANDLE newHandle; bool succeeded = ::DuplicateHandle(GetCurrentProcessHandle(), mMutex, aHandle, &newHandle, 0, FALSE, DUPLICATE_SAME_ACCESS); if (!succeeded) { return nullptr; } return newHandle; }