Bug 686805 part 1 - Make Mappable::munmap, Mappable1stPagePtr::munmap and MappedPtr::munmap private. r=tglek
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 22 Feb 2012 08:12:15 +0100
changeset 87346 c73a25f9fbd3d674b82c0ae996154c499513bdd1
parent 87345 615ee091ee66e30230bf57cfe82aeb9e694ab1ae
child 87347 59237f456cdb05384424942052fbb7f96a24f592
push idunknown
push userunknown
push dateunknown
reviewerstglek
bugs686805
milestone13.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 686805 part 1 - Make Mappable::munmap, Mappable1stPagePtr::munmap and MappedPtr::munmap private. r=tglek
mozglue/linker/CustomElf.cpp
mozglue/linker/Mappable.cpp
mozglue/linker/Mappable.h
mozglue/linker/Utils.h
--- a/mozglue/linker/CustomElf.cpp
+++ b/mozglue/linker/CustomElf.cpp
@@ -81,20 +81,22 @@ void debug_phdr(const char *type, const 
 class Mappable1stPagePtr: public GenericMappedPtr<Mappable1stPagePtr> {
 public:
   Mappable1stPagePtr(Mappable *mappable)
   : GenericMappedPtr<Mappable1stPagePtr>(
       mappable->mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, 0), PAGE_SIZE)
   , mappable(mappable)
   { }
 
+private:
+  friend class GenericMappedPtr<Mappable1stPagePtr>;
   void munmap(void *buf, size_t length) {
     mappable->munmap(buf, length);
   }
-private:
+
   Mappable *mappable;
 };
 
 
 TemporaryRef<LibHandle>
 CustomElf::Load(Mappable *mappable, const char *path, int flags)
 {
   debug("CustomElf::Load(\"%s\", %x) = ...", path, flags);
--- a/mozglue/linker/Mappable.cpp
+++ b/mozglue/linker/Mappable.cpp
@@ -201,17 +201,17 @@ public:
     }
 #endif
     return ::mmap(const_cast<void *>(addr), length, prot, flags, fd, offset);
   }
 
 #ifdef ANDROID
   ~_MappableBuffer() {
     /* Free the additional page we allocated. See _MappableBuffer::Create */
-    munmap(this + ((GetLength() + PAGE_SIZE) & ~(PAGE_SIZE - 1)), PAGE_SIZE);
+    ::munmap(this + ((GetLength() + PAGE_SIZE) & ~(PAGE_SIZE - 1)), PAGE_SIZE);
   }
 #endif
 
 private:
   _MappableBuffer(int fd, void *buf, size_t length)
   : MappedPtr(buf, length), fd(fd) { }
 
   /* File descriptor for the temporary file or ashmem */
--- a/mozglue/linker/Mappable.h
+++ b/mozglue/linker/Mappable.h
@@ -21,20 +21,26 @@
  */
 class Mappable
 {
 public:
   virtual ~Mappable() { }
 
   virtual void *mmap(const void *addr, size_t length, int prot, int flags,
                      off_t offset) = 0;
+
+private:
   virtual void munmap(void *addr, size_t length) {
     ::munmap(addr, length);
   }
+  /* Limit use of Mappable::munmap to classes that keep track of the address
+   * and size of the mapping. This allows to ignore ::munmap return value. */
+  friend class Mappable1stPagePtr;
 
+public:
   /**
    * Indicate to a Mappable instance that no further mmap is going to happen.
    */
   virtual void finalize() = 0;
 };
 
 /**
  * Mappable implementation for plain files
--- a/mozglue/linker/Utils.h
+++ b/mozglue/linker/Utils.h
@@ -242,16 +242,18 @@ private:
 };
 
 struct MappedPtr: public GenericMappedPtr<MappedPtr>
 {
   MappedPtr(void *buf, size_t length)
   : GenericMappedPtr<MappedPtr>(buf, length) { }
   MappedPtr(): GenericMappedPtr<MappedPtr>() { }
 
+private:
+  friend class GenericMappedPtr<MappedPtr>;
   void munmap(void *buf, size_t length)
   {
     ::munmap(buf, length);
   }
 };
 
 /**
  * UnsizedArray is a way to access raw arrays of data in memory.