Bug 1479960 - Fix max_size in shared_memory_posix. r=froydnj
authorJed Davis <jld@mozilla.com>
Wed, 14 Aug 2019 22:48:29 +0000
changeset 488044 bdf7a041928aa4673de020df11c069e0af996d50
parent 488043 f814f58d43d66df993d9d9d492ec39c1417b1a3d
child 488045 6da235c5a77c5fc23b11a7456c588974f1de878c
push id36434
push usercbrindusan@mozilla.com
push dateThu, 15 Aug 2019 09:44:30 +0000
treeherdermozilla-central@144fbfb409b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1479960
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1479960 - Fix max_size in shared_memory_posix. r=froydnj The Unix backend for shared memory needs to keep the mapped size to pass to munmap, while the Windows backend doesn't. Currently it's reusing the max_size field, and then zeroing it when it's unmapped, which breaks the freezing use case. This patch uses a dedicated field for that. Depends on D26740 Differential Revision: https://phabricator.services.mozilla.com/D26741
ipc/chromium/src/base/shared_memory.h
ipc/chromium/src/base/shared_memory_posix.cc
--- a/ipc/chromium/src/base/shared_memory.h
+++ b/ipc/chromium/src/base/shared_memory.h
@@ -155,16 +155,17 @@ class SharedMemory {
 
 #if defined(OS_WIN)
   // If true indicates this came from an external source so needs extra checks
   // before being mapped.
   bool external_section_;
   HANDLE mapped_file_;
 #elif defined(OS_POSIX)
   int mapped_file_;
+  size_t mapped_size_;
 #endif
   void* memory_;
   bool read_only_;
   size_t max_size_;
 
   DISALLOW_EVIL_CONSTRUCTORS(SharedMemory);
 };
 
--- a/ipc/chromium/src/base/shared_memory_posix.cc
+++ b/ipc/chromium/src/base/shared_memory_posix.cc
@@ -20,29 +20,35 @@
 #include "base/logging.h"
 #include "base/string_util.h"
 #include "mozilla/Atomics.h"
 #include "prenv.h"
 
 namespace base {
 
 SharedMemory::SharedMemory()
-    : mapped_file_(-1), memory_(NULL), read_only_(false), max_size_(0) {}
+    : mapped_file_(-1),
+      mapped_size_(0),
+      memory_(nullptr),
+      read_only_(false),
+      max_size_(0) {}
 
 SharedMemory::SharedMemory(SharedMemory&& other) {
   if (this == &other) {
     return;
   }
 
   mapped_file_ = other.mapped_file_;
+  mapped_size_ = other.mapped_size_;
   memory_ = other.memory_;
   read_only_ = other.read_only_;
   max_size_ = other.max_size_;
 
   other.mapped_file_ = -1;
+  other.mapped_size_ = 0;
   other.memory_ = nullptr;
 }
 
 SharedMemory::~SharedMemory() { Close(); }
 
 bool SharedMemory::SetHandle(SharedMemoryHandle handle, bool read_only) {
   DCHECK(mapped_file_ == -1);
 
@@ -170,28 +176,28 @@ bool SharedMemory::Map(size_t bytes, voi
   if (mmap_succeeded) {
     if (fixed_address && memory_ != fixed_address) {
       bool munmap_succeeded = munmap(memory_, bytes) == 0;
       DCHECK(munmap_succeeded) << "Call to munmap failed, errno=" << errno;
       memory_ = NULL;
       return false;
     }
 
-    max_size_ = bytes;
+    mapped_size_ = bytes;
   }
 
   return mmap_succeeded;
 }
 
 bool SharedMemory::Unmap() {
   if (memory_ == NULL) return false;
 
-  munmap(memory_, max_size_);
+  munmap(memory_, mapped_size_);
   memory_ = NULL;
-  max_size_ = 0;
+  mapped_size_ = 0;
   return true;
 }
 
 void* SharedMemory::FindFreeAddressSpace(size_t size) {
   void* memory =
       mmap(NULL, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   munmap(memory, size);
   return memory != MAP_FAILED ? memory : NULL;