Bug 1245241 - part 2 - remove TYPE_SYSV Shmems from IPDL. r=billm
authorLee Salzman <lsalzman@mozilla.com>
Thu, 18 Feb 2016 10:56:15 -0500
changeset 331904 7c656da2e681a2321c9fb2c7b9aa36b03446f89a
parent 331903 da603bc85e3ffb04864e4a630d85c9af57580624
child 331905 48fa8a92f9364a82985021ae1dfe940de09dd898
push id11113
push userrjesup@wgate.com
push dateThu, 18 Feb 2016 19:00:12 +0000
reviewersbillm
bugs1245241
milestone47.0a1
Bug 1245241 - part 2 - remove TYPE_SYSV Shmems from IPDL. r=billm
ipc/glue/Shmem.cpp
ipc/glue/Shmem.h
ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
ipc/ipdl/test/cxx/TestSysVShmem.cpp
ipc/ipdl/test/cxx/TestSysVShmem.h
ipc/ipdl/test/cxx/moz.build
--- a/ipc/glue/Shmem.cpp
+++ b/ipc/glue/Shmem.cpp
@@ -4,17 +4,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Shmem.h"
 
 #include "ProtocolUtils.h"
 #include "SharedMemoryBasic.h"
-#include "SharedMemorySysV.h"
 
 #include "mozilla/unused.h"
 
 
 namespace mozilla {
 namespace ipc {
 
 class ShmemCreated : public IPC::Message
@@ -68,20 +67,16 @@ public:
   }
 };
 
 static SharedMemory*
 NewSegment(SharedMemory::SharedMemoryType aType)
 {
   if (SharedMemory::TYPE_BASIC == aType) {
     return new SharedMemoryBasic;
-#ifdef MOZ_HAVE_SHAREDMEMORYSYSV
-  } else if (SharedMemory::TYPE_SYSV == aType) {
-    return new SharedMemorySysV;
-#endif
   } else {
     NS_ERROR("unknown Shmem type");
     return nullptr;
   }
 }
 
 static already_AddRefed<SharedMemory>
 CreateSegment(SharedMemory::SharedMemoryType aType, size_t aNBytes, size_t aExtraSize)
@@ -469,35 +464,16 @@ void
 Shmem::Dealloc(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
                SharedMemory* aSegment)
 {
   DestroySegment(aSegment);
 }
 
 #endif  // if defined(DEBUG)
 
