Bug 1282737 - Add ResurrectReadOnly() to ipc::Shmem. r?billm
MozReview-Commit-ID: L8v3A5YJdRa
--- 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;
}