From 83b1d64e22a5b8195b4c286df206bccfbf3cbe58 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 13 Mar 2018 12:54:35 -0400 Subject: [PATCH] Bug 1445249 - Part 2 - avoid calling OtherPid() where it might return an invalid pid on android; r=jld MozReview-Commit-ID: EXio3oNJy4U --HG-- extra : rebase_source : a7fe96470b138bb8758c6b8683ba6ad029adb5a1 --- ipc/glue/ProtocolUtils.cpp | 19 ++++++++++++++++++- ipc/glue/ProtocolUtils.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ipc/glue/ProtocolUtils.cpp b/ipc/glue/ProtocolUtils.cpp index 52e96dc2a398..34d397866453 100644 --- a/ipc/glue/ProtocolUtils.cpp +++ b/ipc/glue/ProtocolUtils.cpp @@ -596,6 +596,12 @@ IToplevelProtocol::~IToplevelProtocol() base::ProcessId IToplevelProtocol::OtherPid() const +{ + return OtherPidMaybeInvalid(); +} + +base::ProcessId +IToplevelProtocol::OtherPidMaybeInvalid() const { return mOtherPid; } @@ -721,8 +727,19 @@ IToplevelProtocol::CreateSharedMemory(size_t aSize, Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), segment.get(), id); + + base::ProcessId pid = +#ifdef ANDROID + // We use OtherPidMaybeInvalid() because on Android this method is actually + // called on an unconnected protocol, but Android's shared memory + // implementation doesn't actually use the PID. + OtherPidMaybeInvalid(); +#else + OtherPid(); +#endif + Message* descriptor = shmem.ShareTo( - Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL); + Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), pid, MSG_ROUTING_CONTROL); if (!descriptor) { return nullptr; } diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index 56ebd6604d28..f790fef8925f 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -432,6 +432,8 @@ protected: GetActorEventTargetInternal(IProtocol* aActor) override; private: + base::ProcessId OtherPidMaybeInvalid() const; + ProtocolId mProtocolId; UniquePtr mTrans; base::ProcessId mOtherPid;