Bug 1445249 - Part 2 - avoid calling OtherPid() where it might return an invalid pid on android; r=jld
authorAlex Gaynor <agaynor@mozilla.com>
Tue, 13 Mar 2018 12:54:35 -0400
changeset 464083 6341884397ca46626be778ebffded8a7e661d970
parent 464082 d638bedc1a36ae5a1755550266b96b036dad7504
child 464084 52977e0274275892591c0ed4081e34625078ffe5
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1445249
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1445249 - Part 2 - avoid calling OtherPid() where it might return an invalid pid on android; r=jld MozReview-Commit-ID: EXio3oNJy4U
ipc/glue/ProtocolUtils.cpp
ipc/glue/ProtocolUtils.h
--- a/ipc/glue/ProtocolUtils.cpp
+++ b/ipc/glue/ProtocolUtils.cpp
@@ -592,16 +592,22 @@ IToplevelProtocol::~IToplevelProtocol()
     RefPtr<DeleteTask<Transport>> task = new DeleteTask<Transport>(mTrans.release());
     XRE_GetIOMessageLoop()->PostTask(task.forget());
   }
 }
 
 base::ProcessId
 IToplevelProtocol::OtherPid() const
 {
+  return OtherPidMaybeInvalid();
+}
+
+base::ProcessId
+IToplevelProtocol::OtherPidMaybeInvalid() const
+{
   return mOtherPid;
 }
 
 void
 IToplevelProtocol::SetOtherProcessId(base::ProcessId aOtherPid)
 {
   mOtherPid = aOtherPid;
 }
@@ -716,18 +722,29 @@ IToplevelProtocol::CreateSharedMemory(si
   if (!segment) {
     return nullptr;
   }
   int32_t id = GetSide() == ParentSide ? ++mLastShmemId : --mLastShmemId;
   Shmem shmem(
     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;
   }
   Unused << GetIPCChannel()->Send(descriptor);
 
   *aId = shmem.Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
   Shmem::SharedMemory* rawSegment = segment.get();
   mShmemMap.AddWithID(segment.forget().take(), *aId);
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -427,16 +427,18 @@ protected:
     virtual void ReplaceEventTargetForActorInternal(
       IProtocol* aActor,
       nsIEventTarget* aEventTarget) override;
 
     virtual already_AddRefed<nsIEventTarget>
     GetActorEventTargetInternal(IProtocol* aActor) override;
 
   private:
+    base::ProcessId OtherPidMaybeInvalid() const;
+
     ProtocolId mProtocolId;
     UniquePtr<Transport> mTrans;
     base::ProcessId mOtherPid;
     IDMap<IProtocol*> mActorMap;
     int32_t mLastRouteId;
     IDMap<Shmem::SharedMemory*> mShmemMap;
     Shmem::id_t mLastShmemId;
     bool mIsMainThreadProtocol;