-int
-Shmem::GetSysVID() const
-{
-#ifdef MOZ_HAVE_SHAREDMEMORYSYSV
-  AssertInvariants();
-
-  if (mSegment->Type() != SharedMemory::TYPE_SYSV) {
-    NS_ERROR("Can't call GetSysVID() on a non-SysV Shmem!");
-    return -1;
-  }
-
-  SharedMemorySysV* seg = static_cast<SharedMemorySysV*>(mSegment);
-  return seg->GetHandle();
-#else
-  NS_ERROR("Can't call GetSysVID() with no support for SysV shared memory!");
-  return -1;                    // not reached
-#endif
-}
-
 IPC::Message*
 Shmem::ShareTo(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
                base::ProcessId aTargetPid,
                int32_t routingId)
 {
   AssertInvariants();
 
   IPC::Message *msg = new ShmemCreated(routingId, mId, mSize, mSegment->Type());
--- a/ipc/glue/Shmem.h
+++ b/ipc/glue/Shmem.h
@@ -31,17 +31,17 @@
  *  SharedMemory to the set of shmem segments being managed by IPDL.
  *
  *  (3) IPDL-generated code "shares" the new SharedMemory to the child
  *  process, and then sends a special asynchronous IPC message to the
  *  child notifying it of the creation of the segment.  (What this
  *  means is OS specific.)
  *
  *  (4a) The child receives the special IPC message, and using the
- *  |SharedMemory{SysV,Basic}::Handle| it was passed, creates a
+ *  |SharedMemory{Basic}::Handle| it was passed, creates a
  *  |mozilla::ipc::SharedMemory| in the child
  *  process.
  *
  *  (4b) After sending the "shmem-created" IPC message, IPDL-generated
  *  code in the parent returns a |mozilla::ipc::Shmem| back to the C++
  *  caller of |parentActor->AllocShmem()|.  The |Shmem| is a "weak
  *  reference" to the underlying |SharedMemory|, which is managed by
  *  IPDL-generated code.  C++ consumers of |Shmem| can't get at the
@@ -170,18 +170,16 @@ public:
   Size() const
   {
     AssertInvariants();
     AssertAligned<T>();
 
     return mSize / sizeof(T);
   }
 
-  int GetSysVID() const;
-
   // These shouldn't be used directly, use the IPDL interface instead.
   id_t Id(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead) const {
     return mId;
   }
 
   SharedMemory* Segment(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead) const {
     return mSegment;
   }
deleted file mode 100644
--- a/ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
+++ /dev/null
@@ -1,22 +0,0 @@
-namespace mozilla {
-namespace _ipdltest {
-
-protocol PTestSysVShmem {
-child:
-    async Give(Shmem mem, Shmem unsafe, size_t expectedSize);
-
-parent:
-    async Take(Shmem mem, Shmem unsafe, size_t expectedSize);
-    async __delete__();
-
-
-state GIVING:
-    send Give goto TAKING;
-
-state TAKING:
-    recv Take goto TAKING;
-    recv __delete__;
-};
-
-}
-}
deleted file mode 100644
--- a/ipc/ipdl/test/cxx/TestSysVShmem.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "TestSysVShmem.h"
-
-#include "IPDLUnitTests.h"      // fail etc.
-
-
-namespace mozilla {
-namespace _ipdltest {
-
-//-----------------------------------------------------------------------------
-// Parent
-
-void
-TestSysVShmemParent::Main()
-{
-    Shmem mem;
-    Shmem unsafe;
-
-    size_t size = 12345;
-    if (!AllocShmem(size, SharedMemory::TYPE_SYSV, &mem))
-        fail("can't alloc shmem");
-    if (!AllocUnsafeShmem(size, SharedMemory::TYPE_SYSV, &unsafe))
-        fail("can't alloc shmem");
-
-    if (0 > mem.GetSysVID())
-        fail("invalid shmem ID");
-    if (0 > unsafe.GetSysVID())
-        fail("invalid shmem ID");
-
-    if (mem.Size<char>() != size)
-        fail("shmem is wrong size: expected %lu, got %lu",
-             size, mem.Size<char>());
-    if (unsafe.Size<char>() != size)
-        fail("shmem is wrong size: expected %lu, got %lu",
-             size, unsafe.Size<char>());
-
-    char* ptr = mem.get<char>();
-    memcpy(ptr, "Hello!", sizeof("Hello!"));
-
-    char* unsafeptr = unsafe.get<char>();
-    memcpy(unsafeptr, "Hello!", sizeof("Hello!"));
-
-    Shmem unsafecopy = unsafe;
-    if (!SendGive(mem, unsafe, size))
-        fail("can't send Give()");
-
-    // uncomment the following line for a (nondeterministic) surprise!
-    //char c1 = *ptr;  (void)c1;
-
-    // uncomment the following line for a deterministic surprise!
-    //char c2 = *mem.get<char>(); (void)c2;
-
-    // unsafe shmem gets rid of those checks
-    char uc1 = *unsafeptr;  (void)uc1;
-    char uc2 = *unsafecopy.get<char>(); (void)uc2;
-}
-
-
-bool
-TestSysVShmemParent::RecvTake(Shmem&& mem, Shmem&& unsafe,
-                          const size_t& expectedSize)
-{
-    if (mem.Size<char>() != expectedSize)
-        fail("expected shmem size %lu, but it has size %lu",
-             expectedSize, mem.Size<char>());
-    if (unsafe.Size<char>() != expectedSize)
-        fail("expected shmem size %lu, but it has size %lu",
-             expectedSize, unsafe.Size<char>());
-
-    if (strcmp(mem.get<char>(), "And yourself!"))
-        fail("expected message was not written");
-    if (strcmp(unsafe.get<char>(), "And yourself!"))
-        fail("expected message was not written");
-
-    if (!DeallocShmem(mem))
-        fail("DeallocShmem");
-    if (!DeallocShmem(unsafe))
-        fail("DeallocShmem");
-
-    Close();
-
-    return true;
-}
-
-//-----------------------------------------------------------------------------
-// Child
-
-bool
-TestSysVShmemChild::RecvGive(Shmem&& mem, Shmem&& unsafe, const size_t& expectedSize)
-{
-    if (mem.Size<char>() != expectedSize)
-        fail("expected shmem size %lu, but it has size %lu",
-             expectedSize, mem.Size<char>());
-    if (unsafe.Size<char>() != expectedSize)
-        fail("expected shmem size %lu, but it has size %lu",
-             expectedSize, unsafe.Size<char>());
-
-    if (strcmp(mem.get<char>(), "Hello!"))
-        fail("expected message was not written");
-    if (strcmp(unsafe.get<char>(), "Hello!"))
-        fail("expected message was not written");
-
-    char* unsafeptr = unsafe.get<char>();
-
-    memcpy(mem.get<char>(), "And yourself!", sizeof("And yourself!"));
-    memcpy(unsafeptr, "And yourself!", sizeof("And yourself!"));
-
-    Shmem unsafecopy = unsafe;
-    if (!SendTake(mem, unsafe, expectedSize))
-        fail("can't send Take()");
-
-    // these checks also shouldn't fail in the child
-    char uc1 = *unsafeptr;  (void)uc1;
-    char uc2 = *unsafecopy.get<char>(); (void)uc2;
-
-    return true;
-}
-
-
-} // namespace _ipdltest
-} // namespace mozilla
deleted file mode 100644
--- a/ipc/ipdl/test/cxx/TestSysVShmem.h
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef mozilla__ipdltest_TestSysVShmem_h
-#define mozilla__ipdltest_TestSysVShmem_h
-
-#include "mozilla/_ipdltest/IPDLUnitTests.h"
-
-#include "mozilla/_ipdltest/PTestSysVShmemParent.h"
-#include "mozilla/_ipdltest/PTestSysVShmemChild.h"
-
-namespace mozilla {
-namespace _ipdltest {
-
-
-class TestSysVShmemParent :
-    public PTestSysVShmemParent
-{
-public:
-    TestSysVShmemParent() { }
-    virtual ~TestSysVShmemParent() { }
-
-    static bool RunTestInProcesses() { return true; }
-    static bool RunTestInThreads() { return true; }
-
-    void Main();
-
-protected:
-    virtual bool RecvTake(
-            Shmem&& mem,
-            Shmem&& unsafe,
-            const size_t& expectedSize) override;
-
-    virtual void ActorDestroy(ActorDestroyReason why) override
-    {
-        if (NormalShutdown != why)
-            fail("unexpected destruction!");  
-        passed("ok");
-        QuitParent();
-    }
-};
-
-
-class TestSysVShmemChild :
-    public PTestSysVShmemChild
-{
-public:
-    TestSysVShmemChild() { }
-    virtual ~TestSysVShmemChild() { }
-
-protected:
-    virtual bool RecvGive(
-            Shmem&& mem,
-            Shmem&& unsafe,
-            const size_t& expectedSize) override;
-
-    virtual void ActorDestroy(ActorDestroyReason why) override
-    {
-        if (NormalShutdown != why)
-            fail("unexpected destruction!");
-        QuitChild();
-    }
-};
-
-
-} // namespace _ipdltest
-} // namespace mozilla
-
-#endif // ifndef mozilla__ipdltest_TestSysVShmem_h
--- a/ipc/ipdl/test/cxx/moz.build
+++ b/ipc/ipdl/test/cxx/moz.build
@@ -48,21 +48,16 @@ SOURCES += [
     'TestStackHooks.cpp',
     'TestSyncError.cpp',
     'TestSyncHang.cpp',
     'TestSyncWakeup.cpp',
     'TestUrgency.cpp',
     'TestUrgentHangs.cpp',
 ]
 
-if CONFIG['OS_ARCH'] == 'Linux':
-    SOURCES += [
-        'TestSysVShmem.cpp',
-    ]
-
 SOURCES += [
     '!IPDLUnitTests.cpp',
     'IPDLUnitTestProcessChild.cpp',
     'IPDLUnitTestSubprocess.cpp',
 ]
 
 IPDL_SOURCES += [
     'PTestActorPunning.ipdl',
@@ -122,17 +117,16 @@ IPDL_SOURCES += [
     'PTestShmem.ipdl',
     'PTestShutdown.ipdl',
     'PTestShutdownSub.ipdl',
     'PTestShutdownSubsub.ipdl',
     'PTestStackHooks.ipdl',
     'PTestSyncError.ipdl',
     'PTestSyncHang.ipdl',
     'PTestSyncWakeup.ipdl',
-    'PTestSysVShmem.ipdl',
     'PTestUrgency.ipdl',
     'PTestUrgentHangs.ipdl',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'