Allow passing an empty Endpoint over IPDL. (bug 1302009, r=billm)
authorDavid Anderson <danderson@mozilla.com>
Mon, 19 Sep 2016 19:18:20 -0700
changeset 314467 4ee6bf23101a20376d82db9a8daa13ebb2662e9e
parent 314466 a706f77e10af2581704ac160d7b687c58f231570
child 314468 cee3a96d763b538ae6d985c6ee0e03bf1c58949d
push id20574
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:05:16 +0000
treeherderfx-team@14705f779a46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1302009
milestone52.0a1
Allow passing an empty Endpoint over IPDL. (bug 1302009, r=billm)
ipc/glue/ProtocolUtils.h
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -504,16 +504,19 @@ public:
                           mMode == Transport::MODE_SERVER ? ParentSide : ChildSide)) {
             return false;
         }
         mValid = false;
         aActor->SetTransport(Move(t));
         return true;
     }
 
+    bool IsValid() const {
+        return mValid;
+    }
 
 private:
     friend struct IPC::ParamTraits<Endpoint<PFooSide>>;
 
     Endpoint(const Endpoint&) = delete;
     Endpoint& operator=(const Endpoint&) = delete;
 
     bool mValid;
@@ -644,17 +647,20 @@ struct ParamTraits<mozilla::ipc::ActorHa
 
 template<class PFooSide>
 struct ParamTraits<mozilla::ipc::Endpoint<PFooSide>>
 {
     typedef mozilla::ipc::Endpoint<PFooSide> paramType;
 
     static void Write(Message* aMsg, const paramType& aParam)
     {
-        MOZ_RELEASE_ASSERT(aParam.mValid);
+        IPC::WriteParam(aMsg, aParam.mValid);
+        if (!aParam.mValid) {
+            return;
+        }
 
         IPC::WriteParam(aMsg, static_cast<uint32_t>(aParam.mMode));
 
         // We duplicate the descriptor so that our own file descriptor remains
         // valid after the write. An alternative would be to set
         // aParam.mTransport.mValid to false, but that won't work because aParam
         // is const.
         mozilla::ipc::TransportDescriptor desc = mozilla::ipc::DuplicateDescriptor(aParam.mTransport);
@@ -663,17 +669,25 @@ struct ParamTraits<mozilla::ipc::Endpoin
         IPC::WriteParam(aMsg, aParam.mMyPid);
         IPC::WriteParam(aMsg, aParam.mOtherPid);
         IPC::WriteParam(aMsg, static_cast<uint32_t>(aParam.mProtocolId));
     }
 
     static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
     {
         MOZ_RELEASE_ASSERT(!aResult->mValid);
-        aResult->mValid = true;
+
+        if (!IPC::ReadParam(aMsg, aIter, &aResult->mValid)) {
+            return false;
+        }
+        if (!aResult->mValid) {
+            // Object is empty, but read succeeded.
+            return true;
+        }
+
         uint32_t mode, protocolId;
         if (!IPC::ReadParam(aMsg, aIter, &mode) ||
             !IPC::ReadParam(aMsg, aIter, &aResult->mTransport) ||
             !IPC::ReadParam(aMsg, aIter, &aResult->mMyPid) ||
             !IPC::ReadParam(aMsg, aIter, &aResult->mOtherPid) ||
             !IPC::ReadParam(aMsg, aIter, &protocolId)) {
             return false;
         }