Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=8 et : |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "base/message_loop.h" |
michael@0 | 9 | #include "chrome/common/child_process_info.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/ipc/Transport.h" |
michael@0 | 12 | |
michael@0 | 13 | using namespace base; |
michael@0 | 14 | using namespace std; |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace ipc { |
michael@0 | 18 | |
michael@0 | 19 | bool |
michael@0 | 20 | CreateTransport(ProcessHandle aProcOne, ProcessHandle /*unused*/, |
michael@0 | 21 | TransportDescriptor* aOne, TransportDescriptor* aTwo) |
michael@0 | 22 | { |
michael@0 | 23 | // This id is used to name the IPC pipe. The pointer passed to this |
michael@0 | 24 | // function isn't significant. |
michael@0 | 25 | wstring id = ChildProcessInfo::GenerateRandomChannelID(aOne); |
michael@0 | 26 | // Use MODE_SERVER to force creation of the pipe |
michael@0 | 27 | Transport t(id, Transport::MODE_SERVER, nullptr); |
michael@0 | 28 | HANDLE serverPipe = t.GetServerPipeHandle(); |
michael@0 | 29 | if (!serverPipe) { |
michael@0 | 30 | return false; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // NB: we create the server pipe immediately, instead of just |
michael@0 | 34 | // grabbing an ID, on purpose. In the current setup, the client |
michael@0 | 35 | // needs to connect to an existing server pipe, so to prevent race |
michael@0 | 36 | // conditions, we create the server side here and then dup it to the |
michael@0 | 37 | // eventual server process. |
michael@0 | 38 | HANDLE serverDup; |
michael@0 | 39 | DWORD access = 0; |
michael@0 | 40 | DWORD options = DUPLICATE_SAME_ACCESS; |
michael@0 | 41 | if (!DuplicateHandle(GetCurrentProcess(), serverPipe, aProcOne, |
michael@0 | 42 | &serverDup, |
michael@0 | 43 | access, |
michael@0 | 44 | FALSE/*not inheritable*/, |
michael@0 | 45 | options)) { |
michael@0 | 46 | return false; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | aOne->mPipeName = aTwo->mPipeName = id; |
michael@0 | 50 | aOne->mServerPipe = serverDup; |
michael@0 | 51 | aTwo->mServerPipe = INVALID_HANDLE_VALUE; |
michael@0 | 52 | return true; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | Transport* |
michael@0 | 56 | OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode) |
michael@0 | 57 | { |
michael@0 | 58 | return new Transport(aTd.mPipeName, aTd.mServerPipe, aMode, nullptr); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | Transport* |
michael@0 | 62 | OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode) |
michael@0 | 63 | { |
michael@0 | 64 | NS_NOTREACHED("Not implemented!"); |
michael@0 | 65 | return nullptr; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | CloseDescriptor(const TransportDescriptor& aTd) |
michael@0 | 70 | { |
michael@0 | 71 | CloseHandle(aTd.mServerPipe); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | } // namespace ipc |
michael@0 | 75 | } // namespace mozilla |