Bug 848270 - Various fixups for Android builds on OSX after bug 847479. r=nfroyd
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Mar 2013 17:01:56 +0100
changeset 123968 a7cb66376172365c2718e5705d7f4c6ab8ef5157
parent 123967 03b01594f7c5205db4e63a13de5c2663f968c89a
child 123969 310b85d5fa77516600250779dd3e38f599904469
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersnfroyd
bugs848270, 847479
milestone22.0a1
Bug 848270 - Various fixups for Android builds on OSX after bug 847479. r=nfroyd
mozglue/linker/SeekableZStream.h
mozglue/linker/szip.cpp
--- a/mozglue/linker/SeekableZStream.h
+++ b/mozglue/linker/SeekableZStream.h
@@ -44,22 +44,16 @@ struct SeekableZStreamHeader: public Zip
   /* Size of last chunk (> 0, <= Chunk size) */
   le_uint16 lastChunkSize;
 
   /* windowBits value used when deflating */
   signed char windowBits;
 
   /* Filter Id */
   unsigned char filter;
-
-  /* Maximum supported size for chunkSize */
-  /* Can't use std::min here because it's not constexpr */
-  static const size_t maxChunkSize =
-    1 << ((sizeof(chunkSize) < sizeof(lastChunkSize) ?
-           sizeof(chunkSize) : sizeof(lastChunkSize)) - 1);
 };
 #pragma pack()
 
 MOZ_STATIC_ASSERT(sizeof(SeekableZStreamHeader) == 5 * 4,
                   "SeekableZStreamHeader should be 5 32-bits words");
 
 /**
  * Helper class used to decompress Seekable ZStreams.
--- a/mozglue/linker/szip.cpp
+++ b/mozglue/linker/szip.cpp
@@ -11,23 +11,28 @@
 #include <fcntl.h>
 #include <errno.h>
 #include "mozilla/Assertions.h"
 #include "mozilla/Scoped.h"
 #include "SeekableZStream.h"
 #include "Utils.h"
 #include "Logging.h"
 
+/* Maximum supported size for chunkSize */
+static const size_t maxChunkSize =
+  1 << (8 * std::min(sizeof(((SeekableZStreamHeader *)NULL)->chunkSize),
+                     sizeof(((SeekableZStreamHeader *)NULL)->lastChunkSize)) - 1);
+
 class Buffer: public MappedPtr
 {
 public:
   virtual bool Resize(size_t size)
   {
     void *buf = mmap(NULL, size, PROT_READ | PROT_WRITE,
-                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+                     MAP_PRIVATE | MAP_ANON, -1, 0);
     if (buf == MAP_FAILED)
       return false;
     if (*this != MAP_FAILED)
       memcpy(buf, *this, std::min(size, GetLength()));
     Assign(buf, size);
     return true;
   }
 };
@@ -329,18 +334,17 @@ int main(int argc, char* argv[])
     if (strcmp(firstArg[0], "-d") == 0) {
       compress = false;
     } else if (strcmp(firstArg[0], "-c") == 0) {
       firstArg++;
       argc--;
       if (!firstArg[0])
         break;
       if (!GetSize(firstArg[0], &chunkSize) || !chunkSize ||
-          (chunkSize % 4096) ||
-          (chunkSize > SeekableZStreamHeader::maxChunkSize)) {
+          (chunkSize % 4096) || (chunkSize > maxChunkSize)) {
         log("Invalid chunk size");
         return 1;
       }
     } else if (strcmp(firstArg[0], "-f") == 0) {
       firstArg++;
       argc--;
       if (!firstArg[0])
         break;