Bug 1445249 - Part 2 - avoid calling OtherPid() where it might return an invalid pid on android; r?jld
MozReview-Commit-ID: EXio3oNJy4U
--- 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;