Bug 1282737 - Add ResurrectReadOnly() to ipc::Shmem. r?billm draft
authorKan-Ru Chen <kanru@kanru.info>
Fri, 01 Jul 2016 12:21:06 +0800
changeset 383063 739ed29a7098d6692a3375c8af2c60874bef9093
parent 381966 e45890951ce77c3df05575bd54072b9f300d77b0
child 383064 407140f52ad8f533f00248efaca35c408542a9b8
child 383065 58e1fde45135b0518ae964197731c3c9787971b1
child 383066 7da3b16cbdaba103b39517f69502a521fe9aa2ec
child 383080 b8e5774166b64e2dc2b1cf54b977f1056abe29f9
push id21912
push userbmo:kchen@mozilla.com
push dateFri, 01 Jul 2016 04:28:59 +0000
reviewersbillm
bugs1282737
milestone50.0a1
Bug 1282737 - Add ResurrectReadOnly() to ipc::Shmem. r?billm MozReview-Commit-ID: L8v3A5YJdRa
ipc/glue/Shmem.cpp
ipc/glue/Shmem.h
--- a/ipc/glue/Shmem.cpp
+++ b/ipc/glue/Shmem.cpp
@@ -311,16 +311,23 @@ Shmem::RevokeRights(IHadBetterBeIPDLCode
 
   if (!header->mUnsafe) {
     Protect(mSegment);
   } else {
     mSegment->Protect(reinterpret_cast<char*>(header), pageSize, RightsNone);
   }
 }
 
+void
+Shmem::ResurrectReadOnly()
+{
+  mSegment->Protect(reinterpret_cast<char*>(mSegment->memory()),
+                    mSegment->Size(), RightsRead);
+}
+
 // static
 already_AddRefed<Shmem::SharedMemory>
 Shmem::Alloc(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
              size_t aNBytes,
              SharedMemoryType aType,
              bool aUnsafe,
              bool aProtect)
 {
--- a/ipc/glue/Shmem.h
+++ b/ipc/glue/Shmem.h
@@ -179,16 +179,27 @@ public:
 #ifndef DEBUG
   void RevokeRights(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead)
   {
   }
 #else
   void RevokeRights(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead);
 #endif
 
+  // Violates the invariant that only one side has read access right
+  // to the shmem. Make sure the other side has no access to the shmem
+  // when using this. In other words, don't use it.
+#ifndef DEBUG
+  void ResurrectReadOnly()
+  {
+  }
+#else
+  void ResurrectReadOnly();
+#endif
+
   void forget(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead)
   {
     mSegment = nullptr;
     mData = nullptr;
     mSize = 0;
     mId = 0;
   }