Bug 1525803 - Use MAP_SHARED for read-only file mappings on MacOS and Android. r=glandium
authorJed Davis <jld@mozilla.com>
Thu, 07 Feb 2019 16:30:44 -0700
changeset 4802 e61b118b47e6
parent 4801 753fe0f7964c
child 4803 40ce5d162994
push id309
push userjjones@mozilla.com
push dateWed, 13 Feb 2019 18:05:05 +0000
reviewersglandium
bugs1525803
Bug 1525803 - Use MAP_SHARED for read-only file mappings on MacOS and Android. r=glandium
pr/src/md/unix/unix.c
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -3564,22 +3564,30 @@ PRStatus _MD_CreateFileMap(PRFileMap *fm
             }
             if (PR_Write(fmap->fd, "", 1) != 1) {
                 return PR_FAILURE;
             }
         }
     }
     if (fmap->prot == PR_PROT_READONLY) {
         fmap->md.prot = PROT_READ;
-#ifdef OSF1V4_MAP_PRIVATE_BUG
+#if defined(OSF1V4_MAP_PRIVATE_BUG) || defined(DARWIN) || defined(ANDROID)
         /*
          * Use MAP_SHARED to work around a bug in OSF1 V4.0D
          * (QAR 70220 in the OSF_QAR database) that results in
          * corrupted data in the memory-mapped region.  This
          * bug is fixed in V5.0.
+         *
+         * This is also needed on OS X because its implementation of
+         * POSIX shared memory returns an error for MAP_PRIVATE, even
+         * when the mapping is read-only.
+         *
+         * And this is needed on Android, because mapping ashmem with
+         * MAP_PRIVATE creates a mapping of zeroed memory instead of
+         * the shm contents.
          */
         fmap->md.flags = MAP_SHARED;
 #else
         fmap->md.flags = MAP_PRIVATE;
 #endif
     } else if (fmap->prot == PR_PROT_READWRITE) {
         fmap->md.prot = PROT_READ | PROT_WRITE;
         fmap->md.flags = MAP_SHARED;