Bug 1283629 - [1.1] Check for cached library file availability before reusing it. r=glandium, a=gchang
authorEugen Sawin <esawin@mozilla.com>
Thu, 10 Nov 2016 19:38:27 +0100
changeset 352521 9787dd02d82a55fe62511899a748226a6e879851
parent 352520 ea5bb8b2aaa0dad0b47e6f7beb898e46b8b8cb6c
child 352522 bffc76d5c3e057680ef890c1b540f295ad7e7b04
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, gchang
bugs1283629
milestone52.0a2
Bug 1283629 - [1.1] Check for cached library file availability before reusing it. r=glandium, a=gchang
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);