Bug 1283629 - [1.1] Check for cached library file availability before reusing it. r=glandium
authorEugen Sawin <esawin@mozilla.com>
Thu, 10 Nov 2016 19:38:27 +0100
changeset 322724 b7d42c3980d12dff16df9f6077f34279aeef49d6
parent 322723 bc0e63d09f83724c32ac7abe92c75b041b1c9b03
child 322725 a9c898900950efe519e898507414e6e4f10240b4
push id30961
push userkwierso@gmail.com
push dateThu, 17 Nov 2016 01:08:03 +0000
treeherdermozilla-central@c27117f67fa3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1283629
milestone53.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 1283629 - [1.1] Check for cached library file availability before reusing it. r=glandium
mozglue/linker/Mappable.cpp
--- a/mozglue/linker/Mappable.cpp
+++ b/mozglue/linker/Mappable.cpp
@@ -4,16 +4,17 @@
 
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <cstring>
 #include <cstdlib>
 #include <cstdio>
+#include <string>
 
 #include "Mappable.h"
 
 #include "mozilla/UniquePtr.h"
 
 #ifdef ANDROID
 #include <linux/ashmem.h>
 #endif
@@ -26,16 +27,17 @@
 
 using mozilla::MakeUnique;
 using mozilla::UniquePtr;
 
 class CacheValidator
 {
 public:
   CacheValidator(const char* aCachedLibPath, Zip* aZip, Zip::Stream* aStream)
+    : mCachedLibPath(aCachedLibPath)
   {
     static const char kChecksumSuffix[] = ".crc";
 
     mCachedChecksumPath =
       MakeUnique<char[]>(strlen(aCachedLibPath) + sizeof(kChecksumSuffix));
     sprintf(mCachedChecksumPath.get(), "%s%s", aCachedLibPath, kChecksumSuffix);
     DEBUG_LOG("mCachedChecksumPath: %s", mCachedChecksumPath.get());
 
@@ -55,17 +57,20 @@ public:
 
     DEBUG_LOG("Comparing %x with %s", mChecksum, mCachedChecksumPath.get());
     MappedPtr checksumBuf = checksumMap->mmap(nullptr, checksumMap->GetLength(),
                                               PROT_READ, MAP_PRIVATE, 0);
     if (checksumBuf == MAP_FAILED) {
       WARN("Couldn't map %s to validate checksum", mCachedChecksumPath.get());
       return false;
     }
-    return !memcmp(checksumBuf, &mChecksum, sizeof(mChecksum));
+    if (memcmp(checksumBuf, &mChecksum, sizeof(mChecksum))) {
+      return false;
+    }
+    return !access(mCachedLibPath.c_str(), R_OK);
   }
 
   // Caches the APK-provided checksum used in future cache validations.
   void CacheChecksum() const
   {
     AutoCloseFD fd(open(mCachedChecksumPath.get(),
                         O_TRUNC | O_RDWR | O_CREAT | O_NOATIME,
                         S_IRUSR | S_IWUSR));
@@ -88,16 +93,17 @@ public:
         WARN("Writing checksum %s failed with errno %d",
              mCachedChecksumPath.get(), errno);
         break;
       }
     }
   }
 
 private:
+  const std::string mCachedLibPath;
   UniquePtr<char[]> mCachedChecksumPath;
   uint32_t mChecksum;
 };
 
 Mappable *
 MappableFile::Create(const char *path)
 {
   int fd = open(path, O_RDONLY);